11 breaking releases

0.12.1 Mar 29, 2021
0.11.0 Jan 22, 2021
0.10.0 Dec 28, 2020
0.9.0 Nov 10, 2020
0.2.0 Mar 24, 2020

#101 in Debugging

Download history 2698/week @ 2020-12-25 7729/week @ 2021-01-01 9814/week @ 2021-01-08 8604/week @ 2021-01-15 9643/week @ 2021-01-22 11205/week @ 2021-01-29 10812/week @ 2021-02-05 10296/week @ 2021-02-12 13958/week @ 2021-02-19 16602/week @ 2021-02-26 15156/week @ 2021-03-05 14365/week @ 2021-03-12 15256/week @ 2021-03-19 15617/week @ 2021-03-26 10821/week @ 2021-04-02 11454/week @ 2021-04-09

50,082 downloads per month
Used in 23 crates (11 directly)

Apache-2.0

725KB
14K SLoC

OpenTelemetry — An observability framework for cloud-native software.

OpenTelemetry Jaeger

Jaeger integration for applications instrumented with OpenTelemetry. This includes a jaeger exporter and a jaeger propagator.

Crates.io: opentelemetry-jaeger Documentation LICENSE GitHub Actions CI Gitter chat

Documentation | Chat

Overview

OpenTelemetry is a collection of tools, APIs, and SDKs used to instrument, generate, collect, and export telemetry data (metrics, logs, and traces) for analysis in order to understand your software's performance and behavior. This crate provides a trace pipeline and exporter for sending span information to a Jaeger agent or collector endpoint for processing and visualization.

Compiler support: requires rustc 1.46+

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::global;
use opentelemetry::trace::Tracer;

fn main() -> Result<(), Box<dyn std::error::Error + Send + Sync + 'static>> {
    global::set_text_map_propagator(opentelemetry_jaeger::Propagator::new());
    let tracer = opentelemetry_jaeger::new_pipeline().install_simple()?;

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

    global::shut_down_provider(); // sending remaining spans

    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 rt-tokio, rt-tokio-current-thread or rt-async-std features and specify a runtime on the pipeline builder to have a batch exporter configured for you automatically.

[dependencies]
opentelemetry = { version = "*", features = ["rt-tokio"] }
opentelemetry-jaeger = { version = "*", features = ["tokio"] }
let tracer = opentelemetry_jaeger::new_pipeline()
    .install_batch(opentelemetry::runtime::Tokio)?;

Jaeger Exporter From Environment Variables

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

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 = ["isahc_collector_client"] }

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

// Note that this requires one of the following features enabled so that there is a default http client implementation
// * surf_collector_client
// * reqwest_collector_client
// * reqwest_blocking_collector_client
// * isahc_collector_client

// You can also provide your own implementation by enable
// `collecor_client` and set it with
// new_pipeline().with_http_client() method.
use opentelemetry::trace::Tracer;

fn main() -> Result<(), Box<dyn std::error::Error + Send + Sync + 'static>> {
    let tracer = 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_simple()?;

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

    opentelemetry::global::shut_down_provider(); // sending remaining spans

    Ok(())
}

Kitchen Sink Full Configuration

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

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

fn main() -> Result<(), Box<dyn std::error::Error + Send + Sync + 'static>> {
    global::set_text_map_propagator(opentelemetry_jaeger::Propagator::new());
    let tracer = opentelemetry_jaeger::new_pipeline()
        .with_agent_endpoint("localhost:6831")
        .with_service_name("my_app")
        .with_tags(vec![KeyValue::new("process_key", "process_value")])
        .with_max_packet_size(9_216)
        .with_trace_config(
            trace::config()
                .with_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_batch(opentelemetry::runtime::Tokio)?;

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

    global::shut_down_provider(); // sending remaining spans

    Ok(())
}

Supported Rust Versions

OpenTelemetry is built against the latest stable release. The minimum supported version is 1.46. The current OpenTelemetry version is not guaranteed to build on Rust versions earlier than the minimum supported version.

The current stable Rust compiler and the three most recent minor versions before it will always be supported. For example, if the current stable compiler version is 1.49, the minimum supported version will not be increased past 1.46, three minor versions prior. Increasing the minimum supported compiler version is not considered a semver breaking change as long as doing so complies with this policy.

Dependencies

~2–9.5MB
~193K SLoC