Skip to content

Commit 941be78

Browse files
committed
feat(examples): wrap handler with OTel propagation
1 parent 18556a1 commit 941be78

3 files changed

Lines changed: 14 additions & 2 deletions

File tree

examples/gateway/common/handler.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ import (
66
"github.com/ipfs/boxo/gateway"
77
"github.com/prometheus/client_golang/prometheus"
88
"github.com/prometheus/client_golang/prometheus/promhttp"
9+
"go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp"
10+
"go.opentelemetry.io/otel/propagation"
911
)
1012

1113
func NewHandler(gwAPI gateway.IPFSBackend) http.Handler {
@@ -60,7 +62,8 @@ func NewHandler(gwAPI gateway.IPFSBackend) http.Handler {
6062

6163
// Finally, wrap with the withConnect middleware. This is required since we use
6264
// http.ServeMux which does not support CONNECT by default.
63-
handler = withConnect(handler)
65+
propagators := propagation.NewCompositeTextMapPropagator(propagation.TraceContext{}, propagation.Baggage{})
66+
handler = otelhttp.NewHandler(handler, "Gateway.Request", otelhttp.WithPropagators(propagators))
6467

6568
return handler
6669
}

examples/go.mod

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ require (
1515
github.com/multiformats/go-multicodec v0.8.1
1616
github.com/prometheus/client_golang v1.14.0
1717
github.com/stretchr/testify v1.8.2
18+
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.40.0
19+
go.opentelemetry.io/otel v1.14.0
1820
)
1921

2022
require (
@@ -33,6 +35,7 @@ require (
3335
github.com/docker/go-units v0.5.0 // indirect
3436
github.com/dustin/go-humanize v1.0.0 // indirect
3537
github.com/elastic/gosigar v0.14.2 // indirect
38+
github.com/felixge/httpsnoop v1.0.3 // indirect
3639
github.com/flynn/noise v1.0.0 // indirect
3740
github.com/francoispqt/gojay v1.2.13 // indirect
3841
github.com/gabriel-vasile/mimetype v1.4.1 // indirect
@@ -125,7 +128,7 @@ require (
125128
github.com/whyrusleeping/chunker v0.0.0-20181014151217-fe64bd25879f // indirect
126129
github.com/whyrusleeping/go-keyspace v0.0.0-20160322163242-5b898ac5add1 // indirect
127130
go.opencensus.io v0.24.0 // indirect
128-
go.opentelemetry.io/otel v1.14.0 // indirect
131+
go.opentelemetry.io/otel/metric v0.37.0 // indirect
129132
go.opentelemetry.io/otel/trace v1.14.0 // indirect
130133
go.uber.org/atomic v1.10.0 // indirect
131134
go.uber.org/dig v1.15.0 // indirect

examples/go.sum

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,8 @@ github.com/envoyproxy/go-control-plane v0.9.0/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymF
105105
github.com/envoyproxy/go-control-plane v0.9.1-0.20191026205805-5f8ba28d4473/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4=
106106
github.com/envoyproxy/go-control-plane v0.9.4/go.mod h1:6rpuAdCZL397s3pYoYcLgu1mIlRU8Am5FuJP05cCM98=
107107
github.com/envoyproxy/protoc-gen-validate v0.1.0/go.mod h1:iSmxcyjqTsJpI2R4NaDN7+kN2VEUnK/pcBlmesArF7c=
108+
github.com/felixge/httpsnoop v1.0.3 h1:s/nj+GCswXYzN5v2DpNMuMQYe+0DDwt5WVCU6CWBdXk=
109+
github.com/felixge/httpsnoop v1.0.3/go.mod h1:m8KPJKqk1gH5J9DgRY2ASl2lWCfGKXixSwevea8zH2U=
108110
github.com/flynn/go-shlex v0.0.0-20150515145356-3f9db97f8568/go.mod h1:xEzjJPgXI435gkrCt3MPfRiAkVrwSbHsst4LCFVfpJc=
109111
github.com/flynn/noise v1.0.0 h1:DlTHqmzmvcEiKj+4RYo/imoswx/4r6iBlCMfVtrMXpQ=
110112
github.com/flynn/noise v1.0.0/go.mod h1:xbMo+0i6+IGbYdJhF31t2eR1BIU0CYc12+BNAKwUTag=
@@ -644,8 +646,12 @@ go.opencensus.io v0.22.3/go.mod h1:yxeiOL68Rb0Xd1ddK5vPZ/oVn4vY4Ynel7k9FzqtOIw=
644646
go.opencensus.io v0.22.4/go.mod h1:yxeiOL68Rb0Xd1ddK5vPZ/oVn4vY4Ynel7k9FzqtOIw=
645647
go.opencensus.io v0.24.0 h1:y73uSU6J157QMP2kn2r30vwW1A2W2WFwSCGnAVxeaD0=
646648
go.opencensus.io v0.24.0/go.mod h1:vNK8G9p7aAivkbmorf4v+7Hgx+Zs0yY+0fOtgBfjQKo=
649+
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.40.0 h1:lE9EJyw3/JhrjWH/hEy9FptnalDQgj7vpbgC2KCCCxE=
650+
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.40.0/go.mod h1:pcQ3MM3SWvrA71U4GDqv9UFDJ3HQsW7y5ZO3tDTlUdI=
647651
go.opentelemetry.io/otel v1.14.0 h1:/79Huy8wbf5DnIPhemGB+zEPVwnN6fuQybr/SRXa6hM=
648652
go.opentelemetry.io/otel v1.14.0/go.mod h1:o4buv+dJzx8rohcUeRmWUZhqupFvzWis188WlggnNeU=
653+
go.opentelemetry.io/otel/metric v0.37.0 h1:pHDQuLQOZwYD+Km0eb657A25NaRzy0a+eLyKfDXedEs=
654+
go.opentelemetry.io/otel/metric v0.37.0/go.mod h1:DmdaHfGt54iV6UKxsV9slj2bBRJcKC1B1uvDLIioc1s=
649655
go.opentelemetry.io/otel/trace v1.14.0 h1:wp2Mmvj41tDsyAJXiWDWpfNsOiIyd38fy85pyKcFq/M=
650656
go.opentelemetry.io/otel/trace v1.14.0/go.mod h1:8avnQLK+CG77yNLUae4ea2JDQ6iT+gozhnZjy/rw9G8=
651657
go.uber.org/atomic v1.6.0/go.mod h1:sABNBOSYdrvTF6hTgEIbc7YasKWGhgEQZyfxyTvoXHQ=

0 commit comments

Comments
 (0)