Skip to content

Add device and OS attributes to logs #4493

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 17 commits into from
Jun 17, 2025
Merged

Conversation

adinauer
Copy link
Member

📜 Description

Add device and OS attributes to logs:

  • os.name
  • os.device
  • device.brand
  • device.model
  • device.family

💡 Motivation and Context

Closes #4460

💚 How did you test it?

📝 Checklist

  • I added tests to verify the changes.
  • No new PII added or SDK only sends newly added PII if sendDefaultPII is enabled.
  • I updated the docs if needed.
  • I updated the wizard if needed.
  • Review from the native team if needed.
  • No breaking change or entry added to the changelog.
  • No breaking change for hybrid SDKs or communicated to hybrid SDKs.

🔮 Next steps

Copy link
Contributor

github-actions bot commented Jun 17, 2025

Messages
📖 Do not forget to update Sentry-docs with your feature once the pull request gets approved.

Generated by 🚫 dangerJS against 1419268

Copy link
Contributor

github-actions bot commented Jun 17, 2025

Performance metrics 🚀

  Plain With Sentry Diff
Startup time 381.15 ms 402.29 ms 21.14 ms
Size 1.58 MiB 2.09 MiB 518.66 KiB

Previous results on branch: feat/logs-device-and-os-attributes

Startup times

Revision Plain With Sentry Diff
1d37eac 405.41 ms 455.02 ms 49.61 ms
9705052 417.58 ms 454.69 ms 37.11 ms

App size

Revision Plain With Sentry Diff
1d37eac 1.58 MiB 2.12 MiB 550.51 KiB
9705052 1.58 MiB 2.12 MiB 550.53 KiB

@@ -45,6 +45,17 @@ default SentryReplayEvent process(@NotNull SentryReplayEvent event, @NotNull Hin
return event;
}

/**
Copy link
Member Author

Choose a reason for hiding this comment

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

An alternative to going through EventProcessor would be something very similar to it, like a LogProcessor so I opted for simply extending EventProcessor instead.

We could also offer hooks but I didn't want to hack that in, so I went this route and we can transform it into a better hook API in the future.

* @return the event itself, a mutated SentryLogEvent or null
*/
@Nullable
default SentryLogEvent process(@NotNull SentryLogEvent event) {
Copy link
Member Author

Choose a reason for hiding this comment

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

Decided not to add Hint here since we decided to not have it for logs.beforeSend either. LMK if you think it's needed.

Base automatically changed from feat/logs-user-attributes to main June 17, 2025 08:44
@@ -199,6 +210,37 @@ private void mergeOS(final @NotNull SentryBaseEvent event) {
}
}

Copy link
Member

Choose a reason for hiding this comment

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

so I'm thinking querying DeviceInfoUtil is probably too much work for this, shall we maybe just directly use the const values for brand, model and family from android.os.Build? Same for the OS name and version, those are also const values. Just trying to minimize impact since logs can happen frequent and originate from the main thread.

Copy link
Member Author

Choose a reason for hiding this comment

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

Updated, introduced a LazyEvaluator so we don't run a regex for the family on each log emitted.

* @return the event itself, a mutated SentryLogEvent or null
*/
@Nullable
default SentryLogEvent process(@NotNull SentryLogEvent event) {
Copy link
Member

Choose a reason for hiding this comment

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

Can we also add an empty override to MainEventProcessor? I recall there used to be problems in dotnet/unity due to absence of proper desugaring in some versions, so the default interface methods have caused crashes.

Copy link
Member

@romtsn romtsn left a comment

Choose a reason for hiding this comment

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

a couple of things to address, but LGTM otherwise!

@adinauer adinauer enabled auto-merge (squash) June 17, 2025 14:42
@adinauer adinauer merged commit c6f23ec into main Jun 17, 2025
31 of 33 checks passed
@adinauer adinauer deleted the feat/logs-device-and-os-attributes branch June 17, 2025 15:14
@lucas-zimerman
Copy link
Contributor

@romtsn What's the best way for HybridSDKs to use this feature when capturing logs on the hybrid layer?

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.

Add os and device attributes to Android logs
4 participants