Skip to content

Commit d9ce9cb

Browse files
n2p5dmathieu
andauthored
otelhttp: deprecate WithPublicEndpoint in favor of WithPublicEndpointFn (#8133) (#8152)
Co-authored-by: Damien Mathieu <[email protected]>
1 parent 471b3d7 commit d9ce9cb

File tree

3 files changed

+9
-8
lines changed

3 files changed

+9
-8
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm
2727

2828
### Deprecated
2929

30+
- `WithPublicEndpoint` in `go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp` is deprecated.
31+
Use `WithPublicEndpointFn` instead. (#8152)
3032
- `WithRouteTag` in `go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp` is deprecated.
3133
The route is already added automatically for spans.
3234
For metrics, the alternative is to use the `WithMetricAttributesFn` option. (#8117)

instrumentation/net/http/otelhttp/config.go

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ type config struct {
2626
Meter metric.Meter
2727
Propagators propagation.TextMapPropagator
2828
SpanStartOptions []trace.SpanStartOption
29-
PublicEndpoint bool
3029
PublicEndpointFn func(*http.Request) bool
3130
ReadEvent bool
3231
WriteEvent bool
@@ -96,17 +95,19 @@ func WithMeterProvider(provider metric.MeterProvider) Option {
9695
// WithPublicEndpoint configures the Handler to link the span with an incoming
9796
// span context. If this option is not provided, then the association is a child
9897
// association instead of a link.
98+
//
99+
// Deprecated: Use [WithPublicEndpointFn] instead.
100+
// To migrate, replace WithPublicEndpoint() with:
101+
//
102+
// WithPublicEndpointFn(func(*http.Request) bool { return true })
99103
func WithPublicEndpoint() Option {
100-
return optionFunc(func(c *config) {
101-
c.PublicEndpoint = true
102-
})
104+
return WithPublicEndpointFn(func(*http.Request) bool { return true })
103105
}
104106

105107
// WithPublicEndpointFn runs with every request, and allows conditionally
106108
// configuring the Handler to link the span with an incoming span context. If
107109
// this option is not provided or returns false, then the association is a
108110
// child association instead of a link.
109-
// Note: WithPublicEndpoint takes precedence over WithPublicEndpointFn.
110111
func WithPublicEndpointFn(fn func(*http.Request) bool) Option {
111112
return optionFunc(func(c *config) {
112113
c.PublicEndpointFn = fn

instrumentation/net/http/otelhttp/handler.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ type middleware struct {
2929
writeEvent bool
3030
filters []Filter
3131
spanNameFormatter func(string, *http.Request) string
32-
publicEndpoint bool
3332
publicEndpointFn func(*http.Request) bool
3433
metricAttributesFn func(*http.Request) []attribute.KeyValue
3534

@@ -77,7 +76,6 @@ func (h *middleware) configure(c *config) {
7776
h.writeEvent = c.WriteEvent
7877
h.filters = c.Filters
7978
h.spanNameFormatter = c.SpanNameFormatter
80-
h.publicEndpoint = c.PublicEndpoint
8179
h.publicEndpointFn = c.PublicEndpointFn
8280
h.server = c.ServerName
8381
h.semconv = semconv.NewHTTPServer(c.Meter)
@@ -102,7 +100,7 @@ func (h *middleware) serveHTTP(w http.ResponseWriter, r *http.Request, next http
102100
}
103101

104102
opts = append(opts, h.spanStartOptions...)
105-
if h.publicEndpoint || (h.publicEndpointFn != nil && h.publicEndpointFn(r.WithContext(ctx))) {
103+
if h.publicEndpointFn != nil && h.publicEndpointFn(r.WithContext(ctx)) {
106104
opts = append(opts, trace.WithNewRoot())
107105
// Linking incoming span context if any for public endpoint.
108106
if s := trace.SpanContextFromContext(ctx); s.IsValid() && s.IsRemote() {

0 commit comments

Comments
 (0)