-
-
Notifications
You must be signed in to change notification settings - Fork 357
Support for applying scope attributes to logs #5579
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
base: main
Are you sure you want to change the base?
Conversation
Semver Impact of This PR⚪ None (no version bump detected) 📋 Changelog PreviewThis is how your changes will appear in the changelog.
🤖 This preview updates automatically when you update the PR. |
Android (legacy) Performance metrics 🚀
|
| Revision | Plain | With Sentry | Diff |
|---|---|---|---|
| 3099014+dirty | 439.20 ms | 468.40 ms | 29.20 ms |
| 5526494 | 440.84 ms | 448.36 ms | 7.52 ms |
| 6479fd5+dirty | 412.95 ms | 434.02 ms | 21.07 ms |
| 955f2eb+dirty | 422.74 ms | 410.19 ms | -12.55 ms |
| 90e7cb3+dirty | 470.65 ms | 499.08 ms | 28.43 ms |
| a2bb688+dirty | 409.65 ms | 410.45 ms | 0.80 ms |
| 55b77fc+dirty | 411.87 ms | 417.16 ms | 5.29 ms |
| 266bc7e+dirty | 485.02 ms | 551.94 ms | 66.92 ms |
| 69602ce | 417.47 ms | 443.52 ms | 26.05 ms |
| 6a70a7e+dirty | 381.72 ms | 413.94 ms | 32.22 ms |
App size
| Revision | Plain | With Sentry | Diff |
|---|---|---|---|
| 3099014+dirty | 17.75 MiB | 19.70 MiB | 1.95 MiB |
| 5526494 | 17.75 MiB | 19.68 MiB | 1.93 MiB |
| 6479fd5+dirty | 17.75 MiB | 19.68 MiB | 1.94 MiB |
| 955f2eb+dirty | 17.75 MiB | 19.70 MiB | 1.95 MiB |
| 90e7cb3+dirty | 43.75 MiB | 48.02 MiB | 4.27 MiB |
| a2bb688+dirty | 17.75 MiB | 19.70 MiB | 1.95 MiB |
| 55b77fc+dirty | 43.75 MiB | 47.99 MiB | 4.24 MiB |
| 266bc7e+dirty | 43.75 MiB | 47.99 MiB | 4.24 MiB |
| 69602ce | 17.75 MiB | 19.68 MiB | 1.94 MiB |
| 6a70a7e+dirty | 17.75 MiB | 19.69 MiB | 1.94 MiB |
iOS (legacy) Performance metrics 🚀
|
| Revision | Plain | With Sentry | Diff |
|---|---|---|---|
| c771b48+dirty | 1224.02 ms | 1219.72 ms | -4.30 ms |
| 6c11c6a+dirty | 1202.43 ms | 1212.70 ms | 10.27 ms |
| c9e95bd+dirty | 1240.19 ms | 1246.33 ms | 6.14 ms |
| 266bc7e+dirty | 1190.56 ms | 1191.47 ms | 0.91 ms |
| 785ffb1+dirty | 1237.63 ms | 1240.50 ms | 2.87 ms |
| b3b5b0d+dirty | 1227.71 ms | 1239.50 ms | 11.79 ms |
| af9331b+dirty | 1233.61 ms | 1230.50 ms | -3.11 ms |
| 8d89cc9+dirty | 1222.92 ms | 1239.43 ms | 16.51 ms |
| f17e051+dirty | 1193.71 ms | 1223.51 ms | 29.80 ms |
| 1bea095+dirty | 1234.14 ms | 1233.96 ms | -0.18 ms |
App size
| Revision | Plain | With Sentry | Diff |
|---|---|---|---|
| c771b48+dirty | 3.41 MiB | 4.58 MiB | 1.17 MiB |
| 6c11c6a+dirty | 3.44 MiB | 4.60 MiB | 1.16 MiB |
| c9e95bd+dirty | 2.63 MiB | 3.87 MiB | 1.24 MiB |
| 266bc7e+dirty | 3.41 MiB | 4.58 MiB | 1.17 MiB |
| 785ffb1+dirty | 2.63 MiB | 3.81 MiB | 1.18 MiB |
| b3b5b0d+dirty | 2.63 MiB | 3.91 MiB | 1.28 MiB |
| af9331b+dirty | 2.63 MiB | 3.91 MiB | 1.28 MiB |
| 8d89cc9+dirty | 2.63 MiB | 3.96 MiB | 1.33 MiB |
| f17e051+dirty | 3.41 MiB | 4.67 MiB | 1.25 MiB |
| 1bea095+dirty | 2.63 MiB | 3.99 MiB | 1.35 MiB |
|
@sentry review |
iOS (new) Performance metrics 🚀
|
| Revision | Plain | With Sentry | Diff |
|---|---|---|---|
| 0d6e618+dirty | 1191.59 ms | 1190.35 ms | -1.24 ms |
| 459a438+dirty | 1218.39 ms | 1226.14 ms | 7.75 ms |
| 170d5ea+dirty | 1233.96 ms | 1242.54 ms | 8.58 ms |
| a941c72+dirty | 1187.82 ms | 1192.13 ms | 4.30 ms |
| 294387d+dirty | 1199.23 ms | 1204.16 ms | 4.93 ms |
| 2104bb9+dirty | 1221.63 ms | 1214.73 ms | -6.91 ms |
| 5526494+dirty | 1217.06 ms | 1222.26 ms | 5.20 ms |
| 90afdd3+dirty | 1216.17 ms | 1225.55 ms | 9.38 ms |
| 6fee48d+dirty | 1208.85 ms | 1218.52 ms | 9.67 ms |
| 7be1f99+dirty | 1222.43 ms | 1217.15 ms | -5.28 ms |
App size
| Revision | Plain | With Sentry | Diff |
|---|---|---|---|
| 0d6e618+dirty | 3.41 MiB | 4.58 MiB | 1.17 MiB |
| 459a438+dirty | 3.19 MiB | 4.55 MiB | 1.36 MiB |
| 170d5ea+dirty | 3.19 MiB | 4.55 MiB | 1.36 MiB |
| a941c72+dirty | 3.41 MiB | 4.59 MiB | 1.18 MiB |
| 294387d+dirty | 3.41 MiB | 4.59 MiB | 1.18 MiB |
| 2104bb9+dirty | 3.19 MiB | 4.57 MiB | 1.38 MiB |
| 5526494+dirty | 3.19 MiB | 4.44 MiB | 1.25 MiB |
| 90afdd3+dirty | 3.19 MiB | 4.55 MiB | 1.37 MiB |
| 6fee48d+dirty | 3.19 MiB | 4.53 MiB | 1.35 MiB |
| 7be1f99+dirty | 3.19 MiB | 4.38 MiB | 1.19 MiB |
|
The flaky Native Tests / ios should be fixed with #5577 🤞 |
antonis
left a comment
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.
Thank you for this enhancement @alwx 🙇
The implementation looks solid and well-tested to me 👍
Please also add a changelog entry to communicate the feature enhancement.
q: Should we also sync the attributes to native? I guess we can handle this separately anyway if needed.
Let's also wait for @lucas-zimerman feedback before merging since he has a better understanding of the logs implementation.
|
@sentry review |
|
I am reviewing the code but i dont think the bot is working |
|
|
||
| // Apply scope attributes from all active scopes (global, isolation, and current) | ||
| // These are applied first so they can be overridden by more specific attributes | ||
| const scopeAttributes = collectScopeAttributes(); |
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.
could we try using
const {
user: { id, email, username },
attributes: scopeAttributes = {},
} = getCombinedScopeData(getIsolationScope(), currentScope);
I am not sure why Sentry JS Opted to only load data from isolationScope and currentScope, might be worth checking why.
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.
That's a good suggestion and my first try as well but the thing is getCombinedScopeData is an internal function and not getting exported by the JS SDK. That's why I do the merging and use getCombinedScopeAttributes here.
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.
Regarding the global scope: they do use it, they just call getGlobalScope() directly here: https://github.com/getsentry/sentry-javascript/blob/develop/packages/core/src/utils/scopeData.ts#L125
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.
Oh True, I did a quick test on capacitor and I was able to import it from @sentry/core but not on React Native
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.
EDIT: it should be be exported on @sentry/core
|
@antonis I've added all the missing scope attributes sync methods for both iOS and Android in the latest two commits. Please check! |
Android (new) Performance metrics 🚀
|
| Revision | Plain | With Sentry | Diff |
|---|---|---|---|
| 8ff81c0+dirty | 392.47 ms | 431.52 ms | 39.05 ms |
| 1ef8a04+dirty | 450.73 ms | 482.38 ms | 31.65 ms |
| 785ffb1+dirty | 380.65 ms | 451.83 ms | 71.18 ms |
| ba75c7c+dirty | 377.92 ms | 417.74 ms | 39.83 ms |
| 180638b+dirty | 434.46 ms | 470.90 ms | 36.44 ms |
| 8e653ac+dirty | 304.49 ms | 308.84 ms | 4.35 ms |
| 6416d6c+dirty | 469.16 ms | 508.22 ms | 39.06 ms |
| a2bb688+dirty | 371.19 ms | 389.18 ms | 17.99 ms |
| 59d1977+dirty | 366.15 ms | 393.21 ms | 27.06 ms |
| a699d13+dirty | 441.38 ms | 487.27 ms | 45.89 ms |
App size
| Revision | Plain | With Sentry | Diff |
|---|---|---|---|
| 8ff81c0+dirty | 43.94 MiB | 48.87 MiB | 4.93 MiB |
| 1ef8a04+dirty | 43.94 MiB | 48.87 MiB | 4.93 MiB |
| 785ffb1+dirty | 7.15 MiB | 8.42 MiB | 1.27 MiB |
| ba75c7c+dirty | 7.15 MiB | 8.42 MiB | 1.27 MiB |
| 180638b+dirty | 43.94 MiB | 48.91 MiB | 4.97 MiB |
| 8e653ac+dirty | 7.15 MiB | 8.46 MiB | 1.31 MiB |
| 6416d6c+dirty | 43.94 MiB | 48.88 MiB | 4.94 MiB |
| a2bb688+dirty | 7.15 MiB | 8.43 MiB | 1.28 MiB |
| 59d1977+dirty | 43.94 MiB | 49.22 MiB | 5.29 MiB |
| a699d13+dirty | 43.94 MiB | 48.88 MiB | 4.94 MiB |
packages/core/ios/RNSentry.mm
Outdated
| RCT_EXPORT_METHOD(setAttribute : (NSString *)key value : (NSString *)value) | ||
| { | ||
| [SentrySDKWrapper | ||
| configureScope:^(SentryScope *_Nonnull scope) { [scope setAttribute:value forKey:key]; }]; |
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.
Does setAttribute:forKey exist here? CI is complaining about it.
Same for line 376
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.
@alwx @lucas-zimerman I think this was added recently in 9.x. Probably will need to target v8 for this changes. Would it make sense to ship just the JS side and do the native changes separately?
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 could just leave the placeholders and TODOs in code so that when the native changes are done we're ready to quickly add them.
I can also create an issue to revisit that and move it to "Blocked".
Wdyt @lucas-zimerman @antonis ?
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.
Something like this: bbdb7a5#diff-c68ee9159d63acd4d40c1527f895d595c9e743aa83eb69e1d8f33d31322097a1R735
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.
Sounds good 👍 As you suggested we could open an issue to follow up
| setEvenIfPresent = true, | ||
| ): void { | ||
| if (value && (!logAttributes[key] || setEvenIfPresent)) { | ||
| if (value != null && (!logAttributes[key] || setEvenIfPresent)) { |
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.
Bug: The check !logAttributes[key] incorrectly uses truthiness instead of key presence, causing existing falsy attribute values (0, false, "") to be overridden when they shouldn't be.
Severity: MEDIUM
Suggested Fix
Replace the truthy check !logAttributes[key] with a proper key presence check, such as !(key in logAttributes). This will correctly verify if the key exists in the logAttributes object, regardless of its value's truthiness.
Prompt for AI Agent
Review the code at the location below. A potential bug has been identified by an AI
agent.
Verify if this is a real issue. If it is, propose a fix; if not, explain why it's not
valid.
Location: packages/core/src/js/integrations/logEnricherIntegration.ts#L45
Potential issue: In the `logEnricherIntegration`, when applying scope attributes to a
log event with `setEvenIfPresent` as `false`, the code uses a truthy check
(`!logAttributes[key]`) to determine if an attribute already exists. This causes
existing log attributes with falsy values (e.g., `count: 0`, `enabled: false`, or an
empty string) to be incorrectly overridden by attributes from the scope, even though the
intent is to preserve them. This leads to data loss in logs when these common falsy
values are used.
Did we get this right? 👍 / 👎 to inform future reviews.
📢 Type of change
📜 Description
Implements support for applying scope attributes to logs in the Sentry React Native SDK, aligning with the JavaScript SDK 10.32.0 (#5487).
Fixes #5488
Most of the changes actually come from JS SDK, this PR just exposes the required functions and does merging of scope attributes. I've also added tests for the changes to make sure the merging is being done correctly and that the scope attributes are being applied.
📝 Checklist
sendDefaultPIIis enabled🔮 Next steps