"use strict";var m=(t,e)=>()=>(e||t((e={exports:{}}).exports,e),e.exports),u=m((t,e)=>{var r=/^00-([0-9a-f]{32})-([0-9a-f]{16})-([0-9a-f]{2})$/,i=/^[0-9a-f]{32}$/,a=/^[0-9a-f]{16}$/;e.exports={serializeContext:function(t){if(!t||!t.traceId||!t.spanId)return null;let{traceId:e,spanId:r}=t;if(!i.test(e)||!a.test(r)||/^0+$/.test(e)||/^0+$/.test(r))return null;let s=t.traceFlags,n=("number"==typeof s&&Number.isInteger(s)&&s>=0&&s<=255?s:1).toString(16).padStart(2,"0");return`00-${e}-${r}-${n}`},deserializeContext:function(t){if(!t||"string"!=typeof t)return null;let e=t.match(r);if(!e)return null;let[,i,a,s]=e;return/^0+$/.test(i)||/^0+$/.test(a)?null:{traceId:i,spanId:a,traceFlags:parseInt(s,16),isRemote:!0}}}}),{serializeContext:E,deserializeContext:A}=u(),c={ROOT:"perftest.run",INITIALIZING:"perftest.initializing",EXECUTING:"perftest.executing",COMPLETING:"perftest.completing"},f="running",l=class{constructor(t,e){this.tracer=t,this.api=e,this.rootSpan=null,this.lifecycleSpans={}}createRootSpan(t,e){try{let r;if(this.api&&e){let t=A(e);if(t){let{TraceFlags:e,trace:i,context:a}=this._getApiHelpers(),s={traceId:t.traceId,spanId:t.spanId,traceFlags:t.traceFlags??e.SAMPLED,isRemote:!0};r=i.setSpanContext(a.active(),s)}}let i=this._buildRootAttributes(t);this.rootSpan=this.tracer.startSpan(c.ROOT,{attributes:i},r)}catch{}}startLifecycleSpan(t,e,r){try{let i;if(!this.rootSpan)return;let a={"postman.stage.id":f};if(e&&(a["postman.run.id"]=e),r&&Object.assign(a,r),this.api){let{trace:t,context:e}=this._getApiHelpers();i=t.setSpan(e.active(),this.rootSpan)}this.lifecycleSpans[t]=this.tracer.startSpan(t,{attributes:a},i)}catch{}}setLifecycleSpanAttributes(t,e){try{let r=this.lifecycleSpans[t];if(!r)return;for(let[t,i]of Object.entries(e))null!=i&&r.setAttribute(t,i)}catch{}}endLifecycleSpan(t,e){try{let r=this.lifecycleSpans[t];if(!r)return;e&&this._recordError(r,e),r.end(),delete this.lifecycleSpans[t]}catch{}}getExecutingContext(){try{let t=this.lifecycleSpans[c.EXECUTING];return t?E(t.spanContext()):null}catch{return null}}endRootSpan(t){try{if(!this.rootSpan)return;t&&this._recordError(this.rootSpan,t),this.rootSpan.end(),this.rootSpan=null}catch{}}endAllSpans(t){try{for(let e of Object.keys(this.lifecycleSpans))this.endLifecycleSpan(e,t);this.endRootSpan(t)}catch{}}_recordError(t,e){try{this.api&&t.setStatus({code:this.api.SpanStatusCode.ERROR,message:e.message||String(e)}),t.recordException(e)}catch{}}_buildRootAttributes(t){let e={"postman.stage.id":f};try{t.runId&&(e["postman.run.id"]=t.runId)}catch{}try{if(t.loadProfile){t.loadProfile.type&&(e["postman.test.profile_type"]=t.loadProfile.type);let r=Array.isArray(t.loadProfile.controlPoints)?t.loadProfile.controlPoints.map(t=>t?.load?.count).filter(t=>Number.isFinite(t)):[];if(r.length>0)e["postman.test.virtual_users"]=Math.max(...r);else if(Number.isFinite(t.vuCount))e["postman.test.virtual_users"]=t.vuCount;else if(t.loadProfile.options){let r=t.loadProfile.options;Number.isFinite(r.maxVu)?e["postman.test.virtual_users"]=r.maxVu:Number.isFinite(r.vu)&&(e["postman.test.virtual_users"]=r.vu)}if(t.loadProfile.options){let r=t.loadProfile.options;r.totalDuration&&r.totalDuration.millis&&(e["postman.test.duration_ms"]=r.totalDuration.millis)}}}catch{}try{e["postman.service.name"]=t.otelServiceName||"postman-performance-test",t.collectionId&&(e["postman.collection.id"]=t.collectionId),t.environmentId&&(e["postman.environment.id"]=t.environmentId)}catch{}return e}_getApiHelpers(){return this.api?{trace:this.api.trace,context:this.api.context,TraceFlags:this.api.TraceFlags}:{trace:{},context:{},TraceFlags:{SAMPLED:1}}}};module.exports={SpanManager:l,SPAN_NAMES:c};