"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.traceStep = traceStep;
exports.updateProgress = updateProgress;
const analytics_1 = require("./utils/analytics");
const observability_1 = require("./lib/observability");
/**
 * Run a wizard step inside a Sentry span and update the analytics
 * 'progress' session property.
 *
 * The session property tags every subsequent analytics event with the
 * current step (handy for diagnosing where a session errored). The Sentry
 * span gives the step its own row in the perf waterfall, captures any
 * thrown error with the step name in scope, and auto-instruments outbound
 * HTTP via the default Sentry httpIntegration.
 *
 * Works for both sync and async callbacks. No-ops on the Sentry side when
 * telemetry is disabled.
 */
function traceStep(step, callback) {
    updateProgress(step);
    (0, observability_1.addBreadcrumb)('step', `Step started: ${step}`);
    return (0, observability_1.withWizardSpan)(`step.${step}`, 'wizard.step', { step }, callback);
}
function updateProgress(step) {
    // Track progress as a session property so it reflects the current step
    // on all subsequent events (useful for debugging which step errored).
    analytics_1.analytics.setSessionProperty('progress', step);
}
