@@ -48,26 +48,23 @@ type Config struct {
4848 // Skipper defines a function to skip middleware.
4949 Skipper middleware.Skipper
5050
51- // PublicEndpoint indicates that this middleware serves a public (internet-facing) endpoint
52- // receiving requests from untrusted clients.
51+ // PublicEndpointFn decides per request whether it should be handled as a public
52+ // (internet-facing) endpoint receiving requests from untrusted clients.
5353 //
54- // When enabled, the incoming trace context (e.g. `traceparent`/`tracestate` headers) is not
55- // used as the parent of the server span. Instead, a new root span (new trace) is started
56- // and the incoming remote span context, if valid, is recorded as a span link. This prevents
57- // untrusted clients from injecting arbitrary trace IDs into your traces or influencing the
58- // sampling decision (e.g. suppressing tracing with a `sampled=0` flag).
59- PublicEndpoint bool
60-
61- // PublicEndpointFn allows deciding per request whether it should be handled as a public
62- // endpoint (see PublicEndpoint for the behavior). Requests for which the function returns
63- // true are treated as public endpoint requests.
54+ // When the function returns true, the incoming trace context (e.g. `traceparent`/`tracestate`
55+ // headers) is not used as the parent of the server span. Instead, a new root span (new trace)
56+ // is started and the incoming remote span context, if valid, is recorded as a span link. This
57+ // prevents untrusted clients from injecting arbitrary trace IDs into your traces or
58+ // influencing the sampling decision (e.g. suppressing tracing with a `sampled=0` flag).
59+ //
60+ // To treat every request as public:
61+ //
62+ // config.PublicEndpointFn = func(c *echo.Context, remote oteltrace.SpanContext) bool { return true }
6463 //
6564 // The remote span context extracted from the incoming request by Propagators is passed as
6665 // the second argument. It can be invalid (see trace.SpanContext.IsValid) when the request
6766 // carries no trace context. This allows, for example, trusting only trace contexts that
6867 // originate from known internal systems.
69- //
70- // This function is only called when PublicEndpoint is false.
7168 PublicEndpointFn func (c * echo.Context , remote oteltrace.SpanContext ) bool
7269
7370 // OnNextError is used to specify how errors returned from the next middleware / handler are handled.
@@ -214,7 +211,7 @@ func (config Config) ToMiddleware() (echo.MiddlewareFunc, error) {
214211
215212 ctx := config .Propagators .Extract (request .Context (), propagation .HeaderCarrier (request .Header ))
216213 remote := oteltrace .SpanContextFromContext (ctx )
217- if config .PublicEndpoint || ( config . PublicEndpointFn != nil && config .PublicEndpointFn (c , remote ) ) {
214+ if config .PublicEndpointFn != nil && config .PublicEndpointFn (c , remote ) {
218215 spanStartOptions = append (spanStartOptions , oteltrace .WithNewRoot ())
219216 // keep the incoming (untrusted) trace context visible by linking it to the new root span
220217 if remote .IsValid () && remote .IsRemote () {
0 commit comments