<!--
{
  "availability" : [
    "iOS: 27.0.0 -",
    "iPadOS: 27.0.0 -",
    "macCatalyst: 27.0.0 -",
    "macOS: 27.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "MetricKit",
  "identifier" : "/documentation/MetricKit/MetricManager/trackLaunchTask(id:onTrackingError:_:)-jnu1",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "MetricKit"
    ],
    "preciseIdentifier" : "s:9MetricKit0A7ManagerC15trackLaunchTask2id15onTrackingError_xAA0eF2IDV_yAC0efJ0VcSgxyq_YKXEtq_YKs0J0R_r0_lF"
  },
  "title" : "trackLaunchTask(id:onTrackingError:_:)"
}
-->

# trackLaunchTask(id:onTrackingError:_:)

Measures the duration of a synchronous extended launch task.

```
@MainActor final func trackLaunchTask<Result, Failure>(id: LaunchTaskID, onTrackingError: ((MetricManager.LaunchTaskError) -> Void)? = nil, _ operation: () throws(Failure) -> Result) throws(Failure) -> Result where Failure : Error
```

## Discussion

Use this method to wrap synchronous work that extends your app’s perceived launch time. Pass a [`LaunchTaskID`](/documentation/MetricKit/LaunchTaskID) and a synchronous closure wrapping the work to measure. Measurement begins when the closure starts and ends it when the closure returns, regardless of whether the closure throws.

```swift
manager.trackLaunchTask(id: "register-services") {
    registerAllServices()
}
```

Pass an `onTrackingError` closure to observe [`MetricManager.LaunchTaskError`](/documentation/MetricKit/MetricManager/LaunchTaskError) values without interrupting the tracked work:

```swift
manager.trackLaunchTask(id: "register-services", onTrackingError: { error in
    logger.warning("Tracking error: \(error.reason)")
}) {
    registerAllServices()
}
```

To track asynchronous launch work instead, use [`trackLaunchTask(id:onTrackingError:_:)`](/documentation/MetricKit/MetricManager/trackLaunchTask(id:onTrackingError:_:)-48k2s).

---

Copyright &copy; 2026 Apple Inc. All rights reserved. | [Terms of Use](https://www.apple.com/legal/internet-services/terms/site.html) | [Privacy Policy](https://www.apple.com/privacy/privacy-policy)