Skip to content

Commit 5cbc2c3

Browse files
authored
Merge branch 'main' into addlink
2 parents 4b77bd2 + 13c9dc5 commit 5cbc2c3

File tree

7 files changed

+47
-109
lines changed

7 files changed

+47
-109
lines changed

opentelemetry-sdk/CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
Fix metrics aggregation bug when using Views to drop attributes.
1010
- [#1623](https://github.com/open-telemetry/opentelemetry-rust/pull/1623) Add Drop implementation for SdkMeterProvider, which shuts down
1111
metricreaders, thereby allowing metrics still in memory to be flushed out.
12+
- **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.
1213

1314
## v0.22.1
1415

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
/// Logical name of the service.
2+
///
3+
/// 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`.
4+
///
5+
/// # Examples
6+
///
7+
/// - `shoppingcart`
8+
pub(crate) const SERVICE_NAME: &str = "service.name";
9+
10+
/// The language of the telemetry SDK.
11+
pub(crate) const TELEMETRY_SDK_LANGUAGE: &str = "telemetry.sdk.language";
12+
13+
/// The name of the telemetry SDK as defined above.
14+
///
15+
/// The OpenTelemetry SDK MUST set the `telemetry.sdk.name` attribute to `opentelemetry`.
16+
/// If another SDK, like a fork or a vendor-provided implementation, is used, this SDK MUST set the
17+
/// `telemetry.sdk.name` attribute to the fully-qualified class or module name of this SDK's main entry point
18+
/// or another suitable identifier depending on the language.
19+
/// The identifier `opentelemetry` is reserved and MUST NOT be used in this case.
20+
/// All custom identifiers SHOULD be stable across different versions of an implementation.
21+
///
22+
/// # Examples
23+
///
24+
/// - `opentelemetry`
25+
pub(crate) const TELEMETRY_SDK_NAME: &str = "telemetry.sdk.name";
26+
27+
/// The version string of the telemetry SDK.
28+
///
29+
/// # Examples
30+
///
31+
/// - `1.2.3`
32+
pub(crate) const TELEMETRY_SDK_VERSION: &str = "telemetry.sdk.version";

opentelemetry-sdk/src/resource/env.rs

+6-7
Original file line numberDiff line numberDiff line change
@@ -76,15 +76,15 @@ pub struct SdkProvidedResourceDetector;
7676
impl ResourceDetector for SdkProvidedResourceDetector {
7777
fn detect(&self, _timeout: Duration) -> Resource {
7878
Resource::new(vec![KeyValue::new(
79-
"service.name",
79+
super::SERVICE_NAME,
8080
env::var(OTEL_SERVICE_NAME)
8181
.ok()
8282
.filter(|s| !s.is_empty())
8383
.map(Value::from)
8484
.or_else(|| {
8585
EnvResourceDetector::new()
8686
.detect(Duration::from_secs(0))
87-
.get(Key::new("service.name"))
87+
.get(Key::new(super::SERVICE_NAME))
8888
})
8989
.unwrap_or_else(|| "unknown_service".into()),
9090
)])
@@ -132,18 +132,17 @@ mod tests {
132132

133133
#[test]
134134
fn test_sdk_provided_resource_detector() {
135-
const SERVICE_NAME: &str = "service.name";
136135
// Ensure no env var set
137136
let no_env = SdkProvidedResourceDetector.detect(Duration::from_secs(1));
138137
assert_eq!(
139-
no_env.get(Key::from_static_str(SERVICE_NAME)),
138+
no_env.get(Key::from_static_str(crate::resource::SERVICE_NAME)),
140139
Some(Value::from("unknown_service")),
141140
);
142141

143142
temp_env::with_var(OTEL_SERVICE_NAME, Some("test service"), || {
144143
let with_service = SdkProvidedResourceDetector.detect(Duration::from_secs(1));
145144
assert_eq!(
146-
with_service.get(Key::from_static_str(SERVICE_NAME)),
145+
with_service.get(Key::from_static_str(crate::resource::SERVICE_NAME)),
147146
Some(Value::from("test service")),
148147
)
149148
});
@@ -154,7 +153,7 @@ mod tests {
154153
|| {
155154
let with_service = SdkProvidedResourceDetector.detect(Duration::from_secs(1));
156155
assert_eq!(
157-
with_service.get(Key::from_static_str(SERVICE_NAME)),
156+
with_service.get(Key::from_static_str(crate::resource::SERVICE_NAME)),
158157
Some(Value::from("test service1")),
159158
)
160159
},
@@ -169,7 +168,7 @@ mod tests {
169168
|| {
170169
let with_service = SdkProvidedResourceDetector.detect(Duration::from_secs(1));
171170
assert_eq!(
172-
with_service.get(Key::from_static_str(SERVICE_NAME)),
171+
with_service.get(Key::from_static_str(crate::resource::SERVICE_NAME)),
173172
Some(Value::from("test service"))
174173
);
175174
},

opentelemetry-sdk/src/resource/mod.rs

+5-6
Original file line numberDiff line numberDiff line change
@@ -16,18 +16,17 @@
1616
//! SDK.
1717
//!
1818
//! - [`EnvResourceDetector`] - detect resource from environmental variables.
19-
//! - [`OsResourceDetector`] - detect OS from runtime.
20-
//! - [`ProcessResourceDetector`] - detect process information.
2119
//! - [`TelemetryResourceDetector`] - detect telemetry SDK's information.
20+
//!
21+
//! 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).
2222
mod env;
23-
mod os;
24-
mod process;
2523
mod telemetry;
2624

25+
mod attributes;
26+
pub(crate) use attributes::*;
27+
2728
pub use env::EnvResourceDetector;
2829
pub use env::SdkProvidedResourceDetector;
29-
pub use os::OsResourceDetector;
30-
pub use process::ProcessResourceDetector;
3130
pub use telemetry::TelemetryResourceDetector;
3231

3332
use opentelemetry::{Key, KeyValue, Value};

opentelemetry-sdk/src/resource/os.rs

-46
This file was deleted.

opentelemetry-sdk/src/resource/process.rs

-47
This file was deleted.

opentelemetry-sdk/src/resource/telemetry.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,9 @@ pub struct TelemetryResourceDetector;
1919
impl ResourceDetector for TelemetryResourceDetector {
2020
fn detect(&self, _timeout: Duration) -> Resource {
2121
Resource::new(vec![
22-
KeyValue::new("telemetry.sdk.name", "opentelemetry"),
23-
KeyValue::new("telemetry.sdk.language", "rust"),
24-
KeyValue::new("telemetry.sdk.version", env!("CARGO_PKG_VERSION")),
22+
KeyValue::new(super::TELEMETRY_SDK_NAME, "opentelemetry"),
23+
KeyValue::new(super::TELEMETRY_SDK_LANGUAGE, "rust"),
24+
KeyValue::new(super::TELEMETRY_SDK_VERSION, env!("CARGO_PKG_VERSION")),
2525
])
2626
}
2727
}

0 commit comments

Comments
 (0)