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

feat(trace): add TelemetryResourceDetector #899

Merged
merged 1 commit into from
Oct 24, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion opentelemetry-sdk/src/resource/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,17 @@
//! - [`EnvResourceDetector`] - detect resource from environmental variables.
//! - [`OsResourceDetector`] - detect OS from runtime.
//! - [`ProcessResourceDetector`] - detect process information.
//! - [`TelemetryResourceDetector`] - detect telemetry SDK's information.
mod env;
mod os;
mod process;
mod telemetry;

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

#[cfg(feature = "metrics")]
use opentelemetry_api::attributes;
Expand Down Expand Up @@ -242,7 +245,7 @@ impl<'a> IntoIterator for &'a Resource {
/// ResourceDetector detects OpenTelemetry resource information
///
/// Implementations of this trait can be passed to
/// the `Resource::from_detectors` function to generate a Resource from the merged information.
/// the [`Resource::from_detectors`] function to generate a Resource from the merged information.
pub trait ResourceDetector {
/// detect returns an initialized Resource based on gathered information.
///
Expand Down
27 changes: 27 additions & 0 deletions opentelemetry-sdk/src/resource/telemetry.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
use crate::resource::ResourceDetector;
use crate::Resource;
use opentelemetry_api::KeyValue;
use std::time::Duration;

/// Detect the telemetry SDK information used to capture data recorded by the instrumentation libraries.
///
/// It provides:
/// - The name of the telemetry SDK(`telemetry.sdk.name`). It will be `opentelemetry` for SDK provided by opentelemetry project.
/// - The language of the telemetry SDK(`telemetry.sdk.language`). It will be `rust` for this SDK.
/// - The version of the telemetry SDK(`telemetry.sdk.version`). It will be current `opentelemetry_sdk` crate version.
///
/// Note that the `telemetry.auto.version` is not provided as of now.
///
/// See [semantic conventions](https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/resource/semantic_conventions/README.md#telemetry-sdk) for details.
#[derive(Debug)]
pub struct TelemetryResourceDetector;

impl ResourceDetector for TelemetryResourceDetector {
fn detect(&self, _timeout: Duration) -> Resource {
Resource::new(vec![
KeyValue::new("telemetry.sdk.name", "opentelemetry"),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
KeyValue::new("telemetry.sdk.name", "opentelemetry"),
KeyValue::new("telemetry.sdk.name", "opentelemetry-sdk"),

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good call out, but the spec asks all opentelemetry provided SDK to use opentelemetry as the value for this key

The default OpenTelemetry SDK provided by the OpenTelemetry project MUST set telemetry.sdk.name to the value opentelemetry

KeyValue::new("telemetry.sdk.language", "rust"),
KeyValue::new("telemetry.sdk.version", env!("CARGO_PKG_VERSION")),
])
}
}