Skip to content

Commit

Permalink
update to opentelemetry-rust v0.26.0
Browse files Browse the repository at this point in the history
  • Loading branch information
sezna committed Oct 14, 2024
1 parent c47b8cc commit b7dff38
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 41 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ futures-util = { version = "0.3", default-features = false, optional = true }
opentelemetry = "0.26"
opentelemetry_sdk = "0.26"
opentelemetry-http = "0.26"
opentelemetry-semantic-conventions = "0.26"
opentelemetry-semantic-conventions = { version = "0.26", features = ["semconv_experimental"] }
reqwest = { version = "0.12", default-features = false, features = ["blocking"], optional = true }
serde = { version = "1", features = ["derive"] }
serde_json = "1"
Expand Down
8 changes: 4 additions & 4 deletions examples/opentelemetry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use opentelemetry::{
global,
propagation::TextMapPropagator,
trace::{FutureExt, Span, SpanKind, TraceContextExt, Tracer},
Context, Key,
Context, KeyValue,
};
use opentelemetry_sdk::propagation::TraceContextPropagator;
use std::collections::HashMap;
Expand All @@ -16,8 +16,8 @@ async fn spawn_children(n: u32, process_name: String) {
let tracer = global::tracer("spawn_children");
let mut span = tracer.start("spawn_children");
span.set_attributes([
Key::new("n").i64(n.into()),
Key::new("process_name").string(process_name.clone()),
KeyValue::new("n", Into::<i64>::into(n)),
KeyValue::new("process_name", process_name.clone()),
]);
let cx = Context::current_with_span(span);
for _ in 0..n {
Expand All @@ -33,7 +33,7 @@ async fn spawn_child_process(process_name: &str) {
.span_builder("spawn_child_process")
.with_kind(SpanKind::Client)
.start(&tracer);
span.set_attribute(Key::new("process_name").string(process_name.to_string()));
span.set_attribute(KeyValue::new("process_name", process_name.to_string()));
let cx = Context::current_with_span(span);

let mut injector = HashMap::new();
Expand Down
8 changes: 4 additions & 4 deletions src/convert.rs
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ mod tests {

#[test]
fn attrs_to_properties_filters_ms() {
let attrs = vec![KeyValue::new("a", "b"), KeyValue::new("_MS.a", "b")];
let attrs = [KeyValue::new("a", "b"), KeyValue::new("_MS.a", "b")];
let resource = Resource::new([KeyValue::new("c", "d"), KeyValue::new("_MS.c", "d")]);
let props = attrs_to_properties(attrs.iter(), Some(&resource), &[]).unwrap();
assert_eq!(props.len(), 2);
Expand Down Expand Up @@ -252,7 +252,7 @@ mod tests {

#[test]
fn attrs_map_to_properties_filters_ms() {
let attrs = vec![KeyValue::new("a", "b"), KeyValue::new("_MS.a", "b")];
let attrs = [KeyValue::new("a", "b"), KeyValue::new("_MS.a", "b")];
let attrs_map = attrs_to_map(attrs.iter());
assert_eq!(attrs_map.len(), 2);
let props = attrs_map_to_properties(attrs_map).unwrap();
Expand All @@ -264,9 +264,9 @@ mod tests {
#[test_case(AnyValue::Double(1.2), "1.2" ; "double")]
#[test_case(AnyValue::String("test".into()), "test" ; "string")]
#[test_case(AnyValue::Boolean(true), "true" ; "boolean")]
#[test_case(AnyValue::Bytes(Box::new(vec![])), "[]" ; "empty bytes")]
#[test_case(AnyValue::Bytes(Box::default()), "[]" ; "empty bytes")]
#[test_case(AnyValue::Bytes(Box::new(vec![1, 2, 3])), "[1,2,3]" ; "bytes")]
#[test_case(AnyValue::ListAny(Box::new(vec![])), "[]" ; "empty list")]
#[test_case(AnyValue::ListAny(Box::default()), "[]" ; "empty list")]
#[test_case(AnyValue::ListAny(Box::new(vec![1.into(), "test".into()])), "[1,test]" ; "list")]
#[test_case(AnyValue::Map(Box::new([].into())), "{}" ; "empty map")]
#[test_case(AnyValue::Map(Box::new([("k1".into(), "test".into())].into())), "{k1:test}" ; "map")]
Expand Down
20 changes: 0 additions & 20 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -376,8 +376,6 @@ pub use models::context_tag_keys::attrs;
use opentelemetry::{global, trace::TracerProvider as _, KeyValue, Value};
pub use opentelemetry_http::HttpClient;
use opentelemetry_sdk::export::ExportError;
#[cfg(feature = "metrics")]
use opentelemetry_sdk::metrics::reader::{AggregationSelector, DefaultAggregationSelector};
#[cfg(any(feature = "trace", feature = "logs"))]
use opentelemetry_sdk::Resource;
#[cfg(feature = "trace")]
Expand Down Expand Up @@ -650,7 +648,6 @@ where
instrumentation_key: self.instrumentation_key,
sample_rate: self.sample_rate.unwrap_or(100.0),
#[cfg(feature = "metrics")]
aggregation_selector: Box::new(DefaultAggregationSelector::new()),
resource: Resource::empty(),
}
}
Expand Down Expand Up @@ -737,8 +734,6 @@ pub struct Exporter<C> {
instrumentation_key: String,
#[cfg(feature = "trace")]
sample_rate: f64,
#[cfg(feature = "metrics")]
aggregation_selector: Box<dyn AggregationSelector>,
#[cfg(any(feature = "trace", feature = "logs"))]
resource: Resource,
}
Expand Down Expand Up @@ -769,8 +764,6 @@ impl<C> Exporter<C> {
instrumentation_key,
#[cfg(feature = "trace")]
sample_rate: 100.0,
#[cfg(feature = "metrics")]
aggregation_selector: Box::new(DefaultAggregationSelector::new()),
#[cfg(any(feature = "trace", feature = "logs"))]
resource: Resource::empty(),
}
Expand All @@ -791,8 +784,6 @@ impl<C> Exporter<C> {
instrumentation_key: connection_string.instrumentation_key,
#[cfg(feature = "trace")]
sample_rate: 100.0,
#[cfg(feature = "metrics")]
aggregation_selector: Box::new(DefaultAggregationSelector::new()),
#[cfg(any(feature = "trace", feature = "logs"))]
resource: Resource::empty(),
})
Expand Down Expand Up @@ -822,17 +813,6 @@ impl<C> Exporter<C> {
self.sample_rate = sample_rate * 100.0;
self
}

/// Set aggregation selector.
#[cfg(feature = "metrics")]
#[cfg_attr(docsrs, doc(cfg(feature = "metrics")))]
pub fn with_aggregation_selector(
mut self,
aggregation_selector: impl AggregationSelector + 'static,
) -> Self {
self.aggregation_selector = Box::new(aggregation_selector);
self
}
}

fn append_v2_track(uri: impl ToString) -> Result<http::Uri, http::uri::InvalidUri> {
Expand Down
14 changes: 2 additions & 12 deletions src/metrics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ use opentelemetry_http::HttpClient;
use opentelemetry_sdk::metrics::{
data::{ExponentialHistogram, Gauge, Histogram, Metric, ResourceMetrics, Sum, Temporality},
exporter::PushMetricsExporter,
reader::{AggregationSelector, TemporalitySelector},
Aggregation, InstrumentKind,
reader::TemporalitySelector,
InstrumentKind,
};
use std::{convert::TryInto, sync::Arc, time::SystemTime};

Expand All @@ -39,16 +39,6 @@ where
}
}

#[cfg_attr(docsrs, doc(cfg(feature = "metrics")))]
impl<C> AggregationSelector for Exporter<C>
where
C: Send + Sync,
{
fn aggregation(&self, kind: InstrumentKind) -> Aggregation {
self.aggregation_selector.aggregation(kind)
}
}

#[cfg_attr(docsrs, doc(cfg(feature = "metrics")))]
#[async_trait]
impl<C> PushMetricsExporter for Exporter<C>
Expand Down

0 comments on commit b7dff38

Please sign in to comment.