Skip to content

Instantly share code, notes, and snippets.

@Sushisource
Created May 11, 2021 22:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Sushisource/0c04fcc0fecef386a46cd6dd25c7a296 to your computer and use it in GitHub Desktop.
Save Sushisource/0c04fcc0fecef386a46cd6dd25c7a296 to your computer and use it in GitHub Desktop.
Opentelemetry hang demonstration
[package]
name = "opentelem_hang"
version = "0.1.0"
authors = ["Spencer Judge <sjudge@hey.com>"]
edition = "2018"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
futures = "0.3"
opentelemetry = { version = "0.13", features = ["rt-tokio"] }
opentelemetry-jaeger = "0.12"
tokio = { version = "1.1", features = ["full"] }
tracing = "0.1"
tracing-opentelemetry = "0.12"
tracing-subscriber = "0.2"
#[macro_use]
extern crate tracing;
fn main() {
println!("Hello, world!");
}
#[cfg(test)]
mod tests {
use opentelemetry::global;
use tracing_subscriber::{layer::SubscriberExt, util::SubscriberInitExt, EnvFilter};
#[tokio::test]
async fn hang_demonstration() {
let filter_layer = EnvFilter::try_from_default_env()
.or_else(|_| EnvFilter::try_new("info"))
.unwrap();
let pretty_fmt = tracing_subscriber::fmt::format()
.pretty()
.with_source_location(false);
let tracer = opentelemetry_jaeger::new_pipeline()
.install_batch(opentelemetry::runtime::Tokio)
.unwrap();
let opentelemetry = tracing_opentelemetry::layer().with_tracer(tracer);
tracing_subscriber::registry()
.with(opentelemetry)
.with(filter_layer)
.with(
tracing_subscriber::fmt::layer()
.with_target(false)
.event_format(pretty_fmt),
)
.try_init()
.unwrap();
info!("Hi");
global::shutdown_tracer_provider(); // sending remaining spans
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment