opentelemetry-tide 0.6.1

OpenTelemetry integration for Tide
Documentation

OpenTelemetry integration for Tide

Notes

  • It only implements very basic request tracing on the middleware layer. If you need spans for your executed code, you need to add them yourself.
  • The majority of the implementation is based on https://github.com/OutThereLabs/actix-web-opentelemetry.
  • It does not provide metrics, so it cannot be used for Prometheus metrics. Yet. Maybe I'll add it in the future. Or you want to contribute the extension. ;-)
  • You probably do not want to use it in production. 🤷

How to use

# Run jaeger in background
docker run -d \
  -p6831:6831/udp -p6832:6832/udp -p16686:16686 -p14268:14268 \
  jaegertracing/all-in-one:latest

# Run server example with tracing middleware
cargo run --example server

# Make a request or two ...
curl http://localhost:3000/

# Open browser and view the traces
firefox http://localhost:16686/

example jaeger trace

Code example

Cargo.toml

[dependencies]
async-std = {version =  "1.9", features = ["attributes"]}
opentelemetry = { version = "0.12", features = ["async-std"] }
opentelemetry-jaeger = { version = "0.11", features = ["async-std"] }
opentelemetry-tide = "0.6"
tide = "0.15"

server.rs

use opentelemetry::global as otel_global;
use opentelemetry::sdk::propagation::TraceContextPropagator;
use opentelemetry_semantic_conventions::resource;
use opentelemetry_tide::OpenTelemetryTracingMiddleware;

const VERSION: &str = env!("CARGO_PKG_VERSION");

#[async_std::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    tide::log::start();
    otel_global::set_text_map_propagator(TraceContextPropagator::new());

    let tags = [resource::SERVICE_VERSION.string(VERSION)];

    let (tracer, _uninstall) = opentelemetry_jaeger::new_pipeline()
        .with_service_name("example-server")
        .with_tags(tags.iter().map(ToOwned::to_owned))
        .install()
        .expect("pipeline install failure");

    let mut app = tide::new();
    app.with(OpenTelemetryTracingMiddleware::new(tracer));
    app.at("/").get(|_| async move { Ok("Hello, OpenTelemetry!") });
    app.listen("127.0.0.1:3000").await?;

    Ok(())
}

Cargo Features:

Safety

This crate uses #![forbid(unsafe_code)] to ensure everything is implemented in 100% Safe Rust.

License