Skip to content

Commit

Permalink
fix opentelemetry example (#2110)
Browse files Browse the repository at this point in the history
Co-authored-by: Bryan Garza <[email protected]>
  • Loading branch information
2 people authored and hawkw committed Jun 6, 2022
1 parent f22f286 commit cc19449
Showing 1 changed file with 12 additions and 7 deletions.
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(())
}

0 comments on commit cc19449

Please sign in to comment.