Skip to content

Conversation

@alwx
Copy link
Contributor

@alwx alwx commented Jan 26, 2026

📢 Type of change

  • Bugfix
  • New feature
  • Enhancement
  • Refactoring

📜 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

  • I added tests to verify 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.
  • All tests passing
  • No breaking changes

🔮 Next steps

@alwx alwx self-assigned this Jan 26, 2026
@github-actions
Copy link
Contributor

github-actions bot commented Jan 26, 2026

Semver Impact of This PR

None (no version bump detected)

📋 Changelog Preview

This is how your changes will appear in the changelog.
Entries from this PR are highlighted with a left border (blockquote style).


  • Support for applying scope attributes to logs by alwx in #5579
  • chore(deps): update Bundler Plugins to v4.8.0 by github-actions in #5581
  • feat(tracing): Add sentry-span-attributes prop for custom span attributes by antonis in #5569
  • chore(deps): bump actions/checkout from 6.0.1 to 6.0.2 by dependabot in #5576
  • chore(deps): bump github/codeql-action from 4.31.10 to 4.31.11 by dependabot in #5573
  • chore(deps): bump getsentry/craft from 2.19.0 to 2.20.0 by dependabot in #5575
  • chore(deps): bump getsentry/craft/.github/workflows/changelog-preview.yml from 2.19.0 to 2.20.0 by dependabot in #5574
  • ci(release): Fix changelog-preview permissions by BYK in #5571

🤖 This preview updates automatically when you update the PR.

@alwx alwx added the ready-to-merge Triggers the full CI test suite label Jan 26, 2026
@alwx alwx marked this pull request as ready for review January 26, 2026 11:56
@github-actions
Copy link
Contributor

github-actions bot commented Jan 26, 2026

Android (legacy) Performance metrics 🚀

  Plain With Sentry Diff
Startup time 490.02 ms 523.66 ms 33.64 ms
Size 43.75 MiB 48.40 MiB 4.65 MiB

Baseline results on branch: main

Startup times

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

@github-actions
Copy link
Contributor

github-actions bot commented Jan 26, 2026

iOS (legacy) Performance metrics 🚀

  Plain With Sentry Diff
Startup time 1224.38 ms 1224.74 ms 0.37 ms
Size 3.38 MiB 4.60 MiB 1.22 MiB

Baseline results on branch: main

Startup times

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

@antonis
Copy link
Contributor

antonis commented Jan 26, 2026

@sentry review

@github-actions
Copy link
Contributor

iOS (new) Performance metrics 🚀

  Plain With Sentry Diff
Startup time 1187.98 ms 1189.34 ms 1.36 ms
Size 3.38 MiB 4.60 MiB 1.22 MiB

Baseline results on branch: main

Startup times

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

@antonis
Copy link
Contributor

antonis commented Jan 26, 2026

The flaky Native Tests / ios should be fixed with #5577 🤞

Copy link
Contributor

@antonis antonis left a 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.

@lucas-zimerman
Copy link
Collaborator

@sentry review

@lucas-zimerman
Copy link
Collaborator

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();
Copy link
Collaborator

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.

Copy link
Contributor Author

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.

Copy link
Contributor Author

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

Copy link
Collaborator

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

Copy link
Collaborator

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

@alwx alwx requested a review from lucas-zimerman January 27, 2026 09:03
@alwx
Copy link
Contributor Author

alwx commented Jan 27, 2026

@antonis I've added all the missing scope attributes sync methods for both iOS and Android in the latest two commits. Please check!

@alwx alwx requested a review from antonis January 27, 2026 09:49
@github-actions
Copy link
Contributor

Android (new) Performance metrics 🚀

  Plain With Sentry Diff
Startup time 438.15 ms 460.20 ms 22.05 ms
Size 43.94 MiB 49.26 MiB 5.32 MiB

Baseline results on branch: main

Startup times

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

RCT_EXPORT_METHOD(setAttribute : (NSString *)key value : (NSString *)value)
{
[SentrySDKWrapper
configureScope:^(SentryScope *_Nonnull scope) { [scope setAttribute:value forKey:key]; }];
Copy link
Collaborator

@lucas-zimerman lucas-zimerman Jan 27, 2026

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

Copy link
Contributor

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?

Copy link
Contributor Author

@alwx alwx Jan 27, 2026

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 ?

Copy link
Contributor Author

@alwx alwx Jan 27, 2026

Choose a reason for hiding this comment

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

Copy link
Contributor

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

@alwx alwx requested a review from lucas-zimerman January 27, 2026 15:17
setEvenIfPresent = true,
): void {
if (value && (!logAttributes[key] || setEvenIfPresent)) {
if (value != null && (!logAttributes[key] || setEvenIfPresent)) {
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ready-to-merge Triggers the full CI test suite

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Apply Scope Attributes to Logs

4 participants