opentelemetry_sdk/resource/
telemetry.rs

1use crate::resource::ResourceDetector;
2use crate::Resource;
3use opentelemetry::KeyValue;
4use 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///
14/// See [semantic conventions](https://github.com/open-telemetry/semantic-conventions/blob/main/docs/resource/README.md#telemetry-sdk) for details.
15#[derive(Debug)]
16pub struct TelemetryResourceDetector;
17
18impl ResourceDetector for TelemetryResourceDetector {
19    fn detect(&self, _timeout: Duration) -> Resource {
20        Resource::new(vec![
21            KeyValue::new(super::TELEMETRY_SDK_NAME, "opentelemetry"),
22            KeyValue::new(super::TELEMETRY_SDK_LANGUAGE, "rust"),
23            KeyValue::new(super::TELEMETRY_SDK_VERSION, env!("CARGO_PKG_VERSION")),
24        ])
25    }
26}