-
Notifications
You must be signed in to change notification settings - Fork 468
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: export SDK crate version as constant #2504
base: main
Are you sure you want to change the base?
feat: export SDK crate version as constant #2504
Conversation
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #2504 +/- ##
=====================================
Coverage 77.9% 77.9%
=====================================
Files 123 123
Lines 22944 22944
=====================================
Hits 17880 17880
Misses 5064 5064 ☔ View full report in Codecov by Sentry. |
|
||
/// 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"); |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.:
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 🙂
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for your interest in contributing to the project!
I've requested changes. Please see https://github.com/open-telemetry/opentelemetry-rust/pull/2504/files#r1913817079
Changes
PR adds a simple constant for the SDK crate's version (pulled directly from the crate's manifest [ref]).
This is specifically useful in conjunction with things like populating the value of
telemetry.sdk.version
when building aResource
(for example).Merge requirement checklist
N/A
Unit tests added/updated (if applicable)N/A
AppropriateCHANGELOG.md
files updated for non-trivial, user-facing changesN/A
Changes in public API reviewed (if applicable)