Skip to content

Commit 215a065

Browse files
committed
Send User-Agent header with commit hash
1 parent 5d6b524 commit 215a065

File tree

3 files changed

+11
-1
lines changed

3 files changed

+11
-1
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,3 +20,6 @@
2020
# Go workspace file
2121
go.work
2222
go.work.sum
23+
24+
# Binary
25+
indexer

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ bin/gofumpt: bin
1919
GOBIN=$(PWD)/bin go install mvdan.cc/[email protected]
2020

2121
build: cmd/main.go
22-
CGO_ENABLED=0 go build -o indexer cmd/main.go
22+
CGO_ENABLED=0 go build -ldflags="-X github.com/duneanalytics/blockchain-ingester/client/duneapi.commitHash=$(shell git rev-parse HEAD)" -o indexer cmd/main.go
2323

2424
lint: bin/golangci-lint bin/gofumpt
2525
go fmt ./...

client/duneapi/client.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,12 @@ func (c *client) buildRequest(payloads []models.RPCBlock, buffer *bytes.Buffer)
138138
return request, nil
139139
}
140140

141+
// We inject the commit hash here at build time, using the -X linker flag, so we can use it in the User-Agent header
142+
var (
143+
commitHash string
144+
userAgent = fmt.Sprintf("node-indexer/%s", commitHash)
145+
)
146+
141147
func (c *client) sendRequest(ctx context.Context, request BlockchainIngestRequest) error {
142148
start := time.Now()
143149
var err error
@@ -172,6 +178,7 @@ func (c *client) sendRequest(ctx context.Context, request BlockchainIngestReques
172178
req.Header.Set("Content-Encoding", request.ContentEncoding)
173179
}
174180
req.Header.Set("Content-Type", "application/x-ndjson")
181+
req.Header.Set("User-Agent", userAgent)
175182
req.Header.Set("x-idempotency-key", request.IdempotencyKey)
176183
req.Header.Set("x-dune-evm-stack", request.EVMStack)
177184
req.Header.Set("x-dune-api-key", c.cfg.APIKey)

0 commit comments

Comments
 (0)