Skip to content

Commit

Permalink
Use separate version in tracing example
Browse files Browse the repository at this point in the history
  • Loading branch information
frigus02 committed Oct 17, 2020
1 parent 428a426 commit c040597
Show file tree
Hide file tree
Showing 7 changed files with 48 additions and 17 deletions.
7 changes: 7 additions & 0 deletions .github/workflows/ci.yml
Expand Up @@ -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:
Expand All @@ -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
2 changes: 1 addition & 1 deletion .gitignore
@@ -1,2 +1,2 @@
/target
target/
Cargo.lock
13 changes: 5 additions & 8 deletions Cargo.toml
Expand Up @@ -19,7 +19,6 @@ exclude = [
]

[features]
default = []
reqwest-blocking-client = ["reqwest", "reqwest/blocking"]
reqwest-client = ["reqwest"]
surf-client = ["surf"]
Expand All @@ -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" }
15 changes: 15 additions & 0 deletions examples/tracing/Cargo.toml
@@ -0,0 +1,15 @@
[package]
name = "tracing"
version = "0.1.0"
authors = ["Jan Kuehle <jkuehle90@gmail.com>"]
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"
5 changes: 5 additions & 0 deletions 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`.
14 changes: 7 additions & 7 deletions examples/tracing.rs → 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;
Expand Down Expand Up @@ -43,18 +44,17 @@ async fn run_in_child_process() {

#[tokio::main]
async fn main() -> Result<(), Box<dyn Error>> {
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");
Expand Down
9 changes: 8 additions & 1 deletion src/lib.rs
Expand Up @@ -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};
Expand All @@ -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()
//! }
//!
Expand Down Expand Up @@ -168,9 +169,12 @@ impl<C> PipelineBuilder<C> {
///
/// 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();
/// ```
Expand All @@ -182,10 +186,13 @@ impl<C> PipelineBuilder<C> {

/// 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"),
Expand Down

0 comments on commit c040597

Please sign in to comment.