diff --git a/CHANGELOG.md b/CHANGELOG.md index 4b01b5fd449..3664aaa9629 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -16,6 +16,8 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm - The deprecated `DefaultClient`, `Get`, `Head`, `Post`, and `PostForm` in `go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp`. Use a custom `*http.Client` with `otelhttp.NewTransport(http.DefaultTransport)` instead. (#8266) +- The deprecated `WithPublicEndpoint` in `go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp`. + Use `WithPublicEndpointFn` instead. (#8267) diff --git a/instrumentation/net/http/otelhttp/config.go b/instrumentation/net/http/otelhttp/config.go index f73afb59e9b..f7338b7e527 100644 --- a/instrumentation/net/http/otelhttp/config.go +++ b/instrumentation/net/http/otelhttp/config.go @@ -92,18 +92,6 @@ 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 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 diff --git a/instrumentation/net/http/otelhttp/handler_test.go b/instrumentation/net/http/otelhttp/handler_test.go index 07649df8251..44e7cafa08a 100644 --- a/instrumentation/net/http/otelhttp/handler_test.go +++ b/instrumentation/net/http/otelhttp/handler_test.go @@ -495,51 +495,6 @@ func TestWithSpanNameFormatter(t *testing.T) { } } -func TestWithPublicEndpoint(t *testing.T) { - spanRecorder := tracetest.NewSpanRecorder() - provider := sdktrace.NewTracerProvider( - sdktrace.WithSpanProcessor(spanRecorder), - ) - remoteSpan := trace.SpanContextConfig{ - TraceID: trace.TraceID{0x01}, - SpanID: trace.SpanID{0x01}, - Remote: true, - } - prop := propagation.TraceContext{} - h := NewHandler( - http.HandlerFunc(func(_ http.ResponseWriter, r *http.Request) { - s := trace.SpanFromContext(r.Context()) - sc := s.SpanContext() - - // Should be with new root trace. - assert.True(t, sc.IsValid()) - assert.False(t, sc.IsRemote()) - assert.NotEqual(t, remoteSpan.TraceID, sc.TraceID()) - }), "test_handler", - WithPublicEndpoint(), - WithPropagators(prop), - WithTracerProvider(provider), - ) - - r, err := http.NewRequest(http.MethodGet, "http://localhost/", http.NoBody) - require.NoError(t, err) - - sc := trace.NewSpanContext(remoteSpan) - ctx := trace.ContextWithSpanContext(t.Context(), sc) - prop.Inject(ctx, propagation.HeaderCarrier(r.Header)) - - rr := httptest.NewRecorder() - h.ServeHTTP(rr, r) - assert.Equal(t, http.StatusOK, rr.Result().StatusCode) - - // Recorded span should be linked with an incoming span context. - assert.NoError(t, spanRecorder.ForceFlush(ctx)) - done := spanRecorder.Ended() - require.Len(t, done, 1) - require.Len(t, done[0].Links(), 1, "should contain link") - require.True(t, sc.Equal(done[0].Links()[0].SpanContext), "should link incoming span context") -} - func TestWithPublicEndpointFn(t *testing.T) { remoteSpan := trace.SpanContextConfig{ TraceID: trace.TraceID{0x01},