8 releases (breaking)

new 0.7.0 Oct 17, 2020
0.6.0 Oct 16, 2020
0.5.0 Aug 14, 2020
0.4.0 Jul 27, 2020
0.0.1 Mar 24, 2020

#4 in #zipkin

Download history 116/week @ 2020-06-28 384/week @ 2020-07-05 737/week @ 2020-07-12 606/week @ 2020-07-19 344/week @ 2020-07-26 62/week @ 2020-08-02 60/week @ 2020-08-09 85/week @ 2020-08-16 116/week @ 2020-08-23 157/week @ 2020-08-30 136/week @ 2020-09-06 119/week @ 2020-09-13 79/week @ 2020-09-20 101/week @ 2020-09-27 123/week @ 2020-10-04 117/week @ 2020-10-11

696 downloads per month

Apache-2.0

585KB
11K SLoC

OpenTelemetry Zipkin

A Zipkin exporter implementation for OpenTelemetry Rust.


lib.rs:

OpenTelemetry Zipkin Exporter

Collects OpenTelemetry spans and reports them to a given Zipkin collector endpoint. See the Zipkin Docs for details and deployment information.

Quickstart

First make sure you have a running version of the zipkin process you want to send data to:

$ docker run -d -p 9411:9411 openzipkin/zipkin

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

use opentelemetry::api::trace::Tracer;

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

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

    Ok(())
}

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-zipkin = "*"

Bring your own http clients

Users can choose appropriate http clients to align with their runtime.

Based on the feature enabled. The default http client will be different. If user doesn't specific features or enabled reqwest-blocking-client feature. The blocking reqwest http client will be used as default client. If reqwest-client feature is enabled. The async reqwest http client will be used. If surf-client feature is enabled. The surf http client will be used.

Note that async http clients may need specific runtime otherwise it will panic. User should make sure the http client is running in appropriate runime.

Users can always use their own http clients by implementing HttpClient trait.

Kitchen Sink Full Configuration

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

use opentelemetry::api::{KeyValue, trace::Tracer};
use opentelemetry::sdk::{trace::{self, IdGenerator, Sampler}, Resource};
use opentelemetry::exporter::trace::ExportResult;
use opentelemetry::exporter::trace::HttpClient;
use async_trait::async_trait;
use std::error::Error;

// `reqwest` and `surf` are supported through features, if you prefer an
// alternate http client you can add support by implementing `HttpClient` as
// shown here.
#[derive(Debug)]
struct IsahcClient(isahc::HttpClient);

#[async_trait]
impl HttpClient for IsahcClient {
  async fn send(&self, request: http::Request<Vec<u8>>) -> Result<ExportResult, Box<dyn Error>> {
    let result = self.0.send_async(request).await?;

    if result.status().is_success() {
      Ok(ExportResult::Success)
    } else {
      Ok(ExportResult::FailedNotRetryable)
    }
  }
}

fn main() -> Result<(), Box<dyn Error>> {
    let (tracer, _uninstall) = opentelemetry_zipkin::new_pipeline()
        .with_http_client(IsahcClient(isahc::HttpClient::new()?))
        .with_service_name("my_app")
        .with_service_address("127.0.0.1:8080".parse()?)
        .with_collector_endpoint("http://localhost:9411/api/v2/spans")
        .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.5–8MB
~181K SLoC