import{AsyncApiRealmCLI as c}from"@redocly/realm-asyncapi-sdk";import{ulid as l}from"ulid";import{TELEMETRY_ENABLED as i}from"../../server/constants/common.js";import{shutdowner as s}from"../../server/tools/shutdowner.js";import{envConfig as r}from"../../server/config/env-config.js";import{PACKAGE_NAME as n}from"../../config/product-gates.js";class d extends c.Telemetry{#e=new Map;constructor(){super(),this.updateCloudEventData(()=>({organizationId:r.ORGANIZATION_ID||"",organizationSlug:r.ORGANIZATION_SLUG||"",projectId:r.PROJECT_ID||"",projectSlug:r.PROJECT_SLUG||"",origin:"realmCli",actor:{id:`ann_${l()}`,object:"user",uri:""},source:"urn:redocly:realm:cli",env:r.REDOCLY_ENV}))}initialize(e,t,o){const a=t!==void 0?!(t&&i):!i;this.init({otel:{serviceName:"realm-cli",serviceVersion:`${n}@${e}`,collectorTraceUrl:r.OTEL_TRACES_URL||"https://otel.cloud.redocly.com/v1/traces",isProd:r.isProductionEnv,version:"1.0",tracerName:"cli-telemetry"},disabled:a,verbose:o}),s.registerShutdownCallback(this.#r.bind(this))}addTraceStepCallbacks(e,{error:t,end:o}){this.#e.set(e,{error:t,end:o})}removeTraceStepCallbacks(e){this.#e.delete(e)}async#r(e){for(const[,{error:t,end:o}]of this.#e)e&&t(e),o();this.#e.clear(),await this.forceFlush(),await this.shutdown()}}const m=new d,A=m.tracer;export{m as telemetry,A as telemetryTracer};
