Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update to opentelem dependencies, and trace ID resolving #5

Draft
wants to merge 6 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
target/
Cargo.lock
.idea/
.idea/
.DS_Store
15 changes: 8 additions & 7 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "ddtrace"
version = "0.1.1"
version = "0.1.2"
authors = ["David Steiner <[email protected]", "Fergus Strangways-Dixon <[email protected]>"]
edition = "2021"
license = "MIT"
Expand All @@ -16,16 +16,17 @@ exclude = [".pre-commit-config.yaml"]
axum = ["dep:axum", "dep:tokio", "dep:axum-tracing-opentelemetry"]

[dependencies]
axum = { version = "^0.6.10", optional = true }
axum-tracing-opentelemetry = { version = "^0.11.0", optional = true }
axum = { version = "^0.7.5", optional = true }
axum-tracing-opentelemetry = { version = "0.19.0", optional = true }
chrono = "^0.4.24"
opentelemetry = { version = "^0.19.0", features = ["rt-tokio"] }
opentelemetry-datadog = "^0.7.0"
opentelemetry-otlp = { version = "^0.12.0" }
opentelemetry = { version = "0.23.0" }
opentelemetry-datadog = "0.11.0"
opentelemetry-otlp = { version = "0.16.0" , features = ["tls-roots"]}
opentelemetry_sdk = { version = "0.23.0", features = ["rt-tokio"] }
serde = { version = "^1.0.156", features = ["derive"] }
serde_json = "^1.0.95"
tokio = { version = "^1.26.0", features = ["signal"], optional = true }
tracing = "^0.1.37"
tracing-opentelemetry = "^0.19.0"
tracing-opentelemetry = "0.24.0"
tracing-serde = "^0.1.3"
tracing-subscriber = { version = "^0.3.16", features = ["env-filter", "json"] }
4 changes: 1 addition & 3 deletions src/axum.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,7 @@
//!
//! [`axum-tracing-opentelemetry`]: https://github.com/davidB/axum-tracing-opentelemetry

pub use axum_tracing_opentelemetry::opentelemetry_tracing_layer;
pub use axum_tracing_opentelemetry::opentelemetry_tracing_layer_grpc;

pub use axum_tracing_opentelemetry::middleware::OtelAxumLayer;
pub async fn shutdown_signal() {
tokio::signal::unix::signal(tokio::signal::unix::SignalKind::terminate())
.expect("failed to install signal handler")
Expand Down
3 changes: 2 additions & 1 deletion src/formatter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use std::io;

use chrono::Utc;
use opentelemetry::trace::TraceContextExt;
use opentelemetry::trace::{SpanId, TraceId};
use serde::ser::{SerializeMap, Serializer as _};
use serde::Serialize;
Expand Down Expand Up @@ -45,7 +46,7 @@ where
S: Subscriber + for<'a> LookupSpan<'a>,
{
span_ref.extensions().get::<OtelData>().map(|o| TraceInfo {
trace_id: o.builder.trace_id.unwrap_or(TraceId::INVALID).into(),
trace_id: o.parent_cx.span().span_context().trace_id().into(),
span_id: o.builder.span_id.unwrap_or(SpanId::INVALID).into(),
})
}
Expand Down
7 changes: 3 additions & 4 deletions src/tracer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@
//! to send traces to the Datadog agent in batches over gRPC.
//!
//! It also contains a convenience function to build a layer with the tracer.
use opentelemetry::sdk::trace::{RandomIdGenerator, Sampler, Tracer};
use opentelemetry::sdk::{trace, Resource};
pub use opentelemetry::trace::{TraceError, TraceResult};
use opentelemetry::KeyValue;
use opentelemetry_otlp::WithExportConfig;
use opentelemetry_sdk::trace::{RandomIdGenerator, Sampler, Tracer};
use opentelemetry_sdk::{trace, Resource};
use std::time::Duration;
use tracing::Subscriber;
use tracing_opentelemetry::{OpenTelemetryLayer, PreSampledTracer};
Expand All @@ -18,7 +18,6 @@ pub fn build_tracer(service_name: &str) -> TraceResult<Tracer> {
let exporter = opentelemetry_otlp::new_exporter()
.tonic()
.with_timeout(Duration::from_secs(3));

opentelemetry_otlp::new_pipeline()
.tracing()
.with_trace_config(
Expand All @@ -31,7 +30,7 @@ pub fn build_tracer(service_name: &str) -> TraceResult<Tracer> {
.with_id_generator(RandomIdGenerator::default()),
)
.with_exporter(exporter)
.install_batch(opentelemetry::runtime::Tokio)
.install_batch(opentelemetry_sdk::runtime::Tokio)
}

pub fn build_layer<S>(service_name: &str) -> TraceResult<OpenTelemetryLayer<S, Tracer>>
Expand Down
Loading