Skip to content

Commit

Permalink
Merge pull request #361 from bugsnag/PLAT-13288-split-span-end-and-pr…
Browse files Browse the repository at this point in the history
…ocess

[PLAT-31288] Split out ending a span and closing/sending for processing
  • Loading branch information
kstenerud authored Dec 12, 2024
2 parents 9bec60b + 3307452 commit 3b097a7
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ NS_ASSUME_NONNULL_BEGIN
@property (nonatomic) BSGFirstClass firstClass;
@property (nonatomic) SpanKind kind;
@property (nonatomic,readwrite) BOOL isMutable;
@property (nonatomic,readwrite) BOOL hasBeenProcessed;
@property (nonatomic,readonly) NSUInteger attributeCountLimit;
@property (nonatomic,readwrite) BOOL wasStartOrEndTimeProvided;
@property (nonatomic) BSGInstrumentRendering instrumentRendering;
Expand Down
48 changes: 29 additions & 19 deletions Sources/BugsnagPerformance/Public/BugsnagPerformanceSpan.mm
Original file line number Diff line number Diff line change
Expand Up @@ -90,21 +90,13 @@ - (void)abortIfOpen {
}
self.state = SpanStateAborted;
}
[self callOnSpanClosed];
self.isMutable = false;
[self sendForProcessing];
}

- (void)abortUnconditionally {
bool wasOpen = false;
@synchronized (self) {
BSGLogDebug(@"Span.abortUnconditionally: %@: Was open: %d", self.name, self.state == SpanStateOpen);
wasOpen = self.state == SpanStateOpen;
self.state = SpanStateAborted;
}
if (wasOpen) {
[self callOnSpanClosed];
}
self.isMutable = false;
BSGLogDebug(@"Span.abortUnconditionally: %@: Was open: %d", self.name, self.state == SpanStateOpen);
self.state = SpanStateAborted;
[self sendForProcessing];
}

- (void)end {
Expand Down Expand Up @@ -134,18 +126,36 @@ - (void)endWithAbsoluteTime:(CFAbsoluteTime)endTime {
}
}

self.endAbsTime = currentTimeIfUnset(endTime);
[self markEndAbsoluteTime:endTime];
self.state = SpanStateEnded;
}
[self callOnSpanClosed];
self.isMutable = false;
[self sendForProcessing];
}

- (void)markEndTime:(NSDate *)endTime {
[self markEndAbsoluteTime:dateToAbsoluteTime(endTime)];
}

- (void)callOnSpanClosed {
auto onSpanClosed = self.onSpanClosed;
if(onSpanClosed != nil) {
onSpanClosed(self);
- (void)markEndAbsoluteTime:(CFAbsoluteTime)endTime {
self.endAbsTime = currentTimeIfUnset(endTime);
}

- (void)sendForProcessing {
BOOL hasBeenProcessed = false;
@synchronized (self) {
hasBeenProcessed = self.hasBeenProcessed;
self.hasBeenProcessed = true;
}
if (!hasBeenProcessed) {
auto onSpanClosed = self.onSpanClosed;
if(onSpanClosed != nil) {
onSpanClosed(self);
}
}
if (self.state == SpanStateOpen) {
self.state = SpanStateEnded;
}
self.isMutable = false;
}

- (void)endOnDestroy {
Expand Down

0 comments on commit 3b097a7

Please sign in to comment.