Search code examples
iosswiftanalyticsmetrickit

MetrikKit: signpostMetrics is always empty


I have set up MetricKit in my iOS app in order to send performance measurements taken from os_signpost to my custom analytics endpoint.
I did the setup like it is described for example here:
https://nshipster.com/metrickit/ or here https://www.avanderlee.com/swift/metrickit-launch-time/ .

This is the relevant code:

import MetricKit

class AppDelegate: UIApplicationDelegate {
 func application(_ application: UIApplication
        , didFinishLaunchingWithOptions launchOptions: LaunchOptions?) -> Bool {

        MXMetricManager.shared.add(self)
        // ...
    }
}

class Elsewhere {
    func someFunc() {
        // I verified that this is indeed being called

        let log = OSLog(subsystem: OSLog.subsystem, category: "someFunc")
        let signpostID = OSSignpostID(log: log, object: self)
        os_signpost(.begin, log: log, name: "someFunc", signpostID: signpostID)
        // some code
        os_signpost(.end, log: log, name: "someFunc", signpostID: signpostID)
    }
}

extension AppDelegate: MXMetricManagerSubscriber {

    public func didReceive(_ payloads: [MXMetricPayload]) {
        for payload in payloads {
            for metric in payload.signpostMetrics {

                // this never gets called because signpostMetrics is always empty :(
            }
        }
    }
}

So my problem is, that signpostMetrics is always empty. I would expect it to contain the data that got collected by the os_signpost in my code.


Solution

  • Try to use MetricKit methods

    mxSignpost(.begin, ...)

    mxSignpost(.end, ...)