Skip to content

Commit

Permalink
opentelemetry: update opentelemetry to 0.15 (#1441)
Browse files Browse the repository at this point in the history
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
  • Loading branch information
Drevoed authored and hawkw committed Jun 26, 2021
1 parent 1e361e4 commit bc1c3a3
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 21 deletions.
4 changes: 2 additions & 2 deletions examples/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
6 changes: 3 additions & 3 deletions tracing-opentelemetry/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "tracing-opentelemetry"
version = "0.13.0"
version = "0.14.0"
authors = [
"Julian Tescher <julian@tescher.me>",
"Tokio Contributors <team@tokio.rs>"
Expand All @@ -22,16 +22,16 @@ 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"] }
tracing-log = { path = "../tracing-log", version = "0.1", default-features = false, optional = true }

[dev-dependencies]
async-trait = "0.1"
opentelemetry-jaeger = "0.13"
criterion = { version = "0.3", default_features = false }
opentelemetry-jaeger = "0.14"

[lib]
bench = false
Expand Down
4 changes: 2 additions & 2 deletions tracing-opentelemetry/src/layer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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(),
)));
Expand Down
28 changes: 14 additions & 14 deletions tracing-opentelemetry/src/tracer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
};
Expand Down Expand Up @@ -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();
Expand All @@ -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,
Expand All @@ -154,20 +154,20 @@ 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())),
}
}

#[cfg(test)]
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() {
Expand All @@ -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),
Expand Down Expand Up @@ -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),
Expand Down

0 comments on commit bc1c3a3

Please sign in to comment.