opentelemetry_sdk/resource/
telemetry.rs

1use crate::resource::ResourceDetector;
2use crate::Resource;
3use opentelemetry::KeyValue;
4
5/// Detect the telemetry SDK information used to capture data recorded by the instrumentation libraries.
6///
7/// It provides:
8/// - The name of the telemetry SDK(`telemetry.sdk.name`). It will be `opentelemetry` for SDK provided by opentelemetry project.
9/// - The language of the telemetry SDK(`telemetry.sdk.language`). It will be `rust` for this SDK.
10/// - The version of the telemetry SDK(`telemetry.sdk.version`). It will be current `opentelemetry_sdk` crate version.
11///
12///
13/// See [semantic conventions](https://github.com/open-telemetry/semantic-conventions/blob/main/docs/resource/README.md#telemetry-sdk) for details.
14#[derive(Debug)]
15pub struct TelemetryResourceDetector;
16
17impl ResourceDetector for TelemetryResourceDetector {
18    fn detect(&self) -> Resource {
19        Resource::builder_empty()
20            .with_attributes([
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            .build()
26    }
27}