try{let e=typeof window<`u`?window:typeof global<`u`?global:typeof globalThis<`u`?globalThis:typeof self<`u`?self:{},t=new e.Error().stack;t&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[t]=`b67066c4-af13-499e-964c-0f5302e494df`,e._sentryDebugIdIdentifier=`sentry-dbid-b67066c4-af13-499e-964c-0f5302e494df`)}catch{}import"./rolldown-runtime-eb2nym32.js";import{lg as e}from"./entry.client-dr7r6s9a.js";import{n as t,t as n}from"./index.client-i2a3xk51.js";var r=60*e,i=class{nativeSpanById=new Map;sentryReady=!1;bufferedEvents=[];bufferTimeoutId=null;onSpanStart(e){if(!this.ensureSentryReady()){this.bufferEvent({type:`start`,span:e});return}this.handleStart(e)}onSpanEnd(e){if(!this.ensureSentryReady()){this.bufferEvent({type:`end`,span:e});return}this.handleEnd(e)}ensureSentryReady(){return this.sentryReady?!0:this.isSentryInitialized()?(this.sentryReady=!0,this.flushBufferedEvents(),!0):!1}handleStart(e){e.kind===`root`?this.startRoot(e):this.startChild(e)}handleEnd(e){e.kind===`root`?this.endRoot(e):this.endChild(e)}startRoot(e){let t=(performance.timeOrigin+e.startTime)/1e3,n={};if(e.globalAttributes)for(let[t,r]of Object.entries(e.globalAttributes))n[t]=r;n[`px.kind`]=e.kind;let r=this.createSentrySpan({name:e.name,op:`performance.metrics`,forceTransaction:!0,startTime:t,attributes:n});this.nativeSpanById.set(e.id,r)}endRoot(e){let t=this.nativeSpanById.get(e.id);if(!t)return;this.nativeSpanById.delete(e.id),t.setAttribute(`px.child_span_count`,e.childSpanCount),e.endReason!==void 0&&t.setAttribute(`px.end_reason`,e.endReason),t.setAttribute(`px.status`,e.status);let n=e.status===`error`?2:+(e.status===`ok`);t.setStatus({code:n});let r=(performance.timeOrigin+(e.endTime??performance.now()))/1e3;t.end(r)}startChild(e){let t={};if(e.globalAttributes)for(let[n,r]of Object.entries(e.globalAttributes))t[n]=r;if(e.attributes)for(let[n,r]of Object.entries(e.attributes))t[`px.${n}`]=r;let n;e.parentSpanId===void 0?n=this.nativeSpanById.get(e.rootSpanId):(n=this.nativeSpanById.get(e.parentSpanId),t[`px.parent_span_id`]=e.parentSpanId,e.missingParent&&(t[`px.missing_parent`]=!0)),t[`px.span_id`]=e.id,t[`px.location`]=e.location,t[`px.kind`]=e.kind;let r=(performance.timeOrigin+e.startTime)/1e3,i=this.createSentrySpan({name:e.name,op:`performance.metrics`,parentSpan:n,startTime:r,attributes:t});this.nativeSpanById.set(e.id,i)}endChild(e){let t=this.nativeSpanById.get(e.id);if(!t)return;this.nativeSpanById.delete(e.id),t.updateName(e.name);let n=e.status===`error`?2:+(e.status===`ok`);if(t.setStatus({code:n}),t.setAttribute(`px.status`,e.status),e.attributes){let{attributes:n}=e;for(let e in n)Object.prototype.hasOwnProperty.call(n,e)&&t.setAttribute(`px.${e}`,n[e])}let r=(performance.timeOrigin+(e.endTime??performance.now()))/1e3;t.end(r)}bufferEvent(e){this.bufferedEvents.push(e),this.startBufferTimeout()}flushBufferedEvents(){this.clearBufferTimeout();let e=this.bufferedEvents;this.bufferedEvents=[];for(let t of e)t.type===`start`?this.handleStart(t.span):this.handleEnd(t.span)}startBufferTimeout(){this.bufferTimeoutId===null&&(this.bufferTimeoutId=setTimeout(()=>{this.bufferedEvents=[],this.bufferTimeoutId=null},r))}clearBufferTimeout(){this.bufferTimeoutId!==null&&(clearTimeout(this.bufferTimeoutId),this.bufferTimeoutId=null)}},a=class extends i{createSentrySpan(e){return n({name:e.name,op:e.op,parentSpan:e.parentSpan,startTime:e.startTime,attributes:e.attributes,forceTransaction:e.forceTransaction})}isSentryInitialized(){return t()!==void 0}};export{a as SentryAdapterClient};