Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove os and process resource detectors #1624

Merged
merged 8 commits into from
Mar 19, 2024
Merged
1 change: 1 addition & 0 deletions opentelemetry-sdk/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
Fix metrics aggregation bug when using Views to drop attributes.
- [#1623](https://github.com/open-telemetry/opentelemetry-rust/pull/1623) Add Drop implementation for SdkMeterProvider, which shuts down
metricreaders, thereby allowing metrics still in memory to be flushed out.
- **Breaking** [#1624](https://github.com/open-telemetry/opentelemetry-rust/pull/1624) Remove `OsResourceDetector` and `ProcessResourceDetector` resource detectors, use the `opentelemetry-resource-detector` [crate](https://github.com/open-telemetry/opentelemetry-rust-contrib/tree/main/opentelemetry-resource-detectors) instead.

## v0.22.1

Expand Down
32 changes: 32 additions & 0 deletions opentelemetry-sdk/src/resource/attributes.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/// Logical name of the service.
///
/// MUST be the same for all instances of horizontally scaled services. If the value was not specified, SDKs MUST fallback to `unknown_service:` concatenated with [`process.executable.name`](process.md#process), e.g. `unknown_service:bash`. If `process.executable.name` is not available, the value MUST be set to `unknown_service`.
///
/// # Examples
///
/// - `shoppingcart`
pub(crate) const SERVICE_NAME: &str = "service.name";

/// The language of the telemetry SDK.
pub(crate) const TELEMETRY_SDK_LANGUAGE: &str = "telemetry.sdk.language";

/// The name of the telemetry SDK as defined above.
///
/// The OpenTelemetry SDK MUST set the `telemetry.sdk.name` attribute to `opentelemetry`.
/// If another SDK, like a fork or a vendor-provided implementation, is used, this SDK MUST set the
/// `telemetry.sdk.name` attribute to the fully-qualified class or module name of this SDK's main entry point
/// or another suitable identifier depending on the language.
/// The identifier `opentelemetry` is reserved and MUST NOT be used in this case.
/// All custom identifiers SHOULD be stable across different versions of an implementation.
///
/// # Examples
///
/// - `opentelemetry`
pub(crate) const TELEMETRY_SDK_NAME: &str = "telemetry.sdk.name";

/// The version string of the telemetry SDK.
///
/// # Examples
///
/// - `1.2.3`
pub(crate) const TELEMETRY_SDK_VERSION: &str = "telemetry.sdk.version";
13 changes: 6 additions & 7 deletions opentelemetry-sdk/src/resource/env.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,15 +76,15 @@ pub struct SdkProvidedResourceDetector;
impl ResourceDetector for SdkProvidedResourceDetector {
cijothomas marked this conversation as resolved.
Show resolved Hide resolved
fn detect(&self, _timeout: Duration) -> Resource {
Resource::new(vec![KeyValue::new(
"service.name",
super::SERVICE_NAME,
env::var(OTEL_SERVICE_NAME)
.ok()
.filter(|s| !s.is_empty())
.map(Value::from)
.or_else(|| {
EnvResourceDetector::new()
.detect(Duration::from_secs(0))
.get(Key::new("service.name"))
.get(Key::new(super::SERVICE_NAME))
cijothomas marked this conversation as resolved.
Show resolved Hide resolved
})
.unwrap_or_else(|| "unknown_service".into()),
)])
Expand Down Expand Up @@ -132,18 +132,17 @@ mod tests {

#[test]
fn test_sdk_provided_resource_detector() {
const SERVICE_NAME: &str = "service.name";
// Ensure no env var set
let no_env = SdkProvidedResourceDetector.detect(Duration::from_secs(1));
assert_eq!(
no_env.get(Key::from_static_str(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(Duration::from_secs(1));
assert_eq!(
with_service.get(Key::from_static_str(SERVICE_NAME)),
with_service.get(Key::from_static_str(crate::resource::SERVICE_NAME)),
Some(Value::from("test service")),
)
});
Expand All @@ -154,7 +153,7 @@ mod tests {
|| {
let with_service = SdkProvidedResourceDetector.detect(Duration::from_secs(1));
assert_eq!(
with_service.get(Key::from_static_str(SERVICE_NAME)),
with_service.get(Key::from_static_str(crate::resource::SERVICE_NAME)),
Some(Value::from("test service1")),
)
},
Expand All @@ -169,7 +168,7 @@ mod tests {
|| {
let with_service = SdkProvidedResourceDetector.detect(Duration::from_secs(1));
assert_eq!(
with_service.get(Key::from_static_str(SERVICE_NAME)),
with_service.get(Key::from_static_str(crate::resource::SERVICE_NAME)),
Some(Value::from("test service"))
);
},
Expand Down
11 changes: 5 additions & 6 deletions opentelemetry-sdk/src/resource/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,17 @@
//! SDK.
//!
//! - [`EnvResourceDetector`] - detect resource from environmental variables.
//! - [`OsResourceDetector`] - detect OS from runtime.
//! - [`ProcessResourceDetector`] - detect process information.
//! - [`TelemetryResourceDetector`] - detect telemetry SDK's information.
//!
//! The OS and Process resource detectors are now packaged separately in the `opentelemetry-resource-detector` [crate](https://github.com/open-telemetry/opentelemetry-rust-contrib/tree/main/opentelemetry-resource-detectors).
mod env;
mod os;
mod process;
mod telemetry;

mod attributes;
pub(crate) use attributes::*;

pub use env::EnvResourceDetector;
pub use env::SdkProvidedResourceDetector;
pub use os::OsResourceDetector;
pub use process::ProcessResourceDetector;
pub use telemetry::TelemetryResourceDetector;

use opentelemetry::{Key, KeyValue, Value};
Expand Down
46 changes: 0 additions & 46 deletions opentelemetry-sdk/src/resource/os.rs

This file was deleted.

47 changes: 0 additions & 47 deletions opentelemetry-sdk/src/resource/process.rs

This file was deleted.

6 changes: 3 additions & 3 deletions opentelemetry-sdk/src/resource/telemetry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ pub struct TelemetryResourceDetector;
impl ResourceDetector for TelemetryResourceDetector {
fn detect(&self, _timeout: Duration) -> Resource {
Resource::new(vec![
KeyValue::new("telemetry.sdk.name", "opentelemetry"),
KeyValue::new("telemetry.sdk.language", "rust"),
KeyValue::new("telemetry.sdk.version", env!("CARGO_PKG_VERSION")),
KeyValue::new(super::TELEMETRY_SDK_NAME, "opentelemetry"),
KeyValue::new(super::TELEMETRY_SDK_LANGUAGE, "rust"),
KeyValue::new(super::TELEMETRY_SDK_VERSION, env!("CARGO_PKG_VERSION")),
])
}
}
Loading