-
Notifications
You must be signed in to change notification settings - Fork 57
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
Make sure to call close() on Scope returned from io.opentelemetry.context.Context.makeCurrent() #924
base: series/2.x
Are you sure you want to change the base?
Conversation
…text.Context.makeCurrent()
@joost-de-vries Thanks for spotting this! I'll look into it when I have time and tell you what I think about your solution. The only concern I have is that these changes are not backward-compatible. |
@grouzen thank you for your quick response. Yes, too bad that the Baggage api is affected. I couldn't think of a solution that doesn't. Maybe you have an idea? I've tested this fix on datadog. |
There's still a failing assertion |
Now I realize that it is required to change the Baggage API this way to reflect the |
@joost-de-vries Please pull the changes from |
@grouzen I wonder how to test the fix. One way would be to mock de java OpenTelemetry Context.makeCurrent. And check that |
Thinking about the changed api of Baggage: I guess I can introduce a new trait. And add deprecation warnings to the existing. def baggage(logAnnotated: Boolean = false): URLayer[ContextStorage, Baggage] =
Baggage.live(logAnnotated) I guess we could call the existing trait |
Frankly, I'm still thinking about how to avoid having scoped baggage API. I need to find some time to read the Baggage OTEL spec. I assume it is fine to have nested OTEL scopes when dealing with baggage data because, as far as I remember, according to the spec, it stores the baggage data in the trace context rather than the span, which makes perfect sense to me. |
Sounds good. I think it is a sane way of testing this kind of stuff. |
Yes, I'm chewing on that too. Come to think of it: the latter solution is simplest probably. |
I've looked into this: |
@grouzen I've implemented the latter approach. Existing code will compile unchanged. (of course that raises the question what the implementation of the existing methods should be. I've implemented it with a local |
The documentation for
io.opentelemetry.context.Context.makeCurrent()
statesEvery makeCurrent() must be followed by a Scope#close(). Breaking these rules may lead to memory leaks and incorrect scoping.
Running zio-opentelemetry with
-Dio.opentelemetry.context.enableStrictContext=true
leads to an errorThis PR uses
zio.Scope
to make sure that the otel Scope returned by Context.makeCurrent is always closed.