Skip to content

Commit

Permalink
opentelemetry: update to otel v0.16.x (tokio-rs#1497) (tokio-rs#1500)
Browse files Browse the repository at this point in the history
Updates to the latest otel spec version and addresses small internal
method and module updates.
  • Loading branch information
jtescher authored and kaffarell committed May 22, 2024
1 parent 3a37838 commit 6d31a50
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 16 deletions.
4 changes: 2 additions & 2 deletions tracing-opentelemetry/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"] }
Expand All @@ -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
Expand Down
4 changes: 2 additions & 2 deletions tracing-opentelemetry/benches/trace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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);
Expand Down
17 changes: 10 additions & 7 deletions tracing-opentelemetry/src/layer.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -29,12 +32,12 @@ pub struct OpenTelemetryLayer<S, T> {
_registry: marker::PhantomData<S>,
}

impl<S> Default for OpenTelemetryLayer<S, otel::NoopTracer>
impl<S> Default for OpenTelemetryLayer<S, noop::NoopTracer>
where
S: Subscriber + for<'span> LookupSpan<'span>,
{
fn default() -> Self {
OpenTelemetryLayer::new(otel::NoopTracer::new())
OpenTelemetryLayer::new(noop::NoopTracer::new())
}
}

Expand All @@ -53,7 +56,7 @@ where
/// let subscriber = Registry::default().with(tracing_opentelemetry::layer());
/// # drop(subscriber);
/// ```
pub fn layer<S>() -> OpenTelemetryLayer<S, otel::NoopTracer>
pub fn layer<S>() -> OpenTelemetryLayer<S, noop::NoopTracer>
where
S: Subscriber + for<'span> LookupSpan<'span>,
{
Expand Down Expand Up @@ -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;
Expand All @@ -611,9 +614,9 @@ mod tests {
#[derive(Debug, Clone)]
struct TestTracer(Arc<Mutex<Option<otel::SpanBuilder>>>);
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<T>(&self, _name: T, _context: OtelContext) -> Self::Span
where
Expand Down
8 changes: 4 additions & 4 deletions tracing-opentelemetry/src/tracer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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()
}
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion tracing-opentelemetry/tests/trace_state_propagation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 6d31a50

Please sign in to comment.