Skip to content

Commit f5fe08e

Browse files
committed
more
1 parent f43a144 commit f5fe08e

File tree

5 files changed

+28
-14
lines changed

5 files changed

+28
-14
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 = dsn
35+
options.dsn = "https://00baf901d992a95f8e38837778b392a7@o4509277191143424.ingest.us.sentry.io/4510320463642624"
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 = !SentrySDKOverrides.Other.disableMetricKitRawPayloads.boolValue
74-
}
73+
options.enableMetricKitRawPayload = true
74+
//}
7575
#endif // !os(tvOS)
7676
#endif // !os(macOS) && !os(watchOS) && !os(visionOS)
7777

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

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

@@ -198,6 +198,13 @@ 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+
}
201208

202209
Button(action: oomCrashAction) {
203210
Text("OOM Crash")

Sources/Sentry/SentryMetricKitIntegration.m

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -177,13 +177,12 @@ - (void)didReceiveDiskWriteExceptionDiagnostic:(MXDiskWriteExceptionDiagnostic *
177177
diagnosticJSON:[diagnostic JSONRepresentation]];
178178
}
179179

180-
- (void)didReceiveHangDiagnostic:(MXHangDiagnostic *)diagnostic
181-
callStackTree:(SentryMXCallStackTree *)callStackTree
180+
- (void)didReceiveHangDiagnosticCallStackTree:(SentryMXCallStackTree *)callStackTree
182181
timeStampBegin:(NSDate *)timeStampBegin
183182
timeStampEnd:(NSDate *)timeStampEnd
184183
{
185-
NSString *hangDuration =
186-
[self.measurementFormatter stringFromMeasurement:diagnostic.hangDuration];
184+
NSString *hangDuration = @"2s";
185+
// [self.measurementFormatter stringFromMeasurement:diagnostic.hangDuration];
187186

188187
NSString *exceptionValue = [NSString
189188
stringWithFormat:@"%@ hangDuration:%@", SentryMetricKitHangDiagnosticType, hangDuration];
@@ -198,7 +197,7 @@ - (void)didReceiveHangDiagnostic:(MXHangDiagnostic *)diagnostic
198197

199198
[self captureMXEvent:callStackTree
200199
params:params
201-
diagnosticJSON:[diagnostic JSONRepresentation]];
200+
diagnosticJSON:[NSData data]];
202201
}
203202

204203
- (void)captureMXEvent:(SentryMXCallStackTree *)callStackTree

Sources/Swift/Core/MetricKit/SentryMXCallStackTree.swift

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,7 @@ import Foundation
5555
let count = samplesToCount[sample.frames] ?? 0
5656
samplesToCount[sample.frames] = sample.count + count
5757
}
58-
// Need to reverse because the root node of a flamegraph is the first frame in a stacktrace (usually main)
59-
let frames = samplesToCount.mostSampled()?.reversed().map { $0.toSentryFrame() } ?? []
58+
let frames = samplesToCount.mostSampled()?.map { $0.toSentryFrame() } ?? []
6059
frames.forEach { $0.inApp = NSNumber(value: inAppLogic?.is(inApp: $0.package) ?? false) }
6160
thread.stacktrace = SentryStacktrace(frames: frames, registers: [:])
6261
thread.crashed = NSNumber(value: (callStack.threadAttributed ?? false) && !handled)

Sources/Swift/Core/MetricKit/SentryMXManager.swift

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,18 +15,27 @@ import MetricKit
1515

1616
func didReceiveCpuExceptionDiagnostic(_ diagnostic: MXCPUExceptionDiagnostic, callStackTree: SentryMXCallStackTree, timeStampBegin: Date, timeStampEnd: Date)
1717

18-
func didReceiveHangDiagnostic(_ diagnostic: MXHangDiagnostic, callStackTree: SentryMXCallStackTree, timeStampBegin: Date, timeStampEnd: Date)
18+
func didReceiveHangDiagnosticCallStackTree(_ callStackTree: SentryMXCallStackTree, timeStampBegin: Date, timeStampEnd: Date)
1919
}
2020

2121
@available(macOS 12.0, *)
2222
@available(tvOS, unavailable)
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+
2632
let disableCrashDiagnostics: Bool
2733

2834
init(disableCrashDiagnostics: Bool = true) {
2935
self.disableCrashDiagnostics = disableCrashDiagnostics
36+
super.init()
37+
38+
SentryMXManager.shared = self
3039
}
3140

3241
public weak var delegate: SentryMXManagerDelegate?
@@ -76,7 +85,7 @@ import MetricKit
7685

7786
payload.hangDiagnostics?.forEach { diagnostic in
7887
actOn(callStackTree: diagnostic.callStackTree) { callStackTree in
79-
delegate?.didReceiveHangDiagnostic(diagnostic, callStackTree: callStackTree, timeStampBegin: payload.timeStampBegin, timeStampEnd: payload.timeStampEnd)
88+
delegate?.didReceiveHangDiagnosticCallStackTree(callStackTree, timeStampBegin: payload.timeStampBegin, timeStampEnd: payload.timeStampEnd)
8089
}
8190
}
8291
}

0 commit comments

Comments
 (0)