Skip to content

Commit

Permalink
chore: bump opentelemetry to 0.25
Browse files Browse the repository at this point in the history
  • Loading branch information
ymgyt authored and djc committed Sep 10, 2024
1 parent 8884fe6 commit 18fffd6
Show file tree
Hide file tree
Showing 3 changed files with 102 additions and 116 deletions.
14 changes: 7 additions & 7 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ metrics = ["opentelemetry/metrics","opentelemetry_sdk/metrics", "smallvec"]
metrics_gauge_unstable = ["opentelemetry/otel_unstable"]

[dependencies]
opentelemetry = { version = "0.24", default-features = false, features = ["trace"] }
opentelemetry_sdk = { version = "0.24.1", default-features = false, features = ["trace"] }
opentelemetry = { version = "0.25", default-features = false, features = ["trace"] }
opentelemetry_sdk = { version = "0.25.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 @@ -41,11 +41,11 @@ 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.24", features = ["trace", "metrics"] }
opentelemetry_sdk = { version = "0.24", default-features = false, features = ["trace", "rt-tokio"] }
opentelemetry-stdout = { version = "0.5", features = ["trace", "metrics"] }
opentelemetry-otlp = { version = "0.17", features = ["metrics"] }
opentelemetry-semantic-conventions = "0.16"
opentelemetry = { version = "0.25", features = ["trace", "metrics"] }
opentelemetry_sdk = { version = "0.25", default-features = false, features = ["trace", "rt-tokio"] }
opentelemetry-stdout = { version = "0.25", features = ["trace", "metrics"] }
opentelemetry-otlp = { version = "0.25", features = ["metrics"] }
opentelemetry-semantic-conventions = "0.25"
futures-util = { version = "0.3.17", default-features = false }
tokio = { version = "1", features = ["full"] }
tokio-stream = "0.1"
Expand Down
4 changes: 2 additions & 2 deletions examples/opentelemetry-otlp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use opentelemetry_sdk::{
Resource,
};
use opentelemetry_semantic_conventions::{
resource::{DEPLOYMENT_ENVIRONMENT, SERVICE_NAME, SERVICE_VERSION},
resource::{DEPLOYMENT_ENVIRONMENT_NAME, SERVICE_NAME, SERVICE_VERSION},
SCHEMA_URL,
};
use tracing_core::Level;
Expand All @@ -22,7 +22,7 @@ fn resource() -> Resource {
[
KeyValue::new(SERVICE_NAME, env!("CARGO_PKG_NAME")),
KeyValue::new(SERVICE_VERSION, env!("CARGO_PKG_VERSION")),
KeyValue::new(DEPLOYMENT_ENVIRONMENT, "develop"),
KeyValue::new(DEPLOYMENT_ENVIRONMENT_NAME, "develop"),
],
SCHEMA_URL,
)
Expand Down
200 changes: 93 additions & 107 deletions tests/metrics_publishing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use opentelemetry_sdk::{
AggregationSelector, DefaultAggregationSelector, DefaultTemporalitySelector,
MetricReader, TemporalitySelector,
},
AttributeSet, InstrumentKind, ManualReader, MeterProviderBuilder, SdkMeterProvider,
InstrumentKind, ManualReader, MeterProviderBuilder, SdkMeterProvider,
},
Resource,
};
Expand Down Expand Up @@ -195,16 +195,13 @@ async fn u64_counter_with_attributes_is_exported() {
"hello_world".to_string(),
InstrumentKind::Counter,
1_u64,
Some(AttributeSet::from(
[
KeyValue::new("u64_key_1", 1_i64),
KeyValue::new("i64_key_1", 2_i64),
KeyValue::new("f64_key_1", 3_f64),
KeyValue::new("str_key_1", "foo"),
KeyValue::new("bool_key_1", true),
]
.as_slice(),
)),
Some(vec![
KeyValue::new("u64_key_1", 1_i64),
KeyValue::new("i64_key_1", 2_i64),
KeyValue::new("f64_key_1", 3_f64),
KeyValue::new("str_key_1", "foo"),
KeyValue::new("bool_key_1", true),
]),
);

