Skip to content

Conversation

@itaybre
Copy link
Contributor

@itaybre itaybre commented Nov 20, 2025

Adds setAttribute and removeAttribute to SentryScope as per https://develop.sentry.dev/sdk/telemetry/scopes/#scope-methods

These attributes will be used for logs in a following PR.
Currently units are not supported since Logs don't support them (yet).

Closes #6835

@github-actions
Copy link
Contributor

github-actions bot commented Nov 20, 2025

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

Generated by 🚫 dangerJS against 4dd8845

@itaybre itaybre added the ready-to-merge Use this label to trigger all PR workflows label Nov 20, 2025
@codecov
Copy link

codecov bot commented Nov 20, 2025

Codecov Report

❌ Patch coverage is 77.27273% with 5 lines in your changes missing coverage. Please review.
✅ Project coverage is 84.920%. Comparing base (e5e08fa) to head (b05d464).
✅ All tests successful. No failed tests found.

Files with missing lines Patch % Lines
Sources/Sentry/SentryScope.m 84.210% 3 Missing ⚠️
...tions/SentryWatchdogTerminationScopeObserver.swift 0.000% 2 Missing ⚠️
Additional details and impacted files

Impacted file tree graph

@@              Coverage Diff              @@
##              main     #6830       +/-   ##
=============================================
+ Coverage   84.918%   84.920%   +0.002%     
=============================================
  Files          453       448        -5     
  Lines        27630     27541       -89     
  Branches     12135     12051       -84     
=============================================
- Hits         23463     23388       -75     
+ Misses        4122      3866      -256     
- Partials        45       287      +242     
Files with missing lines Coverage Δ
Sources/Sentry/SentryCrashIntegration.m 100.000% <100.000%> (ø)
...tions/SentryWatchdogTerminationScopeObserver.swift 75.000% <0.000%> (-5.000%) ⬇️
Sources/Sentry/SentryScope.m 96.052% <84.210%> (-0.790%) ⬇️

... and 42 files with indirect coverage changes


Continue to review full report in Codecov by Sentry.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update e5e08fa...b05d464. Read the comment docs.

@github-actions
Copy link
Contributor

github-actions bot commented Nov 20, 2025

Performance metrics 🚀

  Plain With Sentry Diff
Startup time 1218.43 ms 1258.25 ms 39.82 ms
Size 24.14 KiB 1.01 MiB 1015.72 KiB

Baseline results on branch: main

Startup times

Revision Plain With Sentry Diff
effeafa 1225.88 ms 1249.78 ms 23.90 ms
483cc24 1218.00 ms 1242.59 ms 24.59 ms
c5d3752 1221.51 ms 1245.63 ms 24.11 ms
27e7514 1229.47 ms 1245.60 ms 16.13 ms
afaa522 1234.71 ms 1256.19 ms 21.48 ms
7bd90de 1233.48 ms 1249.47 ms 15.99 ms
e5773c1 1235.10 ms 1264.15 ms 29.04 ms
42a95d5 1206.00 ms 1224.26 ms 18.26 ms
2c889f6 1206.35 ms 1233.29 ms 26.94 ms
f9270f9 1227.90 ms 1253.24 ms 25.34 ms

App size

Revision Plain With Sentry Diff
effeafa 23.74 KiB 926.64 KiB 902.89 KiB
483cc24 24.14 KiB 1.01 MiB 1010.98 KiB
c5d3752 24.14 KiB 1.01 MiB 1013.49 KiB
27e7514 23.75 KiB 919.69 KiB 895.94 KiB
afaa522 23.74 KiB 996.91 KiB 973.17 KiB
7bd90de 23.75 KiB 933.33 KiB 909.58 KiB
e5773c1 23.75 KiB 1.00 MiB 1005.08 KiB
42a95d5 23.75 KiB 906.08 KiB 882.33 KiB
2c889f6 23.75 KiB 1010.42 KiB 986.67 KiB
f9270f9 24.14 KiB 1.01 MiB 1012.18 KiB

Previous results on branch: itay/scopes_set_attributes_logs

Startup times

Revision Plain With Sentry Diff
f2aa2be 1218.04 ms 1253.26 ms 35.21 ms
5456d19 1221.64 ms 1256.84 ms 35.20 ms
263d753 1218.82 ms 1250.37 ms 31.55 ms
668b816 1210.54 ms 1247.96 ms 37.42 ms
4f7825f 1229.96 ms 1266.36 ms 36.40 ms

App size

Revision Plain With Sentry Diff
f2aa2be 24.14 KiB 1.01 MiB 1015.08 KiB
5456d19 24.14 KiB 1.02 MiB 1016.14 KiB
263d753 24.14 KiB 1.01 MiB 1013.78 KiB
668b816 24.14 KiB 1.01 MiB 1015.68 KiB
4f7825f 24.15 KiB 1.01 MiB 1015.11 KiB

Copy link

@cursor cursor bot left a comment

Choose a reason for hiding this comment

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

Bug: Attributes not cleared in clear method

The clear method was not updated to reset the attributesDictionary. As a result, scope.attributes persist on the scope object even after scope.clear() is explicitly called.

Sources/Sentry/SentryScope.m#L170-L203

return nil;
}
- (void)clear
{
// As we need to synchronize the accesses of the arrays and dictionaries and we use the
// references instead of self we remove all objects instead of creating new instances. Removing
// all objects is usually O(n). This is acceptable as we don't expect a huge amount of elements
// in the arrays or dictionaries, that would slow down the performance.
[self clearBreadcrumbs];
@synchronized(_tagDictionary) {
[_tagDictionary removeAllObjects];
}
@synchronized(_extraDictionary) {
[_extraDictionary removeAllObjects];
}
@synchronized(_contextDictionary) {
[_contextDictionary removeAllObjects];
}
@synchronized(_fingerprintArray) {
[_fingerprintArray removeAllObjects];
}
[self clearAttachments];
@synchronized(_spanLock) {
_span = nil;
}
self.userObject = nil;
self.distString = nil;
self.environmentString = nil;
self.levelEnum = kSentryLevelNone;
for (id<SentryScopeObserver> observer in self.observers) {
[observer clear];

Fix in Cursor Fix in Web


Copy link
Member

@philipphofmann philipphofmann left a comment

Choose a reason for hiding this comment

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

Please also update the SentryScope+Equality.m test file.

Currently units are not supported since Logs don't support them (yet).

Yes, but please double-check that we can add these without a breaking change. I think we should be good because we will simply add method overloads, but it is still worth checking if that works.

We should merge this PR including #6834 to main cause otherwise the attributes are useless. Thanks for splitting this up into two PRs.

@itaybre
Copy link
Contributor Author

itaybre commented Nov 25, 2025

Please also update the SentryScope+Equality.m test file.

Currently units are not supported since Logs don't support them (yet).

Yes, but please double-check that we can add these without a breaking change. I think we should be good because we will simply add method overloads, but it is still worth checking if that works.

We should merge this PR including #6834 to main cause otherwise the attributes are useless. Thanks for splitting this up into two PRs.

We can just add a new method with the unit parameter, I initially had it like that until I realized we cannot use the unit at this moment.

I am waiting to merge this one and then the other PR.

Copy link
Member

@philipphofmann philipphofmann 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 I found one potential bug. Almost LGTM

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

Labels

ready-to-merge Use this label to trigger all PR workflows Waiting for: Review ⏳

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feat: Add attributes data to SentryScope

3 participants