Skip to content

Commit 7a8774d

Browse files
committed
Fixes
1 parent 347716c commit 7a8774d

File tree

8 files changed

+57
-32
lines changed

8 files changed

+57
-32
lines changed

Samples/SentrySampleShared/SentrySampleShared/SentrySDKWrapper.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ public struct SentrySDKWrapper {
3232
}
3333

3434
func configureSentryOptions(options: Options) {
35-
options.dsn = "https://00baf901d992a95f8e38837778b392a7@o4509277191143424.ingest.us.sentry.io/4510320463642624"
35+
options.dsn = dsn
3636
if let sampleRate = SentrySDKOverrides.Events.sampleRate.floatValue {
3737
options.sampleRate = NSNumber(value: sampleRate)
3838
}
@@ -68,10 +68,10 @@ public struct SentrySDKWrapper {
6868
}
6969

7070
#if !os(tvOS)
71-
//if #available(iOS 15.0, *), !SentrySDKOverrides.Other.disableMetricKit.boolValue {
71+
if #available(iOS 15.0, *), !SentrySDKOverrides.Other.disableMetricKit.boolValue {
7272
options.enableMetricKit = true
73-
options.enableMetricKitRawPayload = true
74-
//}
73+
options.enableMetricKitRawPayload = !SentrySDKOverrides.Other.disableMetricKitRawPayloads.boolValue
74+
}
7575
#endif // !os(tvOS)
7676
#endif // !os(macOS) && !os(watchOS) && !os(visionOS)
7777

Samples/iOS-SwiftUI/iOS-SwiftUI/ContentView.swift

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
@_spi(Private) import Sentry
1+
import Sentry
22
import SentrySwiftUI
33
import SwiftUI
44

@@ -198,13 +198,6 @@ struct ContentView: View {
198198
}) {
199199
Text("Async Crash")
200200
}
201-
202-
Button("MetricKit") {
203-
let url = Bundle.main.url(forResource: "MXDiagnosticPayload-2", withExtension: "json")!
204-
let data = try! Data(contentsOf: url)
205-
let tree = try! JSONDecoder().decode(SentryMXCallStackTree.self, from: data)
206-
SentryMXManager.test(tree: tree)
207-
}
208201

