Skip to content

Commit 2a32fdb

Browse files
committed
PR feedback
1 parent e3d6355 commit 2a32fdb

File tree

3 files changed

+23
-8
lines changed

3 files changed

+23
-8
lines changed

Sources/Sentry/Public/SentryFrame.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,9 @@ NS_SWIFT_NAME(Frame)
7575
*/
7676
@property (nonatomic, copy) NSNumber *_Nullable parentIndex;
7777

78+
/**
79+
* Number of samples recorded that contained this frame, used for flamegraphs.
80+
*/
7881
@property (nonatomic, copy) NSNumber *_Nullable sampleCount;
7982

8083
/**

Sources/Swift/Core/MetricKit/SentryMXCallStackTree+Parsing.swift

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,6 @@ extension SentryMXCallStackTree {
2020
// it represents data that is sampled across many threads and aggregated, we do not
2121
// know which samples came from which thread. Instead we create just one fake thread
2222
// that just contains the most common callstack.
23-
//
24-
// We hope to add flamegraph support at some point and that is tracked here: https://github.com/getsentry/sentry-cocoa/issues/7062
2523
func sentryMXBacktrace(inAppLogic: SentryInAppLogic?, handled: Bool) -> [SentryThread] {
2624
callStacks.enumerated().map { index, callStack in
2725
let thread = SentryThread(threadId: NSNumber(value: index))
@@ -53,7 +51,7 @@ extension SentryMXCallStackTree {
5351
}
5452

5553
/// Flattens the call stack tree into a single thread with all frames.
56-
/// Each frame includes metadata in its `vars` field to allow reconstructing the original tree:
54+
/// Each frame includes metadata to allow reconstructing the original tree:
5755
/// - `parent_frame_index`: The index of the parent frame in the flat list (-1 for root frames)
5856
/// - `sample_count`: The number of samples at this frame
5957
///
@@ -76,8 +74,12 @@ extension SentryMXCallStackTree {
7674

7775
private func flattenFrame(_ mxFrame: SentryMXFrame, parentIndex: Int, frames: inout [Frame], inAppLogic: SentryInAppLogic?) {
7876
let currentIndex = frames.count
79-
let frame = mxFrame.toSentryFrameWithTreeData(frameIndex: currentIndex, parentFrameIndex: parentIndex)
80-
frame.inApp = NSNumber(value: inAppLogic?.is(inApp: frame.package) ?? false)
77+
let frame = mxFrame.toSentryFrameWithTreeData(parentFrameIndex: parentIndex)
78+
if let package = frame.package {
79+
frame.inApp = NSNumber(value: inAppLogic?.is(inApp: package) ?? false)
80+
} else {
81+
frame.inApp = true
82+
}
8183
frames.append(frame)
8284

8385
// Recursively process child frames
@@ -120,9 +122,8 @@ extension SentryMXFrame {
120122
return result
121123
}
122124

123-
/// Converts this frame to a SentryFrame with tree metadata in the `vars` field.
124-
/// The metadata allows reconstructing the original tree structure from a flat list.
125-
func toSentryFrameWithTreeData(frameIndex: Int, parentFrameIndex: Int) -> Frame {
125+
/// Converts this frame to a SentryFrame.
126+
func toSentryFrameWithTreeData(parentFrameIndex: Int) -> Frame {
126127
let frame = Frame()
127128
frame.package = binaryName
128129
frame.instructionAddress = sentry_formatHexAddressUInt64Swift(address)

Tests/SentryTests/Integrations/MetricKit/SentryMXCallStackTreeTests.swift

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,17 @@ final class SentryMXCallStackTreeTests: XCTestCase {
6060
XCTAssertEqual(true, frames[0].inApp?.boolValue)
6161
}
6262

63+
func testInAppTrue_WhenPackageIsNilFlamegraph() throws {
64+
let contents = try contentsOfResource("MetricKitCallstacks/per-thread-nil-package")
65+
let callStackTree = try SentryMXCallStackTree.from(data: contents)
66+
let threads = callStackTree.flattenedBacktrace(inAppLogic: nil, handled: false)
67+
XCTAssertEqual(1, threads.count)
68+
let frames = try XCTUnwrap(threads[0].stacktrace).frames
69+
XCTAssertEqual(1, frames.count)
70+
XCTAssertNil(frames[0].package)
71+
XCTAssertEqual(true, frames[0].inApp?.boolValue)
72+
}
73+
6374
func testDecodeCallStackTree_UnknownFieldsPayload() throws {
6475
let contents = try contentsOfResource("MetricKitCallstacks/tree-unknown-fields")
6576
let callStackTree = try SentryMXCallStackTree.from(data: contents)

0 commit comments

Comments
 (0)