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:

shell $ 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:

```rust use opentelemetry::api::Tracer;

fn main() -> Result<(), Box> { let (tracer, uninstall) = opentelemetryjaeger::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.

toml [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].

```rust use opentelemetry::api::Tracer;

fn main() -> Result<(), Box> { // export OTELSERVICENAME=my-service-name let (tracer, uninstall) = opentelemetryjaeger::newpipeline().fromenv().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.

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

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

``rust // Note that this requires thecollector_client` feature. use opentelemetry::api::Tracer;

fn main() -> Result<(), Box> { let (tracer, uninstall) = opentelemetryjaeger::newpipeline() .withcollectorendpoint("http://localhost:14268/api/traces") // optionally set username and password as well. .withcollectorusername("username") .withcollector_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.

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

fn main() -> Result<(), Box> { let (tracer, uninstall) = opentelemetryjaeger::newpipeline() .fromenv() .withagentendpoint("localhost:6831") .withservicename("myapp") .withtags(vec![KeyValue::new("processkey", "processvalue")]) .withmaxpacketsize(65000) .withtraceconfig( trace::config() .withdefaultsampler(Sampler::AlwaysOn) .withidgenerator(IdGenerator::default()) .withmaxeventsperspan(64) .withmaxattributesperspan(16) .withmaxeventsperspan(16) .with_resource(Resource::new(vec![KeyValue::new("key", "value")])), ) .install()?;

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

Ok(())

} ```