spring-projects-experimental / spring-cloud-sleuth-otel

Spring Cloud Sleuth support for OpenTelemetry
https://spring-projects-experimental.github.io/spring-cloud-sleuth-otel/docs/current/reference/html/
Apache License 2.0
111 stars 33 forks source link

OtelHttpServerHandler.class and SamplerFunction<HttpRequest> #160

Closed hyunbeeds closed 1 year ago

hyunbeeds commented 1 year ago

Is your feature request related to a problem? Please describe.

I want to only trace request using method POST, DELETE.

In the OtelHttpClientHandler and brave, I can easily use SamplerFunction to achieve this, but I can't use that way in the OtelHttpServerHandler.. I can use only skip patterns to filter ServerRequest..

@Override
    public Span handleReceive(HttpServerRequest request) {
        String url = request.path();
        boolean shouldSkip = !StringUtils.isEmpty(url) && this.pattern.matcher(url).matches();
        if (shouldSkip) {
            return OtelSpan.fromOtel(io.opentelemetry.api.trace.Span.getInvalid());
        }
        Context parentContext = Context.current();
        if (instrumenter.shouldStart(parentContext, request)) {
            Context context = instrumenter.start(parentContext, request);
            return span(context, request);
        }
        else {
            return OtelSpan.fromOtel(io.opentelemetry.api.trace.Span.getInvalid());
        }
    }

Describe the solution you'd like add SamplerFunction in OtelHttpServerHandler constructor and use Qualifier might seem to achieve this..

marcingrzejszczak commented 1 year ago

Sleuth and Sleuth OTel are feature complete projects and this looks like a new feature. Unless you're willing to contribute it we would not be planning on adding it.