-
Notifications
You must be signed in to change notification settings - Fork 790
set_global_default
does not seem to work
#3217
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
Comments
It seems like this example although different from what I'm trying to do does demonstrate that use tracing::{info, Level};
use tracing_subscriber::FmtSubscriber;
fn main() {
// a builder for `FmtSubscriber`.
let subscriber = FmtSubscriber::builder()
// all spans/events with a level higher than TRACE (e.g, debug, info, warn, etc.)
// will be written to stdout.
.with_max_level(Level::TRACE)
// completes the builder.
.finish();
tracing::subscriber::set_global_default(subscriber)
.expect("setting default subscriber failed");
let number_of_yaks = 3;
// this creates a new event, outside of any spans.
info!(number_of_yaks, "preparing to shave yaks");
let number_shaved = yak_shave::shave_all(number_of_yaks);
info!(
all_yaks_shaved = number_shaved == number_of_yaks,
"yak shaving completed."
);
} |
Just skimming quickly over open-telemetry/opentelemetry-rust#1961 it seems that this is known and expected. In any case, this is not a tracing issue. |
@joseph-henry It looks like you are missing shutdown call on tracer_provider. Make an explicit shutdown() call, and this should work. As to why this works when you use with_default and not when you use global (simplified)
In short, explicit shutdown should do the trick. |
Yes. This issue can be closed here. |
Thanks for the help but unfortunately adding the following did not help:
I can agree to close the issue soon since this isn't a tracing issue but if there's anything else I should try I'd love to know what that could be. Thanks. |
@joseph-henry Check if you are following the examples from https://github.com/open-telemetry/opentelemetry-rust/tree/main/opentelemetry-otlp/examples If yes and having issues, it's better to report it and discuss on the OpenTelemetry repo itself. |
I'll do just that. Thanks again guys for the assistance. |
Bug Report
Version
Platform
Linux 6.9.3-76060903-generic #202405300957~1738770968~22.04~d5f7c84 SMP PREEMPT_DYNAMIC Wed F x86_64 x86_64 x86_64 GNU/Linux
Crates
I'm not yet sure where the failure is. I suspect it's in
tracing
but here's myCargo.toml
:Description
Hello. I'm trying to set the default subscriber for my entire program using
set_global_default
but am not getting the result that I expect. I can useset_default
successfully, and I can use.with_default
in a closure successfully.When I use method 1 or 2 in the code below, my tracing events are sent to my collector, but when I use method 1 (
set_global_default
) nothing is sent to my collector and no error is emitted when I check its state. Any help would be greatly appreciated. Thanks!Thanks!
The text was updated successfully, but these errors were encountered: