diff --git a/Cargo.toml b/Cargo.toml index a03e50e26..925961778 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -18,8 +18,8 @@ derive_more = "0.99" futures = "0.3" itertools = "0.10" once_cell = "1.5" -opentelemetry-jaeger = "0.11" -opentelemetry = "0.12" +opentelemetry-jaeger = "0.12" +opentelemetry = { version = "0.13", features = ["rt-tokio"] } parking_lot = "0.11" prost = "0.7" prost-types = "0.7" @@ -28,7 +28,7 @@ thiserror = "1.0" tokio = { version = "1.1", features = ["rt", "rt-multi-thread", "parking_lot"] } tracing = { version = "0.1", features = ["log"] } tracing-futures = "0.2" -tracing-opentelemetry = "0.11" +tracing-opentelemetry = "0.12" tracing-subscriber = "0.2" url = "2.2" rand = "0.8.3" diff --git a/README.md b/README.md index c94c23ede..93bc66ae8 100644 --- a/README.md +++ b/README.md @@ -32,16 +32,6 @@ We are using [clippy](https://github.com/rust-lang/rust-clippy) for linting. You can run it using: `cargo clippy --all -- -D warnings` -## Style Guidelines - -### Error handling -Any error which is returned from a public interface should be well-typed, and we use -[thiserror](https://github.com/dtolnay/thiserror) for that purpose. - -Errors returned from things only used in testing are free to use -[anyhow](https://github.com/dtolnay/anyhow) for less verbosity. - - ## Debugging The crate uses [tracing](https://github.com/tokio-rs/tracing) to help with debugging. To enable it for a test, insert the below snippet at the start of the test. By default, tracing data is output @@ -54,4 +44,22 @@ let _enter = s.enter(); ``` To run the Jaeger instance: -`docker run --rm -p6831:6831/udp -p6832:6832/udp -p16686:16686 jaegertracing/all-in-one:latest` \ No newline at end of file +`docker run --rm -p6831:6831/udp -p6832:6832/udp -p16686:16686 jaegertracing/all-in-one:latest` + +To show logs in the console, set the `RUST_LOG` environment variable to `temporal_sdk_core=DEBUG` +or whatever level you desire. The env var is parsed according to tracing's +[EnvFilter](https://docs.rs/tracing-subscriber/latest/tracing_subscriber/struct.EnvFilter.html) +rules. + +If you are working on a language SDK, you are expected to initialize tracing early in your `main` +equivalent. + +## Style Guidelines + +### Error handling +Any error which is returned from a public interface should be well-typed, and we use +[thiserror](https://github.com/dtolnay/thiserror) for that purpose. + +Errors returned from things only used in testing are free to use +[anyhow](https://github.com/dtolnay/anyhow) for less verbosity. + diff --git a/src/core_tracing.rs b/src/core_tracing.rs index 6b99c5d74..1eb8de48c 100644 --- a/src/core_tracing.rs +++ b/src/core_tracing.rs @@ -1,18 +1,17 @@ use itertools::Itertools; -use once_cell::sync::OnceCell; -use opentelemetry_jaeger::Uninstall; -use std::collections::VecDeque; -use tracing_subscriber::{layer::SubscriberExt, util::SubscriberInitExt, EnvFilter}; +use std::{collections::VecDeque, sync::Once}; +use tracing_subscriber::util::SubscriberInitExt; +use tracing_subscriber::{layer::SubscriberExt, EnvFilter}; -static TRACING_INIT: OnceCell = OnceCell::new(); +static TRACING_INIT: Once = Once::new(); /// Initialize tracing subscribers and output. Core will not call this itself, it exists here so /// that consumers and tests have an easy way to initialize tracing. pub fn tracing_init() { - TRACING_INIT.get_or_init(|| { - let (tracer, uninstall) = opentelemetry_jaeger::new_pipeline() + TRACING_INIT.call_once(|| { + let tracer = opentelemetry_jaeger::new_pipeline() .with_service_name("coresdk") - .install() + .install_batch(opentelemetry::runtime::Tokio) .unwrap(); let opentelemetry = tracing_opentelemetry::layer().with_tracer(tracer); let filter_layer = EnvFilter::try_from_default_env() @@ -26,7 +25,6 @@ pub fn tracing_init() { .with(fmt_layer) .try_init() .unwrap(); - uninstall }); }