{"id":20924417,"url":"https://github.com/validus-risk-management/ddtrace","last_synced_at":"2025-06-17T19:11:07.834Z","repository":{"id":149804516,"uuid":"621808896","full_name":"Validus-Risk-Management/ddtrace","owner":"Validus-Risk-Management","description":"Rust utilities for Datadog tracing.","archived":false,"fork":false,"pushed_at":"2024-07-22T14:04:02.000Z","size":42,"stargazers_count":4,"open_issues_count":1,"forks_count":2,"subscribers_count":4,"default_branch":"main","last_synced_at":"2025-05-13T16:37:39.962Z","etag":null,"topics":["datadog","observability","opentelemetry","tracing"],"latest_commit_sha":null,"homepage":"","language":"Rust","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Validus-Risk-Management.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-03-31T12:38:12.000Z","updated_at":"2025-01-06T09:19:44.000Z","dependencies_parsed_at":null,"dependency_job_id":"28eff311-457a-4251-b840-1ae579963595","html_url":"https://github.com/Validus-Risk-Management/ddtrace","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/Validus-Risk-Management/ddtrace","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Validus-Risk-Management%2Fddtrace","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Validus-Risk-Management%2Fddtrace/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Validus-Risk-Management%2Fddtrace/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Validus-Risk-Management%2Fddtrace/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Validus-Risk-Management","download_url":"https://codeload.github.com/Validus-Risk-Management/ddtrace/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Validus-Risk-Management%2Fddtrace/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":260424816,"owners_count":23007047,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["datadog","observability","opentelemetry","tracing"],"created_at":"2024-11-18T20:22:01.150Z","updated_at":"2025-06-17T19:11:02.802Z","avatar_url":"https://github.com/Validus-Risk-Management.png","language":"Rust","readme":"[![crates-badge]](https://crates.io/crates/ddtrace)\n[![docs-badge]](https://docs.rs/ddtrace)\n[![Crates.io](https://img.shields.io/crates/l/ddtrace)](LICENSE)\n\nDatadog tracing and log correlation for Rust services.\n\nDatadog has official support for Python, which includes various SDKs and\nother utilities (such as the Python `ddtrace` library)\nfor tracing and logging in Python applications.\n\nThey don't have similar support for Rust. However, they do support the\n[OpenTelemetry](https://opentelemetry.io/) format for both logs and traces.\nThis crate contains the necessary glue to bridge the gap between OpenTelemetry\nand Datadog.\n\n# Features\n\n`ddtrace` has the following features:\n1. tracing: utilities for building an OpenTelemetry tracer/layer that sends traces to the Datadog agent\n2. log correlation: a log formatter that converts the trace ID and span ID to the Datadog native format and injects them into the `dd.trace_id` and `dd.span_id` fields\n   ([more information](https://docs.datadoghq.com/tracing/other_telemetry/connect_logs_and_traces/opentelemetry/))\n3. propagation: a utility function to set the Datadog propagator as the global propagator\n4. axum (enabled via the `axum` feature): re-exposing the functionality of [axum-tracing-opentelemetry](https://github.com/davidB/axum-tracing-opentelemetry)\n\n# A Complete Example\n\nThe following is an example for using `ddtrace` with the `axum` feature enabled\nto set up an `axum` service with traces and logs sent to Datadog.\n\n```rust\nuse std::net::SocketAddr;\nuse std::time::Duration;\n\nuse axum::{routing::get, Router};\nuse ddtrace::axum::opentelemetry_tracing_layer;\nuse ddtrace::formatter::DatadogFormatter;\nuse ddtrace::set_global_propagator;\nuse ddtrace::tracer::{build_layer, TraceResult};\nuse tracing_subscriber::layer::SubscriberExt;\nuse tracing_subscriber::util::SubscriberInitExt;\n\n#[tokio::main]\nasync fn main() -\u003e TraceResult\u003c()\u003e {\n    let service_name = std::env::var(\"DD_SERVICE\").unwrap_or(\"my-service\".to_string());\n    let tracing_layer = build_layer(\u0026service_name)?;\n    tracing_subscriber::registry()\n        .with(tracing_subscriber::EnvFilter::new(\n            std::env::var(\"RUST_LOG\").unwrap_or_else(|_| \"info\".into()),\n        ))\n        .with(\n            tracing_subscriber::fmt::layer()\n                .json()\n                .event_format(DatadogFormatter),\n        )\n        .with(tracing_layer)\n        .init();\n    set_global_propagator();\n\n    let app = Router::new()\n        .route(\"/\", get(root))\n        .layer(opentelemetry_tracing_layer())\n        .route(\"/health\", get(health));\n\n    let addr = SocketAddr::from(([0, 0, 0, 0], 3025));\n    tracing::info!(\"listening on {}\", addr);\n    axum::Server::bind(\u0026addr)\n        .serve(app.into_make_service())\n        .with_graceful_shutdown(ddtrace::axum::shutdown_signal())\n        .await\n        .unwrap();\n\n    Ok(())\n}\n\nasync fn root() -\u003e \u0026'static str {\n    do_something().await;\n    \"Hello, World!\"\n}\n\n#[tracing::instrument]\nasync fn do_something() {\n    tokio::time::sleep(Duration::from_millis(120)).await;\n    do_something_else().await;\n    tracing::info!(\"in the middle of doing something\");\n    tokio::time::sleep(Duration::from_millis(10)).await;\n    do_something_else().await;\n    tokio::time::sleep(Duration::from_millis(20)).await;\n}\n\n#[tracing::instrument]\nasync fn do_something_else() {\n    tokio::time::sleep(Duration::from_millis(40)).await;\n}\n\nasync fn health() -\u003e \u0026'static str {\n    \"healthy\"\n}\n```\n\nPlease refer to the complete project with the `Cargo.toml`\n[here](https://github.com/Validus-Risk-Management/ddtrace/tree/main/examples/axum).\n\n# Datadog Agent Setup\n\nThe Datadog agent needs to be configured to receive OTel traces over gRPC.\nPlease [refer to the Datadog documentation](https://docs.datadoghq.com/opentelemetry/otlp_ingest_in_the_agent/?tab=docker)\nto set up the agent.\n\n# Further Context and Rationale\n\n## Exporting Traces\nFor traces, the official Datadog agent\n[can ingest OTel trace data](https://docs.datadoghq.com/opentelemetry/)\nwith the correct environment variable settings. The traces can be sent \nvia either HTTP or gRPC. More information on this can be found\n[here](https://docs.datadoghq.com/opentelemetry/otlp_ingest_in_the_agent/?tab=docker).\n\nOpenTelemetry has an official Rust crate with extensions for major \nformats/providers. This includes a Datadog exporter. We have found\nthis exporter to be less reliable than the standard OTel exporter\nsending data to the OTel endpoint of the Datadog agent, though.\nThis crate builds on the OTel exporter.\n\n## Propagation\n\nTwo commonly used propagation standards are `B3` (OpenZipkin's propagation style)\nand Jaeger. OpenTelemetry [supports both](https://opentelemetry.io/docs/reference/specification/context/api-propagators/#propagators-distribution).\n\nMost Datadog SDK's support both `B3` and the Datadog native propagation style.\nFor example, the Python `ddtrace` library supports `B3` but it\n[needs to be explicitly enabled](https://ddtrace.readthedocs.io/en/stable/configuration.html#DD_TRACE_PROPAGATION_STYLE).\n\nFor ease of integration with services written in other languages that use the official Datadog SDK,\nwe opted for sticking with Datadog-style propagation over `B3`. This is set via the\n`set_global_propagator` function.\n\n\n# Reqwest Propagation\nThe Python library takes care of propagation of the trace context automatically.\nUnfortunately, we need to do this manually in Rust.\n\nArguably, propagation in HTTP requests is the most common need.\nThis crate does not provide any additional support, but we recommend using\nthe [reqwest-middleware](https://crates.io/crates/reqwest-middleware) crate\nto inject the necessary headers when using `reqwest`.\nIf you set the global propagator using `ddtrace`, it will work out of the box.\n\n```rust\nuse ddtrace::set_global_propagator;\nuse reqwest_middleware::{ClientBuilder, ClientWithMiddleware};\nuse reqwest_tracing::TracingMiddleware;\n\n#[tokio::main]\nasync fn main() {\n    set_global_propagator();\n    client = get_http_client();\n    \n    // configure tracing, setup your app and inject the client\n}\n\nfn get_http_client() -\u003e ClientWithMiddleware {\n    ClientBuilder::new(reqwest::Client::new())\n        .with(TracingMiddleware::default())\n        .build()\n}\n```\n\n[crates-badge]: https://img.shields.io/crates/v/ddtrace.svg\n[docs-badge]: https://docs.rs/ddtrace/badge.svg\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvalidus-risk-management%2Fddtrace","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fvalidus-risk-management%2Fddtrace","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvalidus-risk-management%2Fddtrace/lists"}