Lightweight MetricKit-based diagnostics reporting.
MeterReporter will capture MetricKit payloads and relay them to a backend. It uses Meter to process and symbolicate payloads. The resulting data is very close to the MetricKit JSON structure. But, it does add some fields to support the additional features.
dependencies: [
.package(url: "https://github.com/ChimeHQ/MeterReporter")
]
let url = URL(string: "https://my.backend.com/reports")!
var config = MeterReporter.Configuration(endpointURL: url)
config.hostIdentifier = Bundle.main.bundleIdentifier
let reporter = MeterReporter(configuration: config)
reporter.start()
By default, MeterReporter uses URLSession
background uploads for both reliability and performance. However, sometimes these can take hours for the OS to actually execute. This can be a pain if you are just testing things out. To make that easier, you can disable background uploads with another property of MeterReporter.Configuration
.
MeterReporter can capture uncaught NSExceptions on macOS. Unfortunately, AppKit interfers with the flow of runtime exceptions. If you want to get this information about uncaught exceptions, some extra work is required.
The top-level NSApplication
instance for your app must be a subclass of ExceptionLoggingApplication
.
import MeterReporter
class Application: ExceptionLoggingApplication {
}
and, you must update your Info.plist to ensure that the NSPrincipalClass
key references this class with <App Module Name>.Application
.
I realize this is a huge pain. If you feel so motivated, please file feedback with Apple to ask them to make AppKit behave like UIKit in this respect.
I would also strongly recommend setting the NSApplicationCrashOnExceptions
defaults key to true. The default setting will allow your application to continue executing post-exception, virtually guaranteeing state corruption and incorrect behavior.
The request made to the endpoint will be an HTTP PUT
. The request will also set some headers.
Content-Type
will beapplication/vnd.chimehq-mxdiagnostic
MeterReporter-Report-Id
will be a unique identifierMeterReporter-Platform
MeterReporter-Host-Id
ifconfiguration.hostIdentifier
is non-nil
We'd love to hear from you! Get in touch via twitter, an issue, or a pull request.
Please note that this project is released with a Contributor Code of Conduct. By participating in this project you agree to abide by its terms.