spring boot - SpanProcessor not invoked on all spans - Stack Overflow

I would like to register a SpanProcessor that adds the current baggage as span attributes.I have decla

I would like to register a SpanProcessor that adds the current baggage as span attributes.

I have declared a configuration bean as follows:

@Bean
public AutoConfigurationCustomizerProvider provider() {
    return provider -> {
        provider.addTracerProviderCustomizer((sdkTracerProviderBuilder, configProperties) ->
                sdkTracerProviderBuilder.addSpanProcessor(
                        BaggageSpanProcessor.allowAllBaggageKeys()
                )
        );
    };
}

BaggageProcessor is from io.opentelemetry.contrib:opentelemetry-baggage-processor:1.44.0-alpha2

Here's how I add create Baggage and Span:

private final Tracer tracer = GlobalOpenTelemetry.getTracer("example-tracer");


private void doSomething(Contact contact) {

    Baggage newBaggage =
            Baggage.current().toBuilder()
                    .put("xxxxxx", "12345678")
                    .build();

    try (Scope scope0 = newBaggage.storeInContext(Context.current()).makeCurrent()) {
        Span span = tracer.spanBuilder("manual-span").startSpan();

        try (var scope1 = span.makeCurrent()) {
            span.addEvent("manual-event");
        } finally {
            span.end();
        }

    }

In debug mode I can confirm that the addTracerProviderCustomizer() method is called. However, the BaggageSpanProcessor.onStart() method is not invoked on all spans, actually using a dummy HTTP handler it is only invoked on one span named "HikariDataSource.getConnection", which is not even part of the 19 spans that I see in Jaeger for this HTTP request... I'm puzzled.

Any idea what I'm doing wrong?

Open Telemetry dependencies based on io.opentelemetry.instrumentation:opentelemetry-instrumentation-bom:2.12.0


EDIT: it works if instead of using GlobalOpenTelemetry.getTracer("example-tracer") I autowire OpenTelemetry and get the Tracer as follows:

Tracer tracer = openTelemetry.getTracer("example-tracer");

Why are they not equivalent?

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745088400a4610542.html

相关推荐

  • spring boot - SpanProcessor not invoked on all spans - Stack Overflow

    I would like to register a SpanProcessor that adds the current baggage as span attributes.I have decla

    16小时前
    20

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信