Skip to content

Commit

Permalink
Upgrade to opentelemetry 0.22 (#100)
Browse files Browse the repository at this point in the history
## Motivation

Would like to upgrade to opentelemetry 0.22.

## Solution

This seems mostly straightforward. Upstream deprecated
`opentelemetry_jaeger::new_pipeline()` (which is used in an example) in
favor of the OTLP collector for Jaeger; given that we already have an
OTLP example should we just delete it?
  • Loading branch information
djc authored Mar 4, 2024
1 parent 6cdd4d7 commit 5e3354e
Show file tree
Hide file tree
Showing 9 changed files with 37 additions and 80 deletions.
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
# 0.23.0 (February 26, 2024)

### Breaking Changes

- Upgrade to opentelemetry 0.22. Refer to the upstream
[changelog](https://github.com/open-telemetry/opentelemetry-rust/releases/tag/v0.22.0)
for more information. In particular, i64 histograms will silently downgrade to
key/value exports.

# 0.22.0 (November 7, 2023)

### Breaking Changes
Expand Down
21 changes: 11 additions & 10 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "tracing-opentelemetry"
version = "0.22.0"
version = "0.23.0"
authors = [
"Julian Tescher <julian@tescher.me>",
"Tokio Contributors <team@tokio.rs>"
Expand All @@ -25,8 +25,8 @@ default = ["tracing-log", "metrics"]
metrics = ["opentelemetry/metrics","opentelemetry_sdk/metrics", "smallvec"]

[dependencies]
opentelemetry = { version = "0.21.0", default-features = false, features = ["trace"] }
opentelemetry_sdk = { version = "0.21.0", default-features = false, features = ["trace"] }
opentelemetry = { version = "0.22.0", default-features = false, features = ["trace"] }
opentelemetry_sdk = { version = "0.22.0", default-features = false, features = ["trace"] }
tracing = { version = "0.1.35", default-features = false, features = ["std"] }
tracing-core = "0.1.28"
tracing-subscriber = { version = "0.3.0", default-features = false, features = ["registry", "std"] }
Expand All @@ -35,19 +35,20 @@ once_cell = "1.13.0"

# Fix minimal-versions
async-trait = { version = "0.1.56", optional = true }
futures-util = { version = "0.3.17", optional = true }
thiserror = { version = "1.0.31", optional = true }
smallvec = { version = "1.0", optional = true }

[dev-dependencies]
async-trait = "0.1.56"
criterion = { version = "0.5.1", default-features = false, features = ["html_reports"] }
opentelemetry = { version = "0.21.0", features = ["trace", "metrics"] }
opentelemetry_sdk = { version = "0.21.0", default-features = false, features = ["trace", "rt-tokio"] }
opentelemetry-jaeger = "0.20.0"
opentelemetry-stdout = { version = "0.2.0", features = ["trace", "metrics"] }
opentelemetry-otlp = { version = "0.14.0", features = ["metrics"] }
opentelemetry-semantic-conventions = "0.13.0"
futures-util = { version = "0.3", default-features = false }
opentelemetry = { version = "0.22.0", features = ["trace", "metrics"] }
opentelemetry_sdk = { version = "0.22.0", default-features = false, features = ["trace", "rt-tokio"] }
opentelemetry-jaeger = "0.21.0"
opentelemetry-stdout = { version = "0.3.0", features = ["trace", "metrics"] }
opentelemetry-otlp = { version = "0.15.0", features = ["metrics"] }
opentelemetry-semantic-conventions = "0.14.0"
futures-util = { version = "0.3.17", default-features = false }
tokio = { version = "1", features = ["full"] }
tokio-stream = "0.1"
tracing = { version = "0.1.35", default-features = false, features = ["std", "attributes"] }
Expand Down
8 changes: 4 additions & 4 deletions examples/opentelemetry-otlp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use opentelemetry::{global, Key, KeyValue};
use opentelemetry_sdk::{
metrics::{
reader::{DefaultAggregationSelector, DefaultTemporalitySelector},
Aggregation, Instrument, MeterProvider, PeriodicReader, Stream,
Aggregation, Instrument, MeterProviderBuilder, PeriodicReader, SdkMeterProvider, Stream,
},
runtime,
trace::{BatchConfig, RandomIdGenerator, Sampler, Tracer},
Expand All @@ -29,7 +29,7 @@ fn resource() -> Resource {
}

// Construct MeterProvider for MetricsLayer
fn init_meter_provider() -> MeterProvider {
fn init_meter_provider() -> SdkMeterProvider {
let exporter = opentelemetry_otlp::new_exporter()
.tonic()
.build_metrics_exporter(
Expand Down Expand Up @@ -78,7 +78,7 @@ fn init_meter_provider() -> MeterProvider {
}
};

let meter_provider = MeterProvider::builder()
let meter_provider = MeterProviderBuilder::default()
.with_resource(resource())
.with_reader(reader)
.with_reader(stdout_reader)
Expand Down Expand Up @@ -128,7 +128,7 @@ fn init_tracing_subscriber() -> OtelGuard {
}

struct OtelGuard {
meter_provider: MeterProvider,
meter_provider: SdkMeterProvider,
}

impl Drop for OtelGuard {
Expand Down
48 changes: 0 additions & 48 deletions examples/opentelemetry.rs

This file was deleted.

8 changes: 1 addition & 7 deletions src/layer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1212,18 +1212,12 @@ fn thread_id_integer(id: thread::ThreadId) -> u64 {
#[cfg(test)]
mod tests {
use super::*;
use crate::OtelData;
use opentelemetry::{
trace::{noop, TraceFlags},
StringValue,
};
use opentelemetry::trace::TraceFlags;
use std::{
borrow::Cow,
collections::HashMap,
error::Error,
fmt::Display,
sync::{Arc, Mutex},
thread,
time::SystemTime,
};
use tracing_subscriber::prelude::*;
Expand Down
6 changes: 3 additions & 3 deletions src/metrics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -218,12 +218,12 @@ impl<'a> Visit for MetricVisitor<'a> {
/// use tracing_opentelemetry::MetricsLayer;
/// use tracing_subscriber::layer::SubscriberExt;
/// use tracing_subscriber::Registry;
/// # use opentelemetry_sdk::metrics::MeterProvider;
/// # use opentelemetry_sdk::metrics::SdkMeterProvider;
///
/// // Constructing a MeterProvider is out-of-scope for the docs here, but there
/// // are examples in the opentelemetry repository. See:
/// // https://github.com/open-telemetry/opentelemetry-rust/blob/dfeac078ff7853e7dc814778524b93470dfa5c9c/examples/metrics-basic/src/main.rs#L7
/// # let meter_provider: MeterProvider = unimplemented!();
/// # let meter_provider: SdkMeterProvider = unimplemented!();
///
/// let opentelemetry_metrics = MetricsLayer::new(meter_provider);
/// let subscriber = Registry::default().with(opentelemetry_metrics);
Expand Down Expand Up @@ -305,7 +305,7 @@ impl<'a> Visit for MetricVisitor<'a> {
/// # use tracing::info;
/// // adds attributes bar="baz" and qux=2 to the `foo` counter.
/// info!(monotonic_counter.foo = 1, bar = "baz", qux = 2);
/// ```
/// ```
///
/// # Implementation Details
///
Expand Down
2 changes: 1 addition & 1 deletion src/tracer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ fn process_sampling_result(
mod tests {
use super::*;
use crate::OtelData;
use opentelemetry::trace::{SpanBuilder, SpanId, TracerProvider as _};
use opentelemetry::trace::TracerProvider as _;
use opentelemetry_sdk::trace::{config, Sampler, TracerProvider};

#[test]
Expand Down
11 changes: 6 additions & 5 deletions tests/metrics_publishing.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
use opentelemetry::{metrics::MetricsError, KeyValue};
use opentelemetry_sdk::{
metrics::{
data,
data::{Histogram, Sum},
data::{self, Histogram, Sum},
reader::{
AggregationSelector, DefaultAggregationSelector, DefaultTemporalitySelector,
MetricReader, TemporalitySelector,
},
InstrumentKind, ManualReader, MeterProvider,
InstrumentKind, ManualReader, MeterProviderBuilder, SdkMeterProvider,
},
AttributeSet, Resource,
};
Expand Down Expand Up @@ -416,7 +415,9 @@ fn init_subscriber<T>(
inner: Arc::new(reader),
};

let provider = MeterProvider::builder().with_reader(reader.clone()).build();
let provider = MeterProviderBuilder::default()
.with_reader(reader.clone())
.build();
let exporter = TestExporter {
expected_metric_name,
expected_instrument_kind,
Expand Down Expand Up @@ -473,7 +474,7 @@ struct TestExporter<T> {
expected_value: T,
expected_attributes: Option<AttributeSet>,
reader: TestReader,
_meter_provider: MeterProvider,
_meter_provider: SdkMeterProvider,
}

impl<T> TestExporter<T>
Expand Down
4 changes: 2 additions & 2 deletions tests/trace_state_propagation.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
use futures_util::future::BoxFuture;
use opentelemetry::{
propagation::TextMapPropagator,
propagation::{TextMapCompositePropagator, TextMapPropagator},
trace::{SpanContext, TraceContextExt, Tracer as _, TracerProvider as _},
Context,
};
use opentelemetry_sdk::{
export::trace::{ExportResult, SpanData, SpanExporter},
propagation::{BaggagePropagator, TextMapCompositePropagator, TraceContextPropagator},
propagation::{BaggagePropagator, TraceContextPropagator},
trace::{Tracer, TracerProvider},
};
use std::collections::{HashMap, HashSet};
Expand Down

0 comments on commit 5e3354e

Please sign in to comment.