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: export SDK crate version as constant #2504

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

the-wondersmith
Copy link

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 a Resource (for example).

Merge requirement checklist

  • CONTRIBUTING guidelines followed
  • N/A Unit tests added/updated (if applicable)
  • N/A Appropriate CHANGELOG.md files updated for non-trivial, user-facing changes
  • N/A Changes in public API reviewed (if applicable)

@the-wondersmith the-wondersmith requested a review from a team as a code owner January 10, 2025 19:50
Copy link

linux-foundation-easycla bot commented Jan 10, 2025

CLA Signed

The committers listed above are authorized under a signed CLA.

Copy link

codecov bot commented Jan 10, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 77.9%. Comparing base (68af3bb) to head (ec8a5c2).

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.
📢 Have feedback on the report? Share it here.


/// 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
Member

@cijothomas cijothomas left a 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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants