Skip to content

Commit

Permalink
ref: Reduce nesting in performance tracker (#4520)
Browse files Browse the repository at this point in the history
Reduce nesting in startSpanWithName by using .span instead of useSpan.
  • Loading branch information
philipphofmann authored Nov 12, 2024
1 parent fecbc76 commit 3396be1
Showing 1 changed file with 24 additions and 24 deletions.
48 changes: 24 additions & 24 deletions Sources/Sentry/SentryPerformanceTracker.m
Original file line number Diff line number Diff line change
Expand Up @@ -61,36 +61,36 @@ - (SentrySpanId *)startSpanWithName:(NSString *)name
operation:operation
origin:origin];

[SentrySDK.currentHub.scope useSpan:^(id<SentrySpan> span) {
BOOL bindToScope = NO;
if (span == nil) {
bindToScope = YES;
}
id<SentrySpan> span = SentrySDK.currentHub.scope.span;

BOOL bindToScope = NO;
if (span == nil) {
bindToScope = YES;
}
#if SENTRY_HAS_UIKIT
else {
if ([SentryUIEventTracker isUIEventOperation:span.operation]) {
SENTRY_LOG_DEBUG(
@"Cancelling previous UI event span %@", span.spanId.sentrySpanIdString);
[span finishWithStatus:kSentrySpanStatusCancelled];
bindToScope = YES;
}
else {
if ([SentryUIEventTracker isUIEventOperation:span.operation]) {
SENTRY_LOG_DEBUG(
@"Cancelling previous UI event span %@", span.spanId.sentrySpanIdString);
[span finishWithStatus:kSentrySpanStatusCancelled];
bindToScope = YES;
}
}
#endif // SENTRY_HAS_UIKIT

SENTRY_LOG_DEBUG(@"Creating new transaction bound to scope: %d", bindToScope);
SENTRY_LOG_DEBUG(@"Creating new transaction bound to scope: %d", bindToScope);

newSpan = [SentrySDK.currentHub
startTransactionWithContext:context
bindToScope:bindToScope
customSamplingContext:@{}
configuration:[SentryTracerConfiguration configurationWithBlock:^(
SentryTracerConfiguration *configuration) {
configuration.waitForChildren = YES;
configuration.finishMustBeCalled = YES;
}]];
newSpan = [SentrySDK.currentHub
startTransactionWithContext:context
bindToScope:bindToScope
customSamplingContext:@{}
configuration:[SentryTracerConfiguration configurationWithBlock:^(
SentryTracerConfiguration *configuration) {
configuration.waitForChildren = YES;
configuration.finishMustBeCalled = YES;
}]];

[(SentryTracer *)newSpan setDelegate:self];
}];
[(SentryTracer *)newSpan setDelegate:self];
}

SentrySpanId *spanId = newSpan.spanId;
Expand Down

0 comments on commit 3396be1

Please sign in to comment.