10 releases (5 breaking)

0.7.0 Apr 2, 2021
0.6.2 Mar 8, 2021
0.6.1 Jan 26, 2021
0.5.2 Dec 16, 2020
0.1.0 Jul 31, 2020

#34 in HTTP server

Download history 16/week @ 2020-12-18 6/week @ 2020-12-25 8/week @ 2021-01-01 29/week @ 2021-01-08 28/week @ 2021-01-15 22/week @ 2021-01-22 10/week @ 2021-01-29 8/week @ 2021-02-05 36/week @ 2021-02-12 12/week @ 2021-02-19 6/week @ 2021-02-26 55/week @ 2021-03-05 4/week @ 2021-03-12 21/week @ 2021-03-19 23/week @ 2021-03-26 48/week @ 2021-04-02

87 downloads per month

MIT/Apache

33KB
326 lines


opentelemetry-tide

OpenTelemetry integration for Tide


Add OpenTelemetry tracing and metrics support to your tide application. Be part of the new observability movement!

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/

# Check the prometheus metrics endpoint
curl http://localhost:3000/metrics

Example

Cargo.toml

# ...

[dependencies]
async-std = { version = "1.9", features = ["attributes"] }
opentelemetry = { version = "0.13", features = ["async-std", "rt-async-std"] }
opentelemetry-jaeger = { version = "0.12", features = ["async-std"] }
opentelemetry-tide = "0.7"
tide = "0.16"

server.rs

use opentelemetry::{global, KeyValue, runtime};
use opentelemetry_semantic_conventions::resource;
use opentelemetry_tide::TideExt;

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

#[async_std::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    tide::log::with_level(tide::log::LevelFilter::Warn);

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

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

    let metrics_kvs = vec![KeyValue::new("K", "V")];

    let mut app = tide::new();

    app.with_middlewares(tracer, Some(metrics_kvs));

    app.at("/").get(|_| async move {
        Ok("Hello, OpenTelemetry!")
    });

    app.listen("0.0.0.0:3000").await?;

    global::shutdown_tracer_provider();

    Ok(())
}

Cargo Features

flag description
trace enables tracing middleware; enabled by default via full
metrics enables metrics middleware; enabled by default via full
full includes both trace and metrics features, enabled by default

Safety

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

License

Licensed under either of Apache License, Version 2.0 or MIT license at your option.
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in this crate by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.

Dependencies

~7–10MB
~206K SLoC