8 releases (breaking)

new 0.8.0 Oct 16, 2020
0.7.0 Aug 14, 2020
0.6.0 Jul 27, 2020
0.5.0 Jun 2, 2020
0.1.0 Feb 8, 2020

#73 in Debugging

Download history 1587/week @ 2020-06-28 2073/week @ 2020-07-05 2161/week @ 2020-07-12 1820/week @ 2020-07-19 2378/week @ 2020-07-26 2853/week @ 2020-08-02 4294/week @ 2020-08-09 3786/week @ 2020-08-16 4196/week @ 2020-08-23 3396/week @ 2020-08-30 3110/week @ 2020-09-06 3184/week @ 2020-09-13 3908/week @ 2020-09-20 5007/week @ 2020-09-27 4906/week @ 2020-10-04 3980/week @ 2020-10-11

15,229 downloads per month
Used in 18 crates (6 directly)

Apache-2.0

680KB
13K SLoC

OpenTelemetry Jaeger

Collects OpenTelemetry spans and reports them to a given Jaeger agent or collector endpoint. See the Jaeger Docs for details about Jaeger and deployment information.

Quickstart

First make sure you have a running version of the Jaeger instance you want to send data to:

$ docker run -d -p6831:6831/udp -p6832:6832/udp -p16686:16686 -p14268:14268 jaegertracing/all-in-one:latest

Then install a new jaeger pipeline with the recommended defaults to start exporting telemetry:

use opentelemetry::api::Tracer;

fn main() -> Result<(), Box<dyn std::error::Error>> {
    let (tracer, _uninstall) = opentelemetry_jaeger::new_pipeline().install()?;

    tracer.in_span("doing_work", |cx| {
        // Traced app logic here...
    });

    Ok(())
}

Jaeger UI

Performance

For optimal performance, a batch exporter is recommended as the simple exporter will export each span synchronously on drop. You can enable the tokio or async-std features to have a batch exporter configured for you automatically for either executor when you install the pipeline.

[dependencies]
opentelemetry = { version = "*", features = ["tokio"] }
opentelemetry-jaeger = { version = "*", features = ["tokio"] }

Jaeger Exporter From Environment Variables

The jaeger pipeline builder can be configured dynamically via the from_env method. All variables are optional, a full list of accepted options can be found in the jaeger variables spec.

use opentelemetry::api::Tracer;

fn main() -> Result<(), Box<dyn std::error::Error>> {
    // export OTEL_SERVICE_NAME=my-service-name
    let (tracer, _uninstall) = opentelemetry_jaeger::new_pipeline().from_env().install()?;

    tracer.in_span("doing_work", |cx| {
        // Traced app logic here...
    });

    Ok(())
}

Jaeger Collector Example

If you want to skip the agent and submit spans directly to a Jaeger collector, you can enable the optional collector_client feature for this crate. This example expects a Jaeger collector running on http://localhost:14268.

[dependencies]
opentelemetry-jaeger = { version = "..", features = ["collector_client"] }

Then you can use the with_collector_endpoint method to specify the endpoint:

// Note that this requires the `collector_client` feature.
use opentelemetry::api::Tracer;

fn main() -> Result<(), Box<dyn std::error::Error>> {
    let (tracer, _uninstall) = opentelemetry_jaeger::new_pipeline()
        .with_collector_endpoint("http://localhost:14268/api/traces")
        // optionally set username and password as well.
        .with_collector_username("username")
        .with_collector_password("s3cr3t")
        .install()?;

    tracer.in_span("doing_work", |cx| {
        // Traced app logic here...
    });

    Ok(())
}

Kitchen Sink Full Configuration

Example showing how to override all configuration options. See the PipelineBuilder docs for details of each option.

use opentelemetry::api::{KeyValue, Tracer};
use opentelemetry::sdk::{trace, IdGenerator, Resource, Sampler};

fn main() -> Result<(), Box<dyn std::error::Error>> {
    let (tracer, _uninstall) = opentelemetry_jaeger::new_pipeline()
        .from_env()
        .with_agent_endpoint("localhost:6831")
        .with_service_name("my_app")
        .with_tags(vec![KeyValue::new("process_key", "process_value")])
        .with_max_packet_size(65_000)
        .with_trace_config(
            trace::config()
                .with_default_sampler(Sampler::AlwaysOn)
                .with_id_generator(IdGenerator::default())
                .with_max_events_per_span(64)
                .with_max_attributes_per_span(16)
                .with_max_events_per_span(16)
                .with_resource(Resource::new(vec![KeyValue::new("key", "value")])),
        )
        .install()?;

    tracer.in_span("doing_work", |cx| {
        // Traced app logic here...
    });

    Ok(())
}

Dependencies

~3–8MB
~167K SLoC