"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.telemetryRegistry = void 0;
/**
 * Singleton registry for the telemetry adapter.
 *
 * Unlike the event registry (which fans out to multiple adapters),
 * telemetry uses a single adapter because OTEL only supports one
 * global TracerProvider at a time.
 *
 * The adapter must be registered and connected BEFORE HotMesh
 * workers start so that spans are captured from the first workflow.
 */
class LTTelemetryRegistry {
    constructor() {
        this.adapter = null;
        this.connected = false;
    }
    /**
     * Register a telemetry adapter. Call before connect().
     * Replaces any previously registered adapter.
     */
    register(adapter) {
        this.adapter = adapter;
    }
    /**
     * Connect the registered adapter (initializes OTEL SDK).
     * Must be called before HotMesh workers start.
     */
    async connect() {
        if (this.connected || !this.adapter)
            return;
        await this.adapter.connect();
        this.connected = true;
    }
    /**
     * Disconnect the adapter (flush + shutdown OTEL SDK).
     * Call during graceful shutdown.
     */
    async disconnect() {
        if (!this.adapter)
            return;
        await this.adapter.disconnect();
        this.connected = false;
    }
    /**
     * Remove the adapter and reset state. Used in tests.
     */
    clear() {
        this.adapter = null;
        this.connected = false;
    }
    /**
     * Check if an adapter is registered.
     */
    get hasAdapter() {
        return this.adapter !== null;
    }
    /**
     * Trace URL template from the registered adapter (if any).
     * Contains `{traceId}` placeholder for substitution.
     */
    get traceUrl() {
        return this.adapter?.traceUrl;
    }
}
/** Singleton telemetry registry */
exports.telemetryRegistry = new LTTelemetryRegistry();
