Skip to content

Commit

Permalink
fix: Linking ongoing trace to crash event (#4393)
Browse files Browse the repository at this point in the history
Fix linking a crash event to an ongoing trace by skipping setting the
trace context in Scope.applyToEvent for crash events.

Fixes GH-4375
  • Loading branch information
philipphofmann authored Oct 3, 2024
1 parent 4eea4d1 commit a353899
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
### Fixes

- Fix the versioning to support app release with Beta versions (#4368)
- Linking ongoing trace to crash event (#4393)

## 8.37.0-beta.1

Expand Down
9 changes: 8 additions & 1 deletion Sources/Sentry/SentryScope.m
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#import "SentryAttachment+Private.h"
#import "SentryBreadcrumb.h"
#import "SentryEnvelopeItemType.h"
#import "SentryEvent.h"
#import "SentryEvent+Private.h"
#import "SentryGlobalEventProcessor.h"
#import "SentryLevelMapper.h"
#import "SentryLog.h"
Expand Down Expand Up @@ -564,6 +564,13 @@ - (SentryEvent *__nullable)applyToEvent:(SentryEvent *)event
[SentryDictionary mergeEntriesFromDictionary:event.context intoDictionary:newContext];
}

// Don't add the trace context of a current trace to a crash event because crash events are from
// a previous run.
if (event.isCrashEvent) {
event.context = newContext;
return event;
}

if (self.span != nil) {
id<SentrySpan> span;
@synchronized(_spanLock) {
Expand Down
11 changes: 11 additions & 0 deletions Tests/SentryTests/SentryScopeSwiftTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,17 @@ class SentryScopeSwiftTests: XCTestCase {
XCTAssertEqual(trace?["span_id"] as? String, fixture.transaction.spanId.sentrySpanIdString)
}

func testApplyToEvent_ScopeWithSpan_NotAppliedToCrashEvent() {
let scope = fixture.scope
scope.span = fixture.transaction
let event = fixture.event
event.isCrashEvent = true

let actual = scope.applyTo(event: event, maxBreadcrumbs: 10)
XCTAssertNil(fixture.event.context?["trace"])
XCTAssertNil(actual?.transaction)
}

func testApplyToEvent_EventWithDist() {
let event = fixture.event
event.dist = "myDist"
Expand Down

0 comments on commit a353899

Please sign in to comment.