From ee46d1a63617212f0d5bd6286b9578227ff4e086 Mon Sep 17 00:00:00 2001 From: Nathan Toups Date: Sat, 8 Nov 2025 21:28:55 -0600 Subject: [PATCH 1/2] otelhttp: deprecate WithPublicEndpoint in favor of WithPublicEndpointFn (#8133) WithPublicEndpoint() now delegates to WithPublicEndpointFn to reduce code duplication and maintenance burden. The PublicEndpoint bool field has been removed from the config and middleware structs in favor of using only PublicEndpointFn. This simplifies the implementation to a single code path while maintaining full backward compatibility. --- CHANGELOG.md | 2 ++ instrumentation/net/http/otelhttp/config.go | 11 ++++++----- instrumentation/net/http/otelhttp/handler.go | 4 +--- 3 files changed, 9 insertions(+), 8 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 20d56c0b70e..9d28412cbdf 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -26,6 +26,8 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm ### Deprecated +- `WithPublicEndpoint` in `go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp` is deprecated. + Use `WithPublicEndpointFn` instead. (#8152) - `WithRouteTag` in `go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp` is deprecated. The route is already added automatically for spans. For metrics, the alternative is to use the `WithMetricAttributesFn` option. (#8117) diff --git a/instrumentation/net/http/otelhttp/config.go b/instrumentation/net/http/otelhttp/config.go index 38fb79c0328..6107728d412 100644 --- a/instrumentation/net/http/otelhttp/config.go +++ b/instrumentation/net/http/otelhttp/config.go @@ -26,7 +26,6 @@ type config struct { Meter metric.Meter Propagators propagation.TextMapPropagator SpanStartOptions []trace.SpanStartOption - PublicEndpoint bool PublicEndpointFn func(*http.Request) bool ReadEvent bool WriteEvent bool @@ -96,17 +95,19 @@ func WithMeterProvider(provider metric.MeterProvider) Option { // WithPublicEndpoint configures the Handler to link the span with an incoming // span context. If this option is not provided, then the association is a child // association instead of a link. +// +// Deprecated: Use [WithPublicEndpointFn] instead. +// To migrate, replace WithPublicEndpoint() with: +// +// WithPublicEndpointFn(func(*http.Request) bool { return true }) func WithPublicEndpoint() Option { - return optionFunc(func(c *config) { - c.PublicEndpoint = true - }) + return WithPublicEndpointFn(func(*http.Request) bool { return true }) } // WithPublicEndpointFn runs with every request, and allows conditionally // configuring the Handler to link the span with an incoming span context. If // this option is not provided or returns false, then the association is a // child association instead of a link. -// Note: WithPublicEndpoint takes precedence over WithPublicEndpointFn. func WithPublicEndpointFn(fn func(*http.Request) bool) Option { return optionFunc(func(c *config) { c.PublicEndpointFn = fn diff --git a/instrumentation/net/http/otelhttp/handler.go b/instrumentation/net/http/otelhttp/handler.go index 4fe099b83cb..c1bbf3a3c2d 100644 --- a/instrumentation/net/http/otelhttp/handler.go +++ b/instrumentation/net/http/otelhttp/handler.go @@ -29,7 +29,6 @@ type middleware struct { writeEvent bool filters []Filter spanNameFormatter func(string, *http.Request) string - publicEndpoint bool publicEndpointFn func(*http.Request) bool metricAttributesFn func(*http.Request) []attribute.KeyValue @@ -77,7 +76,6 @@ func (h *middleware) configure(c *config) { h.writeEvent = c.WriteEvent h.filters = c.Filters h.spanNameFormatter = c.SpanNameFormatter - h.publicEndpoint = c.PublicEndpoint h.publicEndpointFn = c.PublicEndpointFn h.server = c.ServerName h.semconv = semconv.NewHTTPServer(c.Meter) @@ -102,7 +100,7 @@ func (h *middleware) serveHTTP(w http.ResponseWriter, r *http.Request, next http } opts = append(opts, h.spanStartOptions...) - if h.publicEndpoint || (h.publicEndpointFn != nil && h.publicEndpointFn(r.WithContext(ctx))) { + if h.publicEndpointFn != nil && h.publicEndpointFn(r.WithContext(ctx)) { opts = append(opts, trace.WithNewRoot()) // Linking incoming span context if any for public endpoint. if s := trace.SpanContextFromContext(ctx); s.IsValid() && s.IsRemote() { From 32e2d508162f88c3c13f2a99f8e20babdfbbbb58 Mon Sep 17 00:00:00 2001 From: Nathan Toups Date: Sun, 9 Nov 2025 10:21:30 -0600 Subject: [PATCH 2/2] chore: fix CHANGELOG markdown lint error and PR reference --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9d28412cbdf..2d9b0df5058 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -26,7 +26,7 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm ### Deprecated -- `WithPublicEndpoint` in `go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp` is deprecated. +- `WithPublicEndpoint` in `go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp` is deprecated. Use `WithPublicEndpointFn` instead. (#8152) - `WithRouteTag` in `go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp` is deprecated. The route is already added automatically for spans.