Skip to content

Commit

Permalink
fix: Keep status of auto transactions when finishing (#2684)
Browse files Browse the repository at this point in the history
Don't overwrite the existing status of auto-generated transactions
when finishing them.

Fixes GH-2402
  • Loading branch information
philipphofmann authored Feb 14, 2023
1 parent 7f691b5 commit d413317
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

- Cleanup AppHangTracking properly when closing SDK (#2671)
- Add EXC_BAD_ACCESS subtypes to events (#2667)
- Keep status of auto transactions when finishing (#2684)
- Fix atomic import error for profiling (#2683)

## 8.1.0
Expand Down
5 changes: 5 additions & 0 deletions Sources/Sentry/SentryTracer.m
Original file line number Diff line number Diff line change
Expand Up @@ -451,6 +451,11 @@ - (BOOL)hasUnfinishedChildSpansToWaitFor

- (void)finishInternal
{
// Keep existing status of auto generated transactions if set by the user.
if ([self isAutoGeneratedTransaction] && !self.wasFinishCalled
&& self.status != kSentrySpanStatusUndefined) {
_finishStatus = self.status;
}
[super finishWithStatus:_finishStatus];

if (self.finishCallback) {
Expand Down
41 changes: 41 additions & 0 deletions Tests/SentryTests/Performance/SentryTracerTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,47 @@ class SentryTracerTests: XCTestCase {
XCTAssertEqual(sut.status, .ok)
}

func testIdleTransactionWithStatus_KeepsStatusWhenAutoFinishing() {
let status = SentrySpanStatus.aborted
let sut = fixture.getSut(idleTimeout: fixture.idleTimeout, dispatchQueueWrapper: fixture.dispatchQueue)
sut.status = status

let child = sut.startChild(operation: fixture.transactionOperation)
advanceTime(bySeconds: 0.1)
child.finish()

fixture.dispatchQueue.invokeLastDispatchAfter()

assertOneTransactionCaptured(sut)
XCTAssertEqual(status, sut.status)
}

func testWaitForChildrenTransactionWithStatus_OverwriteStatusInFinish() {
let sut = fixture.getSut()
sut.status = .aborted

let finishstatus = SentrySpanStatus.cancelled

let child = sut.startChild(operation: fixture.transactionOperation)
advanceTime(bySeconds: 0.1)
child.finish()

sut.finish(status: finishstatus)

assertOneTransactionCaptured(sut)
XCTAssertEqual(finishstatus, sut.status)
}

func testManualTransaction_OverwritesStatusInFinish() {
let sut = fixture.getSut(waitForChildren: false)
sut.status = .aborted

sut.finish()

assertOneTransactionCaptured(sut)
XCTAssertEqual(.ok, sut.status)
}

func testFinish_WithoutHub_DoesntCaptureTransaction() {
let sut = SentryTracer(transactionContext: fixture.transactionContext, hub: nil, waitForChildren: false)

Expand Down

0 comments on commit d413317

Please sign in to comment.