Skip to content

Commit d421aab

Browse files
authored
feat(trace): add TelemetryResourceDetector (#899)
1 parent 5efe37a commit d421aab

File tree

2 files changed

+31
-1
lines changed

2 files changed

+31
-1
lines changed

opentelemetry-sdk/src/resource/mod.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,17 @@
1818
//! - [`EnvResourceDetector`] - detect resource from environmental variables.
1919
//! - [`OsResourceDetector`] - detect OS from runtime.
2020
//! - [`ProcessResourceDetector`] - detect process information.
21+
//! - [`TelemetryResourceDetector`] - detect telemetry SDK's information.
2122
mod env;
2223
mod os;
2324
mod process;
25+
mod telemetry;
2426

2527
pub use env::EnvResourceDetector;
2628
pub use env::SdkProvidedResourceDetector;
2729
pub use os::OsResourceDetector;
2830
pub use process::ProcessResourceDetector;
31+
pub use telemetry::TelemetryResourceDetector;
2932

3033
#[cfg(feature = "metrics")]
3134
use opentelemetry_api::attributes;
@@ -242,7 +245,7 @@ impl<'a> IntoIterator for &'a Resource {
242245
/// ResourceDetector detects OpenTelemetry resource information
243246
///
244247
/// Implementations of this trait can be passed to
245-
/// the `Resource::from_detectors` function to generate a Resource from the merged information.
248+
/// the [`Resource::from_detectors`] function to generate a Resource from the merged information.
246249
pub trait ResourceDetector {
247250
/// detect returns an initialized Resource based on gathered information.
248251
///
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
use crate::resource::ResourceDetector;
2+
use crate::Resource;
3+
use opentelemetry_api::KeyValue;
4+
use std::time::Duration;
5+
6+
/// Detect the telemetry SDK information used to capture data recorded by the instrumentation libraries.
7+
///
8+
/// It provides:
9+
/// - The name of the telemetry SDK(`telemetry.sdk.name`). It will be `opentelemetry` for SDK provided by opentelemetry project.
10+
/// - The language of the telemetry SDK(`telemetry.sdk.language`). It will be `rust` for this SDK.
11+
/// - The version of the telemetry SDK(`telemetry.sdk.version`). It will be current `opentelemetry_sdk` crate version.
12+
///
13+
/// Note that the `telemetry.auto.version` is not provided as of now.
14+
///
15+
/// See [semantic conventions](https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/resource/semantic_conventions/README.md#telemetry-sdk) for details.
16+
#[derive(Debug)]
17+
pub struct TelemetryResourceDetector;
18+
19+
impl ResourceDetector for TelemetryResourceDetector {
20+
fn detect(&self, _timeout: Duration) -> Resource {
21+
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")),
25+
])
26+
}
27+
}

0 commit comments

Comments
 (0)