Skip to content

refactor(logs): cache default attributes and add OS attributes #842

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

Merged
merged 7 commits into from
Jun 16, 2025

Conversation

lcian
Copy link
Member

@lcian lcian commented Jun 13, 2025

  • Cache default attributes and store them on the client
  • They are always the same anyway. This way we clone once (from the cached attributes map to the actual log attributes) instead of doing multiple smaller clones.
  • Add os.name and os.version attributes to the log, which are mandatory for native SDKs according to the spec, and personally I think they could be useful.
  • The best way I've found to retrieve the OS context in sentry-core without making breaking changes or exposing additional API surface is the one I'm proposing, which still sucks.

Copy link

codecov bot commented Jun 13, 2025

Codecov Report

Attention: Patch coverage is 94.73684% with 3 lines in your changes missing coverage. Please review.

Project coverage is 74.04%. Comparing base (34db51d) to head (9e30911).
Report is 1 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #842      +/-   ##
==========================================
+ Coverage   73.82%   74.04%   +0.22%     
==========================================
  Files          64       64              
  Lines        7762     7778      +16     
==========================================
+ Hits         5730     5759      +29     
+ Misses       2032     2019      -13     
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copy link
Member

@Swatinem Swatinem left a comment

Choose a reason for hiding this comment

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

I think the workaround is reasonable, in particular as its only a one-time cost at initialization time.

Still reminds me that splitting the SDK up into multiple crates was a really bad decision :-D

Comment on lines 495 to 497
if let Some(default_attributes) = self.default_log_attributes.clone() {
for (key, val) in default_attributes.into_iter() {
log.attributes.entry(key).or_insert(val);
Copy link
Member

Choose a reason for hiding this comment

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

I would iterate over default_log_attributes and then clone each key/val separately. This should be cheaper as it avoids having to clone/deallocate the container itself.

Copy link
Member Author

Choose a reason for hiding this comment

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

Okay, I thought this would be better because it's just a single call to clone but maybe I'm wrong (and the compiler does whatever it wants anyways). I'll do it like you said.

Copy link
Member Author

@lcian lcian Jun 16, 2025

Choose a reason for hiding this comment

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

Still reminds me that splitting the SDK up into multiple crates was a really bad decision :-D

I think the sentry-core and sentry split is useful, maybe it would be better for all integrations to live in sentry.

Copy link
Member Author

Choose a reason for hiding this comment

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

But I guess this is a topic for v1 😄

Copy link
Member Author

@lcian lcian Jun 16, 2025

Choose a reason for hiding this comment

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

Fwiw this problem of fetching the OS context applies to other SDKs such as Java, there we will add a new method to the Integration interface to process logs.
I like this approach we're using here more as it seems like a one-off thing and doesn't require API changes, especially as they wouldn't be aligned across SDKs.
We can always revisit in the future.

@lcian lcian marked this pull request as ready for review June 16, 2025 12:18
@lcian lcian merged commit 4553e2e into master Jun 16, 2025
18 checks passed
@lcian lcian deleted the lcian/ref/logs-default-attrs branch June 16, 2025 14:06
@lcian lcian linked an issue Jul 3, 2025 that may be closed by this pull request
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.

[Structured logging] Attach OS context to logs
2 participants