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

OpenTelemetry and tagged baggage does not create a tag #375

Closed
mhalbritter opened this issue Oct 2, 2023 · 2 comments
Closed

OpenTelemetry and tagged baggage does not create a tag #375

mhalbritter opened this issue Oct 2, 2023 · 2 comments
Labels
bug A general bug
Milestone

Comments

@mhalbritter
Copy link
Contributor

I have this code:

    @GetMapping("/call1")
    public String call1() {
        ScopedSpan span = this.tracer.startScopedSpan("call1");
        try {
            try (BaggageInScope scope7 = this.tracer.createBaggageInScope("t1", "t1-v1")) {
// ...
            }
        } catch (RuntimeException | Error ex) {
            span.error(ex);
            throw ex;
        } finally {
            span.end();
        }
    }

and t1 configured as tag fields on the OtelBaggageManager.

While it creates the span, the t1 tag is missing.

If I add

this.tracer.getBaggage("t1").makeCurrent("t1-v1").close();

to the try-with-resources, the tag appears.

@marcingrzejszczak marcingrzejszczak added the bug A general bug label Dec 8, 2023
@marcingrzejszczak marcingrzejszczak added this to the 1.0.13 milestone Dec 8, 2023
@marcingrzejszczak
Copy link
Contributor

marcingrzejszczak commented Dec 8, 2023

@mhalbritter so in Micrometer 1.0.x I fixed the bug in OTel and that got propagated forward.

However with Brave it works with 1.0.x if you add the separate tag setting handler, but it won't work with 1.1.x onwards. That's because we've aligned that the Brave's baggage should work like OTel one which means that it has a value only within the scope. The handler however is called after the span is finished so it's way after the baggage scope gets closed. So what I did is I added a constructor for BraveBaggageManager that requires to pass the list of tags to it (it's a non-breaking change cause the default constructor assumes that there are no tag keys) and whenever a baggage is created I will tag the span (instead of doing it at the end of span I do it at the beginning of baggage). That means that Boot will need to align here to change the way the BBM bean is being created.

The only potential problem I see is that someone creates a span but doesn't it put it in scope and wants to set a baggage on it, but baggage as such must live within a scope so I can't imagine someone creating a span not in scope and then a baggage in scope. If someone wants baggage they need to have a span in scope too 🤷

@mhalbritter
Copy link
Contributor Author

Thanks. I've opened spring-projects/spring-boot#38724.

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