-
-
Notifications
You must be signed in to change notification settings - Fork 335
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: Collect MetricKit payloads (#2316)
Add code to the iOS-Swift sample app to collect MetricKit payloads by sending them to Sentry as receiving an MXDiagnosticPayload via Xcode debug Simulate MeticKit Payload doesn't work.
- Loading branch information
1 parent
d883642
commit 8607e67
Showing
3 changed files
with
68 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import Foundation | ||
import MetricKit | ||
import Sentry | ||
|
||
@available(iOS 14.0, *) | ||
class MetricKitManager: NSObject, MXMetricManagerSubscriber { | ||
func receiveReports() { | ||
let shared = MXMetricManager.shared | ||
shared.add(self) | ||
} | ||
|
||
func pauseReports() { | ||
let shared = MXMetricManager.shared | ||
shared.remove(self) | ||
} | ||
|
||
func didReceive(_ payloads: [MXMetricPayload]) { | ||
var attachments: [Attachment] = [] | ||
for payload in payloads { | ||
let attachment = Attachment(data: payload.jsonRepresentation(), filename: "MXDiagnosticPayload.json") | ||
attachments.append(attachment) | ||
} | ||
|
||
SentrySDK.capture(message: "MetricKit received MXMetricPayload.") { scope in | ||
attachments.forEach { scope.add($0) } | ||
} | ||
} | ||
|
||
func didReceive(_ payloads: [MXDiagnosticPayload]) { | ||
var attachments: [Attachment] = [] | ||
for payload in payloads { | ||
let attachment = Attachment(data: payload.jsonRepresentation(), filename: "MXDiagnosticPayload.json") | ||
attachments.append(attachment) | ||
} | ||
|
||
SentrySDK.capture(message: "MetricKit received MXDiagnosticPayload.") { scope in | ||
attachments.forEach { scope.add($0) } | ||
} | ||
} | ||
} |