Skip to content

Commit

Permalink
Merge branch 'main' into value-map-collect
Browse files Browse the repository at this point in the history
  • Loading branch information
cijothomas authored Nov 6, 2024
2 parents f343aa0 + 1fd871a commit fc04691
Show file tree
Hide file tree
Showing 20 changed files with 135 additions and 121 deletions.
8 changes: 4 additions & 4 deletions opentelemetry-appender-tracing/src/layer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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.
Expand Down
7 changes: 2 additions & 5 deletions opentelemetry-otlp/tests/integration_test/tests/logs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,15 @@ use log::{info, Level};
use opentelemetry::logs::LogError;
use opentelemetry::KeyValue;
use opentelemetry_appender_log::OpenTelemetryLogBridge;
use opentelemetry_otlp::{LogExporter, WithExportConfig};
use opentelemetry_otlp::LogExporter;
use opentelemetry_sdk::logs::LoggerProvider;
use opentelemetry_sdk::{logs as sdklogs, runtime, Resource};
use std::error::Error;
use std::fs::File;
use std::os::unix::fs::MetadataExt;

fn init_logs() -> Result<sdklogs::LoggerProvider, LogError> {
let exporter = LogExporter::builder()
.with_tonic()
.with_endpoint("0.0.0.0:4317")
.build()?;
let exporter = LogExporter::builder().with_tonic().build()?;

Ok(LoggerProvider::builder()
.with_batch_exporter(exporter, runtime::Tokio)
Expand Down
20 changes: 8 additions & 12 deletions opentelemetry-proto/src/transform/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
}
Expand Down Expand Up @@ -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()
}
}
Expand All @@ -112,8 +108,8 @@ pub mod tonic {
#[derive(Default, Debug)]
pub struct Attributes(pub ::std::vec::Vec<crate::proto::tonic::common::v1::KeyValue>);

impl From<Vec<opentelemetry::KeyValue>> for Attributes {
fn from(kvs: Vec<opentelemetry::KeyValue>) -> Self {
impl<I: IntoIterator<Item = opentelemetry::KeyValue>> From<I> for Attributes {
fn from(kvs: I) -> Self {
Attributes(
kvs.into_iter()
.map(|api_kv| KeyValue {
Expand Down
7 changes: 3 additions & 4 deletions opentelemetry-proto/src/transform/logs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()],
Expand All @@ -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()
Expand Down
5 changes: 2 additions & 3 deletions opentelemetry-proto/src/transform/metrics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
}
}
Expand Down
5 changes: 2 additions & 3 deletions opentelemetry-proto/src/transform/trace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion opentelemetry-sdk/src/logs/log_emitter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
15 changes: 7 additions & 8 deletions opentelemetry-sdk/src/logs/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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")]));
}
}
12 changes: 5 additions & 7 deletions opentelemetry-sdk/src/metrics/instrument.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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())
}
}

Expand Down
34 changes: 17 additions & 17 deletions opentelemetry-sdk/src/metrics/meter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand All @@ -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));
Expand All @@ -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."
);
Expand All @@ -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));
Expand All @@ -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));
Expand All @@ -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."
);
Expand All @@ -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));
Expand All @@ -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));
Expand All @@ -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."
);
Expand All @@ -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));
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand Down
20 changes: 9 additions & 11 deletions opentelemetry-sdk/src/metrics/meter_provider.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
Loading

0 comments on commit fc04691

Please sign in to comment.