Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Baggage should be reverted after scopedSpan#end when using Otel #928

Open
wapkch opened this issue Jan 1, 2025 · 1 comment
Open

Baggage should be reverted after scopedSpan#end when using Otel #928

wapkch opened this issue Jan 1, 2025 · 1 comment

Comments

@wapkch
Copy link

wapkch commented Jan 1, 2025

According to #879, for async baggage propagation, we do not close baggageInScope.

But the baggage cannot be reverted even after scopedSpan#end when using micrometer-tracing-bridge-otel, but if using micrometer-tracing-bridge-brave, the baggage will be reverted.

Tested with the latest version (1.4.1):

    @Bean
    CommandLineRunner commandLineRunner1(Tracer tracer) {
        return args -> {
            ScopedSpan scopedSpan = tracer.startScopedSpan("test");

            try {
                // We do not close baggageInScope for async baggage propagation.
                BaggageInScope baggageInScope = tracer.getBaggage("xyz").makeCurrent("123");

                ExecutorService executorService = ContextExecutorService.wrap(Executors.newCachedThreadPool(), ContextSnapshot::captureAll);
                executorService.execute(() -> {
                    try {
                        // do some work...
                        Thread.sleep(3000);
                        // check baggage
                        String xyz = tracer.getBaggage("xyz").get();
                        Assert.state(xyz.equals("123"), "Baggage should be propagated");
                    } catch (InterruptedException e) {
                        throw new RuntimeException(e);
                    }
                });
            } finally {
                scopedSpan.end();
            }

            String xyz = tracer.getBaggage("xyz").get();
            Assert.state(xyz == null, "Baggage should be reverted"); // failed when using otel, succeed when using brave
        };
    }
@marcingrzejszczak
Copy link
Contributor

You haven't closed the baggageInScope variable.

For Brave baggage is always tied to the span so even if you've left the opened scope for baggage, the span scope is closed.

For OTel span and baggage scopes are separate. You've opened a baggage scope and never closed it. This is why you have the problem you've mentioned.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants