From bc1c3a32ec52a2221b84518d621697896f76caca Mon Sep 17 00:00:00 2001 From: Kirill Mironov Date: Mon, 21 Jun 2021 21:53:45 +0300 Subject: [PATCH] opentelemetry: update opentelemetry to 0.15 (#1441) This backports PR #1441 from `master` ## Motivation Newest versions of opentelemetry and opentelemetry-jaeger don't work with the tracing-opentelemtry due to the latter still depending on a 0.14 version. ## Solution Adjust dependencies and use new TraceFlags struct instead of constants --- examples/Cargo.toml | 4 ++-- tracing-opentelemetry/Cargo.toml | 6 +++--- tracing-opentelemetry/src/layer.rs | 4 ++-- tracing-opentelemetry/src/tracer.rs | 28 ++++++++++++++-------------- 4 files changed, 21 insertions(+), 21 deletions(-) diff --git a/examples/Cargo.toml b/examples/Cargo.toml index 08fdff3f97..061bc877a3 100644 --- a/examples/Cargo.toml +++ b/examples/Cargo.toml @@ -53,5 +53,5 @@ inferno = "0.10.0" tempdir = "0.3.7" # opentelemetry example -opentelemetry = { version = "0.14", default-features = false, features = ["trace"] } -opentelemetry-jaeger = "0.13" +opentelemetry = { version = "0.15", default-features = false, features = ["trace"] } +opentelemetry-jaeger = "0.14" diff --git a/tracing-opentelemetry/Cargo.toml b/tracing-opentelemetry/Cargo.toml index 708162c4e7..e5f426bc43 100644 --- a/tracing-opentelemetry/Cargo.toml +++ b/tracing-opentelemetry/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "tracing-opentelemetry" -version = "0.13.0" +version = "0.14.0" authors = [ "Julian Tescher ", "Tokio Contributors " @@ -22,7 +22,7 @@ edition = "2018" default = ["tracing-log"] [dependencies] -opentelemetry = { version = "0.14", default-features = false, features = ["trace"] } +opentelemetry = { version = "0.15", default-features = false, features = ["trace"] } tracing = { path = "../tracing", version = "0.1", default-features = false, features = ["std"] } tracing-core = { path = "../tracing-core", version = "0.1" } tracing-subscriber = { path = "../tracing-subscriber", version = "0.2", default-features = false, features = ["registry"] } @@ -30,8 +30,8 @@ tracing-log = { path = "../tracing-log", version = "0.1", default-features = fal [dev-dependencies] async-trait = "0.1" -opentelemetry-jaeger = "0.13" criterion = { version = "0.3", default_features = false } +opentelemetry-jaeger = "0.14" [lib] bench = false diff --git a/tracing-opentelemetry/src/layer.rs b/tracing-opentelemetry/src/layer.rs index 7d24d5b025..bf3d5380f8 100644 --- a/tracing-opentelemetry/src/layer.rs +++ b/tracing-opentelemetry/src/layer.rs @@ -615,7 +615,7 @@ impl Timings { #[cfg(test)] mod tests { use super::*; - use opentelemetry::trace::SpanKind; + use opentelemetry::trace::{SpanKind, TraceFlags}; use std::borrow::Cow; use std::sync::{Arc, Mutex}; use std::time::SystemTime; @@ -744,7 +744,7 @@ mod tests { let existing_cx = OtelContext::current_with_span(TestSpan(otel::SpanContext::new( trace_id, otel::SpanId::from_u64(1), - 0, + TraceFlags::default(), false, Default::default(), ))); diff --git a/tracing-opentelemetry/src/tracer.rs b/tracing-opentelemetry/src/tracer.rs index 9c7d3d445b..200219cc48 100644 --- a/tracing-opentelemetry/src/tracer.rs +++ b/tracing-opentelemetry/src/tracer.rs @@ -2,8 +2,8 @@ use opentelemetry::sdk::trace::{SamplingDecision, SamplingResult, Tracer, Tracer use opentelemetry::{ trace as otel, trace::{ - SpanBuilder, SpanContext, SpanId, SpanKind, TraceContextExt, TraceId, TraceState, - TRACE_FLAG_SAMPLED, + SpanBuilder, SpanContext, SpanId, SpanKind, TraceContextExt, TraceFlags, TraceId, + TraceState, }, Context as OtelContext, }; @@ -124,7 +124,7 @@ fn current_trace_state( builder: &SpanBuilder, parent_cx: &OtelContext, provider: &TracerProvider, -) -> (bool, TraceId, bool, u8) { +) -> (bool, TraceId, bool, TraceFlags) { if parent_cx.has_active_span() { let span = parent_cx.span(); let sc = span.span_context(); @@ -136,15 +136,15 @@ fn current_trace_state( .trace_id .unwrap_or_else(|| provider.config().id_generator.new_trace_id()), false, - 0, + Default::default(), ) } } fn process_sampling_result( sampling_result: &SamplingResult, - trace_flags: u8, -) -> Option<(u8, TraceState)> { + trace_flags: TraceFlags, +) -> Option<(TraceFlags, TraceState)> { match sampling_result { SamplingResult { decision: SamplingDecision::Drop, @@ -154,12 +154,12 @@ fn process_sampling_result( decision: SamplingDecision::RecordOnly, trace_state, .. - } => Some((trace_flags & !TRACE_FLAG_SAMPLED, trace_state.clone())), + } => Some((trace_flags & !TraceFlags::SAMPLED, trace_state.clone())), SamplingResult { decision: SamplingDecision::RecordAndSample, trace_state, .. - } => Some((trace_flags | TRACE_FLAG_SAMPLED, trace_state.clone())), + } => Some((trace_flags | TraceFlags::SAMPLED, trace_state.clone())), } } @@ -167,7 +167,7 @@ fn process_sampling_result( mod tests { use super::*; use opentelemetry::sdk::trace::{config, Sampler, TracerProvider}; - use opentelemetry::trace::{SpanBuilder, SpanId, TracerProvider as _, TRACE_FLAG_NOT_SAMPLED}; + use opentelemetry::trace::{SpanBuilder, SpanId, TracerProvider as _}; #[test] fn assigns_default_trace_id_if_missing() { @@ -191,10 +191,10 @@ mod tests { ("empty_parent_cx_always_off", Sampler::AlwaysOff, OtelContext::new(), None, false), // Remote parent samples - ("remote_parent_cx_always_on", Sampler::AlwaysOn, OtelContext::new().with_remote_span_context(span_context(TRACE_FLAG_SAMPLED, true)), None, true), - ("remote_parent_cx_always_off", Sampler::AlwaysOff, OtelContext::new().with_remote_span_context(span_context(TRACE_FLAG_SAMPLED, true)), None, false), - ("sampled_remote_parent_cx_parent_based", Sampler::ParentBased(Box::new(Sampler::AlwaysOff)), OtelContext::new().with_remote_span_context(span_context(TRACE_FLAG_SAMPLED, true)), None, true), - ("unsampled_remote_parent_cx_parent_based", Sampler::ParentBased(Box::new(Sampler::AlwaysOn)), OtelContext::new().with_remote_span_context(span_context(TRACE_FLAG_NOT_SAMPLED, true)), None, false), + ("remote_parent_cx_always_on", Sampler::AlwaysOn, OtelContext::new().with_remote_span_context(span_context(TraceFlags::SAMPLED, true)), None, true), + ("remote_parent_cx_always_off", Sampler::AlwaysOff, OtelContext::new().with_remote_span_context(span_context(TraceFlags::SAMPLED, true)), None, false), + ("sampled_remote_parent_cx_parent_based", Sampler::ParentBased(Box::new(Sampler::AlwaysOff)), OtelContext::new().with_remote_span_context(span_context(TraceFlags::SAMPLED, true)), None, true), + ("unsampled_remote_parent_cx_parent_based", Sampler::ParentBased(Box::new(Sampler::AlwaysOn)), OtelContext::new().with_remote_span_context(span_context(TraceFlags::default(), true)), None, false), // Existing sampling result defers ("previous_drop_result_always_on", Sampler::AlwaysOn, OtelContext::new(), Some(SamplingResult { decision: SamplingDecision::Drop, attributes: vec![], trace_state: Default::default() }), false), @@ -227,7 +227,7 @@ mod tests { } } - fn span_context(trace_flags: u8, is_remote: bool) -> SpanContext { + fn span_context(trace_flags: TraceFlags, is_remote: bool) -> SpanContext { SpanContext::new( TraceId::from_u128(1), SpanId::from_u64(1),