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 is lost when explicitly setting parent observation #882

Open
jamesmoessis opened this issue Oct 30, 2024 · 4 comments
Open

Baggage is lost when explicitly setting parent observation #882

jamesmoessis opened this issue Oct 30, 2024 · 4 comments

Comments

@jamesmoessis
Copy link
Contributor

jamesmoessis commented Oct 30, 2024

Using: id("org.springframework.boot") version "3.3.5"

I would expect baggage to be carried over when setting a parent observation. Currently it is lost. I am using the otel tracing bridge.

Example:

    @GetMapping("observation")
    public Mono<String> observation() {
        String baggageBefore = tracer.getBaggage("key").get();
        Observation parent = observationRegistry.getCurrentObservation();
        Observation o = Observation.createNotStarted("child", observationRegistry).parentObservation(parent);
        try(Observation.Scope ignored = o.openScope()) {
            String baggageAfter = tracer.getBaggage("key").get(); // expect "val" but is null
            return Mono.just("baggagebefore="+baggageBefore+", baggageAfter="+baggageAfter);
        }
    }

Full minimal reproduction in this repo: https://github.com/jamesmoessis/baggage-bug-demo

Reproduce by running it then:

$ curl http://localhost:8080/observation -H 'baggage: key=val'
baggagebefore=val, baggageAfter=null%   
@shakuzen
Copy link
Member

shakuzen commented Dec 12, 2024

Typically I would expect creating the child observation in the opened scope from the parent observation, which would allow this to work. Is there a reason in your code you can't do that?

Edit: for completeness, I changed your controller method to this:

    @GetMapping("observation")
    public Mono<String> observation() {
        String baggageBefore = tracer.getBaggage("key").get();
        Observation parent = observationRegistry.getCurrentObservation();
        try(Observation.Scope ignored = parent.openScope()) {
            Observation o = Observation.createNotStarted("child", observationRegistry);
            System.out.println(parent.equals(o.getContext().getParentObservation()));
            String baggageAfter = tracer.getBaggage("key").get();
            return Mono.just("baggagebefore="+baggageBefore+", baggageAfter="+baggageAfter);
        }
    }

And I get:

curl http://localhost:8080/observation -H 'baggage: key=val'
baggagebefore=val, baggageAfter=val%

And sysout prints true

@jamesmoessis
Copy link
Contributor Author

@shakuzen thanks for clarifying. Given that #455 was only recently closed, we can assume this feature is supported now. I assume it wasn't supported when I raised this issue initially.

Is there a reason in your code you can't do that?

I suppose there's many scenarios in which a context is not in current threadlocal scope, but yet you still want to use it as a parent context, but it's kind of beside the point. It's unclear why I would need parent context to be the current active context in order for this to work. It doesn't work like that for trace context, and as far as I understand this is not documented behaviour.

I oversee the usage of this library at our company for hundreds of service, and people use it in all kinds of ways. They come to me with their issues using this library. If the API supports it, it should work - and oftentimes the API just does not work and I come here to raise an issue. It's simply too brittle to use at this scale, and this is another example. It's a shame because I would like to recommend a single observability API that integrates with Spring well, but unfortunately it's too buggy so I just point people towards the OTel API which does what it says on the tin.

@marcingrzejszczak
Copy link
Contributor

I oversee the usage of this library at our company for hundreds of service, and people use it in all kinds of ways. They come to me with their issues using this library. If the API supports it, it should work - and oftentimes the API just does not work and I come here to raise an issue. It's simply too brittle to use at this scale, and this is another example. It's a shame because I would like to recommend a single observability API that integrates with Spring well, but unfortunately it's too buggy so I just point people towards the OTel API which does what it says on the tin.

We're sorry that you find the API too brittle. You're providing the baggage being lost when using explicitly as one example and I can understand that. Are there any others that you can mention? We don't see too many issue tickets related to the API and bugs so that's quite some news to us.

@marcingrzejszczak
Copy link
Contributor

Also with reactor we explain how to use the baggage over here https://docs.micrometer.io/tracing/reference/configuring.html#_context_propagation_with_micrometer_tracing

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

No branches or pull requests

3 participants