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

Fix the example installing OpenTelemetryLayer into a global subscriber #175

Merged
merged 4 commits into from
Nov 25, 2024

Conversation

mzabaluev
Copy link
Contributor

@mzabaluev mzabaluev commented Oct 15, 2024

Fixes #159

Motivation

Use of global::shutdown_tracer_provider has regressed since opentelemetry 0.23.

Solution

Change the opentelemtry-otlp example to call shutdown on the TracingProvider available in scope.

Also added an integration test to verify the export behavior is as expected.

@djc
Copy link
Collaborator

djc commented Oct 15, 2024

Use of the global::shutdown_tracer_provider has regressed since opentelemetry 0.23.

Have you discussed this regression upstream?

@mzabaluev
Copy link
Contributor Author

Have you discussed this regression upstream?

It has been discussed in open-telemetry/opentelemetry-rust#1961.

@marioplumbarius
Copy link

@djc any plans to get this merged soon? I spent a few hours jumping across github issues until I found this.

@djc
Copy link
Collaborator

djc commented Nov 25, 2024

@mzabaluev sorry -- could you get this rebased (if still necessary)?

Shutting down the tracer provider via the opentelemetry::global API
has not worked since opentelemetry 0.24 when the batch processor
is in use: buffered traces were not exported. It's not necessary
to install the global provider for the tracing integration, as tracing
has its own way to manage the global subscriber.
Instead, manage the instance in the scope guard the same way as the
meter provider instance, and call the shutdown method on it when the
guard is dropped.
Make sure that an SDK TracerProvider set up with a batch exporter
flushes all buffered spans on shutdown.
In the opentelemetry-otlp example, add a comment explaining how
filtering should prevent reentrancy into the globally installed
tracing layer from the opentelemetry stack where any dependencies
might themselves use tracing.
This illustrates the problem with opentelemetry::global
that prevents proper use of the batched TracerProvider when installed
as the global provider, flushing it at the end of the program
also with the global API.
@mzabaluev mzabaluev force-pushed the fix-global-subscriber-example branch from 0b69a1d to 0c3c091 Compare November 25, 2024 11:11
@mzabaluev
Copy link
Contributor Author

@mzabaluev sorry -- could you get this rebased (if still necessary)?

Done.

@djc djc merged commit a969b9e into tokio-rs:v0.1.x Nov 25, 2024
14 checks passed
@djc
Copy link
Collaborator

djc commented Nov 25, 2024

Thanks!

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

Successfully merging this pull request may close these issues.

Adding tracing_opentelemetry::layer to tracing_subscriber::registry breaks span exporting to Jaeger
3 participants