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

[PLAT-31288] Split out ending a span and closing/sending for processing #361

Merged
merged 1 commit into from
Dec 12, 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
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
Loading