Skip to content
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

impr: Slightly speed up serializing scope #4661

Merged
merged 3 commits into from
Dec 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

- Improve compiler error message for missing Swift declarations due to APPLICATION_EXTENSION_API_ONLY (#4603)
- Mask screenshots for errors (#4623)
- Slightly speed up serializing scope (#4661)

### Features

Expand Down
14 changes: 7 additions & 7 deletions Sources/Sentry/SentryScope.m
Original file line number Diff line number Diff line change
Expand Up @@ -465,9 +465,14 @@ - (void)clearAttachments
}

NSDictionary *traceContext = nil;
@synchronized(_spanLock) {
traceContext = [self buildTraceContext:_span];
id<SentrySpan> span = nil;

if (self.span != nil) {
@synchronized(_spanLock) {
span = self.span;
}
}
traceContext = [self buildTraceContext:span];
serializedData[@"traceContext"] = traceContext;

NSDictionary *context = [self context];
Expand Down Expand Up @@ -606,8 +611,6 @@ - (SentryEvent *__nullable)applyToEvent:(SentryEvent *)event
}
}

// We don't need call synchronized(_spanLock) here because we get a copy of the span in the
// _spanLock above.
newContext[@"trace"] = [self buildTraceContext:span];

event.context = newContext;
Expand All @@ -619,9 +622,6 @@ - (void)addObserver:(id<SentryScopeObserver>)observer
[self.observers addObject:observer];
}

/**
* Make sure to call this inside @c synchronized(_spanLock) caus this method isn't thread safe.
*/
- (NSDictionary *)buildTraceContext:(nullable id<SentrySpan>)span
{
if (span != nil) {
Expand Down
Loading