diff --git a/examples/go/go.mod b/examples/go/go.mod index 9aa312c7..8e7e4a5b 100644 --- a/examples/go/go.mod +++ b/examples/go/go.mod @@ -3,8 +3,8 @@ module dice go 1.24.0 require ( - go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.64.0 - go.opentelemetry.io/contrib/instrumentation/runtime v0.64.0 + go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.65.0 + go.opentelemetry.io/contrib/instrumentation/runtime v0.65.0 go.opentelemetry.io/otel v1.40.0 go.opentelemetry.io/otel/exporters/otlp/otlplog/otlploghttp v0.16.0 go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetrichttp v1.40.0 @@ -28,7 +28,7 @@ require ( github.com/go-logr/stdr v1.2.2 // indirect github.com/google/uuid v1.6.0 // indirect github.com/grpc-ecosystem/grpc-gateway/v2 v2.27.7 // indirect - go.opentelemetry.io/contrib/bridges/otelslog v0.14.0 + go.opentelemetry.io/contrib/bridges/otelslog v0.15.0 go.opentelemetry.io/otel/metric v1.40.0 go.opentelemetry.io/otel/trace v1.40.0 // indirect go.opentelemetry.io/proto/otlp v1.9.0 // indirect diff --git a/examples/go/go.sum b/examples/go/go.sum index 8aecc595..b3cb66e1 100644 --- a/examples/go/go.sum +++ b/examples/go/go.sum @@ -25,12 +25,12 @@ github.com/stretchr/testify v1.11.1 h1:7s2iGBzp5EwR7/aIZr8ao5+dra3wiQyKjjFuvgVKu github.com/stretchr/testify v1.11.1/go.mod h1:wZwfW3scLgRK+23gO65QZefKpKQRnfz6sD981Nm4B6U= go.opentelemetry.io/auto/sdk v1.2.1 h1:jXsnJ4Lmnqd11kwkBV2LgLoFMZKizbCi5fNZ/ipaZ64= go.opentelemetry.io/auto/sdk v1.2.1/go.mod h1:KRTj+aOaElaLi+wW1kO/DZRXwkF4C5xPbEe3ZiIhN7Y= -go.opentelemetry.io/contrib/bridges/otelslog v0.14.0 h1:eypSOd+0txRKCXPNyqLPsbSfA0jULgJcGmSAdFAnrCM= -go.opentelemetry.io/contrib/bridges/otelslog v0.14.0/go.mod h1:CRGvIBL/aAxpQU34ZxyQVFlovVcp67s4cAmQu8Jh9mc= -go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.64.0 h1:ssfIgGNANqpVFCndZvcuyKbl0g+UAVcbBcqGkG28H0Y= -go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.64.0/go.mod h1:GQ/474YrbE4Jx8gZ4q5I4hrhUzM6UPzyrqJYV2AqPoQ= -go.opentelemetry.io/contrib/instrumentation/runtime v0.64.0 h1:/+/+UjlXjFcdDlXxKL1PouzX8Z2Vl0OxolRKeBEgYDw= -go.opentelemetry.io/contrib/instrumentation/runtime v0.64.0/go.mod h1:Ldm/PDuzY2DP7IypudopCR3OCOW42NJlN9+mNEroevo= +go.opentelemetry.io/contrib/bridges/otelslog v0.15.0 h1:yOYhGNPZseueTTvWp5iBD3/CthrmvayUXYEX862dDi4= +go.opentelemetry.io/contrib/bridges/otelslog v0.15.0/go.mod h1:CvaNVqIfcybc+7xqZNubbE+26K6P7AKZF/l0lE2kdCk= +go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.65.0 h1:7iP2uCb7sGddAr30RRS6xjKy7AZ2JtTOPA3oolgVSw8= +go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.65.0/go.mod h1:c7hN3ddxs/z6q9xwvfLPk+UHlWRQyaeR1LdgfL/66l0= +go.opentelemetry.io/contrib/instrumentation/runtime v0.65.0 h1:n8qdwrebNEHF/zHpueuZ4OacdJ8CdSaP7xef9WRZXTQ= +go.opentelemetry.io/contrib/instrumentation/runtime v0.65.0/go.mod h1:Z1pjGxUL3nJ/IbDDfL6rBD0Xbz7ZOViRqrIUg4l1CYE= go.opentelemetry.io/otel v1.40.0 h1:oA5YeOcpRTXq6NN7frwmwFR0Cn3RhTVZvXsP4duvCms= go.opentelemetry.io/otel v1.40.0/go.mod h1:IMb+uXZUKkMXdPddhwAHm6UfOwJyh4ct1ybIlV14J0g= go.opentelemetry.io/otel/exporters/otlp/otlplog/otlploghttp v0.16.0 h1:djrxvDxAe44mJUrKataUbOhCKhR3F8QCyWucO16hTQs= diff --git a/examples/go/main.go b/examples/go/main.go index 09e36bf3..9d65c4be 100644 --- a/examples/go/main.go +++ b/examples/go/main.go @@ -66,23 +66,10 @@ func run() (err error) { func newHTTPHandler() http.Handler { mux := http.NewServeMux() - // handleFunc is a replacement for mux.HandleFunc - // which enriches the handler's HTTP instrumentation with the pattern as the http.route. - // - // NOTE: otelhttp.WithRouteTag is marked deprecated, claiming that http.route is - // automatically extracted from http.Request.Pattern (Go 1.22+). However, as of - // otelhttp v0.64.0 this does not work when otelhttp wraps a ServeMux: the - // http.route attribute is read at span creation time, before the ServeMux has - // routed the request and populated r.Pattern. WithRouteTag is still needed. - handleFunc := func(pattern string, handlerFunc func(http.ResponseWriter, *http.Request)) { - handler := otelhttp.WithRouteTag(pattern, http.HandlerFunc(handlerFunc)) //nolint:staticcheck - mux.Handle(pattern, handler) - } - // Register handlers. - handleFunc("/rolldice", rolldice) + // Wrap each handler with otelhttp.NewHandler so that the http.route + // attribute is set correctly from r.Pattern (populated by ServeMux). + mux.Handle("/rolldice", otelhttp.NewHandler(http.HandlerFunc(rolldice), "/rolldice")) - // Add HTTP instrumentation for the whole server. - handler := otelhttp.NewHandler(mux, "/") - return handler + return mux } diff --git a/examples/go/oats.yaml b/examples/go/oats.yaml index e9c15b9f..16bf8391 100644 --- a/examples/go/oats.yaml +++ b/examples/go/oats.yaml @@ -10,7 +10,7 @@ input: expected: traces: - traceql: '{ span.http.route = "/rolldice" }' - equals: "/" # should be "GET /rolldice" + equals: "/rolldice" attributes: otel.library.name: go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp metrics: