Crates.io | dd-trace-layer |
lib.rs | dd-trace-layer |
version | 0.0.2 |
source | src |
created_at | 2022-10-07 02:54:40.475344 |
updated_at | 2023-06-23 03:03:32.171083 |
description | A middleware for sending Datadog's trace |
homepage | |
repository | https://github.com/pepabo/dd-trace-layer |
max_upload_size | |
id | 681717 |
size | 43,577 |
dd-trace-layer
is a middleware for sending Datadog's trace. It's based on Tower and OpenTelemetry Rust.
This can be used in hyper
or axum
, etc. See examples.
use dd_trace_layer::{init, ApiVersion, DDTraceLayer};
use hyper::{server::Server, Body, Error, Request, Response};
use std::net::SocketAddr;
use tower::{make::Shared, ServiceBuilder};
#[tokio::main]
async fn main() {
init("service_name", "http://localhost:8126", ApiVersion::Version05);
let service = ServiceBuilder::new()
.layer(DDTraceLayer::new("operation_name".to_string()))
.service_fn(hello_world);
let addr = SocketAddr::from(([127, 0, 0, 1], 8080));
Server::bind(&addr)
.serve(Shared::new(service))
.await
.expect("server error");
}
async fn hello_world(_: Request<Body>) -> Result<Response<Body>, Error> {
Ok(Response::new(Body::from("Hello, World!")))
}
cargo test
command and confirm that it passescargo fmt
and pass cargo clippy