Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Opentelemetry: Fix example bug of missing root span #2110

Merged
merged 2 commits into from
May 10, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 12 additions & 7 deletions examples/examples/opentelemetry.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use opentelemetry::global;
use std::{error::Error, thread, time::Duration};
use tracing::{span, trace, warn};
use tracing_attributes::instrument;
Expand Down Expand Up @@ -26,16 +27,20 @@ fn main() -> Result<(), Box<dyn Error + Send + Sync + 'static>> {
.with(opentelemetry)
.try_init()?;

let root = span!(tracing::Level::INFO, "app_start", work_units = 2);
let _enter = root.enter();
{
let root = span!(tracing::Level::INFO, "app_start", work_units = 2);
let _enter = root.enter();

let work_result = expensive_work();
let work_result = expensive_work();

span!(tracing::Level::INFO, "faster_work")
.in_scope(|| thread::sleep(Duration::from_millis(10)));
span!(tracing::Level::INFO, "faster_work")
.in_scope(|| thread::sleep(Duration::from_millis(10)));

warn!("About to exit!");
trace!("status: {}", work_result);
warn!("About to exit!");
trace!("status: {}", work_result);
}

global::shutdown_tracer_provider();

Ok(())
}