GithubHelp home page GithubHelp logo

asaaki / opentelemetry-tide Goto Github PK

View Code? Open in Web Editor NEW
19.0 2.0 4.0 248 KB

๐Ÿ”ญ๐ŸŒŠ OpenTelemetry integration for Tide

Home Page: https://crates.io/crates/opentelemetry-tide

License: Apache License 2.0

Rust 100.00%
opentelemetry opentelemetry-rust rust tracing metrics opentelemetry-tide otel

opentelemetry-tide's Introduction


opentelemetry-tide

OpenTelemetry integration for Tide


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

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.
  • It provides basic prometheus metrics, based on the RED method.
  • This project got inspired by https://github.com/OutThereLabs/actix-web-opentelemetry.
  • 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/

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

Example

Cargo.toml

# ...

[dependencies]
async-std = { version = "1.10", features = ["attributes"] }
opentelemetry = { version = "0.17.0", features = ["rt-async-std"] }
opentelemetry-jaeger = { version = "0.16.0", features = ["rt-async-std"] }
opentelemetry-tide = "0.12"
tide = "0.16"

server.rs

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

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_tags(tags.iter().map(ToOwned::to_owned))
        .install_batch(runtime::AsyncStd)
        .expect("pipeline install failure");
    let tracer = global::tracer("example-server");

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

    let mut app = tide::new();

    // use the trait
    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
metrics enables metrics middleware; 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.

opentelemetry-tide's People

Contributors

arlyon avatar asaaki avatar dependabot[bot] avatar fiag avatar kyrias avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Forkers

arlyon fiag kyrias

opentelemetry-tide's Issues

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.