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

fix: Avoid stringifying int values unless necessary #2795

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

Conversation

cijothomas
Copy link
Member

Though this works, I am wondering if AnyValue should contain variants to store u64 too?

@cijothomas cijothomas requested a review from a team as a code owner March 12, 2025 16:57
@cijothomas
Copy link
Member Author

Though this works, I am wondering if AnyValue should contain variants to store u64 too?

https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/logs/data-model.md#type-any
Only signed is required as per spec, so if we get a u64, a reasonable option is to do what this PR is doing...

Copy link

codecov bot commented Mar 12, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 79.6%. Comparing base (ad88615) to head (fbe687a).

Additional details and impacted files
@@          Coverage Diff          @@
##            main   #2795   +/-   ##
=====================================
  Coverage   79.6%   79.6%           
=====================================
  Files        124     124           
  Lines      23174   23216   +42     
=====================================
+ Hits       18456   18497   +41     
- Misses      4718    4719    +1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

- `u64` and `usize` values are stored as `opentelemetry::logs::AnyValue::Int`
when conversion is feasible. Otherwise stored as
`opentelemetry::logs::AnyValue::String`. This avoids unnecessary string
allocation when values can be represented in their original types.
Copy link
Member

Choose a reason for hiding this comment

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

nit - indicate it as breaking change, for customers who were expecting u64 to be serialized as string in backends?

Copy link
Member Author

Choose a reason for hiding this comment

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

I am unsure about that. I think it is a bug to convert a u64 to string by default, so this is more like a bug fix. And naturally, every bug fix can be thought of as breaking change to those whole relied on buggy behavior 🤣

We may still do more tweaks here..Do you think it should NOT be done post 1.0?

Copy link
Contributor

Choose a reason for hiding this comment

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

I'm curious. It looks like you have only added record_u64 method implementation. How does it help usize values?

Copy link
Member Author

Choose a reason for hiding this comment

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

tracing fired the u64 callbacks for usize. (they don't have a usize callback)

Copy link
Member

Choose a reason for hiding this comment

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

Not sure if we treat this as bug fix. - converting u64 to string, or u64 to i64 both are type conversion.

if is_duplicated_metadata(field.name()) {
return;
}
match i64::try_from(value) {
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: Use if let Ok() construct instead of match for a cleaner less indented code.

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.

3 participants