From c04059726c4f483e370ff28f1f4162b733c0fdcd Mon Sep 17 00:00:00 2001 From: Jan Kuehle Date: Sat, 17 Oct 2020 17:53:10 +0100 Subject: [PATCH] Use separate version in tracing example --- .github/workflows/ci.yml | 7 +++++++ .gitignore | 2 +- Cargo.toml | 13 +++++-------- examples/tracing/Cargo.toml | 15 +++++++++++++++ examples/tracing/README.md | 5 +++++ examples/{tracing.rs => tracing/src/main.rs} | 14 +++++++------- src/lib.rs | 9 ++++++++- 7 files changed, 48 insertions(+), 17 deletions(-) create mode 100644 examples/tracing/Cargo.toml create mode 100644 examples/tracing/README.md rename examples/{tracing.rs => tracing/src/main.rs} (88%) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 85faa03..0454510 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -16,6 +16,7 @@ jobs: uses: actions-rs/cargo@v1 with: command: test + args: --all-features - name: Run cargo fmt uses: actions-rs/cargo@v1 with: @@ -25,3 +26,9 @@ jobs: uses: actions-rs/cargo@v1 with: command: clippy + args: --all-features + - name: Build tracing example + uses: actions-rs/cargo@v1 + with: + command: build + args: --manifest-path examples/tracing/Cargo.toml diff --git a/.gitignore b/.gitignore index 96ef6c0..2c96eb1 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,2 @@ -/target +target/ Cargo.lock diff --git a/Cargo.toml b/Cargo.toml index ee4803e..e28c390 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -19,7 +19,6 @@ exclude = [ ] [features] -default = [] reqwest-blocking-client = ["reqwest", "reqwest/blocking"] reqwest-client = ["reqwest"] surf-client = ["surf"] @@ -39,16 +38,14 @@ surf = { version = "2.0", optional = true } [dev-dependencies] backtrace = "0.3.50" -env_logger = "0.7.1" -opentelemetry-application-insights = { path = ".", features = ["reqwest-client"] } +env_logger = "0.8.1" +opentelemetry-application-insights = { path = ".", features = ["reqwest-client", "reqwest-blocking-client"] } test-case = "1.0.0" tokio = { version = "0.3.0", features = ["macros", "process", "rt-multi-thread", "time"] } -tracing = "0.1.19" -tracing-attributes = "0.1.10" -tracing-futures = "0.2.4" -tracing-opentelemetry = "0.8.0" -tracing-subscriber = "0.2.11" version-sync = "0.9.1" +[package.metadata.docs.rs] +all-features = true + [badges] github = { repository = "frigus02/opentelemetry-application-insights", workflow = "CI" } diff --git a/examples/tracing/Cargo.toml b/examples/tracing/Cargo.toml new file mode 100644 index 0000000..f067a1a --- /dev/null +++ b/examples/tracing/Cargo.toml @@ -0,0 +1,15 @@ +[package] +name = "tracing" +version = "0.1.0" +authors = ["Jan Kuehle "] +edition = "2018" + +[dependencies] +opentelemetry = "0.8.0" +opentelemetry-application-insights = "0.4.0" +tokio = { version = "0.3.0", features = ["macros", "process", "rt-multi-thread", "time"] } +tracing = "0.1.21" +tracing-attributes = "0.1.11" +tracing-futures = "0.2.4" +tracing-opentelemetry = "0.8.0" +tracing-subscriber = "0.2.13" diff --git a/examples/tracing/README.md b/examples/tracing/README.md new file mode 100644 index 0000000..483dd5a --- /dev/null +++ b/examples/tracing/README.md @@ -0,0 +1,5 @@ +# `tracing` example + +This example shows how to use OpenTelemetry and the OpenTelemetry Application Insights exporter with [`tracing`](https://crates.io/crates/tracing). + +Note: Because this relies on `tracing-opentelemetry`, which also has a dependency on `opentelemetry` itself, this example does not use the latest master version of `opentelemetry-application-insights`. diff --git a/examples/tracing.rs b/examples/tracing/src/main.rs similarity index 88% rename from examples/tracing.rs rename to examples/tracing/src/main.rs index 475be16..5bfe771 100644 --- a/examples/tracing.rs +++ b/examples/tracing/src/main.rs @@ -1,5 +1,6 @@ use opentelemetry::{ - api::propagation::TextMapPropagator, sdk::propagation::TraceContextPropagator, + api::{HttpTextFormat, Provider, TraceContextPropagator}, + sdk, }; use std::collections::HashMap; use std::env; @@ -43,18 +44,17 @@ async fn run_in_child_process() { #[tokio::main] async fn main() -> Result<(), Box> { - env_logger::init(); - let mut iter = env::args(); let process_name = iter.next().expect("0th argument should exist"); let traceparent = iter.next(); let instrumentation_key = env::var("INSTRUMENTATION_KEY").expect("env var INSTRUMENTATION_KEY should exist"); - let (tracer, _uninstall) = - opentelemetry_application_insights::new_pipeline(instrumentation_key) - .with_client(reqwest::Client::new()) - .install(); + let exporter = opentelemetry_application_insights::Exporter::new(instrumentation_key); + let provider = sdk::Provider::builder() + .with_simple_exporter(exporter) + .build(); + let tracer = provider.get_tracer("example-tracing"); let telemetry = tracing_opentelemetry::layer().with_tracer(tracer); let subscriber = Registry::default().with(telemetry); tracing::subscriber::set_global_default(subscriber).expect("setting global default failed"); diff --git a/src/lib.rs b/src/lib.rs index b3ee10d..9fe7ecf 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -8,7 +8,7 @@ //! # Usage //! //! Configure a OpenTelemetry pipeline using the Application Insights exporter and start creating -//! spans: +//! spans (this example requires the **reqwest-client-blocking** feature): //! //! ```no_run //! use opentelemetry::{api::trace::Tracer as _, sdk::trace::Tracer}; @@ -17,6 +17,7 @@ //! fn init_tracer() -> (Tracer, Uninstall) { //! let instrumentation_key = "...".to_string(); //! opentelemetry_application_insights::new_pipeline(instrumentation_key) +//! .with_client(reqwest::blocking::Client::new()) //! .install() //! } //! @@ -168,9 +169,12 @@ impl PipelineBuilder { /// /// Default: 1.0 /// + /// Note: This example requires the **reqwest-client-blocking** feature. + /// /// ``` /// let sample_rate = 0.3; /// let (tracer, _uninstall) = opentelemetry_application_insights::new_pipeline("...".into()) + /// .with_client(reqwest::blocking::Client::new()) /// .with_sample_rate(sample_rate) /// .install(); /// ``` @@ -182,10 +186,13 @@ impl PipelineBuilder { /// Assign the SDK config for the exporter pipeline. /// + /// Note: This example requires the **reqwest-client-blocking** feature. + /// /// ``` /// # use opentelemetry::{api::KeyValue, sdk}; /// # use std::sync::Arc; /// let (tracer, _uninstall) = opentelemetry_application_insights::new_pipeline("...".into()) + /// .with_client(reqwest::blocking::Client::new()) /// .with_trace_config(sdk::trace::Config { /// resource: Arc::new(sdk::Resource::new(vec![ /// KeyValue::new("service.name", "my-application"),