Add OpenTelemetry tracing and metrics support to your tide application. Be part of the new observability movement!
```sh
docker run -d \ -p6831:6831/udp -p6832:6832/udp -p16686:16686 -p14268:14268 \ jaegertracing/all-in-one:latest
cargo run --example server
curl http://localhost:3000/
firefox http://localhost:16686/
curl http://localhost:3000/metrics ```
Cargo.toml
```toml
[dependencies] async-std = { version = "1.9", features = ["attributes"] } opentelemetry = { version = "0.14", features = ["async-std", "rt-async-std"] } opentelemetry-jaeger = { version = "0.13", features = ["async-std"] } opentelemetry-tide = "0.8" tide = "0.16" ```
server.rs
```rust use opentelemetry::{global, KeyValue, runtime}; use opentelemetrysemanticconventions::resource; use opentelemetry_tide::TideExt;
const VERSION: &'static str = env!("CARGOPKGVERSION");
async fn main() -> Result<(), Box
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(())
} ```
| 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
This crate uses #![forbid(unsafe_code)]
to ensure everything is implemented in 100% Safe Rust.
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.