(
command: string,
opts: {
json?: boolean
properties?: Record<string, unknown>
},
action: (telemetry: TelemetryClient) => Promise<T>,
)
| 582 | } |
| 583 | |
| 584 | async function runWithTelemetry<T>( |
| 585 | command: string, |
| 586 | opts: { |
| 587 | json?: boolean |
| 588 | properties?: Record<string, unknown> |
| 589 | }, |
| 590 | action: (telemetry: TelemetryClient) => Promise<T>, |
| 591 | ) { |
| 592 | const telemetry = await createTelemetryClient({ json: opts.json }) |
| 593 | const startedAt = Date.now() |
| 594 | currentTelemetry = telemetry |
| 595 | telemetry.captureCommandStarted(command, { |
| 596 | ...getInvocationTelemetryProperties(), |
| 597 | ...opts.properties, |
| 598 | cli_version: VERSION, |
| 599 | }) |
| 600 | |
| 601 | try { |
| 602 | const result = await action(telemetry) |
| 603 | await telemetry.captureCommandCompleted(command, Date.now() - startedAt) |
| 604 | return result |
| 605 | } catch (error) { |
| 606 | await telemetry.captureCommandFailed(command, Date.now() - startedAt, error) |
| 607 | throw error |
| 608 | } finally { |
| 609 | currentTelemetry = undefined |
| 610 | } |
| 611 | } |
| 612 | |
| 613 | program |
| 614 | .name(name) |
no test coverage detected