tracing::subscriber::with_default(subscriber, || {
Expand All @@ -227,16 +224,13 @@ async fn f64_counter_with_attributes_is_exported() {
"hello_world".to_string(),
InstrumentKind::Counter,
1_f64,
Some(AttributeSet::from(
[
KeyValue::new("u64_key_1", 1_i64),
KeyValue::new("i64_key_1", 2_i64),
KeyValue::new("f64_key_1", 3_f64),
KeyValue::new("str_key_1", "foo"),
KeyValue::new("bool_key_1", true),
]
.as_slice(),
)),
Some(vec![
KeyValue::new("u64_key_1", 1_i64),
KeyValue::new("i64_key_1", 2_i64),
KeyValue::new("f64_key_1", 3_f64),
KeyValue::new("str_key_1", "foo"),
KeyValue::new("bool_key_1", true),
]),
);

tracing::subscriber::with_default(subscriber, || {
Expand All @@ -259,16 +253,13 @@ async fn i64_up_down_counter_with_attributes_is_exported() {
"hello_world".to_string(),
InstrumentKind::UpDownCounter,
-1_i64,
Some(AttributeSet::from(
[
KeyValue::new("u64_key_1", 1_i64),
KeyValue::new("i64_key_1", 2_i64),
KeyValue::new("f64_key_1", 3_f64),
KeyValue::new("str_key_1", "foo"),
KeyValue::new("bool_key_1", true),
]
.as_slice(),
)),
Some(vec![
KeyValue::new("u64_key_1", 1_i64),
KeyValue::new("i64_key_1", 2_i64),
KeyValue::new("f64_key_1", 3_f64),
KeyValue::new("str_key_1", "foo"),
KeyValue::new("bool_key_1", true),
]),
);

tracing::subscriber::with_default(subscriber, || {
Expand All @@ -291,16 +282,13 @@ async fn f64_up_down_counter_with_attributes_is_exported() {
"hello_world".to_string(),
InstrumentKind::UpDownCounter,
-1_f64,
Some(AttributeSet::from(
[
KeyValue::new("u64_key_1", 1_i64),
KeyValue::new("i64_key_1", 2_i64),
KeyValue::new("f64_key_1", 3_f64),
KeyValue::new("str_key_1", "foo"),
KeyValue::new("bool_key_1", true),
]
.as_slice(),
)),
Some(vec![
KeyValue::new("u64_key_1", 1_i64),
KeyValue::new("i64_key_1", 2_i64),
KeyValue::new("f64_key_1", 3_f64),
KeyValue::new("str_key_1", "foo"),
KeyValue::new("bool_key_1", true),
]),
);

tracing::subscriber::with_default(subscriber, || {
Expand All @@ -324,16 +312,13 @@ async fn f64_gauge_with_attributes_is_exported() {
"hello_world".to_string(),
InstrumentKind::Gauge,
1_f64,
Some(AttributeSet::from(
[
KeyValue::new("u64_key_1", 1_i64),
KeyValue::new("i64_key_1", 2_i64),
KeyValue::new("f64_key_1", 3_f64),
KeyValue::new("str_key_1", "foo"),
KeyValue::new("bool_key_1", true),
]
.as_slice(),
)),
Some(vec![
KeyValue::new("u64_key_1", 1_i64),
KeyValue::new("i64_key_1", 2_i64),
KeyValue::new("f64_key_1", 3_f64),
KeyValue::new("str_key_1", "foo"),
KeyValue::new("bool_key_1", true),
]),
);

tracing::subscriber::with_default(subscriber, || {
Expand All @@ -357,16 +342,13 @@ async fn u64_gauge_with_attributes_is_exported() {
"hello_world".to_string(),
InstrumentKind::Gauge,
1_u64,
Some(AttributeSet::from(
[
KeyValue::new("u64_key_1", 1_i64),
KeyValue::new("i64_key_1", 2_i64),
KeyValue::new("f64_key_1", 3_f64),
KeyValue::new("str_key_1", "foo"),
KeyValue::new("bool_key_1", true),
]
.as_slice(),
)),
Some(vec![
KeyValue::new("u64_key_1", 1_i64),
KeyValue::new("i64_key_1", 2_i64),
KeyValue::new("f64_key_1", 3_f64),
KeyValue::new("str_key_1", "foo"),
KeyValue::new("bool_key_1", true),
]),
);

tracing::subscriber::with_default(subscriber, || {
Expand All @@ -390,16 +372,13 @@ async fn i64_gauge_with_attributes_is_exported() {
"hello_world".to_string(),
InstrumentKind::Gauge,
1_i64,
Some(AttributeSet::from(
[
KeyValue::new("u64_key_1", 1_i64),
KeyValue::new("i64_key_1", 2_i64),
KeyValue::new("f64_key_1", 3_f64),
KeyValue::new("str_key_1", "foo"),
KeyValue::new("bool_key_1", true),
]
.as_slice(),
)),
Some(vec![
KeyValue::new("u64_key_1", 1_i64),
KeyValue::new("i64_key_1", 2_i64),
KeyValue::new("f64_key_1", 3_f64),
KeyValue::new("str_key_1", "foo"),
KeyValue::new("bool_key_1", true),
]),
);

tracing::subscriber::with_default(subscriber, || {
Expand All @@ -422,16 +401,13 @@ async fn u64_histogram_with_attributes_is_exported() {
"hello_world".to_string(),
InstrumentKind::Histogram,
1_u64,
Some(AttributeSet::from(
[
KeyValue::new("u64_key_1", 1_i64),
KeyValue::new("i64_key_1", 2_i64),
KeyValue::new("f64_key_1", 3_f64),
KeyValue::new("str_key_1", "foo"),
KeyValue::new("bool_key_1", true),
]
.as_slice(),
)),
Some(vec![
KeyValue::new("u64_key_1", 1_i64),
KeyValue::new("i64_key_1", 2_i64),
KeyValue::new("f64_key_1", 3_f64),
KeyValue::new("str_key_1", "foo"),
KeyValue::new("bool_key_1", true),
]),
);

tracing::subscriber::with_default(subscriber, || {
Expand All @@ -454,16 +430,13 @@ async fn f64_histogram_with_attributes_is_exported() {
"hello_world".to_string(),
InstrumentKind::Histogram,
1_f64,
Some(AttributeSet::from(
[
KeyValue::new("u64_key_1", 1_i64),
KeyValue::new("i64_key_1", 2_i64),
KeyValue::new("f64_key_1", 3_f64),
KeyValue::new("str_key_1", "foo"),
KeyValue::new("bool_key_1", true),
]
.as_slice(),
)),
Some(vec![
KeyValue::new("u64_key_1", 1_i64),
KeyValue::new("i64_key_1", 2_i64),
KeyValue::new("f64_key_1", 3_f64),
KeyValue::new("str_key_1", "foo"),
KeyValue::new("bool_key_1", true),
]),
);

tracing::subscriber::with_default(subscriber, || {
Expand All @@ -486,9 +459,7 @@ async fn display_attribute_is_exported() {
"hello_world".to_string(),
InstrumentKind::Counter,
1_u64,
Some(AttributeSet::from(
[KeyValue::new("display_key_1", "display: foo")].as_slice(),
)),
Some(vec![KeyValue::new("display_key_1", "display: foo")]),
);

struct DisplayAttribute(String);
Expand Down Expand Up @@ -517,9 +488,7 @@ async fn debug_attribute_is_exported() {
"hello_world".to_string(),
InstrumentKind::Counter,
1_u64,
Some(AttributeSet::from(
[KeyValue::new("debug_key_1", "debug: foo")].as_slice(),
)),
Some(vec![KeyValue::new("debug_key_1", "debug: foo")]),
);

struct DebugAttribute(String);
Expand All @@ -546,7 +515,7 @@ fn init_subscriber<T>(
expected_metric_name: String,
expected_instrument_kind: InstrumentKind,
expected_value: T,
expected_attributes: Option<AttributeSet>,
expected_attributes: Option<Vec<KeyValue>>,
) -> (impl Subscriber + 'static, TestExporter<T>) {
let reader = ManualReader::builder()
.with_aggregation_selector(DefaultAggregationSelector::new())
Expand All @@ -563,12 +532,7 @@ fn init_subscriber<T>(
expected_metric_name,
expected_instrument_kind,
expected_value,
expected_attributes: expected_attributes.map(|attrs| {
attrs
.iter()
.map(|(k, v)| KeyValue::new(k.clone(), v.clone()))
.collect()
}),
expected_attributes,
reader,
_meter_provider: provider.clone(),
};
Expand Down Expand Up @@ -659,7 +623,10 @@ where

if let Some(expected_attributes) = self.expected_attributes.as_ref() {
sum.data_points.iter().for_each(|data_point| {
assert_eq!(expected_attributes, &data_point.attributes)
assert!(compare_attributes(
expected_attributes,
&data_point.attributes,
))
});
}
}
Expand All @@ -677,7 +644,10 @@ where

if let Some(expected_attributes) = self.expected_attributes.as_ref() {
gauge.data_points.iter().for_each(|data_point| {
assert_eq!(expected_attributes, &data_point.attributes)
assert!(compare_attributes(
expected_attributes,
&data_point.attributes,
))
});
}
}
Expand All @@ -689,7 +659,10 @@ where
assert_eq!(histogram_data.sum, self.expected_value);

if let Some(expected_attributes) = self.expected_attributes.as_ref() {
assert_eq!(expected_attributes, &histogram_data.attributes);
assert!(compare_attributes(
expected_attributes,
&histogram_data.attributes
))
}
}
unexpected => {
Expand All @@ -702,3 +675,16 @@ where
Ok(())
}
}

// After sorting the KeyValue vec, compare them.
// Return true if they are equal.
#[allow(clippy::ptr_arg)]
fn compare_attributes(expected: &Vec<KeyValue>, actual: &Vec<KeyValue>) -> bool {
let mut expected = expected.clone();
let mut actual = actual.clone();

expected.sort();
actual.sort();

expected == actual
}

0 comments on commit 18fffd6

Please sign in to comment.