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]=`ebcea221-6d7e-4c8c-93de-d20610aa4827`,e._sentryDebugIdIdentifier=`sentry-dbid-ebcea221-6d7e-4c8c-93de-d20610aa4827`)}catch{}import"./rolldown-runtime-nx40z1zs.js";import"./entry.client-mpghtlrl.js";var e=`ws://127.0.0.1:8088/perf`,t=1,n=2e3,r=256,i=e=>new WebSocket(e),a=class{ready=!1;queue=[];constructor(t=i,n=e,r){this.wsFactory=t,this.bridgeUrl=n,this.logger=r}connect(){return new Promise(e=>{let t;try{t=this.wsFactory(this.bridgeUrl)}catch{e(!1);return}let r=window.setTimeout(()=>{try{t.close()}catch{}e(!1)},n);t.onopen=()=>{window.clearTimeout(r);try{t.send(JSON.stringify({hello:{source:`Bayside`}})),this.socket=t,this.ready=!0,this.flushQueue(),e(!0)}catch{this.ready=!1,e(!1)}},t.onerror=()=>{window.clearTimeout(r),this.ready=!1,e(!1)},t.onclose=()=>{this.ready=!1}})}emit(e){let n;try{n=JSON.stringify({...e,schemaVersion:t,timestampUtc:new Date().toISOString()})}catch(e){this.logger?.warn(`PerfBridgeClient: emit() failed to serialise event — skipping`,{error:e});return}if(!this.ready||!this.socket){this.queue.length>=r&&this.queue.shift(),this.queue.push(n);return}try{this.socket.send(n)}catch{}}close(){try{this.socket?.close(1e3,`bye`)}catch{}this.ready=!1}flushQueue(){if(this.socket){for(let e of this.queue)try{this.socket.send(e)}catch{break}this.queue.length=0}}};function o(e){return e===`start`?`scenario.start`:`scenario.end`}function s(){try{return crypto.randomUUID()}catch{return`${Date.now()}-${Math.random().toString(36).slice(2)}`}}var c=class{runId=s();constructor(e,t,n){this.client=e??new a(void 0,t,n)}connect(){return this.client.connect()}onSpanStart(e){let t={eventName:o(`start`),scenarioId:e.id,spanName:e.name,runId:this.runId,...e.kind===`performance`&&e.location!==void 0&&{route:e.location}};this.client.emit(t)}onSpanEnd(e){let t={eventName:o(`end`),scenarioId:e.id,...e.duration!==void 0&&{durationMs:e.duration},spanName:e.name,spanStatus:e.status,runId:this.runId,...e.kind===`performance`&&e.location!==void 0&&{route:e.location}};this.client.emit(t)}close(){this.client.close()}};export{c as PerfBridgeAdapter};