209202
Button(action: oomCrashAction) {
210203
Text("OOM Crash")

Sources/Sentry/include/SentryPrivate.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525
#import "SentryFormatterSwift.h"
2626
#import "SentryHub+Private.h"
2727
#import "SentryIntegrationProtocol.h"
28-
#import "SentryInternalDefines.h"
2928
#import "SentryNSDataUtils.h"
3029
#import "SentrySDK+Private.h"
3130
#import "SentryTime.h"

Sources/Swift/Core/MetricKit/SentryMXCallStackTree.swift

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ import Foundation
5050
let thread = SentryThread(threadId: 0)
5151
let samples = callStack.callStackRootFrames.flatMap { $0.toSamples() }
5252
// Group by stacktrace in case there are multiple samples with the same trace
53-
var samplesToCount = [[Sample.Frame]: Int]()
53+
var samplesToCount = [[Sample.MXFrame]: Int]()
5454
for sample in samples {
5555
let count = samplesToCount[sample.frames] ?? 0
5656
samplesToCount[sample.frames] = sample.count + count
@@ -68,16 +68,16 @@ import Foundation
6868
// It is less compact than Apple's MetricKit format, but contains the same data and is easier to work with
6969
struct Sample {
7070
let count: Int
71-
let frames: [Frame]
71+
let frames: [MXFrame]
7272

73-
struct Frame: Hashable {
73+
struct MXFrame: Hashable {
7474
let binaryUUID: UUID
7575
let offsetIntoBinaryTextSegment: Int
7676
let binaryName: String?
7777
let address: UInt64
7878

79-
func toSentryFrame() -> Sentry.Frame {
80-
let frame = Sentry.Frame()
79+
func toSentryFrame() -> Frame {
80+
let frame = Frame()
8181
frame.package = binaryName
8282
frame.instructionAddress = sentry_formatHexAddressUInt64Swift(address)
8383
frame.imageAddress = sentry_formatHexAddressUInt64Swift(address - UInt64(offsetIntoBinaryTextSegment))
@@ -107,15 +107,15 @@ struct SentryMXFrame: Decodable {
107107

108108
func toDebugMeta() -> [DebugMeta] {
109109
let result = DebugMeta()
110-
result.type = SentryDebugImageType
110+
result.type = "macho"
111111
result.debugID = binaryUUID.uuidString
112112
result.codeFile = binaryName
113113
result.imageAddress = sentry_formatHexAddressUInt64Swift(address - UInt64(offsetIntoBinaryTextSegment))
114114
return [result] + (subFrames?.flatMap { $0.toDebugMeta() } ?? [])
115115
}
116116

117117
func toSamples() -> [Sample] {
118-
let selfFrame = Sample.Frame(binaryUUID: binaryUUID, offsetIntoBinaryTextSegment: offsetIntoBinaryTextSegment, binaryName: binaryName, address: address)
118+
let selfFrame = Sample.MXFrame(binaryUUID: binaryUUID, offsetIntoBinaryTextSegment: offsetIntoBinaryTextSegment, binaryName: binaryName, address: address)
119119
let subframes = subFrames ?? []
120120

121121
let childCount = subframes.map { $0.sampleCount ?? 0 }.reduce(0, +)

Sources/Swift/Core/MetricKit/SentryMXManager.swift

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,19 +23,11 @@ import MetricKit
2323
@available(watchOS, unavailable)
2424
@objcMembers @_spi(Private) public final class SentryMXManager: NSObject, MXMetricManagerSubscriber {
2525

26-
static var shared: SentryMXManager?
27-
// static public func test(tree: SentryMXCallStackTree) {
28-
// let start = Date.now.addingTimeInterval(-60)
29-
// shared?.delegate?.didReceiveHangDiagnosticCallStackTree(tree, timeStampBegin: start, timeStampEnd: Date.now)
30-
// }
31-
3226
let disableCrashDiagnostics: Bool
3327

3428
init(disableCrashDiagnostics: Bool = true) {
3529
self.disableCrashDiagnostics = disableCrashDiagnostics
3630
super.init()
37-
38-
SentryMXManager.shared = self
3931
}
4032

4133
public weak var delegate: SentryMXManagerDelegate?
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
{
2+
"callStacks": [
3+
{
4+
"threadAttributed": true,
5+
"callStackRootFrames": [
6+
{
7+
"binaryUUID": "9E8D8DE6-EEC1-3199-8720-9ED68EE3F967",
8+
"offsetIntoBinaryTextSegment": 0,
9+
"sampleCount": 3,
10+
"subFrames": [
11+
{
12+
"binaryUUID": "CA12CAFA-91BA-3E1C-BE9C-E34DB96FE7DF",
13+
"offsetIntoBinaryTextSegment": 0,
14+
"sampleCount": 3,
15+
"binaryName": "iOS-Swift",
16+
"address": 1,
17+
"subFrames": [
18+
{
19+
"binaryUUID": "CA12CAFA-91BA-3E1C-BE9C-E34DB96FE7DF",
20+
"offsetIntoBinaryTextSegment": 0,
21+
"sampleCount": 1,
22+
"binaryName": "iOS-Swift",
23+
"address": 2
24+
},
25+
{
26+
"binaryUUID": "CA12CAFA-91BA-3E1C-BE9C-E34DB96FE7DF",
27+
"offsetIntoBinaryTextSegment": 0,
28+
"sampleCount": 2,
29+
"binaryName": "iOS-Swift",
30+
"address": 3
31+
}
32+
]
33+
}
34+
],
35+
"binaryName": "Sentry",
36+
"address": 0
37+
}
38+
]
39+
}
40+
],
41+
"callStackPerThread": true
42+
}

Tests/SentryTests/Integrations/MetricKit/SentryMXCallStackTreeTests.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,8 @@ final class SentryMXCallStackTreeTests: XCTestCase {
4545
let frames = try XCTUnwrap(threads[0].stacktrace).frames
4646
XCTAssertEqual(3, frames.count)
4747
XCTAssertEqual("0x0000000000000000", frames[0].instructionAddress)
48-
XCTAssertEqual("0x0000000000000001", frames[0].instructionAddress)
49-
XCTAssertEqual("0x0000000000000003", frames[0].instructionAddress)
48+
XCTAssertEqual("0x0000000000000001", frames[1].instructionAddress)
49+
XCTAssertEqual("0x0000000000000003", frames[2].instructionAddress)
5050
}
5151

5252
func testDecodeCallStackTree_UnknownFieldsPayload() throws {

Tests/SentryTests/Integrations/MetricKit/SentryMetricKitIntegrationTests.swift

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -173,10 +173,9 @@ final class SentryMetricKitIntegrationTests: SentrySDKIntegrationTestsBase {
173173
}
174174

175175
let invocations = client.captureEventWithScopeInvocations.invocations
176-
XCTAssertEqual(2, client.captureEventWithScopeInvocations.count)
176+
XCTAssertEqual(1, client.captureEventWithScopeInvocations.count)
177177

178178
try assertEvent(event: try XCTUnwrap(invocations.first).event)
179-
try assertEvent(event: try XCTUnwrap(invocations.element(at: 1)).event)
180179

181180
func assertEvent(event: Event) throws {
182181
let sentryFrames = try XCTUnwrap(event.threads?.first?.stacktrace?.frames, "Event has no frames.")

0 commit comments

Comments
 (0)