MetricManager
An object that delivers metric and diagnostic reports to your app.
Declaration
final class MetricManagerMentioned in
Discussion
MetricManager is an instantiable class rather than a shared singleton. Create an instance and hold it for as long as you need reports. Share that instance across your app rather than creating multiple instances with the same domains. If you create more than one MetricManager, two tasks concurrently iterating the same sequence both receive a non-deterministic subset of reports rather than a full copy.
Metric reports arrive through metricReports, and diagnostic reports through diagnosticReports. Both are typed AsyncSequence properties that never throw, so you iterate them with for await in long-lived tasks:
let manager = MetricManager()
Task {
for await report in manager.metricReports {
process(report)
}
}
Task {
for await report in manager.diagnosticReports {
process(report)
}
}To receive metrics segmented by app state, pass a set of StateReportingDomain values to init(enabledStateReportingDomains:). When state reporting is enabled, stateEntries carries metrics grouped by each recorded state in addition to the standard intervalEntries.
Topics
Initialization
Reports
Custom metric logs
Extended launch
trackLaunchTask(id:onTrackingError:_:)trackLaunchTask(id:onTrackingError:_:)MetricManager.LaunchTaskErrorLaunchTaskID