diff --git a/opentelemetry-appender-tracing/src/layer.rs b/opentelemetry-appender-tracing/src/layer.rs index 6b07a8a72d..1d1a1160fe 100644 --- a/opentelemetry-appender-tracing/src/layer.rs +++ b/opentelemetry-appender-tracing/src/layer.rs @@ -334,7 +334,7 @@ mod tests { .expect("Atleast one log is expected to be present."); // Validate common fields - assert_eq!(log.instrumentation.name, "opentelemetry-appender-tracing"); + assert_eq!(log.instrumentation.name(), "opentelemetry-appender-tracing"); assert_eq!(log.record.severity_number, Some(Severity::Error)); // Validate trace context is none. @@ -428,7 +428,7 @@ mod tests { .expect("Atleast one log is expected to be present."); // validate common fields. - assert_eq!(log.instrumentation.name, "opentelemetry-appender-tracing"); + assert_eq!(log.instrumentation.name(), "opentelemetry-appender-tracing"); assert_eq!(log.record.severity_number, Some(Severity::Error)); // validate trace context. @@ -526,7 +526,7 @@ mod tests { .expect("Atleast one log is expected to be present."); // Validate common fields - assert_eq!(log.instrumentation.name, "opentelemetry-appender-tracing"); + assert_eq!(log.instrumentation.name(), "opentelemetry-appender-tracing"); assert_eq!(log.record.severity_number, Some(Severity::Error)); // Validate trace context is none. @@ -605,7 +605,7 @@ mod tests { .expect("Atleast one log is expected to be present."); // validate common fields. - assert_eq!(log.instrumentation.name, "opentelemetry-appender-tracing"); + assert_eq!(log.instrumentation.name(), "opentelemetry-appender-tracing"); assert_eq!(log.record.severity_number, Some(Severity::Error)); // validate trace context. diff --git a/opentelemetry-proto/src/transform/common.rs b/opentelemetry-proto/src/transform/common.rs index 0821165c89..37efc27199 100644 --- a/opentelemetry-proto/src/transform/common.rs +++ b/opentelemetry-proto/src/transform/common.rs @@ -64,9 +64,9 @@ pub mod tonic { } } else { InstrumentationScope { - name: library.name.into_owned(), - version: library.version.map(Cow::into_owned).unwrap_or_default(), - attributes: Attributes::from(library.attributes).0, + name: library.name().to_owned(), + version: library.version().map(ToOwned::to_owned).unwrap_or_default(), + attributes: Attributes::from(library.attributes().cloned()).0, ..Default::default() } } @@ -95,13 +95,9 @@ pub mod tonic { } } else { InstrumentationScope { - name: library.name.to_string(), - version: library - .version - .as_ref() - .map(ToString::to_string) - .unwrap_or_default(), - attributes: Attributes::from(library.attributes.clone()).0, + name: library.name().to_owned(), + version: library.version().map(ToOwned::to_owned).unwrap_or_default(), + attributes: Attributes::from(library.attributes().cloned()).0, ..Default::default() } } @@ -112,8 +108,8 @@ pub mod tonic { #[derive(Default, Debug)] pub struct Attributes(pub ::std::vec::Vec); - impl From> for Attributes { - fn from(kvs: Vec) -> Self { + impl> From for Attributes { + fn from(kvs: I) -> Self { Attributes( kvs.into_iter() .map(|api_kv| KeyValue { diff --git a/opentelemetry-proto/src/transform/logs.rs b/opentelemetry-proto/src/transform/logs.rs index 52fd3cace4..a85b2ed7a7 100644 --- a/opentelemetry-proto/src/transform/logs.rs +++ b/opentelemetry-proto/src/transform/logs.rs @@ -167,9 +167,8 @@ pub mod tonic { schema_url: resource.schema_url.clone().unwrap_or_default(), scope_logs: vec![ScopeLogs { schema_url: instrumentation - .schema_url - .clone() - .map(Into::into) + .schema_url() + .map(ToOwned::to_owned) .unwrap_or_default(), scope: Some((instrumentation, log_record.target.clone()).into()), log_records: vec![log_record.into()], @@ -196,7 +195,7 @@ pub mod tonic { let key = log_record .target .clone() - .unwrap_or_else(|| Cow::Owned(instrumentation.name.clone().into_owned())); + .unwrap_or_else(|| Cow::Owned(instrumentation.name().to_owned())); scope_map .entry(key) .or_default() diff --git a/opentelemetry-proto/src/transform/metrics.rs b/opentelemetry-proto/src/transform/metrics.rs index df3e105803..2e9b2c1402 100644 --- a/opentelemetry-proto/src/transform/metrics.rs +++ b/opentelemetry-proto/src/transform/metrics.rs @@ -137,9 +137,8 @@ pub mod tonic { metrics: sm.metrics.iter().map(Into::into).collect(), schema_url: sm .scope - .schema_url - .as_ref() - .map(ToString::to_string) + .schema_url() + .map(ToOwned::to_owned) .unwrap_or_default(), } } diff --git a/opentelemetry-proto/src/transform/trace.rs b/opentelemetry-proto/src/transform/trace.rs index 27018d624a..fc031c5e32 100644 --- a/opentelemetry-proto/src/transform/trace.rs +++ b/opentelemetry-proto/src/transform/trace.rs @@ -102,9 +102,8 @@ pub mod tonic { scope_spans: vec![ScopeSpans { schema_url: source_span .instrumentation_scope - .schema_url - .as_ref() - .map(ToString::to_string) + .schema_url() + .map(ToOwned::to_owned) .unwrap_or_default(), scope: Some((source_span.instrumentation_scope, None).into()), spans: vec![Span { diff --git a/opentelemetry-sdk/src/logs/log_emitter.rs b/opentelemetry-sdk/src/logs/log_emitter.rs index 7bc9026d35..0a199f9d85 100644 --- a/opentelemetry-sdk/src/logs/log_emitter.rs +++ b/opentelemetry-sdk/src/logs/log_emitter.rs @@ -296,7 +296,7 @@ impl opentelemetry::logs::Logger for Logger { || processor.event_enabled( level, target, - self.instrumentation_scope().name.as_ref(), + self.instrumentation_scope().name().as_ref(), ); } enabled diff --git a/opentelemetry-sdk/src/logs/mod.rs b/opentelemetry-sdk/src/logs/mod.rs index c4dd5ec44d..a3ea712bea 100644 --- a/opentelemetry-sdk/src/logs/mod.rs +++ b/opentelemetry-sdk/src/logs/mod.rs @@ -87,7 +87,7 @@ mod tests { let log = exported_logs .first() .expect("Atleast one log is expected to be present."); - assert_eq!(log.instrumentation.name, "test-logger"); + assert_eq!(log.instrumentation.name(), "test-logger"); assert_eq!(log.record.severity_number, Some(Severity::Error)); assert_eq!(log.record.attributes_len(), 10); for i in 1..=10 { @@ -111,14 +111,13 @@ mod tests { let logger = provider.logger_with_scope(scope); let instrumentation_scope = logger.instrumentation_scope(); - let attributes = &instrumentation_scope.attributes; - assert_eq!(instrumentation_scope.name, "test_logger"); + assert_eq!(instrumentation_scope.name(), "test_logger"); assert_eq!( - instrumentation_scope.schema_url, - Some("https://opentelemetry.io/schema/1.0.0".into()) + instrumentation_scope.schema_url(), + Some("https://opentelemetry.io/schema/1.0.0") ); - assert_eq!(attributes.len(), 1); - assert_eq!(attributes[0].key, "test_k".into()); - assert_eq!(attributes[0].value, "test_v".into()); + assert!(instrumentation_scope + .attributes() + .eq(&[KeyValue::new("test_k", "test_v")])); } } diff --git a/opentelemetry-sdk/src/metrics/instrument.rs b/opentelemetry-sdk/src/metrics/instrument.rs index c2b3ce5219..f73246a2ce 100644 --- a/opentelemetry-sdk/src/metrics/instrument.rs +++ b/opentelemetry-sdk/src/metrics/instrument.rs @@ -160,13 +160,11 @@ impl Instrument { } pub(crate) fn matches_scope(&self, other: &Instrument) -> bool { - (self.scope.name.is_empty() || self.scope.name.as_ref() == other.scope.name.as_ref()) - && (self.scope.version.is_none() - || self.scope.version.as_ref().map(AsRef::as_ref) - == other.scope.version.as_ref().map(AsRef::as_ref)) - && (self.scope.schema_url.is_none() - || self.scope.schema_url.as_ref().map(AsRef::as_ref) - == other.scope.schema_url.as_ref().map(AsRef::as_ref)) + (self.scope.name().is_empty() || self.scope.name() == other.scope.name()) + && (self.scope.version().is_none() + || self.scope.version().as_ref() == other.scope.version().as_ref()) + && (self.scope.schema_url().is_none() + || self.scope.schema_url().as_ref() == other.scope.schema_url().as_ref()) } } diff --git a/opentelemetry-sdk/src/metrics/meter.rs b/opentelemetry-sdk/src/metrics/meter.rs index c552109362..430bf5e57b 100644 --- a/opentelemetry-sdk/src/metrics/meter.rs +++ b/opentelemetry-sdk/src/metrics/meter.rs @@ -76,7 +76,7 @@ impl SdkMeter { if let Err(err) = validation_result { otel_error!( name: "InstrumentCreationFailed", - meter_name = self.scope.name.as_ref(), + meter_name = self.scope.name(), instrument_name = builder.name.as_ref(), message = "Measurements from this Counter will be ignored.", reason = format!("{}", err) @@ -98,7 +98,7 @@ impl SdkMeter { Err(err) => { otel_error!( name: "InstrumentCreationFailed", - meter_name = self.scope.name.as_ref(), + meter_name = self.scope.name(), instrument_name = builder.name.as_ref(), message = "Measurements from this Counter will be ignored.", reason = format!("{}", err) @@ -120,7 +120,7 @@ impl SdkMeter { if let Err(err) = validation_result { otel_error!( name: "InstrumentCreationFailed", - meter_name = self.scope.name.as_ref(), + meter_name = self.scope.name(), instrument_name = builder.name.as_ref(), message = "Callbacks for this ObservableCounter will not be invoked.", reason = format!("{}", err)); @@ -138,7 +138,7 @@ impl SdkMeter { if ms.is_empty() { otel_error!( name: "InstrumentCreationFailed", - meter_name = self.scope.name.as_ref(), + meter_name = self.scope.name(), instrument_name = builder.name.as_ref(), message = "Callbacks for this ObservableCounter will not be invoked. Check View Configuration." ); @@ -158,7 +158,7 @@ impl SdkMeter { Err(err) => { otel_error!( name: "InstrumentCreationFailed", - meter_name = self.scope.name.as_ref(), + meter_name = self.scope.name(), instrument_name = builder.name.as_ref(), message = "Callbacks for this ObservableCounter will not be invoked.", reason = format!("{}", err)); @@ -179,7 +179,7 @@ impl SdkMeter { if let Err(err) = validation_result { otel_error!( name: "InstrumentCreationFailed", - meter_name = self.scope.name.as_ref(), + meter_name = self.scope.name(), instrument_name = builder.name.as_ref(), message = "Callbacks for this ObservableUpDownCounter will not be invoked.", reason = format!("{}", err)); @@ -197,7 +197,7 @@ impl SdkMeter { if ms.is_empty() { otel_error!( name: "InstrumentCreationFailed", - meter_name = self.scope.name.as_ref(), + meter_name = self.scope.name(), instrument_name = builder.name.as_ref(), message = "Callbacks for this ObservableUpDownCounter will not be invoked. Check View Configuration." ); @@ -217,7 +217,7 @@ impl SdkMeter { Err(err) => { otel_error!( name: "InstrumentCreationFailed", - meter_name = self.scope.name.as_ref(), + meter_name = self.scope.name(), instrument_name = builder.name.as_ref(), message = "Callbacks for this ObservableUpDownCounter will not be invoked.", reason = format!("{}", err)); @@ -238,7 +238,7 @@ impl SdkMeter { if let Err(err) = validation_result { otel_error!( name: "InstrumentCreationFailed", - meter_name = self.scope.name.as_ref(), + meter_name = self.scope.name(), instrument_name = builder.name.as_ref(), message = "Callbacks for this ObservableGauge will not be invoked.", reason = format!("{}", err)); @@ -256,7 +256,7 @@ impl SdkMeter { if ms.is_empty() { otel_error!( name: "InstrumentCreationFailed", - meter_name = self.scope.name.as_ref(), + meter_name = self.scope.name(), instrument_name = builder.name.as_ref(), message = "Callbacks for this ObservableGauge will not be invoked. Check View Configuration." ); @@ -276,7 +276,7 @@ impl SdkMeter { Err(err) => { otel_error!( name: "InstrumentCreationFailed", - meter_name = self.scope.name.as_ref(), + meter_name = self.scope.name(), instrument_name = builder.name.as_ref(), message = "Callbacks for this ObservableGauge will not be invoked.", reason = format!("{}", err)); @@ -297,7 +297,7 @@ impl SdkMeter { if let Err(err) = validation_result { otel_error!( name: "InstrumentCreationFailed", - meter_name = self.scope.name.as_ref(), + meter_name = self.scope.name(), instrument_name = builder.name.as_ref(), message = "Measurements from this UpDownCounter will be ignored.", reason = format!("{}", err) @@ -319,7 +319,7 @@ impl SdkMeter { Err(err) => { otel_error!( name: "InstrumentCreationFailed", - meter_name = self.scope.name.as_ref(), + meter_name = self.scope.name(), instrument_name = builder.name.as_ref(), message = "Measurements from this UpDownCounter will be ignored.", reason = format!("{}", err) @@ -341,7 +341,7 @@ impl SdkMeter { if let Err(err) = validation_result { otel_error!( name: "InstrumentCreationFailed", - meter_name = self.scope.name.as_ref(), + meter_name = self.scope.name(), instrument_name = builder.name.as_ref(), message = "Measurements from this Gauge will be ignored.", reason = format!("{}", err) @@ -363,7 +363,7 @@ impl SdkMeter { Err(err) => { otel_error!( name: "InstrumentCreationFailed", - meter_name = self.scope.name.as_ref(), + meter_name = self.scope.name(), instrument_name = builder.name.as_ref(), message = "Measurements from this Gauge will be ignored.", reason = format!("{}", err) @@ -385,7 +385,7 @@ impl SdkMeter { if let Err(err) = validation_result { otel_error!( name: "InstrumentCreationFailed", - meter_name = self.scope.name.as_ref(), + meter_name = self.scope.name(), instrument_name = builder.name.as_ref(), message = "Measurements from this Histogram will be ignored.", reason = format!("{}", err) @@ -407,7 +407,7 @@ impl SdkMeter { Err(err) => { otel_error!( name: "InstrumentCreationFailed", - meter_name = self.scope.name.as_ref(), + meter_name = self.scope.name(), instrument_name = builder.name.as_ref(), message = "Measurements from this Histogram will be ignored.", reason = format!("{}", err) diff --git a/opentelemetry-sdk/src/metrics/meter_provider.rs b/opentelemetry-sdk/src/metrics/meter_provider.rs index 4c53e8d12e..b7aec1ca25 100644 --- a/opentelemetry-sdk/src/metrics/meter_provider.rs +++ b/opentelemetry-sdk/src/metrics/meter_provider.rs @@ -465,18 +465,16 @@ mod tests { assert_eq!(provider.inner.meters.lock().unwrap().len(), 2); // these are different meters because meter names are case sensitive - let mut library = InstrumentationScope::builder("ABC") - .with_version("1.0.0") - .with_schema_url("http://example.com") - .build(); - - let _meter6 = provider.meter_with_scope(library.clone()); - - library.name = "Abc".into(); - let _meter7 = provider.meter_with_scope(library.clone()); + let make_scope = |name| { + InstrumentationScope::builder(name) + .with_version("1.0.0") + .with_schema_url("http://example.com") + .build() + }; - library.name = "abc".into(); - let _meter8 = provider.meter_with_scope(library); + let _meter6 = provider.meter_with_scope(make_scope("ABC")); + let _meter7 = provider.meter_with_scope(make_scope("Abc")); + let _meter8 = provider.meter_with_scope(make_scope("abc")); assert_eq!(provider.inner.meters.lock().unwrap().len(), 5); } diff --git a/opentelemetry-sdk/src/metrics/mod.rs b/opentelemetry-sdk/src/metrics/mod.rs index 0e7d46acad..0eb4eabc86 100644 --- a/opentelemetry-sdk/src/metrics/mod.rs +++ b/opentelemetry-sdk/src/metrics/mod.rs @@ -137,7 +137,6 @@ mod tests { use opentelemetry::InstrumentationScope; use opentelemetry::{metrics::MeterProvider as _, KeyValue}; use rand::{rngs, Rng, SeedableRng}; - use std::borrow::Cow; use std::cmp::{max, min}; use std::sync::atomic::{AtomicBool, Ordering}; use std::sync::{Arc, Mutex}; @@ -638,16 +637,18 @@ mod tests { // Act // Meters are identical except for scope attributes, but scope attributes are not an identifying property. // Hence there should be a single metric stream output for this test. - let mut scope = InstrumentationScope::builder("test.meter") - .with_version("v0.1.0") - .with_schema_url("http://example.com") - .with_attributes(vec![KeyValue::new("key", "value1")]) - .build(); - - let meter1 = meter_provider.meter_with_scope(scope.clone()); + let make_scope = |attributes| { + InstrumentationScope::builder("test.meter") + .with_version("v0.1.0") + .with_schema_url("http://example.com") + .with_attributes(attributes) + .build() + }; - scope.attributes = vec![KeyValue::new("key", "value2")]; - let meter2 = meter_provider.meter_with_scope(scope); + let meter1 = + meter_provider.meter_with_scope(make_scope(vec![KeyValue::new("key", "value1")])); + let meter2 = + meter_provider.meter_with_scope(make_scope(vec![KeyValue::new("key", "value2")])); let counter1 = meter1 .u64_counter("my_counter") @@ -682,13 +683,13 @@ mod tests { ); let scope = &resource_metrics[0].scope_metrics[0].scope; - assert_eq!(scope.name, "test.meter"); - assert_eq!(scope.version, Some(Cow::Borrowed("v0.1.0"))); - assert_eq!(scope.schema_url, Some(Cow::Borrowed("http://example.com"))); + assert_eq!(scope.name(), "test.meter"); + assert_eq!(scope.version(), Some("v0.1.0")); + assert_eq!(scope.schema_url(), Some("http://example.com")); // This is validating current behavior, but it is not guaranteed to be the case in the future, // as this is a user error and SDK reserves right to change this behavior. - assert_eq!(scope.attributes, vec![KeyValue::new("key", "value1")]); + assert!(scope.attributes().eq(&[KeyValue::new("key", "value1")])); let metric = &resource_metrics[0].scope_metrics[0].metrics[0]; assert_eq!(metric.name, "my_counter"); @@ -2341,7 +2342,7 @@ mod tests { ) -> Option<&'a ScopeMetrics> { metrics .iter() - .find(|&scope_metric| scope_metric.scope.name == name) + .find(|&scope_metric| scope_metric.scope.name() == name) } struct TestContext { diff --git a/opentelemetry-sdk/src/trace/mod.rs b/opentelemetry-sdk/src/trace/mod.rs index 7ce5e7b977..e8dd8922d9 100644 --- a/opentelemetry-sdk/src/trace/mod.rs +++ b/opentelemetry-sdk/src/trace/mod.rs @@ -83,7 +83,7 @@ mod tests { assert_eq!(exported_spans.len(), 1); let span = &exported_spans[0]; assert_eq!(span.name, "span_name_updated"); - assert_eq!(span.instrumentation_scope.name, "test_tracer"); + assert_eq!(span.instrumentation_scope.name(), "test_tracer"); assert_eq!(span.attributes.len(), 1); assert_eq!(span.events.len(), 1); assert_eq!(span.events[0].name, "test-event"); @@ -118,7 +118,7 @@ mod tests { assert_eq!(exported_spans.len(), 1); let span = &exported_spans[0]; assert_eq!(span.name, "span_name"); - assert_eq!(span.instrumentation_scope.name, "test_tracer"); + assert_eq!(span.instrumentation_scope.name(), "test_tracer"); assert_eq!(span.attributes.len(), 1); assert_eq!(span.events.len(), 1); assert_eq!(span.events[0].name, "test-event"); @@ -155,7 +155,7 @@ mod tests { let span = &exported_spans[0]; assert_eq!(span.name, "span_name"); assert_eq!(span.span_kind, SpanKind::Server); - assert_eq!(span.instrumentation_scope.name, "test_tracer"); + assert_eq!(span.instrumentation_scope.name(), "test_tracer"); assert_eq!(span.attributes.len(), 1); assert_eq!(span.events.len(), 1); assert_eq!(span.events[0].name, "test-event"); @@ -333,9 +333,8 @@ mod tests { let tracer = provider.tracer_with_scope(scope); let instrumentation_scope = tracer.instrumentation_scope(); - let attributes = &instrumentation_scope.attributes; - assert_eq!(attributes.len(), 1); - assert_eq!(attributes[0].key, "test_k".into()); - assert_eq!(attributes[0].value, "test_v".into()); + assert!(instrumentation_scope + .attributes() + .eq(&[KeyValue::new("test_k", "test_v")])); } } diff --git a/opentelemetry-sdk/src/trace/tracer.rs b/opentelemetry-sdk/src/trace/tracer.rs index 2004fdf2cd..cf2a58583d 100644 --- a/opentelemetry-sdk/src/trace/tracer.rs +++ b/opentelemetry-sdk/src/trace/tracer.rs @@ -30,8 +30,8 @@ impl fmt::Debug for Tracer { /// Omitting `provider` here is necessary to avoid cycles. fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { f.debug_struct("Tracer") - .field("name", &self.scope.name) - .field("version", &self.scope.version) + .field("name", &self.scope.name()) + .field("version", &self.scope.version()) .finish() } } diff --git a/opentelemetry-stdout/src/common.rs b/opentelemetry-stdout/src/common.rs index 83685d3f03..4da706f893 100644 --- a/opentelemetry-stdout/src/common.rs +++ b/opentelemetry-stdout/src/common.rs @@ -236,9 +236,9 @@ pub(crate) struct Scope { impl From for Scope { fn from(value: opentelemetry::InstrumentationScope) -> Self { Scope { - name: value.name, - version: value.version, - attributes: value.attributes.into_iter().map(Into::into).collect(), + name: value.name().to_owned().into(), + version: value.version().map(ToOwned::to_owned).map(Into::into), + attributes: value.attributes().map(Into::into).collect(), dropped_attributes_count: 0, } } diff --git a/opentelemetry-stdout/src/metrics/exporter.rs b/opentelemetry-stdout/src/metrics/exporter.rs index b2b078a51b..ed82f8a8ca 100644 --- a/opentelemetry-stdout/src/metrics/exporter.rs +++ b/opentelemetry-stdout/src/metrics/exporter.rs @@ -72,17 +72,16 @@ impl PushMetricExporter for MetricExporter { fn print_metrics(metrics: &[ScopeMetrics]) { for (i, metric) in metrics.iter().enumerate() { println!("\tInstrumentation Scope #{}", i); - println!("\t\tName : {}", &metric.scope.name); - if let Some(version) = &metric.scope.version { + println!("\t\tName : {}", &metric.scope.name()); + if let Some(version) = &metric.scope.version() { println!("\t\tVersion : {:?}", version); } - if let Some(schema_url) = &metric.scope.schema_url { + if let Some(schema_url) = &metric.scope.schema_url() { println!("\t\tSchemaUrl: {:?}", schema_url); } metric .scope - .attributes - .iter() + .attributes() .enumerate() .for_each(|(index, kv)| { if index == 0 { diff --git a/opentelemetry-stdout/src/trace/exporter.rs b/opentelemetry-stdout/src/trace/exporter.rs index 798e6b4247..4435e75d32 100644 --- a/opentelemetry-stdout/src/trace/exporter.rs +++ b/opentelemetry-stdout/src/trace/exporter.rs @@ -72,16 +72,18 @@ fn print_spans(batch: Vec) { for (i, span) in batch.into_iter().enumerate() { println!("Span #{}", i); println!("\tInstrumentation Scope"); - println!("\t\tName : {:?}", &span.instrumentation_scope.name); - if let Some(version) = &span.instrumentation_scope.version { + println!( + "\t\tName : {:?}", + &span.instrumentation_scope.name() + ); + if let Some(version) = &span.instrumentation_scope.version() { println!("\t\tVersion : {:?}", version); } - if let Some(schema_url) = &span.instrumentation_scope.schema_url { + if let Some(schema_url) = &span.instrumentation_scope.schema_url() { println!("\t\tSchemaUrl: {:?}", schema_url); } span.instrumentation_scope - .attributes - .iter() + .attributes() .enumerate() .for_each(|(index, kv)| { if index == 0 { diff --git a/opentelemetry-zipkin/src/exporter/model/mod.rs b/opentelemetry-zipkin/src/exporter/model/mod.rs index 15646429c9..a78708a2ae 100644 --- a/opentelemetry-zipkin/src/exporter/model/mod.rs +++ b/opentelemetry-zipkin/src/exporter/model/mod.rs @@ -46,11 +46,14 @@ pub(crate) fn into_zipkin_span(local_endpoint: Endpoint, span_data: SpanData) -> [ ( INSTRUMENTATION_LIBRARY_NAME, - Some(span_data.instrumentation_scope.name), + Some(span_data.instrumentation_scope.name().to_owned()), ), ( INSTRUMENTATION_LIBRARY_VERSION, - span_data.instrumentation_scope.version, + span_data + .instrumentation_scope + .version() + .map(ToOwned::to_owned), ), ] .into_iter() diff --git a/opentelemetry/CHANGELOG.md b/opentelemetry/CHANGELOG.md index 2b181cc8ad..d208cbe7b9 100644 --- a/opentelemetry/CHANGELOG.md +++ b/opentelemetry/CHANGELOG.md @@ -38,6 +38,8 @@ let counter = meter.u64_counter("my_counter").build(); - `global::handle_error` usage inside the opentelemetry crates has been replaced with `global::otel_info`, `otel_warn`, `otel_debug` and `otel_error` macros based on the severity of the internal logs. - The default behavior of `global::handle_error` was to log the error using `eprintln!`. With otel macro, the internal logs get emitted via `tracing` macros of matching severity. Users now need to configure the `tracing` layer to capture these logs. - Refer to this PR description for migration guide. Also refer to [self-diagnostics](https://github.com/open-telemetry/opentelemetry-rust/tree/main/examples/self-diagnostics) example on how to configure the tracing layer for internal logs. +- **Breaking change**: replaced `InstrumentationScope` public attributes by getters [#2275](https://github.com/open-telemetry/opentelemetry-rust/pull/2275) + ## v0.26.0 Released 2024-Sep-30 diff --git a/opentelemetry/src/common.rs b/opentelemetry/src/common.rs index f152826b23..078831a64e 100644 --- a/opentelemetry/src/common.rs +++ b/opentelemetry/src/common.rs @@ -419,18 +419,18 @@ pub struct InstrumentationScope { /// The library name. /// /// This should be the name of the crate providing the instrumentation. - pub name: Cow<'static, str>, + name: Cow<'static, str>, /// The library version. - pub version: Option>, + version: Option>, /// [Schema URL] used by this library. /// /// [Schema URL]: https://github.com/open-telemetry/opentelemetry-specification/blob/v1.9.0/specification/schemas/overview.md#schema-url - pub schema_url: Option>, + schema_url: Option>, /// Specifies the instrumentation scope attributes to associate with emitted telemetry. - pub attributes: Vec, + attributes: Vec, } // Uniqueness for InstrumentationScope does not depend on attributes @@ -462,6 +462,32 @@ impl InstrumentationScope { attributes: None, } } + + /// Returns the instrumentation library name. + #[inline] + pub fn name(&self) -> &str { + &self.name + } + + /// Returns the instrumentation library version. + #[inline] + pub fn version(&self) -> Option<&str> { + self.version.as_deref() + } + + /// Returns the [Schema URL] used by this library. + /// + /// [Schema URL]: https://github.com/open-telemetry/opentelemetry-specification/blob/v1.9.0/specification/schemas/overview.md#schema-url + #[inline] + pub fn schema_url(&self) -> Option<&str> { + self.schema_url.as_deref() + } + + /// Returns the instrumentation scope attributes to associate with emitted telemetry. + #[inline] + pub fn attributes(&self) -> impl Iterator { + self.attributes.iter() + } } /// Configuration options for [InstrumentationScope]. @@ -478,11 +504,8 @@ impl InstrumentationScope { #[derive(Debug)] pub struct InstrumentationScopeBuilder { name: Cow<'static, str>, - version: Option>, - schema_url: Option>, - attributes: Option>, }