Skip to content

Commit f8c898d

Browse files
committed
feat: add OpenTelemetry HTTP client instrumentation
Add otelhttp transport to HTTP client for automatic distributed tracing of all outbound HTTP requests. This enables better observability and tracing of GitHub API calls.
1 parent 2d5544a commit f8c898d

File tree

3 files changed

+9
-1
lines changed

3 files changed

+9
-1
lines changed

go.mod

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ toolchain go1.25.3
77
require (
88
github.com/d0ugal/promexporter v1.7.1
99
github.com/prometheus/client_golang v1.23.2
10+
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.63.0
1011
go.opentelemetry.io/otel v1.38.0
1112
gopkg.in/yaml.v3 v3.0.1
1213
)
@@ -19,6 +20,7 @@ require (
1920
github.com/cenkalti/backoff/v5 v5.0.3 // indirect
2021
github.com/cespare/xxhash/v2 v2.3.0 // indirect
2122
github.com/cloudwego/base64x v0.1.6 // indirect
23+
github.com/felixge/httpsnoop v1.0.4 // indirect
2224
github.com/gabriel-vasile/mimetype v1.4.11 // indirect
2325
github.com/gin-contrib/sse v1.1.0 // indirect
2426
github.com/gin-gonic/gin v1.11.0 // indirect

go.sum

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ github.com/d0ugal/promexporter v1.7.1/go.mod h1:p0n8/4FE6X0P05tWWicjxHh0lXq9h4qs
1717
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
1818
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
1919
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
20+
github.com/felixge/httpsnoop v1.0.4 h1:NFTV2Zj1bL4mc9sqWACXbQFVBBg2W3GPvqp8/ESS2Wg=
21+
github.com/felixge/httpsnoop v1.0.4/go.mod h1:m8KPJKqk1gH5J9DgRY2ASl2lWCfGKXixSwevea8zH2U=
2022
github.com/gabriel-vasile/mimetype v1.4.11 h1:AQvxbp830wPhHTqc1u7nzoLT+ZFxGY7emj5DR5DYFik=
2123
github.com/gabriel-vasile/mimetype v1.4.11/go.mod h1:d+9Oxyo1wTzWdyVUPMmXFvp4F9tea18J8ufA774AB3s=
2224
github.com/gin-contrib/sse v1.1.0 h1:n0w2GMuUpWDVp7qSpvze6fAu9iRxJY4Hmj6AmBOU05w=
@@ -107,6 +109,8 @@ github.com/ugorji/go/codec v1.3.1 h1:waO7eEiFDwidsBN6agj1vJQ4AG7lh2yqXyOXqhgQuyY
107109
github.com/ugorji/go/codec v1.3.1/go.mod h1:pRBVtBSKl77K30Bv8R2P+cLSGaTtex6fsA2Wjqmfxj4=
108110
go.opentelemetry.io/auto/sdk v1.2.1 h1:jXsnJ4Lmnqd11kwkBV2LgLoFMZKizbCi5fNZ/ipaZ64=
109111
go.opentelemetry.io/auto/sdk v1.2.1/go.mod h1:KRTj+aOaElaLi+wW1kO/DZRXwkF4C5xPbEe3ZiIhN7Y=
112+
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.63.0 h1:RbKq8BG0FI8OiXhBfcRtqqHcZcka+gU3cskNuf05R18=
113+
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.63.0/go.mod h1:h06DGIukJOevXaj/xrNjhi/2098RZzcLTbc0jDAUbsg=
110114
go.opentelemetry.io/otel v1.38.0 h1:RkfdswUDRimDg0m2Az18RKOsnI8UDzppJAtj01/Ymk8=
111115
go.opentelemetry.io/otel v1.38.0/go.mod h1:zcmtmQ1+YmQM9wrNsTGV/q/uyusom3P8RxwExxkZhjM=
112116
go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.38.0 h1:GqRJVj7UmLjCVyVJ3ZFLdPRmhDUp2zFmQe3RHIOsw24=

internal/collectors/ghcr_collector.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import (
1717
"github.com/d0ugal/promexporter/app"
1818
"github.com/d0ugal/promexporter/tracing"
1919
"github.com/prometheus/client_golang/prometheus"
20+
"go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp"
2021
"go.opentelemetry.io/otel/attribute"
2122
)
2223

@@ -79,7 +80,8 @@ func NewGHCRCollector(cfg *config.Config, registry *metrics.GHCRRegistry, app *a
7980
metrics: registry,
8081
app: app,
8182
client: &http.Client{
82-
Timeout: 30 * time.Second,
83+
Timeout: 30 * time.Second,
84+
Transport: otelhttp.NewTransport(http.DefaultTransport),
8385
},
8486
token: cfg.GitHub.Token.Value(),
8587
}

0 commit comments

Comments
 (0)