---
title: "trackLaunchTask(id:onTrackingError:_:)"
framework: metrickit
role: symbol
role_heading: Instance Method
path: "metrickit/metricmanager/tracklaunchtask(id:ontrackingerror:_:)-jnu1"
---

# trackLaunchTask(id:onTrackingError:_:)

Measures the duration of a synchronous extended launch task.

## Declaration

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

## Discussion

Discussion Use this method to wrap synchronous work that extends your app’s perceived launch time. Pass a 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. manager.trackLaunchTask(id: "register-services") {     registerAllServices() } Pass an onTrackingError closure to observe MetricManager.LaunchTaskError values without interrupting the tracked work: manager.trackLaunchTask(id: "register-services", onTrackingError: { error in     logger.warning("Tracking error: \(error.reason)") }) {     registerAllServices() } This method replaces the paired MXMetricManager.extendLaunchMeasurement(forTaskID:) and MXMetricManager.finishExtendedLaunchMeasurement(forTaskID:) calls. To track asynchronous launch work instead, use trackLaunchTask(id:onTrackingError:_:).

## See Also

### Extended launch

- [trackLaunchTask(id:onTrackingError:_:)](metrickit/metricmanager/tracklaunchtask(id:ontrackingerror:_:)-48k2s.md)
- [MetricManager.LaunchTaskError](metrickit/metricmanager/launchtaskerror.md)
- [LaunchTaskID](metrickit/launchtaskid.md)
