From 6d31a50148dde4be20e61acfa7fe77168afc3fd0 Mon Sep 17 00:00:00 2001 From: Julian Tescher Date: Wed, 11 Aug 2021 13:43:40 -0700 Subject: [PATCH] opentelemetry: update to otel v0.16.x (#1497) (#1500) Updates to the latest otel spec version and addresses small internal method and module updates. --- tracing-opentelemetry/Cargo.toml | 4 ++-- tracing-opentelemetry/benches/trace.rs | 4 ++-- tracing-opentelemetry/src/layer.rs | 17 ++++++++++------- tracing-opentelemetry/src/tracer.rs | 8 ++++---- .../tests/trace_state_propagation.rs | 2 +- 5 files changed, 19 insertions(+), 16 deletions(-) diff --git a/tracing-opentelemetry/Cargo.toml b/tracing-opentelemetry/Cargo.toml index e5f426bc43..a85538f1a7 100644 --- a/tracing-opentelemetry/Cargo.toml +++ b/tracing-opentelemetry/Cargo.toml @@ -22,7 +22,7 @@ edition = "2018" default = ["tracing-log"] [dependencies] -opentelemetry = { version = "0.15", default-features = false, features = ["trace"] } +opentelemetry = { version = "0.16", 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"] } @@ -31,7 +31,7 @@ tracing-log = { path = "../tracing-log", version = "0.1", default-features = fal [dev-dependencies] async-trait = "0.1" criterion = { version = "0.3", default_features = false } -opentelemetry-jaeger = "0.14" +opentelemetry-jaeger = "0.15" [lib] bench = false diff --git a/tracing-opentelemetry/benches/trace.rs b/tracing-opentelemetry/benches/trace.rs index 92498cc00e..9752b17f3d 100644 --- a/tracing-opentelemetry/benches/trace.rs +++ b/tracing-opentelemetry/benches/trace.rs @@ -13,7 +13,7 @@ fn many_children(c: &mut Criterion) { group.bench_function("spec_baseline", |b| { let provider = TracerProvider::default(); - let tracer = provider.get_tracer("bench", None); + let tracer = provider.tracer("bench", None); b.iter(|| { fn dummy(tracer: &Tracer, cx: &Context) { for _ in 0..99 { @@ -41,7 +41,7 @@ fn many_children(c: &mut Criterion) { { let provider = TracerProvider::default(); - let tracer = provider.get_tracer("bench", None); + let tracer = provider.tracer("bench", None); let otel_layer = tracing_opentelemetry::layer() .with_tracer(tracer) .with_tracked_inactivity(false); diff --git a/tracing-opentelemetry/src/layer.rs b/tracing-opentelemetry/src/layer.rs index f9eff7a66e..2879c51790 100644 --- a/tracing-opentelemetry/src/layer.rs +++ b/tracing-opentelemetry/src/layer.rs @@ -1,5 +1,8 @@ use crate::PreSampledTracer; -use opentelemetry::{trace as otel, trace::TraceContextExt, Context as OtelContext, Key, KeyValue}; +use opentelemetry::{ + trace::{self as otel, noop, TraceContextExt}, + Context as OtelContext, Key, KeyValue, +}; use std::any::TypeId; use std::fmt; use std::marker; @@ -29,12 +32,12 @@ pub struct OpenTelemetryLayer { _registry: marker::PhantomData, } -impl Default for OpenTelemetryLayer +impl Default for OpenTelemetryLayer where S: Subscriber + for<'span> LookupSpan<'span>, { fn default() -> Self { - OpenTelemetryLayer::new(otel::NoopTracer::new()) + OpenTelemetryLayer::new(noop::NoopTracer::new()) } } @@ -53,7 +56,7 @@ where /// let subscriber = Registry::default().with(tracing_opentelemetry::layer()); /// # drop(subscriber); /// ``` -pub fn layer() -> OpenTelemetryLayer +pub fn layer() -> OpenTelemetryLayer where S: Subscriber + for<'span> LookupSpan<'span>, { @@ -602,7 +605,7 @@ impl Timings { #[cfg(test)] mod tests { use super::*; - use opentelemetry::trace::{SpanKind, TraceFlags}; + use opentelemetry::trace::{noop, SpanKind, TraceFlags}; use std::borrow::Cow; use std::sync::{Arc, Mutex}; use std::time::SystemTime; @@ -611,9 +614,9 @@ mod tests { #[derive(Debug, Clone)] struct TestTracer(Arc>>); impl otel::Tracer for TestTracer { - type Span = otel::NoopSpan; + type Span = noop::NoopSpan; fn invalid(&self) -> Self::Span { - otel::NoopSpan::new() + noop::NoopSpan::new() } fn start_with_context(&self, _name: T, _context: OtelContext) -> Self::Span where diff --git a/tracing-opentelemetry/src/tracer.rs b/tracing-opentelemetry/src/tracer.rs index a2b9e44ebc..bc6be57c10 100644 --- a/tracing-opentelemetry/src/tracer.rs +++ b/tracing-opentelemetry/src/tracer.rs @@ -2,7 +2,7 @@ use opentelemetry::sdk::trace::{SamplingDecision, SamplingResult, Tracer, Tracer use opentelemetry::{ trace as otel, trace::{ - SpanBuilder, SpanContext, SpanId, SpanKind, TraceContextExt, TraceFlags, TraceId, + noop, SpanBuilder, SpanContext, SpanId, SpanKind, TraceContextExt, TraceFlags, TraceId, TraceState, }, Context as OtelContext, @@ -49,7 +49,7 @@ pub trait PreSampledTracer { fn new_span_id(&self) -> otel::SpanId; } -impl PreSampledTracer for otel::NoopTracer { +impl PreSampledTracer for noop::NoopTracer { fn sampled_context(&self, builder: &mut otel::SpanBuilder) -> OtelContext { builder.parent_context.clone() } @@ -172,7 +172,7 @@ mod tests { #[test] fn assigns_default_trace_id_if_missing() { let provider = TracerProvider::default(); - let tracer = provider.get_tracer("test", None); + let tracer = provider.tracer("test", None); let mut builder = SpanBuilder::from_name("empty".to_string()); builder.span_id = Some(SpanId::from_u64(1)); builder.trace_id = None; @@ -212,7 +212,7 @@ mod tests { let provider = TracerProvider::builder() .with_config(config().with_sampler(sampler)) .build(); - let tracer = provider.get_tracer("test", None); + let tracer = provider.tracer("test", None); let mut builder = SpanBuilder::from_name("parent".to_string()); builder.parent_context = parent_cx; builder.sampling_result = previous_sampling_result; diff --git a/tracing-opentelemetry/tests/trace_state_propagation.rs b/tracing-opentelemetry/tests/trace_state_propagation.rs index 600381de9b..8b0255269a 100644 --- a/tracing-opentelemetry/tests/trace_state_propagation.rs +++ b/tracing-opentelemetry/tests/trace_state_propagation.rs @@ -115,7 +115,7 @@ fn test_tracer() -> (Tracer, TracerProvider, TestExporter, impl Subscriber) { let provider = TracerProvider::builder() .with_simple_exporter(exporter.clone()) .build(); - let tracer = provider.get_tracer("test", None); + let tracer = provider.tracer("test", None); let subscriber = tracing_subscriber::registry().with(layer().with_tracer(tracer.clone())); (tracer, provider, exporter, subscriber)