Skip to content
Closed
Changes from 1 commit
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
4 changes: 4 additions & 0 deletions opentelemetry-sdk/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -150,3 +150,7 @@ pub mod util;
pub use resource::Resource;

pub mod error;

/// The crate's version string, useful for populating [`Resource`] keys like
/// [`telemetry.sdk.version`](https://docs.rs/opentelemetry-semantic-conventions/latest/opentelemetry_semantic_conventions/attribute/constant.TELEMETRY_SDK_VERSION.html)
pub const VERSION: &str = env!("CARGO_PKG_VERSION");
Copy link
Member

Choose a reason for hiding this comment

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

we try to keep public API as lean as possible, so unless there is a strong reason to expose this, we should not.
Users rarely need this as this is automatically populated.

Copy link
Author

@the-wondersmith the-wondersmith Jan 16, 2025

Choose a reason for hiding this comment

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

FWIW, my specific usecase involves setting the value of telemetry.sdk.version (as defined in opentelemetry_semantic_conventions), e.x.:

Screenshot 2025-01-16 at 3 10 26 PM

Specifically, that's in a library crate intended for use in other "actual" crates to simplify setting up tracing with export to an OTLP collector, so it's a layer removed even from the opentelemetry_sdk crate itself and users are likely to not even be pulling in the sdk crate themselves, so I can't really have them supply it.

Including this simple constant just makes it much easier to "stay in line" with the defined convention without having to constantly remember to update that static string whenever the SDK version changes. Plus, cargo does do a certain amount of fudging with version numbers, so unless I pin explicitly to something like opentelemetry_sdk = "= 0.27.0" the actual version of the SDK that ends up getting used could be anything in the 0.27.* range. Much easier and more reliable to just... export a simple string constant, don't you think? 😅

Oh, and not to potentially talk past the close, but this simple constant won't meaningfully inflate the "weight" of the crate's public API at all - unless it's explicitly used in some downstream crate it won't be included in compiled binaries. In terms of compile-time overhead, cargo takes the time to determine and set that value unconditionally, so it's no extra overhead there either 🙂

Copy link
Author

Choose a reason for hiding this comment

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

@cijothomas ^bump 🙂

Copy link
Author

Choose a reason for hiding this comment

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

@cijothomas ^bump 🙃

Copy link
Member

Choose a reason for hiding this comment

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

Sorry was busy with few other issues, will recheck today, thanks for reminder!

Copy link
Author

Choose a reason for hiding this comment

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

No problem at all! Thank you for taking the time 😅

Copy link
Member

@lalitb lalitb Jan 30, 2025

Choose a reason for hiding this comment

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

@the-wondersmith Can you use TelemetryResourceDetector to populate the otel-sdk version? As an example here -

Resource::from_detectors(
Duration::from_secs(0),
vec![
Box::new(SdkProvidedResourceDetector),
Box::new(EnvResourceDetector::new()),
Box::new(TelemetryResourceDetector),
],

Copy link
Author

Choose a reason for hiding this comment

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

@lalitb Yup, sure can! 😁

Loading