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

Add ThreadLocalAccessor to propagate Baggage with Reactor #319

Closed
jonatan-ivanov opened this issue Jul 31, 2023 · 1 comment
Closed

Add ThreadLocalAccessor to propagate Baggage with Reactor #319

jonatan-ivanov opened this issue Jul 31, 2023 · 1 comment
Labels
bug A general bug
Milestone

Comments

@jonatan-ivanov
Copy link
Member

Example that should work:

@RequestMapping("/")
Mono<String> baggageTest() {
    try (BaggageInScope scope = this.tracer.createBaggageInScope("test", "42")) {
        return webClient.get().uri("/").retrieve().bodyToMono(String.class);
    }
}
@marcingrzejszczak
Copy link
Contributor

marcingrzejszczak commented Aug 18, 2023

For Tracing 1.0.x I've written such a test

@Test
    void baggageWithContextPropagation() {
        Hooks.enableAutomaticContextPropagation();

        Span span = tracer.nextSpan().start();
        try (Tracer.SpanInScope spanInScope = tracer.withSpan(span)) {
            try (BaggageInScope scope = this.tracer.createBaggage(KEY_1, VALUE_1).makeCurrent()) {
                String baggageOutside = this.tracer.getBaggage(KEY_1).get();
                then(baggageOutside).isEqualTo(VALUE_1);
                log.info("BAGGAGE OUTSIDE OF REACTOR [" + baggageOutside + "], thread [" + Thread.currentThread() + "]");
                Baggage baggageFromReactor = Mono.just(KEY_1)
                    .publishOn(Schedulers.boundedElastic())
                    .flatMap(s -> Mono.just(this.tracer.getBaggage(s))
                        .doOnNext(baggage -> log.info("BAGGAGE IN OF REACTOR [" + baggageOutside + "], thread [" + Thread.currentThread() + "]")))
                    .block();
                then(baggageFromReactor).isNotNull();
                then(baggageFromReactor.get()).isEqualTo(VALUE_1);
            }
        }
    }

And it's passing 🤷 , logs

Aug 18, 2023 1:30:27 PM io.micrometer.tracing.otel.bridge.BaggageTests baggageWithContextPropagation
INFO: BAGGAGE OUTSIDE OF REACTOR [value1], thread [Thread[Test worker,5,main]]
Aug 18, 2023 1:30:27 PM io.micrometer.tracing.otel.bridge.BaggageTests lambda$baggageWithContextPropagation$1
INFO: BAGGAGE IN OF REACTOR [value1], thread [Thread[boundedElastic-1,5,main]]

It's working both for OTel and Brave.

UPDATE: It's working cause get() is called in the same thread as Reactor...

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

No branches or pull requests

2 participants