From dd739cfd450d86be2461bd64bcf9defd6b5fa3b0 Mon Sep 17 00:00:00 2001 From: Gaiaz Iusipov Date: Fri, 6 Feb 2026 00:27:39 +0800 Subject: [PATCH 1/9] internal/shared/semconv: Reduce allocations --- .../otelrestful/internal/semconv/client.go | 20 +++++++++---------- .../otelrestful/internal/semconv/server.go | 10 +++++----- .../gin/otelgin/internal/semconv/client.go | 20 +++++++++---------- .../gin/otelgin/internal/semconv/server.go | 10 +++++----- .../mux/otelmux/internal/semconv/client.go | 20 +++++++++---------- .../mux/otelmux/internal/semconv/server.go | 10 +++++----- .../echo/otelecho/internal/semconv/client.go | 20 +++++++++---------- .../echo/otelecho/internal/semconv/server.go | 10 +++++----- .../otelhttptrace/internal/semconv/client.go | 20 +++++++++---------- .../otelhttptrace/internal/semconv/server.go | 10 +++++----- .../http/otelhttp/internal/semconv/client.go | 20 +++++++++---------- .../http/otelhttp/internal/semconv/server.go | 10 +++++----- internal/shared/semconv/client.go.tmpl | 20 +++++++++---------- internal/shared/semconv/server.go.tmpl | 10 +++++----- 14 files changed, 105 insertions(+), 105 deletions(-) diff --git a/instrumentation/github.com/emicklei/go-restful/otelrestful/internal/semconv/client.go b/instrumentation/github.com/emicklei/go-restful/otelrestful/internal/semconv/client.go index afd99287b78..a973740153a 100644 --- a/instrumentation/github.com/emicklei/go-restful/otelrestful/internal/semconv/client.go +++ b/instrumentation/github.com/emicklei/go-restful/otelrestful/internal/semconv/client.go @@ -23,7 +23,7 @@ import ( "go.opentelemetry.io/otel/semconv/v1.39.0/httpconv" ) -type HTTPClient struct{ +type HTTPClient struct { requestBodySize httpconv.ClientRequestBodySize requestDuration httpconv.ClientRequestDuration } @@ -248,21 +248,21 @@ func (o MetricOpts) AddOptions() metric.AddOption { } func (n HTTPClient) MetricOptions(ma MetricAttributes) map[string]MetricOpts { - opts := map[string]MetricOpts{} - attributes := n.MetricAttributes(ma.Req, ma.StatusCode, ma.AdditionalAttributes) set := metric.WithAttributeSet(attribute.NewSet(attributes...)) - opts["new"] = MetricOpts{ - measurement: set, - addOptions: set, - } - return opts + return map[string]MetricOpts{ + "new": { + measurement: set, + addOptions: set, + }, + } } func (n HTTPClient) RecordMetrics(ctx context.Context, md MetricData, opts map[string]MetricOpts) { - n.requestBodySize.Inst().Record(ctx, md.RequestSize, opts["new"].MeasurementOption()) - n.requestDuration.Inst().Record(ctx, md.ElapsedTime/1000, opts["new"].MeasurementOption()) + o := []metric.RecordOption{opts["new"].MeasurementOption()} + n.requestBodySize.Inst().Record(ctx, md.RequestSize, o...) + n.requestDuration.Inst().Record(ctx, md.ElapsedTime, o...) } // TraceAttributes returns attributes for httptrace. diff --git a/instrumentation/github.com/emicklei/go-restful/otelrestful/internal/semconv/server.go b/instrumentation/github.com/emicklei/go-restful/otelrestful/internal/semconv/server.go index fb3375aa1e4..9b096057d9a 100644 --- a/instrumentation/github.com/emicklei/go-restful/otelrestful/internal/semconv/server.go +++ b/instrumentation/github.com/emicklei/go-restful/otelrestful/internal/semconv/server.go @@ -36,7 +36,7 @@ type ResponseTelemetry struct { WriteError error } -type HTTPServer struct{ +type HTTPServer struct { requestBodySizeHistogram httpconv.ServerRequestBodySize responseBodySizeHistogram httpconv.ServerResponseBodySize requestDurationHistogram httpconv.ServerRequestDuration @@ -373,8 +373,8 @@ func (n HTTPServer) MetricAttributes(server string, req *http.Request, statusCod } if route != "" { - num++ - } + num++ + } attributes := slices.Grow(additionalAttributes, num) attributes = append(attributes, @@ -397,7 +397,7 @@ func (n HTTPServer) MetricAttributes(server string, req *http.Request, statusCod } if route != "" { - attributes = append(attributes, semconv.HTTPRoute(route)) - } + attributes = append(attributes, semconv.HTTPRoute(route)) + } return attributes } diff --git a/instrumentation/github.com/gin-gonic/gin/otelgin/internal/semconv/client.go b/instrumentation/github.com/gin-gonic/gin/otelgin/internal/semconv/client.go index f8b58046e41..beca4dfa654 100644 --- a/instrumentation/github.com/gin-gonic/gin/otelgin/internal/semconv/client.go +++ b/instrumentation/github.com/gin-gonic/gin/otelgin/internal/semconv/client.go @@ -23,7 +23,7 @@ import ( "go.opentelemetry.io/otel/semconv/v1.39.0/httpconv" ) -type HTTPClient struct{ +type HTTPClient struct { requestBodySize httpconv.ClientRequestBodySize requestDuration httpconv.ClientRequestDuration } @@ -248,21 +248,21 @@ func (o MetricOpts) AddOptions() metric.AddOption { } func (n HTTPClient) MetricOptions(ma MetricAttributes) map[string]MetricOpts { - opts := map[string]MetricOpts{} - attributes := n.MetricAttributes(ma.Req, ma.StatusCode, ma.AdditionalAttributes) set := metric.WithAttributeSet(attribute.NewSet(attributes...)) - opts["new"] = MetricOpts{ - measurement: set, - addOptions: set, - } - return opts + return map[string]MetricOpts{ + "new": { + measurement: set, + addOptions: set, + }, + } } func (n HTTPClient) RecordMetrics(ctx context.Context, md MetricData, opts map[string]MetricOpts) { - n.requestBodySize.Inst().Record(ctx, md.RequestSize, opts["new"].MeasurementOption()) - n.requestDuration.Inst().Record(ctx, md.ElapsedTime/1000, opts["new"].MeasurementOption()) + o := []metric.RecordOption{opts["new"].MeasurementOption()} + n.requestBodySize.Inst().Record(ctx, md.RequestSize, o...) + n.requestDuration.Inst().Record(ctx, md.ElapsedTime, o...) } // TraceAttributes returns attributes for httptrace. diff --git a/instrumentation/github.com/gin-gonic/gin/otelgin/internal/semconv/server.go b/instrumentation/github.com/gin-gonic/gin/otelgin/internal/semconv/server.go index 123748cfda0..965e4ca0354 100644 --- a/instrumentation/github.com/gin-gonic/gin/otelgin/internal/semconv/server.go +++ b/instrumentation/github.com/gin-gonic/gin/otelgin/internal/semconv/server.go @@ -36,7 +36,7 @@ type ResponseTelemetry struct { WriteError error } -type HTTPServer struct{ +type HTTPServer struct { requestBodySizeHistogram httpconv.ServerRequestBodySize responseBodySizeHistogram httpconv.ServerResponseBodySize requestDurationHistogram httpconv.ServerRequestDuration @@ -373,8 +373,8 @@ func (n HTTPServer) MetricAttributes(server string, req *http.Request, statusCod } if route != "" { - num++ - } + num++ + } attributes := slices.Grow(additionalAttributes, num) attributes = append(attributes, @@ -397,7 +397,7 @@ func (n HTTPServer) MetricAttributes(server string, req *http.Request, statusCod } if route != "" { - attributes = append(attributes, semconv.HTTPRoute(route)) - } + attributes = append(attributes, semconv.HTTPRoute(route)) + } return attributes } diff --git a/instrumentation/github.com/gorilla/mux/otelmux/internal/semconv/client.go b/instrumentation/github.com/gorilla/mux/otelmux/internal/semconv/client.go index ecb05ab98f4..7c75d6f7e5a 100644 --- a/instrumentation/github.com/gorilla/mux/otelmux/internal/semconv/client.go +++ b/instrumentation/github.com/gorilla/mux/otelmux/internal/semconv/client.go @@ -23,7 +23,7 @@ import ( "go.opentelemetry.io/otel/semconv/v1.39.0/httpconv" ) -type HTTPClient struct{ +type HTTPClient struct { requestBodySize httpconv.ClientRequestBodySize requestDuration httpconv.ClientRequestDuration } @@ -248,21 +248,21 @@ func (o MetricOpts) AddOptions() metric.AddOption { } func (n HTTPClient) MetricOptions(ma MetricAttributes) map[string]MetricOpts { - opts := map[string]MetricOpts{} - attributes := n.MetricAttributes(ma.Req, ma.StatusCode, ma.AdditionalAttributes) set := metric.WithAttributeSet(attribute.NewSet(attributes...)) - opts["new"] = MetricOpts{ - measurement: set, - addOptions: set, - } - return opts + return map[string]MetricOpts{ + "new": { + measurement: set, + addOptions: set, + }, + } } func (n HTTPClient) RecordMetrics(ctx context.Context, md MetricData, opts map[string]MetricOpts) { - n.requestBodySize.Inst().Record(ctx, md.RequestSize, opts["new"].MeasurementOption()) - n.requestDuration.Inst().Record(ctx, md.ElapsedTime/1000, opts["new"].MeasurementOption()) + o := []metric.RecordOption{opts["new"].MeasurementOption()} + n.requestBodySize.Inst().Record(ctx, md.RequestSize, o...) + n.requestDuration.Inst().Record(ctx, md.ElapsedTime, o...) } // TraceAttributes returns attributes for httptrace. diff --git a/instrumentation/github.com/gorilla/mux/otelmux/internal/semconv/server.go b/instrumentation/github.com/gorilla/mux/otelmux/internal/semconv/server.go index f40acff93d8..51df626a33b 100644 --- a/instrumentation/github.com/gorilla/mux/otelmux/internal/semconv/server.go +++ b/instrumentation/github.com/gorilla/mux/otelmux/internal/semconv/server.go @@ -36,7 +36,7 @@ type ResponseTelemetry struct { WriteError error } -type HTTPServer struct{ +type HTTPServer struct { requestBodySizeHistogram httpconv.ServerRequestBodySize responseBodySizeHistogram httpconv.ServerResponseBodySize requestDurationHistogram httpconv.ServerRequestDuration @@ -373,8 +373,8 @@ func (n HTTPServer) MetricAttributes(server string, req *http.Request, statusCod } if route != "" { - num++ - } + num++ + } attributes := slices.Grow(additionalAttributes, num) attributes = append(attributes, @@ -397,7 +397,7 @@ func (n HTTPServer) MetricAttributes(server string, req *http.Request, statusCod } if route != "" { - attributes = append(attributes, semconv.HTTPRoute(route)) - } + attributes = append(attributes, semconv.HTTPRoute(route)) + } return attributes } diff --git a/instrumentation/github.com/labstack/echo/otelecho/internal/semconv/client.go b/instrumentation/github.com/labstack/echo/otelecho/internal/semconv/client.go index 5797b436be1..161fd5ff71f 100644 --- a/instrumentation/github.com/labstack/echo/otelecho/internal/semconv/client.go +++ b/instrumentation/github.com/labstack/echo/otelecho/internal/semconv/client.go @@ -23,7 +23,7 @@ import ( "go.opentelemetry.io/otel/semconv/v1.39.0/httpconv" ) -type HTTPClient struct{ +type HTTPClient struct { requestBodySize httpconv.ClientRequestBodySize requestDuration httpconv.ClientRequestDuration } @@ -248,21 +248,21 @@ func (o MetricOpts) AddOptions() metric.AddOption { } func (n HTTPClient) MetricOptions(ma MetricAttributes) map[string]MetricOpts { - opts := map[string]MetricOpts{} - attributes := n.MetricAttributes(ma.Req, ma.StatusCode, ma.AdditionalAttributes) set := metric.WithAttributeSet(attribute.NewSet(attributes...)) - opts["new"] = MetricOpts{ - measurement: set, - addOptions: set, - } - return opts + return map[string]MetricOpts{ + "new": { + measurement: set, + addOptions: set, + }, + } } func (n HTTPClient) RecordMetrics(ctx context.Context, md MetricData, opts map[string]MetricOpts) { - n.requestBodySize.Inst().Record(ctx, md.RequestSize, opts["new"].MeasurementOption()) - n.requestDuration.Inst().Record(ctx, md.ElapsedTime/1000, opts["new"].MeasurementOption()) + o := []metric.RecordOption{opts["new"].MeasurementOption()} + n.requestBodySize.Inst().Record(ctx, md.RequestSize, o...) + n.requestDuration.Inst().Record(ctx, md.ElapsedTime, o...) } // TraceAttributes returns attributes for httptrace. diff --git a/instrumentation/github.com/labstack/echo/otelecho/internal/semconv/server.go b/instrumentation/github.com/labstack/echo/otelecho/internal/semconv/server.go index b4164cd88de..a58b6ab1cca 100644 --- a/instrumentation/github.com/labstack/echo/otelecho/internal/semconv/server.go +++ b/instrumentation/github.com/labstack/echo/otelecho/internal/semconv/server.go @@ -36,7 +36,7 @@ type ResponseTelemetry struct { WriteError error } -type HTTPServer struct{ +type HTTPServer struct { requestBodySizeHistogram httpconv.ServerRequestBodySize responseBodySizeHistogram httpconv.ServerResponseBodySize requestDurationHistogram httpconv.ServerRequestDuration @@ -373,8 +373,8 @@ func (n HTTPServer) MetricAttributes(server string, req *http.Request, statusCod } if route != "" { - num++ - } + num++ + } attributes := slices.Grow(additionalAttributes, num) attributes = append(attributes, @@ -397,7 +397,7 @@ func (n HTTPServer) MetricAttributes(server string, req *http.Request, statusCod } if route != "" { - attributes = append(attributes, semconv.HTTPRoute(route)) - } + attributes = append(attributes, semconv.HTTPRoute(route)) + } return attributes } diff --git a/instrumentation/net/http/httptrace/otelhttptrace/internal/semconv/client.go b/instrumentation/net/http/httptrace/otelhttptrace/internal/semconv/client.go index bb0baea9e5b..7e1c0a6352d 100644 --- a/instrumentation/net/http/httptrace/otelhttptrace/internal/semconv/client.go +++ b/instrumentation/net/http/httptrace/otelhttptrace/internal/semconv/client.go @@ -23,7 +23,7 @@ import ( "go.opentelemetry.io/otel/semconv/v1.39.0/httpconv" ) -type HTTPClient struct{ +type HTTPClient struct { requestBodySize httpconv.ClientRequestBodySize requestDuration httpconv.ClientRequestDuration } @@ -248,21 +248,21 @@ func (o MetricOpts) AddOptions() metric.AddOption { } func (n HTTPClient) MetricOptions(ma MetricAttributes) map[string]MetricOpts { - opts := map[string]MetricOpts{} - attributes := n.MetricAttributes(ma.Req, ma.StatusCode, ma.AdditionalAttributes) set := metric.WithAttributeSet(attribute.NewSet(attributes...)) - opts["new"] = MetricOpts{ - measurement: set, - addOptions: set, - } - return opts + return map[string]MetricOpts{ + "new": { + measurement: set, + addOptions: set, + }, + } } func (n HTTPClient) RecordMetrics(ctx context.Context, md MetricData, opts map[string]MetricOpts) { - n.requestBodySize.Inst().Record(ctx, md.RequestSize, opts["new"].MeasurementOption()) - n.requestDuration.Inst().Record(ctx, md.ElapsedTime/1000, opts["new"].MeasurementOption()) + o := []metric.RecordOption{opts["new"].MeasurementOption()} + n.requestBodySize.Inst().Record(ctx, md.RequestSize, o...) + n.requestDuration.Inst().Record(ctx, md.ElapsedTime, o...) } // TraceAttributes returns attributes for httptrace. diff --git a/instrumentation/net/http/httptrace/otelhttptrace/internal/semconv/server.go b/instrumentation/net/http/httptrace/otelhttptrace/internal/semconv/server.go index 82e39b66374..d3bb857a50b 100644 --- a/instrumentation/net/http/httptrace/otelhttptrace/internal/semconv/server.go +++ b/instrumentation/net/http/httptrace/otelhttptrace/internal/semconv/server.go @@ -36,7 +36,7 @@ type ResponseTelemetry struct { WriteError error } -type HTTPServer struct{ +type HTTPServer struct { requestBodySizeHistogram httpconv.ServerRequestBodySize responseBodySizeHistogram httpconv.ServerResponseBodySize requestDurationHistogram httpconv.ServerRequestDuration @@ -373,8 +373,8 @@ func (n HTTPServer) MetricAttributes(server string, req *http.Request, statusCod } if route != "" { - num++ - } + num++ + } attributes := slices.Grow(additionalAttributes, num) attributes = append(attributes, @@ -397,7 +397,7 @@ func (n HTTPServer) MetricAttributes(server string, req *http.Request, statusCod } if route != "" { - attributes = append(attributes, semconv.HTTPRoute(route)) - } + attributes = append(attributes, semconv.HTTPRoute(route)) + } return attributes } diff --git a/instrumentation/net/http/otelhttp/internal/semconv/client.go b/instrumentation/net/http/otelhttp/internal/semconv/client.go index 29d6f508c18..7c493b61d68 100644 --- a/instrumentation/net/http/otelhttp/internal/semconv/client.go +++ b/instrumentation/net/http/otelhttp/internal/semconv/client.go @@ -23,7 +23,7 @@ import ( "go.opentelemetry.io/otel/semconv/v1.39.0/httpconv" ) -type HTTPClient struct{ +type HTTPClient struct { requestBodySize httpconv.ClientRequestBodySize requestDuration httpconv.ClientRequestDuration } @@ -248,21 +248,21 @@ func (o MetricOpts) AddOptions() metric.AddOption { } func (n HTTPClient) MetricOptions(ma MetricAttributes) map[string]MetricOpts { - opts := map[string]MetricOpts{} - attributes := n.MetricAttributes(ma.Req, ma.StatusCode, ma.AdditionalAttributes) set := metric.WithAttributeSet(attribute.NewSet(attributes...)) - opts["new"] = MetricOpts{ - measurement: set, - addOptions: set, - } - return opts + return map[string]MetricOpts{ + "new": { + measurement: set, + addOptions: set, + }, + } } func (n HTTPClient) RecordMetrics(ctx context.Context, md MetricData, opts map[string]MetricOpts) { - n.requestBodySize.Inst().Record(ctx, md.RequestSize, opts["new"].MeasurementOption()) - n.requestDuration.Inst().Record(ctx, md.ElapsedTime/1000, opts["new"].MeasurementOption()) + o := []metric.RecordOption{opts["new"].MeasurementOption()} + n.requestBodySize.Inst().Record(ctx, md.RequestSize, o...) + n.requestDuration.Inst().Record(ctx, md.ElapsedTime, o...) } // TraceAttributes returns attributes for httptrace. diff --git a/instrumentation/net/http/otelhttp/internal/semconv/server.go b/instrumentation/net/http/otelhttp/internal/semconv/server.go index e0e9ebc05d4..292aeacb885 100644 --- a/instrumentation/net/http/otelhttp/internal/semconv/server.go +++ b/instrumentation/net/http/otelhttp/internal/semconv/server.go @@ -36,7 +36,7 @@ type ResponseTelemetry struct { WriteError error } -type HTTPServer struct{ +type HTTPServer struct { requestBodySizeHistogram httpconv.ServerRequestBodySize responseBodySizeHistogram httpconv.ServerResponseBodySize requestDurationHistogram httpconv.ServerRequestDuration @@ -373,8 +373,8 @@ func (n HTTPServer) MetricAttributes(server string, req *http.Request, statusCod } if route != "" { - num++ - } + num++ + } attributes := slices.Grow(additionalAttributes, num) attributes = append(attributes, @@ -397,7 +397,7 @@ func (n HTTPServer) MetricAttributes(server string, req *http.Request, statusCod } if route != "" { - attributes = append(attributes, semconv.HTTPRoute(route)) - } + attributes = append(attributes, semconv.HTTPRoute(route)) + } return attributes } diff --git a/internal/shared/semconv/client.go.tmpl b/internal/shared/semconv/client.go.tmpl index 1c12cf9f8a0..c1603ba06cb 100644 --- a/internal/shared/semconv/client.go.tmpl +++ b/internal/shared/semconv/client.go.tmpl @@ -23,7 +23,7 @@ import ( "go.opentelemetry.io/otel/semconv/v1.39.0/httpconv" ) -type HTTPClient struct{ +type HTTPClient struct { requestBodySize httpconv.ClientRequestBodySize requestDuration httpconv.ClientRequestDuration } @@ -248,21 +248,21 @@ func (o MetricOpts) AddOptions() metric.AddOption { } func (n HTTPClient) MetricOptions(ma MetricAttributes) map[string]MetricOpts { - opts := map[string]MetricOpts{} - attributes := n.MetricAttributes(ma.Req, ma.StatusCode, ma.AdditionalAttributes) set := metric.WithAttributeSet(attribute.NewSet(attributes...)) - opts["new"] = MetricOpts{ - measurement: set, - addOptions: set, - } - return opts + return map[string]MetricOpts{ + "new": { + measurement: set, + addOptions: set, + }, + } } func (n HTTPClient) RecordMetrics(ctx context.Context, md MetricData, opts map[string]MetricOpts) { - n.requestBodySize.Inst().Record(ctx, md.RequestSize, opts["new"].MeasurementOption()) - n.requestDuration.Inst().Record(ctx, md.ElapsedTime/1000, opts["new"].MeasurementOption()) + o := []metric.RecordOption{opts["new"].MeasurementOption()} + n.requestBodySize.Inst().Record(ctx, md.RequestSize, o...) + n.requestDuration.Inst().Record(ctx, md.ElapsedTime, o...) } // TraceAttributes returns attributes for httptrace. diff --git a/internal/shared/semconv/server.go.tmpl b/internal/shared/semconv/server.go.tmpl index 43af7c1a33c..f15cc7ddd0a 100644 --- a/internal/shared/semconv/server.go.tmpl +++ b/internal/shared/semconv/server.go.tmpl @@ -36,7 +36,7 @@ type ResponseTelemetry struct { WriteError error } -type HTTPServer struct{ +type HTTPServer struct { requestBodySizeHistogram httpconv.ServerRequestBodySize responseBodySizeHistogram httpconv.ServerResponseBodySize requestDurationHistogram httpconv.ServerRequestDuration @@ -373,8 +373,8 @@ func (n HTTPServer) MetricAttributes(server string, req *http.Request, statusCod } if route != "" { - num++ - } + num++ + } attributes := slices.Grow(additionalAttributes, num) attributes = append(attributes, @@ -397,7 +397,7 @@ func (n HTTPServer) MetricAttributes(server string, req *http.Request, statusCod } if route != "" { - attributes = append(attributes, semconv.HTTPRoute(route)) - } + attributes = append(attributes, semconv.HTTPRoute(route)) + } return attributes } From 32f9c254c6e6e3a0933166f8265c7e57054ba1ba Mon Sep 17 00:00:00 2001 From: Gaiaz Iusipov Date: Fri, 6 Feb 2026 00:37:59 +0800 Subject: [PATCH 2/9] Update `CHANGELOG.md` --- CHANGELOG.md | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0a5ccb5542f..c36fa4bbf76 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -17,6 +17,16 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm - Enforce that `client_certificate_file` and `client_key_file` are provided together in `go.opentelemetry.io/contrib/otelconf`. (#8450) - Fixed broken CSS and JavaScript CDN URLs in `go.opentelemetry.io/contrib/zpages` by replacing the inaccessible code.getmdl.io CDN with cdnjs.cloudflare.com. (#8502) +### Changed + +- Improve performance by reducing allocations in the modules below. (#8511) + - `go.opentelemetry.io/contrib/instrumentation/github.com/emicklei/go-restful/otelrestful` + - `go.opentelemetry.io/contrib/instrumentation/github.com/gin-gonic/gin/otelgin` + - `go.opentelemetry.io/contrib/instrumentation/github.com/gorilla/mux/otelmux` + - `go.opentelemetry.io/contrib/instrumentation/github.com/labstack/echo/otelecho` + - `go.opentelemetry.io/contrib/instrumentation/net/http/httptrace/otelhttptrace` + - `go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp` + ### Removed - Removed the deprecated zipkin exporter example in `go.opentelemetry.io/contrib/examples/zipkin`. (#8501) From 0fe425b5d9ed205a40594671330afa78f00ffe2c Mon Sep 17 00:00:00 2001 From: Gaiaz Iusipov Date: Fri, 6 Feb 2026 17:28:23 +0800 Subject: [PATCH 3/9] feat: Remove redundant map wrapper in `HTTPClient.MetricOptions` --- .../otelrestful/internal/semconv/client.go | 36 +++++++++---------- .../gin/otelgin/internal/semconv/client.go | 36 +++++++++---------- .../mux/otelmux/internal/semconv/client.go | 36 +++++++++---------- .../echo/otelecho/internal/semconv/client.go | 36 +++++++++---------- .../otelhttptrace/internal/semconv/client.go | 36 +++++++++---------- .../http/otelhttp/internal/semconv/client.go | 36 +++++++++---------- internal/shared/semconv/client.go.tmpl | 14 ++++---- 7 files changed, 108 insertions(+), 122 deletions(-) diff --git a/instrumentation/github.com/emicklei/go-restful/otelrestful/internal/semconv/client.go b/instrumentation/github.com/emicklei/go-restful/otelrestful/internal/semconv/client.go index a973740153a..89a0ccd71e8 100644 --- a/instrumentation/github.com/emicklei/go-restful/otelrestful/internal/semconv/client.go +++ b/instrumentation/github.com/emicklei/go-restful/otelrestful/internal/semconv/client.go @@ -57,14 +57,14 @@ func (n HTTPClient) Status(code int) (codes.Code, string) { // RequestTraceAttrs returns trace attributes for an HTTP request made by a client. func (n HTTPClient) RequestTraceAttrs(req *http.Request) []attribute.KeyValue { /* - below attributes are returned: - - http.request.method - - http.request.method.original - - url.full - - server.address - - server.port - - network.protocol.name - - network.protocol.version + below attributes are returned: + - http.request.method + - http.request.method.original + - url.full + - server.address + - server.port + - network.protocol.name + - network.protocol.version */ numOfAttributes := 3 // URL, server address, proto, and method. @@ -139,9 +139,9 @@ func (n HTTPClient) RequestTraceAttrs(req *http.Request) []attribute.KeyValue { // ResponseTraceAttrs returns trace attributes for an HTTP response made by a client. func (n HTTPClient) ResponseTraceAttrs(resp *http.Response) []attribute.KeyValue { /* - below attributes are returned: - - http.response.status_code - - error.type + below attributes are returned: + - http.response.status_code + - error.type */ var count int if resp.StatusCode > 0 { @@ -247,20 +247,18 @@ func (o MetricOpts) AddOptions() metric.AddOption { return o.addOptions } -func (n HTTPClient) MetricOptions(ma MetricAttributes) map[string]MetricOpts { +func (n HTTPClient) MetricOptions(ma MetricAttributes) MetricOpts { attributes := n.MetricAttributes(ma.Req, ma.StatusCode, ma.AdditionalAttributes) set := metric.WithAttributeSet(attribute.NewSet(attributes...)) - return map[string]MetricOpts{ - "new": { - measurement: set, - addOptions: set, - }, + return MetricOpts{ + measurement: set, + addOptions: set, } } -func (n HTTPClient) RecordMetrics(ctx context.Context, md MetricData, opts map[string]MetricOpts) { - o := []metric.RecordOption{opts["new"].MeasurementOption()} +func (n HTTPClient) RecordMetrics(ctx context.Context, md MetricData, opts MetricOpts) { + o := []metric.RecordOption{opts.MeasurementOption()} n.requestBodySize.Inst().Record(ctx, md.RequestSize, o...) n.requestDuration.Inst().Record(ctx, md.ElapsedTime, o...) } diff --git a/instrumentation/github.com/gin-gonic/gin/otelgin/internal/semconv/client.go b/instrumentation/github.com/gin-gonic/gin/otelgin/internal/semconv/client.go index beca4dfa654..0ba50e1308b 100644 --- a/instrumentation/github.com/gin-gonic/gin/otelgin/internal/semconv/client.go +++ b/instrumentation/github.com/gin-gonic/gin/otelgin/internal/semconv/client.go @@ -57,14 +57,14 @@ func (n HTTPClient) Status(code int) (codes.Code, string) { // RequestTraceAttrs returns trace attributes for an HTTP request made by a client. func (n HTTPClient) RequestTraceAttrs(req *http.Request) []attribute.KeyValue { /* - below attributes are returned: - - http.request.method - - http.request.method.original - - url.full - - server.address - - server.port - - network.protocol.name - - network.protocol.version + below attributes are returned: + - http.request.method + - http.request.method.original + - url.full + - server.address + - server.port + - network.protocol.name + - network.protocol.version */ numOfAttributes := 3 // URL, server address, proto, and method. @@ -139,9 +139,9 @@ func (n HTTPClient) RequestTraceAttrs(req *http.Request) []attribute.KeyValue { // ResponseTraceAttrs returns trace attributes for an HTTP response made by a client. func (n HTTPClient) ResponseTraceAttrs(resp *http.Response) []attribute.KeyValue { /* - below attributes are returned: - - http.response.status_code - - error.type + below attributes are returned: + - http.response.status_code + - error.type */ var count int if resp.StatusCode > 0 { @@ -247,20 +247,18 @@ func (o MetricOpts) AddOptions() metric.AddOption { return o.addOptions } -func (n HTTPClient) MetricOptions(ma MetricAttributes) map[string]MetricOpts { +func (n HTTPClient) MetricOptions(ma MetricAttributes) MetricOpts { attributes := n.MetricAttributes(ma.Req, ma.StatusCode, ma.AdditionalAttributes) set := metric.WithAttributeSet(attribute.NewSet(attributes...)) - return map[string]MetricOpts{ - "new": { - measurement: set, - addOptions: set, - }, + return MetricOpts{ + measurement: set, + addOptions: set, } } -func (n HTTPClient) RecordMetrics(ctx context.Context, md MetricData, opts map[string]MetricOpts) { - o := []metric.RecordOption{opts["new"].MeasurementOption()} +func (n HTTPClient) RecordMetrics(ctx context.Context, md MetricData, opts MetricOpts) { + o := []metric.RecordOption{opts.MeasurementOption()} n.requestBodySize.Inst().Record(ctx, md.RequestSize, o...) n.requestDuration.Inst().Record(ctx, md.ElapsedTime, o...) } diff --git a/instrumentation/github.com/gorilla/mux/otelmux/internal/semconv/client.go b/instrumentation/github.com/gorilla/mux/otelmux/internal/semconv/client.go index 7c75d6f7e5a..01a61b1f439 100644 --- a/instrumentation/github.com/gorilla/mux/otelmux/internal/semconv/client.go +++ b/instrumentation/github.com/gorilla/mux/otelmux/internal/semconv/client.go @@ -57,14 +57,14 @@ func (n HTTPClient) Status(code int) (codes.Code, string) { // RequestTraceAttrs returns trace attributes for an HTTP request made by a client. func (n HTTPClient) RequestTraceAttrs(req *http.Request) []attribute.KeyValue { /* - below attributes are returned: - - http.request.method - - http.request.method.original - - url.full - - server.address - - server.port - - network.protocol.name - - network.protocol.version + below attributes are returned: + - http.request.method + - http.request.method.original + - url.full + - server.address + - server.port + - network.protocol.name + - network.protocol.version */ numOfAttributes := 3 // URL, server address, proto, and method. @@ -139,9 +139,9 @@ func (n HTTPClient) RequestTraceAttrs(req *http.Request) []attribute.KeyValue { // ResponseTraceAttrs returns trace attributes for an HTTP response made by a client. func (n HTTPClient) ResponseTraceAttrs(resp *http.Response) []attribute.KeyValue { /* - below attributes are returned: - - http.response.status_code - - error.type + below attributes are returned: + - http.response.status_code + - error.type */ var count int if resp.StatusCode > 0 { @@ -247,20 +247,18 @@ func (o MetricOpts) AddOptions() metric.AddOption { return o.addOptions } -func (n HTTPClient) MetricOptions(ma MetricAttributes) map[string]MetricOpts { +func (n HTTPClient) MetricOptions(ma MetricAttributes) MetricOpts { attributes := n.MetricAttributes(ma.Req, ma.StatusCode, ma.AdditionalAttributes) set := metric.WithAttributeSet(attribute.NewSet(attributes...)) - return map[string]MetricOpts{ - "new": { - measurement: set, - addOptions: set, - }, + return MetricOpts{ + measurement: set, + addOptions: set, } } -func (n HTTPClient) RecordMetrics(ctx context.Context, md MetricData, opts map[string]MetricOpts) { - o := []metric.RecordOption{opts["new"].MeasurementOption()} +func (n HTTPClient) RecordMetrics(ctx context.Context, md MetricData, opts MetricOpts) { + o := []metric.RecordOption{opts.MeasurementOption()} n.requestBodySize.Inst().Record(ctx, md.RequestSize, o...) n.requestDuration.Inst().Record(ctx, md.ElapsedTime, o...) } diff --git a/instrumentation/github.com/labstack/echo/otelecho/internal/semconv/client.go b/instrumentation/github.com/labstack/echo/otelecho/internal/semconv/client.go index 161fd5ff71f..a560deae929 100644 --- a/instrumentation/github.com/labstack/echo/otelecho/internal/semconv/client.go +++ b/instrumentation/github.com/labstack/echo/otelecho/internal/semconv/client.go @@ -57,14 +57,14 @@ func (n HTTPClient) Status(code int) (codes.Code, string) { // RequestTraceAttrs returns trace attributes for an HTTP request made by a client. func (n HTTPClient) RequestTraceAttrs(req *http.Request) []attribute.KeyValue { /* - below attributes are returned: - - http.request.method - - http.request.method.original - - url.full - - server.address - - server.port - - network.protocol.name - - network.protocol.version + below attributes are returned: + - http.request.method + - http.request.method.original + - url.full + - server.address + - server.port + - network.protocol.name + - network.protocol.version */ numOfAttributes := 3 // URL, server address, proto, and method. @@ -139,9 +139,9 @@ func (n HTTPClient) RequestTraceAttrs(req *http.Request) []attribute.KeyValue { // ResponseTraceAttrs returns trace attributes for an HTTP response made by a client. func (n HTTPClient) ResponseTraceAttrs(resp *http.Response) []attribute.KeyValue { /* - below attributes are returned: - - http.response.status_code - - error.type + below attributes are returned: + - http.response.status_code + - error.type */ var count int if resp.StatusCode > 0 { @@ -247,20 +247,18 @@ func (o MetricOpts) AddOptions() metric.AddOption { return o.addOptions } -func (n HTTPClient) MetricOptions(ma MetricAttributes) map[string]MetricOpts { +func (n HTTPClient) MetricOptions(ma MetricAttributes) MetricOpts { attributes := n.MetricAttributes(ma.Req, ma.StatusCode, ma.AdditionalAttributes) set := metric.WithAttributeSet(attribute.NewSet(attributes...)) - return map[string]MetricOpts{ - "new": { - measurement: set, - addOptions: set, - }, + return MetricOpts{ + measurement: set, + addOptions: set, } } -func (n HTTPClient) RecordMetrics(ctx context.Context, md MetricData, opts map[string]MetricOpts) { - o := []metric.RecordOption{opts["new"].MeasurementOption()} +func (n HTTPClient) RecordMetrics(ctx context.Context, md MetricData, opts MetricOpts) { + o := []metric.RecordOption{opts.MeasurementOption()} n.requestBodySize.Inst().Record(ctx, md.RequestSize, o...) n.requestDuration.Inst().Record(ctx, md.ElapsedTime, o...) } diff --git a/instrumentation/net/http/httptrace/otelhttptrace/internal/semconv/client.go b/instrumentation/net/http/httptrace/otelhttptrace/internal/semconv/client.go index 7e1c0a6352d..90f68d0bc2f 100644 --- a/instrumentation/net/http/httptrace/otelhttptrace/internal/semconv/client.go +++ b/instrumentation/net/http/httptrace/otelhttptrace/internal/semconv/client.go @@ -57,14 +57,14 @@ func (n HTTPClient) Status(code int) (codes.Code, string) { // RequestTraceAttrs returns trace attributes for an HTTP request made by a client. func (n HTTPClient) RequestTraceAttrs(req *http.Request) []attribute.KeyValue { /* - below attributes are returned: - - http.request.method - - http.request.method.original - - url.full - - server.address - - server.port - - network.protocol.name - - network.protocol.version + below attributes are returned: + - http.request.method + - http.request.method.original + - url.full + - server.address + - server.port + - network.protocol.name + - network.protocol.version */ numOfAttributes := 3 // URL, server address, proto, and method. @@ -139,9 +139,9 @@ func (n HTTPClient) RequestTraceAttrs(req *http.Request) []attribute.KeyValue { // ResponseTraceAttrs returns trace attributes for an HTTP response made by a client. func (n HTTPClient) ResponseTraceAttrs(resp *http.Response) []attribute.KeyValue { /* - below attributes are returned: - - http.response.status_code - - error.type + below attributes are returned: + - http.response.status_code + - error.type */ var count int if resp.StatusCode > 0 { @@ -247,20 +247,18 @@ func (o MetricOpts) AddOptions() metric.AddOption { return o.addOptions } -func (n HTTPClient) MetricOptions(ma MetricAttributes) map[string]MetricOpts { +func (n HTTPClient) MetricOptions(ma MetricAttributes) MetricOpts { attributes := n.MetricAttributes(ma.Req, ma.StatusCode, ma.AdditionalAttributes) set := metric.WithAttributeSet(attribute.NewSet(attributes...)) - return map[string]MetricOpts{ - "new": { - measurement: set, - addOptions: set, - }, + return MetricOpts{ + measurement: set, + addOptions: set, } } -func (n HTTPClient) RecordMetrics(ctx context.Context, md MetricData, opts map[string]MetricOpts) { - o := []metric.RecordOption{opts["new"].MeasurementOption()} +func (n HTTPClient) RecordMetrics(ctx context.Context, md MetricData, opts MetricOpts) { + o := []metric.RecordOption{opts.MeasurementOption()} n.requestBodySize.Inst().Record(ctx, md.RequestSize, o...) n.requestDuration.Inst().Record(ctx, md.ElapsedTime, o...) } diff --git a/instrumentation/net/http/otelhttp/internal/semconv/client.go b/instrumentation/net/http/otelhttp/internal/semconv/client.go index 7c493b61d68..71e8fe2de2d 100644 --- a/instrumentation/net/http/otelhttp/internal/semconv/client.go +++ b/instrumentation/net/http/otelhttp/internal/semconv/client.go @@ -57,14 +57,14 @@ func (n HTTPClient) Status(code int) (codes.Code, string) { // RequestTraceAttrs returns trace attributes for an HTTP request made by a client. func (n HTTPClient) RequestTraceAttrs(req *http.Request) []attribute.KeyValue { /* - below attributes are returned: - - http.request.method - - http.request.method.original - - url.full - - server.address - - server.port - - network.protocol.name - - network.protocol.version + below attributes are returned: + - http.request.method + - http.request.method.original + - url.full + - server.address + - server.port + - network.protocol.name + - network.protocol.version */ numOfAttributes := 3 // URL, server address, proto, and method. @@ -139,9 +139,9 @@ func (n HTTPClient) RequestTraceAttrs(req *http.Request) []attribute.KeyValue { // ResponseTraceAttrs returns trace attributes for an HTTP response made by a client. func (n HTTPClient) ResponseTraceAttrs(resp *http.Response) []attribute.KeyValue { /* - below attributes are returned: - - http.response.status_code - - error.type + below attributes are returned: + - http.response.status_code + - error.type */ var count int if resp.StatusCode > 0 { @@ -247,20 +247,18 @@ func (o MetricOpts) AddOptions() metric.AddOption { return o.addOptions } -func (n HTTPClient) MetricOptions(ma MetricAttributes) map[string]MetricOpts { +func (n HTTPClient) MetricOptions(ma MetricAttributes) MetricOpts { attributes := n.MetricAttributes(ma.Req, ma.StatusCode, ma.AdditionalAttributes) set := metric.WithAttributeSet(attribute.NewSet(attributes...)) - return map[string]MetricOpts{ - "new": { - measurement: set, - addOptions: set, - }, + return MetricOpts{ + measurement: set, + addOptions: set, } } -func (n HTTPClient) RecordMetrics(ctx context.Context, md MetricData, opts map[string]MetricOpts) { - o := []metric.RecordOption{opts["new"].MeasurementOption()} +func (n HTTPClient) RecordMetrics(ctx context.Context, md MetricData, opts MetricOpts) { + o := []metric.RecordOption{opts.MeasurementOption()} n.requestBodySize.Inst().Record(ctx, md.RequestSize, o...) n.requestDuration.Inst().Record(ctx, md.ElapsedTime, o...) } diff --git a/internal/shared/semconv/client.go.tmpl b/internal/shared/semconv/client.go.tmpl index c1603ba06cb..f06a7b0eb98 100644 --- a/internal/shared/semconv/client.go.tmpl +++ b/internal/shared/semconv/client.go.tmpl @@ -247,20 +247,18 @@ func (o MetricOpts) AddOptions() metric.AddOption { return o.addOptions } -func (n HTTPClient) MetricOptions(ma MetricAttributes) map[string]MetricOpts { +func (n HTTPClient) MetricOptions(ma MetricAttributes) MetricOpts { attributes := n.MetricAttributes(ma.Req, ma.StatusCode, ma.AdditionalAttributes) set := metric.WithAttributeSet(attribute.NewSet(attributes...)) - return map[string]MetricOpts{ - "new": { - measurement: set, - addOptions: set, - }, + return MetricOpts{ + measurement: set, + addOptions: set, } } -func (n HTTPClient) RecordMetrics(ctx context.Context, md MetricData, opts map[string]MetricOpts) { - o := []metric.RecordOption{opts["new"].MeasurementOption()} +func (n HTTPClient) RecordMetrics(ctx context.Context, md MetricData, opts MetricOpts) { + o := []metric.RecordOption{opts.MeasurementOption()} n.requestBodySize.Inst().Record(ctx, md.RequestSize, o...) n.requestDuration.Inst().Record(ctx, md.ElapsedTime, o...) } From 7d5570064412410110b43cfb8b05ea661ffe92c3 Mon Sep 17 00:00:00 2001 From: Gaiaz Iusipov Date: Fri, 6 Feb 2026 17:30:42 +0800 Subject: [PATCH 4/9] Revert indent changes --- .../otelrestful/internal/semconv/client.go | 22 +++++++++---------- .../gin/otelgin/internal/semconv/client.go | 22 +++++++++---------- .../mux/otelmux/internal/semconv/client.go | 22 +++++++++---------- .../echo/otelecho/internal/semconv/client.go | 22 +++++++++---------- .../otelhttptrace/internal/semconv/client.go | 22 +++++++++---------- .../http/otelhttp/internal/semconv/client.go | 22 +++++++++---------- 6 files changed, 66 insertions(+), 66 deletions(-) diff --git a/instrumentation/github.com/emicklei/go-restful/otelrestful/internal/semconv/client.go b/instrumentation/github.com/emicklei/go-restful/otelrestful/internal/semconv/client.go index 89a0ccd71e8..11decf88c15 100644 --- a/instrumentation/github.com/emicklei/go-restful/otelrestful/internal/semconv/client.go +++ b/instrumentation/github.com/emicklei/go-restful/otelrestful/internal/semconv/client.go @@ -57,14 +57,14 @@ func (n HTTPClient) Status(code int) (codes.Code, string) { // RequestTraceAttrs returns trace attributes for an HTTP request made by a client. func (n HTTPClient) RequestTraceAttrs(req *http.Request) []attribute.KeyValue { /* - below attributes are returned: - - http.request.method - - http.request.method.original - - url.full - - server.address - - server.port - - network.protocol.name - - network.protocol.version + below attributes are returned: + - http.request.method + - http.request.method.original + - url.full + - server.address + - server.port + - network.protocol.name + - network.protocol.version */ numOfAttributes := 3 // URL, server address, proto, and method. @@ -139,9 +139,9 @@ func (n HTTPClient) RequestTraceAttrs(req *http.Request) []attribute.KeyValue { // ResponseTraceAttrs returns trace attributes for an HTTP response made by a client. func (n HTTPClient) ResponseTraceAttrs(resp *http.Response) []attribute.KeyValue { /* - below attributes are returned: - - http.response.status_code - - error.type + below attributes are returned: + - http.response.status_code + - error.type */ var count int if resp.StatusCode > 0 { diff --git a/instrumentation/github.com/gin-gonic/gin/otelgin/internal/semconv/client.go b/instrumentation/github.com/gin-gonic/gin/otelgin/internal/semconv/client.go index 0ba50e1308b..dd531f5eda6 100644 --- a/instrumentation/github.com/gin-gonic/gin/otelgin/internal/semconv/client.go +++ b/instrumentation/github.com/gin-gonic/gin/otelgin/internal/semconv/client.go @@ -57,14 +57,14 @@ func (n HTTPClient) Status(code int) (codes.Code, string) { // RequestTraceAttrs returns trace attributes for an HTTP request made by a client. func (n HTTPClient) RequestTraceAttrs(req *http.Request) []attribute.KeyValue { /* - below attributes are returned: - - http.request.method - - http.request.method.original - - url.full - - server.address - - server.port - - network.protocol.name - - network.protocol.version + below attributes are returned: + - http.request.method + - http.request.method.original + - url.full + - server.address + - server.port + - network.protocol.name + - network.protocol.version */ numOfAttributes := 3 // URL, server address, proto, and method. @@ -139,9 +139,9 @@ func (n HTTPClient) RequestTraceAttrs(req *http.Request) []attribute.KeyValue { // ResponseTraceAttrs returns trace attributes for an HTTP response made by a client. func (n HTTPClient) ResponseTraceAttrs(resp *http.Response) []attribute.KeyValue { /* - below attributes are returned: - - http.response.status_code - - error.type + below attributes are returned: + - http.response.status_code + - error.type */ var count int if resp.StatusCode > 0 { diff --git a/instrumentation/github.com/gorilla/mux/otelmux/internal/semconv/client.go b/instrumentation/github.com/gorilla/mux/otelmux/internal/semconv/client.go index 01a61b1f439..fffc1d4d890 100644 --- a/instrumentation/github.com/gorilla/mux/otelmux/internal/semconv/client.go +++ b/instrumentation/github.com/gorilla/mux/otelmux/internal/semconv/client.go @@ -57,14 +57,14 @@ func (n HTTPClient) Status(code int) (codes.Code, string) { // RequestTraceAttrs returns trace attributes for an HTTP request made by a client. func (n HTTPClient) RequestTraceAttrs(req *http.Request) []attribute.KeyValue { /* - below attributes are returned: - - http.request.method - - http.request.method.original - - url.full - - server.address - - server.port - - network.protocol.name - - network.protocol.version + below attributes are returned: + - http.request.method + - http.request.method.original + - url.full + - server.address + - server.port + - network.protocol.name + - network.protocol.version */ numOfAttributes := 3 // URL, server address, proto, and method. @@ -139,9 +139,9 @@ func (n HTTPClient) RequestTraceAttrs(req *http.Request) []attribute.KeyValue { // ResponseTraceAttrs returns trace attributes for an HTTP response made by a client. func (n HTTPClient) ResponseTraceAttrs(resp *http.Response) []attribute.KeyValue { /* - below attributes are returned: - - http.response.status_code - - error.type + below attributes are returned: + - http.response.status_code + - error.type */ var count int if resp.StatusCode > 0 { diff --git a/instrumentation/github.com/labstack/echo/otelecho/internal/semconv/client.go b/instrumentation/github.com/labstack/echo/otelecho/internal/semconv/client.go index a560deae929..0dc27c132ee 100644 --- a/instrumentation/github.com/labstack/echo/otelecho/internal/semconv/client.go +++ b/instrumentation/github.com/labstack/echo/otelecho/internal/semconv/client.go @@ -57,14 +57,14 @@ func (n HTTPClient) Status(code int) (codes.Code, string) { // RequestTraceAttrs returns trace attributes for an HTTP request made by a client. func (n HTTPClient) RequestTraceAttrs(req *http.Request) []attribute.KeyValue { /* - below attributes are returned: - - http.request.method - - http.request.method.original - - url.full - - server.address - - server.port - - network.protocol.name - - network.protocol.version + below attributes are returned: + - http.request.method + - http.request.method.original + - url.full + - server.address + - server.port + - network.protocol.name + - network.protocol.version */ numOfAttributes := 3 // URL, server address, proto, and method. @@ -139,9 +139,9 @@ func (n HTTPClient) RequestTraceAttrs(req *http.Request) []attribute.KeyValue { // ResponseTraceAttrs returns trace attributes for an HTTP response made by a client. func (n HTTPClient) ResponseTraceAttrs(resp *http.Response) []attribute.KeyValue { /* - below attributes are returned: - - http.response.status_code - - error.type + below attributes are returned: + - http.response.status_code + - error.type */ var count int if resp.StatusCode > 0 { diff --git a/instrumentation/net/http/httptrace/otelhttptrace/internal/semconv/client.go b/instrumentation/net/http/httptrace/otelhttptrace/internal/semconv/client.go index 90f68d0bc2f..375eedc9841 100644 --- a/instrumentation/net/http/httptrace/otelhttptrace/internal/semconv/client.go +++ b/instrumentation/net/http/httptrace/otelhttptrace/internal/semconv/client.go @@ -57,14 +57,14 @@ func (n HTTPClient) Status(code int) (codes.Code, string) { // RequestTraceAttrs returns trace attributes for an HTTP request made by a client. func (n HTTPClient) RequestTraceAttrs(req *http.Request) []attribute.KeyValue { /* - below attributes are returned: - - http.request.method - - http.request.method.original - - url.full - - server.address - - server.port - - network.protocol.name - - network.protocol.version + below attributes are returned: + - http.request.method + - http.request.method.original + - url.full + - server.address + - server.port + - network.protocol.name + - network.protocol.version */ numOfAttributes := 3 // URL, server address, proto, and method. @@ -139,9 +139,9 @@ func (n HTTPClient) RequestTraceAttrs(req *http.Request) []attribute.KeyValue { // ResponseTraceAttrs returns trace attributes for an HTTP response made by a client. func (n HTTPClient) ResponseTraceAttrs(resp *http.Response) []attribute.KeyValue { /* - below attributes are returned: - - http.response.status_code - - error.type + below attributes are returned: + - http.response.status_code + - error.type */ var count int if resp.StatusCode > 0 { diff --git a/instrumentation/net/http/otelhttp/internal/semconv/client.go b/instrumentation/net/http/otelhttp/internal/semconv/client.go index 71e8fe2de2d..124b9b6d751 100644 --- a/instrumentation/net/http/otelhttp/internal/semconv/client.go +++ b/instrumentation/net/http/otelhttp/internal/semconv/client.go @@ -57,14 +57,14 @@ func (n HTTPClient) Status(code int) (codes.Code, string) { // RequestTraceAttrs returns trace attributes for an HTTP request made by a client. func (n HTTPClient) RequestTraceAttrs(req *http.Request) []attribute.KeyValue { /* - below attributes are returned: - - http.request.method - - http.request.method.original - - url.full - - server.address - - server.port - - network.protocol.name - - network.protocol.version + below attributes are returned: + - http.request.method + - http.request.method.original + - url.full + - server.address + - server.port + - network.protocol.name + - network.protocol.version */ numOfAttributes := 3 // URL, server address, proto, and method. @@ -139,9 +139,9 @@ func (n HTTPClient) RequestTraceAttrs(req *http.Request) []attribute.KeyValue { // ResponseTraceAttrs returns trace attributes for an HTTP response made by a client. func (n HTTPClient) ResponseTraceAttrs(resp *http.Response) []attribute.KeyValue { /* - below attributes are returned: - - http.response.status_code - - error.type + below attributes are returned: + - http.response.status_code + - error.type */ var count int if resp.StatusCode > 0 { From 64959576f18630b3a96e2d58289c660dd62818ca Mon Sep 17 00:00:00 2001 From: Gaiaz Iusipov Date: Mon, 9 Feb 2026 13:44:10 +0400 Subject: [PATCH 5/9] Update CHANGELOG.md Co-authored-by: Damien Mathieu <42@dmathieu.com> --- CHANGELOG.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c36fa4bbf76..8d0206b6135 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -19,7 +19,8 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm ### Changed -- Improve performance by reducing allocations in the modules below. (#8511) +- Reduce allocations in the generated HTTP `internal/semconv` packages. (#8511) + Updated modules include: - `go.opentelemetry.io/contrib/instrumentation/github.com/emicklei/go-restful/otelrestful` - `go.opentelemetry.io/contrib/instrumentation/github.com/gin-gonic/gin/otelgin` - `go.opentelemetry.io/contrib/instrumentation/github.com/gorilla/mux/otelmux` From 52013e7828ba7a9e853265b73a352c2a5aa8c2ee Mon Sep 17 00:00:00 2001 From: Gaiaz Iusipov Date: Wed, 18 Feb 2026 00:10:28 +0800 Subject: [PATCH 6/9] Update `CHANGELOG.md` --- CHANGELOG.md | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index bc6ec600b6d..22720263663 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -25,6 +25,10 @@ The next release will require at least [Go 1.25]. - Enforce that `client_certificate_file` and `client_key_file` are provided together in `go.opentelemetry.io/contrib/otelconf`. (#8450) - Fixed broken CSS and JavaScript CDN URLs in `go.opentelemetry.io/contrib/zpages` by replacing the inaccessible code.getmdl.io CDN with cdnjs.cloudflare.com. (#8502) +### Removed + +- Removed the deprecated zipkin exporter example in `go.opentelemetry.io/contrib/examples/zipkin`. (#8501) + ### Changed - Reduce allocations in the generated HTTP `internal/semconv` packages. (#8511) @@ -35,13 +39,6 @@ The next release will require at least [Go 1.25]. - `go.opentelemetry.io/contrib/instrumentation/github.com/labstack/echo/otelecho` - `go.opentelemetry.io/contrib/instrumentation/net/http/httptrace/otelhttptrace` - `go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp` - -### Removed - -- Removed the deprecated zipkin exporter example in `go.opentelemetry.io/contrib/examples/zipkin`. (#8501) - -### Changed - - Updated the configuration schema used in `go.opentelemetry.io/contrib/otelconf` to [rc.3](https://github.com/open-telemetry/opentelemetry-configuration/releases/tag/v1.0.0-rc.3). (#8505) From 6dbcfe87e4cbda6dab9f77982d7a894b2f4ce389 Mon Sep 17 00:00:00 2001 From: Gaiaz Iusipov Date: Tue, 24 Feb 2026 21:02:17 +0800 Subject: [PATCH 7/9] fix(internal/shared/semconv): Restore the removed division --- .../otelrestful/internal/semconv/client.go | 24 +++++++++---------- .../gin/otelgin/internal/semconv/client.go | 24 +++++++++---------- .../mux/otelmux/internal/semconv/client.go | 24 +++++++++---------- .../echo/otelecho/internal/semconv/client.go | 24 +++++++++---------- .../otelhttptrace/internal/semconv/client.go | 24 +++++++++---------- .../http/otelhttp/internal/semconv/client.go | 24 +++++++++---------- internal/shared/semconv/client.go.tmpl | 2 +- 7 files changed, 73 insertions(+), 73 deletions(-) diff --git a/instrumentation/github.com/emicklei/go-restful/otelrestful/internal/semconv/client.go b/instrumentation/github.com/emicklei/go-restful/otelrestful/internal/semconv/client.go index 11decf88c15..0bef0ab01c6 100644 --- a/instrumentation/github.com/emicklei/go-restful/otelrestful/internal/semconv/client.go +++ b/instrumentation/github.com/emicklei/go-restful/otelrestful/internal/semconv/client.go @@ -57,14 +57,14 @@ func (n HTTPClient) Status(code int) (codes.Code, string) { // RequestTraceAttrs returns trace attributes for an HTTP request made by a client. func (n HTTPClient) RequestTraceAttrs(req *http.Request) []attribute.KeyValue { /* - below attributes are returned: - - http.request.method - - http.request.method.original - - url.full - - server.address - - server.port - - network.protocol.name - - network.protocol.version + below attributes are returned: + - http.request.method + - http.request.method.original + - url.full + - server.address + - server.port + - network.protocol.name + - network.protocol.version */ numOfAttributes := 3 // URL, server address, proto, and method. @@ -139,9 +139,9 @@ func (n HTTPClient) RequestTraceAttrs(req *http.Request) []attribute.KeyValue { // ResponseTraceAttrs returns trace attributes for an HTTP response made by a client. func (n HTTPClient) ResponseTraceAttrs(resp *http.Response) []attribute.KeyValue { /* - below attributes are returned: - - http.response.status_code - - error.type + below attributes are returned: + - http.response.status_code + - error.type */ var count int if resp.StatusCode > 0 { @@ -260,7 +260,7 @@ func (n HTTPClient) MetricOptions(ma MetricAttributes) MetricOpts { func (n HTTPClient) RecordMetrics(ctx context.Context, md MetricData, opts MetricOpts) { o := []metric.RecordOption{opts.MeasurementOption()} n.requestBodySize.Inst().Record(ctx, md.RequestSize, o...) - n.requestDuration.Inst().Record(ctx, md.ElapsedTime, o...) + n.requestDuration.Inst().Record(ctx, md.ElapsedTime/1000, o...) } // TraceAttributes returns attributes for httptrace. diff --git a/instrumentation/github.com/gin-gonic/gin/otelgin/internal/semconv/client.go b/instrumentation/github.com/gin-gonic/gin/otelgin/internal/semconv/client.go index dd531f5eda6..62cd254b0d5 100644 --- a/instrumentation/github.com/gin-gonic/gin/otelgin/internal/semconv/client.go +++ b/instrumentation/github.com/gin-gonic/gin/otelgin/internal/semconv/client.go @@ -57,14 +57,14 @@ func (n HTTPClient) Status(code int) (codes.Code, string) { // RequestTraceAttrs returns trace attributes for an HTTP request made by a client. func (n HTTPClient) RequestTraceAttrs(req *http.Request) []attribute.KeyValue { /* - below attributes are returned: - - http.request.method - - http.request.method.original - - url.full - - server.address - - server.port - - network.protocol.name - - network.protocol.version + below attributes are returned: + - http.request.method + - http.request.method.original + - url.full + - server.address + - server.port + - network.protocol.name + - network.protocol.version */ numOfAttributes := 3 // URL, server address, proto, and method. @@ -139,9 +139,9 @@ func (n HTTPClient) RequestTraceAttrs(req *http.Request) []attribute.KeyValue { // ResponseTraceAttrs returns trace attributes for an HTTP response made by a client. func (n HTTPClient) ResponseTraceAttrs(resp *http.Response) []attribute.KeyValue { /* - below attributes are returned: - - http.response.status_code - - error.type + below attributes are returned: + - http.response.status_code + - error.type */ var count int if resp.StatusCode > 0 { @@ -260,7 +260,7 @@ func (n HTTPClient) MetricOptions(ma MetricAttributes) MetricOpts { func (n HTTPClient) RecordMetrics(ctx context.Context, md MetricData, opts MetricOpts) { o := []metric.RecordOption{opts.MeasurementOption()} n.requestBodySize.Inst().Record(ctx, md.RequestSize, o...) - n.requestDuration.Inst().Record(ctx, md.ElapsedTime, o...) + n.requestDuration.Inst().Record(ctx, md.ElapsedTime/1000, o...) } // TraceAttributes returns attributes for httptrace. diff --git a/instrumentation/github.com/gorilla/mux/otelmux/internal/semconv/client.go b/instrumentation/github.com/gorilla/mux/otelmux/internal/semconv/client.go index fffc1d4d890..59dfec78bfb 100644 --- a/instrumentation/github.com/gorilla/mux/otelmux/internal/semconv/client.go +++ b/instrumentation/github.com/gorilla/mux/otelmux/internal/semconv/client.go @@ -57,14 +57,14 @@ func (n HTTPClient) Status(code int) (codes.Code, string) { // RequestTraceAttrs returns trace attributes for an HTTP request made by a client. func (n HTTPClient) RequestTraceAttrs(req *http.Request) []attribute.KeyValue { /* - below attributes are returned: - - http.request.method - - http.request.method.original - - url.full - - server.address - - server.port - - network.protocol.name - - network.protocol.version + below attributes are returned: + - http.request.method + - http.request.method.original + - url.full + - server.address + - server.port + - network.protocol.name + - network.protocol.version */ numOfAttributes := 3 // URL, server address, proto, and method. @@ -139,9 +139,9 @@ func (n HTTPClient) RequestTraceAttrs(req *http.Request) []attribute.KeyValue { // ResponseTraceAttrs returns trace attributes for an HTTP response made by a client. func (n HTTPClient) ResponseTraceAttrs(resp *http.Response) []attribute.KeyValue { /* - below attributes are returned: - - http.response.status_code - - error.type + below attributes are returned: + - http.response.status_code + - error.type */ var count int if resp.StatusCode > 0 { @@ -260,7 +260,7 @@ func (n HTTPClient) MetricOptions(ma MetricAttributes) MetricOpts { func (n HTTPClient) RecordMetrics(ctx context.Context, md MetricData, opts MetricOpts) { o := []metric.RecordOption{opts.MeasurementOption()} n.requestBodySize.Inst().Record(ctx, md.RequestSize, o...) - n.requestDuration.Inst().Record(ctx, md.ElapsedTime, o...) + n.requestDuration.Inst().Record(ctx, md.ElapsedTime/1000, o...) } // TraceAttributes returns attributes for httptrace. diff --git a/instrumentation/github.com/labstack/echo/otelecho/internal/semconv/client.go b/instrumentation/github.com/labstack/echo/otelecho/internal/semconv/client.go index 0dc27c132ee..1535e59fe34 100644 --- a/instrumentation/github.com/labstack/echo/otelecho/internal/semconv/client.go +++ b/instrumentation/github.com/labstack/echo/otelecho/internal/semconv/client.go @@ -57,14 +57,14 @@ func (n HTTPClient) Status(code int) (codes.Code, string) { // RequestTraceAttrs returns trace attributes for an HTTP request made by a client. func (n HTTPClient) RequestTraceAttrs(req *http.Request) []attribute.KeyValue { /* - below attributes are returned: - - http.request.method - - http.request.method.original - - url.full - - server.address - - server.port - - network.protocol.name - - network.protocol.version + below attributes are returned: + - http.request.method + - http.request.method.original + - url.full + - server.address + - server.port + - network.protocol.name + - network.protocol.version */ numOfAttributes := 3 // URL, server address, proto, and method. @@ -139,9 +139,9 @@ func (n HTTPClient) RequestTraceAttrs(req *http.Request) []attribute.KeyValue { // ResponseTraceAttrs returns trace attributes for an HTTP response made by a client. func (n HTTPClient) ResponseTraceAttrs(resp *http.Response) []attribute.KeyValue { /* - below attributes are returned: - - http.response.status_code - - error.type + below attributes are returned: + - http.response.status_code + - error.type */ var count int if resp.StatusCode > 0 { @@ -260,7 +260,7 @@ func (n HTTPClient) MetricOptions(ma MetricAttributes) MetricOpts { func (n HTTPClient) RecordMetrics(ctx context.Context, md MetricData, opts MetricOpts) { o := []metric.RecordOption{opts.MeasurementOption()} n.requestBodySize.Inst().Record(ctx, md.RequestSize, o...) - n.requestDuration.Inst().Record(ctx, md.ElapsedTime, o...) + n.requestDuration.Inst().Record(ctx, md.ElapsedTime/1000, o...) } // TraceAttributes returns attributes for httptrace. diff --git a/instrumentation/net/http/httptrace/otelhttptrace/internal/semconv/client.go b/instrumentation/net/http/httptrace/otelhttptrace/internal/semconv/client.go index 375eedc9841..a2619af393f 100644 --- a/instrumentation/net/http/httptrace/otelhttptrace/internal/semconv/client.go +++ b/instrumentation/net/http/httptrace/otelhttptrace/internal/semconv/client.go @@ -57,14 +57,14 @@ func (n HTTPClient) Status(code int) (codes.Code, string) { // RequestTraceAttrs returns trace attributes for an HTTP request made by a client. func (n HTTPClient) RequestTraceAttrs(req *http.Request) []attribute.KeyValue { /* - below attributes are returned: - - http.request.method - - http.request.method.original - - url.full - - server.address - - server.port - - network.protocol.name - - network.protocol.version + below attributes are returned: + - http.request.method + - http.request.method.original + - url.full + - server.address + - server.port + - network.protocol.name + - network.protocol.version */ numOfAttributes := 3 // URL, server address, proto, and method. @@ -139,9 +139,9 @@ func (n HTTPClient) RequestTraceAttrs(req *http.Request) []attribute.KeyValue { // ResponseTraceAttrs returns trace attributes for an HTTP response made by a client. func (n HTTPClient) ResponseTraceAttrs(resp *http.Response) []attribute.KeyValue { /* - below attributes are returned: - - http.response.status_code - - error.type + below attributes are returned: + - http.response.status_code + - error.type */ var count int if resp.StatusCode > 0 { @@ -260,7 +260,7 @@ func (n HTTPClient) MetricOptions(ma MetricAttributes) MetricOpts { func (n HTTPClient) RecordMetrics(ctx context.Context, md MetricData, opts MetricOpts) { o := []metric.RecordOption{opts.MeasurementOption()} n.requestBodySize.Inst().Record(ctx, md.RequestSize, o...) - n.requestDuration.Inst().Record(ctx, md.ElapsedTime, o...) + n.requestDuration.Inst().Record(ctx, md.ElapsedTime/1000, o...) } // TraceAttributes returns attributes for httptrace. diff --git a/instrumentation/net/http/otelhttp/internal/semconv/client.go b/instrumentation/net/http/otelhttp/internal/semconv/client.go index 124b9b6d751..102e03785a8 100644 --- a/instrumentation/net/http/otelhttp/internal/semconv/client.go +++ b/instrumentation/net/http/otelhttp/internal/semconv/client.go @@ -57,14 +57,14 @@ func (n HTTPClient) Status(code int) (codes.Code, string) { // RequestTraceAttrs returns trace attributes for an HTTP request made by a client. func (n HTTPClient) RequestTraceAttrs(req *http.Request) []attribute.KeyValue { /* - below attributes are returned: - - http.request.method - - http.request.method.original - - url.full - - server.address - - server.port - - network.protocol.name - - network.protocol.version + below attributes are returned: + - http.request.method + - http.request.method.original + - url.full + - server.address + - server.port + - network.protocol.name + - network.protocol.version */ numOfAttributes := 3 // URL, server address, proto, and method. @@ -139,9 +139,9 @@ func (n HTTPClient) RequestTraceAttrs(req *http.Request) []attribute.KeyValue { // ResponseTraceAttrs returns trace attributes for an HTTP response made by a client. func (n HTTPClient) ResponseTraceAttrs(resp *http.Response) []attribute.KeyValue { /* - below attributes are returned: - - http.response.status_code - - error.type + below attributes are returned: + - http.response.status_code + - error.type */ var count int if resp.StatusCode > 0 { @@ -260,7 +260,7 @@ func (n HTTPClient) MetricOptions(ma MetricAttributes) MetricOpts { func (n HTTPClient) RecordMetrics(ctx context.Context, md MetricData, opts MetricOpts) { o := []metric.RecordOption{opts.MeasurementOption()} n.requestBodySize.Inst().Record(ctx, md.RequestSize, o...) - n.requestDuration.Inst().Record(ctx, md.ElapsedTime, o...) + n.requestDuration.Inst().Record(ctx, md.ElapsedTime/1000, o...) } // TraceAttributes returns attributes for httptrace. diff --git a/internal/shared/semconv/client.go.tmpl b/internal/shared/semconv/client.go.tmpl index f06a7b0eb98..6e1ff5af642 100644 --- a/internal/shared/semconv/client.go.tmpl +++ b/internal/shared/semconv/client.go.tmpl @@ -260,7 +260,7 @@ func (n HTTPClient) MetricOptions(ma MetricAttributes) MetricOpts { func (n HTTPClient) RecordMetrics(ctx context.Context, md MetricData, opts MetricOpts) { o := []metric.RecordOption{opts.MeasurementOption()} n.requestBodySize.Inst().Record(ctx, md.RequestSize, o...) - n.requestDuration.Inst().Record(ctx, md.ElapsedTime, o...) + n.requestDuration.Inst().Record(ctx, md.ElapsedTime/1000, o...) } // TraceAttributes returns attributes for httptrace. From 260c3ccec22cfce2df35568dce9fe9e78655f3a3 Mon Sep 17 00:00:00 2001 From: Gaiaz Iusipov Date: Thu, 26 Feb 2026 04:10:32 +0800 Subject: [PATCH 8/9] fix(internal/shared/semconv): Use `sync.Pool` for `HTTPClient.RecordMetrics` --- .../otelrestful/internal/semconv/client.go | 12 +++++++++--- .../gin-gonic/gin/otelgin/internal/semconv/client.go | 12 +++++++++--- .../gorilla/mux/otelmux/internal/semconv/client.go | 12 +++++++++--- .../echo/otelecho/internal/semconv/client.go | 12 +++++++++--- .../otelhttptrace/internal/semconv/client.go | 12 +++++++++--- .../net/http/otelhttp/internal/semconv/client.go | 12 +++++++++--- internal/shared/semconv/client.go.tmpl | 12 +++++++++--- 7 files changed, 63 insertions(+), 21 deletions(-) diff --git a/instrumentation/github.com/emicklei/go-restful/otelrestful/internal/semconv/client.go b/instrumentation/github.com/emicklei/go-restful/otelrestful/internal/semconv/client.go index 0bef0ab01c6..5f567d80d04 100644 --- a/instrumentation/github.com/emicklei/go-restful/otelrestful/internal/semconv/client.go +++ b/instrumentation/github.com/emicklei/go-restful/otelrestful/internal/semconv/client.go @@ -258,9 +258,15 @@ func (n HTTPClient) MetricOptions(ma MetricAttributes) MetricOpts { } func (n HTTPClient) RecordMetrics(ctx context.Context, md MetricData, opts MetricOpts) { - o := []metric.RecordOption{opts.MeasurementOption()} - n.requestBodySize.Inst().Record(ctx, md.RequestSize, o...) - n.requestDuration.Inst().Record(ctx, md.ElapsedTime/1000, o...) + recordOpts := metricRecordOptionPool.Get().(*[]metric.RecordOption) + defer func() { + *recordOpts = (*recordOpts)[:0] + metricRecordOptionPool.Put(recordOpts) + }() + *recordOpts = append(*recordOpts, opts.MeasurementOption()) + + n.requestBodySize.Inst().Record(ctx, md.RequestSize, *recordOpts...) + n.requestDuration.Inst().Record(ctx, md.ElapsedTime/1000, *recordOpts...) } // TraceAttributes returns attributes for httptrace. diff --git a/instrumentation/github.com/gin-gonic/gin/otelgin/internal/semconv/client.go b/instrumentation/github.com/gin-gonic/gin/otelgin/internal/semconv/client.go index 62cd254b0d5..b5157e80c49 100644 --- a/instrumentation/github.com/gin-gonic/gin/otelgin/internal/semconv/client.go +++ b/instrumentation/github.com/gin-gonic/gin/otelgin/internal/semconv/client.go @@ -258,9 +258,15 @@ func (n HTTPClient) MetricOptions(ma MetricAttributes) MetricOpts { } func (n HTTPClient) RecordMetrics(ctx context.Context, md MetricData, opts MetricOpts) { - o := []metric.RecordOption{opts.MeasurementOption()} - n.requestBodySize.Inst().Record(ctx, md.RequestSize, o...) - n.requestDuration.Inst().Record(ctx, md.ElapsedTime/1000, o...) + recordOpts := metricRecordOptionPool.Get().(*[]metric.RecordOption) + defer func() { + *recordOpts = (*recordOpts)[:0] + metricRecordOptionPool.Put(recordOpts) + }() + *recordOpts = append(*recordOpts, opts.MeasurementOption()) + + n.requestBodySize.Inst().Record(ctx, md.RequestSize, *recordOpts...) + n.requestDuration.Inst().Record(ctx, md.ElapsedTime/1000, *recordOpts...) } // TraceAttributes returns attributes for httptrace. diff --git a/instrumentation/github.com/gorilla/mux/otelmux/internal/semconv/client.go b/instrumentation/github.com/gorilla/mux/otelmux/internal/semconv/client.go index 59dfec78bfb..2494687b49c 100644 --- a/instrumentation/github.com/gorilla/mux/otelmux/internal/semconv/client.go +++ b/instrumentation/github.com/gorilla/mux/otelmux/internal/semconv/client.go @@ -258,9 +258,15 @@ func (n HTTPClient) MetricOptions(ma MetricAttributes) MetricOpts { } func (n HTTPClient) RecordMetrics(ctx context.Context, md MetricData, opts MetricOpts) { - o := []metric.RecordOption{opts.MeasurementOption()} - n.requestBodySize.Inst().Record(ctx, md.RequestSize, o...) - n.requestDuration.Inst().Record(ctx, md.ElapsedTime/1000, o...) + recordOpts := metricRecordOptionPool.Get().(*[]metric.RecordOption) + defer func() { + *recordOpts = (*recordOpts)[:0] + metricRecordOptionPool.Put(recordOpts) + }() + *recordOpts = append(*recordOpts, opts.MeasurementOption()) + + n.requestBodySize.Inst().Record(ctx, md.RequestSize, *recordOpts...) + n.requestDuration.Inst().Record(ctx, md.ElapsedTime/1000, *recordOpts...) } // TraceAttributes returns attributes for httptrace. diff --git a/instrumentation/github.com/labstack/echo/otelecho/internal/semconv/client.go b/instrumentation/github.com/labstack/echo/otelecho/internal/semconv/client.go index 1535e59fe34..c6dadb91a5e 100644 --- a/instrumentation/github.com/labstack/echo/otelecho/internal/semconv/client.go +++ b/instrumentation/github.com/labstack/echo/otelecho/internal/semconv/client.go @@ -258,9 +258,15 @@ func (n HTTPClient) MetricOptions(ma MetricAttributes) MetricOpts { } func (n HTTPClient) RecordMetrics(ctx context.Context, md MetricData, opts MetricOpts) { - o := []metric.RecordOption{opts.MeasurementOption()} - n.requestBodySize.Inst().Record(ctx, md.RequestSize, o...) - n.requestDuration.Inst().Record(ctx, md.ElapsedTime/1000, o...) + recordOpts := metricRecordOptionPool.Get().(*[]metric.RecordOption) + defer func() { + *recordOpts = (*recordOpts)[:0] + metricRecordOptionPool.Put(recordOpts) + }() + *recordOpts = append(*recordOpts, opts.MeasurementOption()) + + n.requestBodySize.Inst().Record(ctx, md.RequestSize, *recordOpts...) + n.requestDuration.Inst().Record(ctx, md.ElapsedTime/1000, *recordOpts...) } // TraceAttributes returns attributes for httptrace. diff --git a/instrumentation/net/http/httptrace/otelhttptrace/internal/semconv/client.go b/instrumentation/net/http/httptrace/otelhttptrace/internal/semconv/client.go index a2619af393f..6b68559c66a 100644 --- a/instrumentation/net/http/httptrace/otelhttptrace/internal/semconv/client.go +++ b/instrumentation/net/http/httptrace/otelhttptrace/internal/semconv/client.go @@ -258,9 +258,15 @@ func (n HTTPClient) MetricOptions(ma MetricAttributes) MetricOpts { } func (n HTTPClient) RecordMetrics(ctx context.Context, md MetricData, opts MetricOpts) { - o := []metric.RecordOption{opts.MeasurementOption()} - n.requestBodySize.Inst().Record(ctx, md.RequestSize, o...) - n.requestDuration.Inst().Record(ctx, md.ElapsedTime/1000, o...) + recordOpts := metricRecordOptionPool.Get().(*[]metric.RecordOption) + defer func() { + *recordOpts = (*recordOpts)[:0] + metricRecordOptionPool.Put(recordOpts) + }() + *recordOpts = append(*recordOpts, opts.MeasurementOption()) + + n.requestBodySize.Inst().Record(ctx, md.RequestSize, *recordOpts...) + n.requestDuration.Inst().Record(ctx, md.ElapsedTime/1000, *recordOpts...) } // TraceAttributes returns attributes for httptrace. diff --git a/instrumentation/net/http/otelhttp/internal/semconv/client.go b/instrumentation/net/http/otelhttp/internal/semconv/client.go index 102e03785a8..44a6386f032 100644 --- a/instrumentation/net/http/otelhttp/internal/semconv/client.go +++ b/instrumentation/net/http/otelhttp/internal/semconv/client.go @@ -258,9 +258,15 @@ func (n HTTPClient) MetricOptions(ma MetricAttributes) MetricOpts { } func (n HTTPClient) RecordMetrics(ctx context.Context, md MetricData, opts MetricOpts) { - o := []metric.RecordOption{opts.MeasurementOption()} - n.requestBodySize.Inst().Record(ctx, md.RequestSize, o...) - n.requestDuration.Inst().Record(ctx, md.ElapsedTime/1000, o...) + recordOpts := metricRecordOptionPool.Get().(*[]metric.RecordOption) + defer func() { + *recordOpts = (*recordOpts)[:0] + metricRecordOptionPool.Put(recordOpts) + }() + *recordOpts = append(*recordOpts, opts.MeasurementOption()) + + n.requestBodySize.Inst().Record(ctx, md.RequestSize, *recordOpts...) + n.requestDuration.Inst().Record(ctx, md.ElapsedTime/1000, *recordOpts...) } // TraceAttributes returns attributes for httptrace. diff --git a/internal/shared/semconv/client.go.tmpl b/internal/shared/semconv/client.go.tmpl index 6e1ff5af642..2aa23f2d57c 100644 --- a/internal/shared/semconv/client.go.tmpl +++ b/internal/shared/semconv/client.go.tmpl @@ -258,9 +258,15 @@ func (n HTTPClient) MetricOptions(ma MetricAttributes) MetricOpts { } func (n HTTPClient) RecordMetrics(ctx context.Context, md MetricData, opts MetricOpts) { - o := []metric.RecordOption{opts.MeasurementOption()} - n.requestBodySize.Inst().Record(ctx, md.RequestSize, o...) - n.requestDuration.Inst().Record(ctx, md.ElapsedTime/1000, o...) + recordOpts := metricRecordOptionPool.Get().(*[]metric.RecordOption) + defer func() { + *recordOpts = (*recordOpts)[:0] + metricRecordOptionPool.Put(recordOpts) + }() + *recordOpts = append(*recordOpts, opts.MeasurementOption()) + + n.requestBodySize.Inst().Record(ctx, md.RequestSize, *recordOpts...) + n.requestDuration.Inst().Record(ctx, md.ElapsedTime/1000, *recordOpts...) } // TraceAttributes returns attributes for httptrace. From 57c81186931e4267e22dccdbd71b7c59473d4ff4 Mon Sep 17 00:00:00 2001 From: Gaiaz Iusipov Date: Thu, 26 Feb 2026 04:35:05 +0800 Subject: [PATCH 9/9] style(internal/shared/semconv): Fix comments padding --- internal/shared/semconv/client.go.tmpl | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/internal/shared/semconv/client.go.tmpl b/internal/shared/semconv/client.go.tmpl index 2aa23f2d57c..5ce0950e7d5 100644 --- a/internal/shared/semconv/client.go.tmpl +++ b/internal/shared/semconv/client.go.tmpl @@ -57,14 +57,14 @@ func (n HTTPClient) Status(code int) (codes.Code, string) { // RequestTraceAttrs returns trace attributes for an HTTP request made by a client. func (n HTTPClient) RequestTraceAttrs(req *http.Request) []attribute.KeyValue { /* - below attributes are returned: - - http.request.method - - http.request.method.original - - url.full - - server.address - - server.port - - network.protocol.name - - network.protocol.version + below attributes are returned: + - http.request.method + - http.request.method.original + - url.full + - server.address + - server.port + - network.protocol.name + - network.protocol.version */ numOfAttributes := 3 // URL, server address, proto, and method. @@ -139,9 +139,9 @@ func (n HTTPClient) RequestTraceAttrs(req *http.Request) []attribute.KeyValue { // ResponseTraceAttrs returns trace attributes for an HTTP response made by a client. func (n HTTPClient) ResponseTraceAttrs(resp *http.Response) []attribute.KeyValue { /* - below attributes are returned: - - http.response.status_code - - error.type + below attributes are returned: + - http.response.status_code + - error.type */ var count int if resp.StatusCode > 0 {