Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions opentelemetry-sdk/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,8 @@ re-introduced in a future date, along with the ability to change the cardinality
limit.

- *Breaking* Removed unused `opentelemetry_sdk::Error` enum.
- *Breaking* Resource.get() modified to require reference to Key instead of owned.
Replace `get(Key::from_static_str("key"))` with `get(&Key::from_static_str("key"))`
- *Breaking* (Affects custom Exporter authors only) Moved `ExportError` trait from `opentelemetry::export::ExportError` to `opentelemetry_sdk::ExportError`
- *Breaking (Affects custom SpanExporter, SpanProcessor authors only)*: Rename namespaces for Span exporter structs/traits
before:
Expand Down
8 changes: 4 additions & 4 deletions opentelemetry-sdk/src/logs/log_emitter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -403,22 +403,22 @@ mod tests {
assert_eq!(
provider
.resource()
.get(Key::from_static_str(resource_key))
.get(&Key::from_static_str(resource_key))
.map(|v| v.to_string()),
expect.map(|s| s.to_string())
);
};
let assert_telemetry_resource = |provider: &super::LoggerProvider| {
assert_eq!(
provider.resource().get(TELEMETRY_SDK_LANGUAGE.into()),
provider.resource().get(&TELEMETRY_SDK_LANGUAGE.into()),
Some(Value::from("rust"))
);
assert_eq!(
provider.resource().get(TELEMETRY_SDK_NAME.into()),
provider.resource().get(&TELEMETRY_SDK_NAME.into()),
Some(Value::from("opentelemetry"))
);
assert_eq!(
provider.resource().get(TELEMETRY_SDK_VERSION.into()),
provider.resource().get(&TELEMETRY_SDK_VERSION.into()),
Some(Value::from(env!("CARGO_PKG_VERSION")))
);
};
Expand Down
8 changes: 4 additions & 4 deletions opentelemetry-sdk/src/metrics/meter_provider.rs
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,7 @@ mod tests {
assert_eq!(
provider.inner.pipes.0[0]
.resource
.get(Key::from_static_str(resource_key))
.get(&Key::from_static_str(resource_key))
.map(|v| v.to_string()),
expect.map(|s| s.to_string())
);
Expand All @@ -328,19 +328,19 @@ mod tests {
assert_eq!(
provider.inner.pipes.0[0]
.resource
.get(TELEMETRY_SDK_LANGUAGE.into()),
.get(&TELEMETRY_SDK_LANGUAGE.into()),
Some(Value::from("rust"))
);
assert_eq!(
provider.inner.pipes.0[0]
.resource
.get(TELEMETRY_SDK_NAME.into()),
.get(&TELEMETRY_SDK_NAME.into()),
Some(Value::from("opentelemetry"))
);
assert_eq!(
provider.inner.pipes.0[0]
.resource
.get(TELEMETRY_SDK_VERSION.into()),
.get(&TELEMETRY_SDK_VERSION.into()),
Some(Value::from(env!("CARGO_PKG_VERSION")))
);
};
Expand Down
10 changes: 5 additions & 5 deletions opentelemetry-sdk/src/resource/env.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ impl ResourceDetector for SdkProvidedResourceDetector {
.or_else(|| {
EnvResourceDetector::new()
.detect()
.get(Key::new(super::SERVICE_NAME))
.get(&Key::new(super::SERVICE_NAME))
})
.unwrap_or_else(|| "unknown_service".into()),
)])
Expand Down Expand Up @@ -138,14 +138,14 @@ mod tests {
// Ensure no env var set
let no_env = SdkProvidedResourceDetector.detect();
assert_eq!(
no_env.get(Key::from_static_str(crate::resource::SERVICE_NAME)),
no_env.get(&Key::from_static_str(crate::resource::SERVICE_NAME)),
Some(Value::from("unknown_service")),
);

temp_env::with_var(OTEL_SERVICE_NAME, Some("test service"), || {
let with_service = SdkProvidedResourceDetector.detect();
assert_eq!(
with_service.get(Key::from_static_str(crate::resource::SERVICE_NAME)),
with_service.get(&Key::from_static_str(crate::resource::SERVICE_NAME)),
Some(Value::from("test service")),
)
});
Expand All @@ -156,7 +156,7 @@ mod tests {
|| {
let with_service = SdkProvidedResourceDetector.detect();
assert_eq!(
with_service.get(Key::from_static_str(crate::resource::SERVICE_NAME)),
with_service.get(&Key::from_static_str(crate::resource::SERVICE_NAME)),
Some(Value::from("test service1")),
)
},
Expand All @@ -171,7 +171,7 @@ mod tests {
|| {
let with_service = SdkProvidedResourceDetector.detect();
assert_eq!(
with_service.get(Key::from_static_str(crate::resource::SERVICE_NAME)),
with_service.get(&Key::from_static_str(crate::resource::SERVICE_NAME)),
Some(Value::from("test service"))
);
},
Expand Down
11 changes: 4 additions & 7 deletions opentelemetry-sdk/src/resource/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,11 @@ pub struct Resource {
impl Resource {
/// Creates a [ResourceBuilder] that allows you to configure multiple aspects of the Resource.
///
/// This [ResourceBuilder] will always include the following [ResourceDetector]s:
/// This [ResourceBuilder] will include the following [ResourceDetector]s:
/// - [SdkProvidedResourceDetector]
/// - [TelemetryResourceDetector]
/// - [EnvResourceDetector]
/// If you'd like to start from an empty resource, use [Resource::builder_empty].
pub fn builder() -> ResourceBuilder {
ResourceBuilder {
resource: Self::from_detectors(&[
Expand Down Expand Up @@ -138,8 +139,6 @@ impl Resource {
}

/// Create a new `Resource` from resource detectors.
///
/// timeout will be applied to each detector.
fn from_detectors(detectors: &[Box<dyn ResourceDetector>]) -> Self {
let mut resource = Resource::empty();
for detector in detectors {
Expand Down Expand Up @@ -227,8 +226,8 @@ impl Resource {
}

/// Retrieve the value from resource associate with given key.
pub fn get(&self, key: Key) -> Option<Value> {
self.inner.attrs.get(&key).cloned()
pub fn get(&self, key: &Key) -> Option<Value> {
self.inner.attrs.get(key).cloned()
}
}

Expand Down Expand Up @@ -260,8 +259,6 @@ impl<'a> IntoIterator for &'a Resource {
pub trait ResourceDetector {
/// detect returns an initialized Resource based on gathered information.
///
/// timeout is used in case the detection operation takes too much time.
///
/// If source information to construct a Resource is inaccessible, an empty Resource should be returned
///
/// If source information to construct a Resource is invalid, for example,
Expand Down
11 changes: 7 additions & 4 deletions opentelemetry-sdk/src/trace/provider.rs
Original file line number Diff line number Diff line change
Expand Up @@ -552,7 +552,7 @@ mod tests {
provider
.config()
.resource
.get(Key::from_static_str(resource_key))
.get(&Key::from_static_str(resource_key))
.map(|v| v.to_string()),
expect.map(|s| s.to_string())
);
Expand All @@ -562,15 +562,18 @@ mod tests {
provider
.config()
.resource
.get(TELEMETRY_SDK_LANGUAGE.into()),
.get(&TELEMETRY_SDK_LANGUAGE.into()),
Some(Value::from("rust"))
);
assert_eq!(
provider.config().resource.get(TELEMETRY_SDK_NAME.into()),
provider.config().resource.get(&TELEMETRY_SDK_NAME.into()),
Some(Value::from("opentelemetry"))
);
assert_eq!(
provider.config().resource.get(TELEMETRY_SDK_VERSION.into()),
provider
.config()
.resource
.get(&TELEMETRY_SDK_VERSION.into()),
Some(Value::from(env!("CARGO_PKG_VERSION")))
);
};
Expand Down
2 changes: 1 addition & 1 deletion opentelemetry-sdk/src/trace/span_processor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1222,7 +1222,7 @@ mod tests {
exported_resource
.as_ref()
.unwrap()
.get(Key::new("service.name")),
.get(&Key::new("service.name")),
Some(Value::from("test_service"))
);
}
Expand Down
2 changes: 1 addition & 1 deletion opentelemetry-zipkin/src/exporter/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@
} else {
let service_name = SdkProvidedResourceDetector
.detect()
.get(semcov::resource::SERVICE_NAME.into())
.get(&semcov::resource::SERVICE_NAME.into())

Check warning on line 119 in opentelemetry-zipkin/src/exporter/mod.rs

View check run for this annotation

Codecov / codecov/patch

opentelemetry-zipkin/src/exporter/mod.rs#L119

Added line #L119 was not covered by tests
.unwrap()
.to_string();
(
Expand Down
Loading