UNPKG

@sentry/node

Version:

Sentry Node SDK using OpenTelemetry for performance instrumentation

6 lines • 30.1 kB
/*! @sentry/node 11.20.0 (4559506) | https://github.com/getsentry/sentry-javascript */ import{Session as e}from"node:inspector";import{parentPort as t,workerData as n}from"node:worker_threads";import{posix as r,sep as i}from"node:path";import*as a from"node:net";import*as o from"node:http";import*as s from"node:https";import{Readable as c}from"node:stream";import{createGzip as l}from"node:zlib";import*as u from"node:tls";const d=typeof __SENTRY_DEBUG__>`u`||__SENTRY_DEBUG__,f=globalThis,p=`11.20.0`;function m(){return h(f),f}function h(e){let t=e.__SENTRY__=e.__SENTRY__||{};return t.version=t.version||`11.20.0`,t[p]=t[`11.20.0`]||{}}function g(e,t,n=f){let r=n.__SENTRY__=n.__SENTRY__||{},i=r[p]=r[`11.20.0`]||{};return i[e]||(i[e]=t())}const _={};function v(e){if(!(`console`in f))return e();let t=f.console,n={},r=Object.keys(_);r.forEach(e=>{let r=_[e];n[e]=t[e],t[e]=r});try{return e()}finally{r.forEach(e=>{t[e]=n[e]})}}function ee(){b().enabled=!0}function te(){b().enabled=!1}function ne(){return b().enabled}function re(...e){y(`log`,...e)}function ie(...e){y(`warn`,...e)}function ae(...e){y(`error`,...e)}function y(e,...t){d&&ne()&&v(()=>{f.console[e](`Sentry Logger [${e}]:`,...t)})}function b(){return d?g(`loggerSettings`,()=>({enabled:!1})):{enabled:!1}}const x={enable:ee,disable:te,isEnabled:ne,log:re,warn:ie,error:ae},S=/captureMessage|captureException/;function oe(e){if(!e.length)return[];let t=Array.from(e);return/sentryWrapped/.test(C(t).function||``)&&t.pop(),t.reverse(),S.test(C(t).function||``)&&(t.pop(),S.test(C(t).function||``)&&t.pop()),t.slice(0,50).map(e=>({...e,filename:e.filename||C(t).filename,function:e.function||`?`}))}function C(e){return e[e.length-1]||{}}const w=`<anonymous>`;function se(e){try{return!e||typeof e!=`function`?w:e.name||w}catch{return w}}const ce=Object.prototype.toString;function le(e){switch(ce.call(e)){case`[object Error]`:case`[object Exception]`:case`[object DOMException]`:case`[object WebAssembly.Exception]`:return!0;default:return he(e,Error)}}function ue(e,t){return ce.call(e)===`[object ${t}]`}function de(e){return ue(e,`Object`)}function fe(e){return typeof e==`object`&&!!e}function pe(e){return typeof Event<`u`&&he(e,Event)}function me(e){return!!(e?.then&&typeof e.then==`function`)}function he(e,t){try{return e instanceof t}catch{return!1}}function ge(e,t,n){try{Object.defineProperty(e,t,{value:n,writable:!0,configurable:!0})}catch{d&&x.log(`Failed to add non-enumerable property "${String(t)}" to object`,e)}}function _e(e){if(le(e))return{message:e.message,name:e.name,stack:e.stack,...ve(e)};if(pe(e)){let{type:t,target:n,currentTarget:r,detail:i}=e;return{type:t,target:n,currentTarget:r,...i?{detail:i}:{},...ve(e)}}return e}function ve(e){return fe(e)?Object.fromEntries(Object.entries(e)):{}}let T;function E(e){if(T!==void 0)return T?T(e):e();let t=Symbol.for(`__SENTRY_SAFE_RANDOM_ID_WRAPPER__`),n=f;return t in n&&typeof n[t]==`function`?(T=n[t],T(e)):(T=null,e())}function ye(){return E(()=>Math.random())}function D(){return E(()=>Date.now())}const be=Symbol.for(`sentry.skipNormalization`),xe=Symbol.for(`sentry.overrideNormalizationDepth`);function Se(e){return!!e[be]}function Ce(e){let t=e[xe];return typeof t==`number`?t:void 0}function we(e,t=100,n=1/0){try{return k(``,e,t,n)}catch(e){return{ERROR:`**non-serializable** (${O(e)})`}}}function O(e){try{return String(e)}catch{return`unknown error`}}function k(e,t,n=1/0,r=1/0,i=De()){let[a,o]=i;if(t==null||[`boolean`,`string`].includes(typeof t)||typeof t==`number`&&Number.isFinite(t))return t;let s=Te(e,t);if(!s.startsWith(`[object `))return s;if(Se(t))return t;let c=Ce(t),l=c===void 0?n:c;if(l===0)return s.replace(`object `,``);if(a(t))return`[Circular ~]`;let u=t;if(u&&typeof u.toJSON==`function`)try{return k(``,u.toJSON(),l-1,r,i)}catch{}let d=Array.isArray(t)?[]:{},f=0,p=_e(t);for(let e in p){if(!Object.prototype.hasOwnProperty.call(p,e))continue;if(f>=r){d[e]=`[MaxProperties ~]`;break}let t=p[e];d[e]=k(e,t,l-1,r,i),f++}return o(t),d}function Te(e,t){try{return typeof global<`u`&&t===global?`[Global]`:typeof t==`number`&&!Number.isFinite(t)?`[${t}]`:typeof t==`function`?`[Function: ${se(t)}]`:typeof t==`symbol`?`[${String(t)}]`:typeof t==`bigint`?`[BigInt: ${String(t)}]`:`[object ${Ee(t)}]`}catch(e){return`**non-serializable** (${O(e)})`}}function Ee(e){let t=Object.getPrototypeOf(e);return t?.constructor?t.constructor.name:`null prototype`}function A(e,t){let n=t.replace(/\\/g,`/`).replace(/[|\\{}()[\]^$+*?.]/g,`\\$&`),r=e;try{r=decodeURI(e)}catch{}return r.replace(/\\/g,`/`).replace(/webpack:\/?/g,``).replace(RegExp(`(file://)?/*${n}/*`,`ig`),`app:///`)}function De(){let e=/* @__PURE__ */ new WeakSet;function t(t){return e.has(t)?!0:(e.add(t),!1)}function n(t){e.delete(t)}return[t,n]}function Oe(e,t=0){return typeof e!=`string`||t===0||e.length<=t?e:`${e.slice(0,t)}...`}function ke(){let e=f;return e.crypto||e.msCrypto}let j;function Ae(){return ye()*16}function M(e=ke()){try{if(e?.randomUUID)return E(()=>e.randomUUID()).replace(/-/g,``)}catch{}return j||(j=`10000000100040008000100000000000`),j.replace(/[018]/g,e=>(e^(Ae()&15)>>e/4).toString(16))}const N=1e3;function P(){return D()/N}let F=[];function je(){let{performance:e}=f;if(!e?.now||!e.timeOrigin)return e?.now&&(F=[{from:0,origin:D()-E(()=>e.now())}]),P;let t=e.timeOrigin;F=[{from:0,origin:t}];let n=!0,r=0;return()=>E(()=>{let i=e.now(),a=Date.now();return Math.abs(t+i-a)>1e3&&(t=a-i,n?F=[{from:0,origin:t}]:(F.push({from:r,origin:t}),F.length>100&&F.splice(1,1))),n=!1,r=i,(t+i)/N})}let Me;function Ne(){return(Me??(Me=je()))()}function Pe(e){let t=Ne(),n={sid:M(),init:!0,timestamp:t,started:t,duration:0,status:`ok`,errors:0,ignoreDuration:!1,toJSON:()=>Fe(n)};return e&&I(n,e),n}function I(e,t={}){if(t.user&&(!e.ipAddress&&t.user.ip_address&&(e.ipAddress=t.user.ip_address),!e.did&&!t.did&&(e.did=t.user.id||t.user.email||t.user.username)),e.timestamp=t.timestamp||Ne(),t.abnormal_mechanism&&(e.abnormal_mechanism=t.abnormal_mechanism),t.ignoreDuration&&(e.ignoreDuration=t.ignoreDuration),t.sid&&(e.sid=t.sid.length===32?t.sid:M()),t.init!==void 0&&(e.init=t.init),!e.did&&t.did&&(e.did=`${t.did}`),typeof t.started==`number`&&(e.started=t.started),e.ignoreDuration)e.duration=void 0;else if(typeof t.duration==`number`)e.duration=t.duration;else{let t=e.timestamp-e.started;e.duration=t>=0?t:0}t.release&&(e.release=t.release),t.environment&&(e.environment=t.environment),!e.ipAddress&&t.ipAddress&&(e.ipAddress=t.ipAddress),!e.userAgent&&t.userAgent&&(e.userAgent=t.userAgent),typeof t.errors==`number`&&(e.errors=t.errors),t.status&&(e.status=t.status)}function Fe(e){return{sid:`${e.sid}`,init:e.init,started:(/* @__PURE__ */ new Date(e.started*1e3)).toISOString(),timestamp:(/* @__PURE__ */ new Date(e.timestamp*1e3)).toISOString(),status:e.status,errors:e.errors,did:typeof e.did==`number`||typeof e.did==`string`?`${e.did}`:void 0,duration:e.duration,abnormal_mechanism:e.abnormal_mechanism,attrs:{release:e.release,environment:e.environment,ip_address:e.ipAddress,user_agent:e.userAgent}}}function Ie(e,t,n=2){if(!t||typeof t!=`object`||n<=0)return t;if(e&&Object.keys(t).length===0)return e;let r={...e};for(let e in t)Object.prototype.hasOwnProperty.call(t,e)&&(r[e]=Ie(r[e],t[e],n-1));return r}function Le(){return M()}function Re(){return M().substring(16)}var L=class e{constructor(){this.x=!1,this.w=[],this.h=[],this.t=[],this.u=[],this.l={},this.o={},this.r={},this.a={},this.n={},this.d={},ge(this,`refs`,{}),this.s={traceId:Le(),sampleRand:ye()}}clone(){let t=new e;return t.t=[...this.t],t.o={...this.o},t.r={...this.r},t.a={...this.a},t.n={...this.n},this.n.flags&&(t.n.flags={values:[...this.n.flags.values]}),t.l=this.l,t._=this._,t.c=this.c,t.S=this.S,t.g=this.g,t.h=[...this.h],t.u=[...this.u],t.d={...this.d},t.s={...this.s},t.i=this.i,t.b=this.b,t.m=this.m,t.refs={...this.refs},t}setClient(e){this.i=e}setLastEventId(e){this.b=e}getClient(){return this.i}lastEventId(){return this.b}addScopeListener(e){this.w.push(e)}addEventProcessor(e){return this.h.push(e),this}setUser(e){return this.l=e||{email:void 0,id:void 0,ip_address:void 0,username:void 0},this.c&&I(this.c,{user:e}),this.e(),this}getUser(){return this.l}setConversationId(e){return this.m=e||void 0,this.e(),this}setTags(e){return this.o={...this.o,...e},this.e(),this}setTag(e,t){return this.setTags({[e]:t})}setAttributes(e){return this.r={...this.r,...e},this.e(),this}setAttribute(e,t){return this.setAttributes({[e]:t})}removeAttribute(e){return e in this.r&&(delete this.r[e],this.e()),this}setExtras(e){return this.a={...this.a,...e},this.e(),this}setExtra(e,t){return this.a={...this.a,[e]:t},this.e(),this}setFingerprint(e){return this.g=e,this.e(),this}setLevel(e){return this._=e,this.e(),this}setTransactionName(e){return this.S=e,this.e(),this}setContext(e,t){return t===null?delete this.n[e]:this.n[e]=t,this.e(),this}setSession(e){return e?this.c=e:delete this.c,this.e(),this}getSession(){return this.c}update(t){if(!t)return this;let n=typeof t==`function`?t(this):t,{tags:r,attributes:i,extra:a,user:o,contexts:s,level:c,fingerprint:l=[],propagationContext:u,conversationId:d}=(n instanceof e?n.getScopeData():de(n)?t:void 0)||{};return this.o={...this.o,...r},this.r={...this.r,...i},this.a={...this.a,...a},this.n={...this.n,...s},o&&Object.keys(o).length&&(this.l=o),c&&(this._=c),l.length&&(this.g=l),u&&(this.s=u),d&&(this.m=d),this}addBreadcrumb(e,t){let n=typeof t==`number`?t:100;if(n<=0)return this;let r={timestamp:P(),...e,message:e.message?Oe(e.message,2048):e.message};return this.t.push(r),this.t.length>n&&(this.t=this.t.slice(-n)),this.e(),this}getLastBreadcrumb(){return this.t[this.t.length-1]}clearBreadcrumbs(){return this.t=[],this.e(),this}addAttachment(e){return this.u.push(e),this}clearAttachments(){return this.u=[],this}getScopeData(){return{breadcrumbs:this.t,attachments:this.u,contexts:this.n,tags:this.o,attributes:this.r,extra:this.a,user:this.l,level:this._,fingerprint:this.g||[],eventProcessors:this.h,propagationContext:this.s,sdkProcessingMetadata:this.d,transactionName:this.S,conversationId:this.m}}setSDKProcessingMetadata(e){return this.d=Ie(this.d,e,2),this}setPropagationContext(e){return this.s=e,this}getPropagationContext(){return this.s}captureException(e,t){let n=t?.event_id||M();if(!this.i)return d&&x.warn(`No client configured on scope - will not capture exception!`),n;let r=/* @__PURE__ */ Error(`Sentry syntheticException`);return this.i.captureException(e,{originalException:e,syntheticException:r,...t,event_id:n},this),n}captureMessage(e,t,n){let r=n?.event_id||M();if(!this.i)return d&&x.warn(`No client configured on scope - will not capture message!`),r;let i=n?.syntheticException??Error(e);return this.i.captureMessage(e,t,{originalException:e,syntheticException:i,...n,event_id:r},this),r}captureEvent(e,t){let n=e.event_id||t?.event_id||M();return this.i?(this.i.captureEvent(e,{...t,event_id:n},this),n):(d&&x.warn(`No client configured on scope - will not capture event!`),n)}e(){this.x||(this.x=!0,this.w.forEach(e=>{e(this)}),this.x=!1)}};function ze(){return g(`defaultCurrentScope`,()=>new L)}function Be(){return g(`defaultIsolationScope`,()=>new L)}const R=`__SENTRY_SUPPRESS_TRACING__`,z=e=>e instanceof Promise&&!e[Ve],Ve=Symbol(`chained PromiseLike`),He=(e,t,n)=>{let r=e.then(e=>(t(e),e),e=>{throw n(e),e});return z(r)&&z(e)?r:Ue(e,r)},Ue=(e,t)=>{if(!t)return e;let n=!1;for(let r in e){if(r in t)continue;n=!0;let i=e[r];typeof i==`function`?Object.defineProperty(t,r,{value:(...t)=>i.apply(e,t),enumerable:!0,configurable:!0,writable:!0}):t[r]=i}return n&&Object.assign(t,{[Ve]:!0}),t};var We=class{constructor(e,t){let n;n=e||new L;let r;r=t||new L,this.f=[{scope:n}],this.E=r}withScope(e){let t=this.D(),n;try{n=e(t)}catch(e){throw this.v(),e}return me(n)?He(n,()=>this.v(),()=>this.v()):(this.v(),n)}getClient(){return this.getStackTop().client}getScope(){return this.getStackTop().scope}getIsolationScope(){return this.E}getStackTop(){return this.f[this.f.length-1]}D(){let e=this.getScope().clone();return this.f.push({client:this.getClient(),scope:e}),e}v(){return this.f.length<=1?!1:!!this.f.pop()}};function B(){let e=h(m());return e.stack=e.stack||new We(ze(),Be())}function Ge(e){return B().withScope(e)}function Ke(e,t){let n=B();return n.withScope(()=>(n.getStackTop().scope=e,t(e)))}function qe(e){return B().withScope(()=>e(B().getIsolationScope()))}function Je(){return{suppressTracing:Ye,withIsolationScope:qe,withScope:Ge,withSetScope:Ke,withSetIsolationScope:(e,t)=>qe(t),getCurrentScope:()=>B().getScope(),getIsolationScope:()=>B().getIsolationScope()}}function Ye(e){return Ge(t=>{t.setSDKProcessingMetadata({[R]:!0});let n=e();return t.setSDKProcessingMetadata({[R]:void 0}),n})}function Xe(e){let t=h(e);return t.acs?t.acs:Je()}function Ze(...e){let t=Xe(m());if(e.length===2){let[n,r]=e;return n?t.withSetScope(n,r):t.withScope(r)}return t.withScope(e[0])}function Qe(e,t=!1){let{host:n,path:r,pass:i,port:a,projectId:o,protocol:s,publicKey:c}=e;return`${s}://${c}${t&&i?`:${i}`:``}@${n}${a?`:${a}`:``}/${r&&`${r}/`}${o}`}function $e(e,t){let{fingerprint:n,breadcrumbs:r,sdkProcessingMetadata:i}=t;et(e,t),rt(e,n),tt(e,r),nt(e,i)}function et(e,t){let{extra:n,tags:r,user:i,contexts:a,level:o,transactionName:s}=t;Object.keys(n).length&&(e.extra={...n,...e.extra}),Object.keys(r).length&&(e.tags={...r,...e.tags}),Object.keys(i).length&&(e.user={...i,...e.user}),Object.keys(a).length&&(e.contexts={...a,...e.contexts}),o&&(e.level=o),s&&e.type!==`transaction`&&(e.transaction=s)}function tt(e,t){let n=[...e.breadcrumbs||[],...t];e.breadcrumbs=n.length?n:void 0}function nt(e,t){e.sdkProcessingMetadata={...e.sdkProcessingMetadata,...t}}function rt(e,t){e.fingerprint=e.fingerprint?Array.isArray(e.fingerprint)?e.fingerprint:[e.fingerprint]:[],t&&(e.fingerprint=e.fingerprint.concat(t)),e.fingerprint.length||delete e.fingerprint}function it(e){return typeof e==`object`&&typeof e.unref==`function`&&e.unref(),e}function V(e,t=[]){return[e,t]}function H(e,t){let n=e[1];for(let e of n){let n=e[0].type;if(t(e,n))return!0}return!1}function at(e,t){return H(e,(e,n)=>t.includes(n))}function ot(e){let t=h(f);return t.encodePolyfill?t.encodePolyfill(e):new TextEncoder().encode(e)}function st(e){let[t,n]=e,r=JSON.stringify(t);function i(e){typeof r==`string`?r=typeof e==`string`?r+e:[ot(r),e]:r.push(typeof e==`string`?ot(e):e)}for(let e of n){let[t,n]=e;if(i(`\n${JSON.stringify(t)}\n`),typeof n==`string`||n instanceof Uint8Array)i(n);else{let e;try{e=JSON.stringify(n)}catch{e=JSON.stringify(we(n))}i(e)}}return typeof r==`string`?r:ct(r)}function ct(e){let t=e.reduce((e,t)=>e+t.length,0),n=new Uint8Array(t),r=0;for(let t of e)n.set(t,r),r+=t.length;return n}const lt={sessions:`session`,event:`error`,client_report:`internal`,user_report:`default`,profile_chunk:`profile`,replay_event:`replay`,replay_recording:`replay`,check_in:`monitor`,raw_security:`security`,log:`log_item`,metric:`trace_metric`};function ut(e){return e in lt}function dt(e){return ut(e)?lt[e]:e}function ft(e){if(!e?.sdk)return;let{name:t,version:n}=e.sdk;return{name:t,version:n}}function pt(e,t,n,r){let i=e.sdkProcessingMetadata?.dynamicSamplingContext;return{event_id:e.event_id,sent_at:new Date(D()).toISOString(),...t&&{sdk:t},...!!n&&r&&{dsn:Qe(r)},...i&&{trace:i}}}function mt(e){let t=ht();return t.suppressTracing?t.suppressTracing(e):Ze(t=>(t.setSDKProcessingMetadata({[R]:!0}),e()))}function ht(){return Xe(m())}function gt(e,t){if(!t)return e;let n=e.sdk||{};return e.sdk={...n,name:n.name||t.name,version:n.version||t.version,integrations:[...e.sdk?.integrations||[],...t.integrations||[]],packages:[...e.sdk?.packages||[],...t.packages||[]],settings:e.sdk?.settings||t.settings?{...e.sdk?.settings,...t.settings}:void 0},e}function _t(e,t,n,r){let i=ft(n);return V({sent_at:new Date(D()).toISOString(),...i&&{sdk:i},...!!r&&t&&{dsn:Qe(t)}},[`aggregates`in e?[{type:`sessions`},e]:[{type:`session`},e.toJSON()]])}function vt(e,t,n,r){let i=ft(n),a=e.type&&e.type!==`replay_event`?e.type:`event`;gt(e,n?.sdk);let o=pt(e,i,r,t);return delete e.sdkProcessingMetadata,V(o,[[{type:a},e]])}function yt(e){return new xt(t=>{t(e)})}function bt(e){return new xt((t,n)=>{n(e)})}var xt=class e{constructor(e){this.p=0,this.y=[],this.O(e)}then(t,n){return new e((e,r)=>{this.y.push([!1,n=>{if(!t)e(n);else try{e(t(n))}catch(e){r(e)}},t=>{if(!n)r(t);else try{e(n(t))}catch(e){r(e)}}]),this.C()})}catch(e){return this.then(e=>e,e)}finally(t){return new e((e,n)=>{let r,i;return this.then(e=>{i=!1,r=e,t&&t()},e=>{i=!0,r=e,t&&t()}).then(()=>{i?n(r):e(r)})})}C(){if(this.p===0)return;let e=this.y.slice();this.y=[],e.forEach(e=>{e[0]||(this.p===1&&e[1](this.T),this.p===2&&e[2](this.T),e[0]=!0)})}O(e){let t=(e,t)=>{this.p===0&&(me(t)?t.then(n,r):(this.p=e,this.T=t,this.C()))},n=e=>{t(1,e)},r=e=>{t(2,e)};try{e(n,r)}catch(e){r(e)}}};function St(e){let t=e.protocol?`${e.protocol}:`:``,n=e.port?`:${e.port}`:``;return`${t}//${e.host}${n}${e.path?`/${e.path}`:``}/api/`}function Ct(e){return`${St(e)}${e.projectId}/envelope/`}function wt(e,t){let n={sentry_version:`7`};return e.publicKey&&(n.sentry_key=e.publicKey),t&&(n.sentry_client=`${t.name}/${t.version}`),new URLSearchParams(n).toString()}function Tt(e,t,n){return t||`${Ct(e)}?${wt(e,n)}`}const Et=Symbol.for(`SentryBufferFullError`);function Dt(e=100){let t=/* @__PURE__ */ new Set;function n(){return t.size<e}function r(e){t.delete(e)}function i(e){if(!n())return bt(Et);let i=e();return t.add(i),i.then(()=>r(i),()=>r(i)),i}function a(e){if(!t.size)return yt(!0);let n=Promise.allSettled(Array.from(t)).then(()=>!0);if(!e)return n;let r=[n,new Promise(t=>it(setTimeout(()=>t(!1),e)))];return Promise.race(r)}return{get $(){return Array.from(t)},add:i,drain:a}}function Ot(e,t=D()){let n=parseInt(`${e}`,10);if(!isNaN(n))return n*1e3;let r=Date.parse(`${e}`);return isNaN(r)?6e4:r-t}function kt(e,t){return e[t]||e.all||0}function At(e,t,n=D()){return kt(e,t)>n}function jt(e,t,n=D()){let r={...e};return Mt(t,n,(e,t)=>{r[e]=Math.max(r[e]||0,t)}),r}function Mt({statusCode:e,headers:t},n,r){let i=t?.[`x-sentry-rate-limits`],a=t?.[`retry-after`];if(i)for(let e of i.trim().split(`,`)){let[t,i,,,a]=e.split(`:`,5),o=parseInt(t,10),s=(isNaN(o)?60:o)*1e3;if(!i)r(`all`,n+s);else for(let e of i.split(`;`))e===`metric_bucket`?(!a||a.split(`;`).includes(`custom`))&&r(e,n+s):r(e,n+s)}else a?r(`all`,n+Ot(a,n)):e===429&&r(`all`,n+6e4)}function Nt(e,t,n=Dt(e.bufferSize||64)){let r={},i=e=>n.drain(e);function a(t,[n,r],i){let a=dt(i);i===`transaction`&&e.recordDroppedEvent(t,`span`,(r.spans?.length??0)+1),e.recordDroppedEvent(t,a,typeof n.item_count==`number`?n.item_count:1)}function o(e){let i=[];if(H(e,(e,t)=>{At(r,dt(t))?a(`ratelimit_backoff`,e,t):i.push(e)}),i.length===0)return Promise.resolve({});let o=V(e[0],i),s=e=>{at(o,[`client_report`])?d&&x.warn(`Dropping client report. Will not send outcomes (reason: ${e}).`):H(o,(t,n)=>{a(e,t,n)})};return n.add(()=>t({body:st(o)}).then(e=>e.statusCode===413?(d&&x.error(`Sentry responded with status code 413. Envelope was discarded due to exceeding size limits.`),s(`send_error`),e):(d&&e.statusCode!==void 0&&(e.statusCode<200||e.statusCode>=300)&&x.warn(`Sentry responded with status code ${e.statusCode} to sent event.`),r=jt(r,e),e),e=>{throw s(`network_error`),d&&x.error(`Encountered error running transport request:`,e),e})).then(e=>e,e=>{if(e===Et)return d&&x.error(`Skipped sending event because buffer is full.`),s(`queue_overflow`),Promise.resolve({});throw e})}return{send:o,flush:i}}const Pt=/^(\S+:\\|\/?)([\s\S]*?)((?:\.{1,2}|[^/\\]+?|)(\.[^./\\]*|))(?:[/\\]*)$/;function Ft(e){let t=e.length>1024?`<truncated>${e.slice(-1024)}`:e,n=Pt.exec(t);return n?n.slice(1):[]}function It(e){let t=Ft(e),n=t[0]||``,r=t[1];return!n&&!r?`.`:(r&&(r=r.slice(0,r.length-1)),n+r)}function Lt(e,t=!1){return!(t||e&&!e.startsWith(`/`)&&!e.match(/^[A-Z]:/)&&!e.startsWith(`.`)&&!e.match(/^[a-zA-Z]([a-zA-Z0-9.\-+])*:\/\//))&&e!==void 0&&!e.includes(`node_modules/`)}function Rt(e,t,n,r){let i=e(),a=!1,o=!0;return setInterval(()=>{let e=i.getTimeMs();a===!1&&e>t+n&&(a=!0,o&&r()),e<t+n&&(a=!1)},20),{poll:()=>{i.reset()},enabled:e=>{o=e}}}function zt(e,t,n){let r=t?t.replace(/^file:\/\//,``):void 0,i=e.location.columnNumber?e.location.columnNumber+1:void 0,a=e.location.lineNumber?e.location.lineNumber+1:void 0;return{filename:r,module:n(r),function:e.functionName||`?`,colno:i,lineno:a,in_app:r?Lt(r):void 0}}function Bt(e){return e.replace(/^[A-Z]:/,``).replace(/\\/g,`/`)}function Vt(e=process.argv[1]?It(process.argv[1]):process.cwd(),t=i===`\\`){let n=t?Bt(e):e;return e=>{if(!e)return;let i=t?Bt(e):e,{dir:a,base:o,ext:s}=r.parse(i);(s===`.js`||s===`.mjs`||s===`.cjs`)&&(o=o.slice(0,s.length*-1));let c=decodeURIComponent(o);a||(a=`.`);let l=a.lastIndexOf(`/node_modules`);if(l>-1)return`${a.slice(l+14).replace(/\//g,`.`)}:${c}`;if(a.startsWith(n)){let e=a.slice(n.length+1).replace(/\//g,`.`);return e?`${e}:${c}`:c}return c}}const U=Symbol(`AgentBaseInternalState`);var Ht=class extends o.Agent{constructor(e){super(e),this[U]={}}isSecureEndpoint(e){if(e){if(typeof e.secureEndpoint==`boolean`)return e.secureEndpoint;if(typeof e.protocol==`string`)return e.protocol===`https:`}let{stack:t}=/* @__PURE__ */ Error();return typeof t==`string`&&t.split(` `).some(e=>e.indexOf(`(https.js:`)!==-1||e.indexOf(`node:https:`)!==-1)}createSocket(e,t,n){let r={...t,secureEndpoint:this.isSecureEndpoint(t)};Promise.resolve().then(()=>this.connect(e,r)).then(i=>{if(i instanceof o.Agent)return i.addRequest(e,r);this[U].currentSocket=i,super.createSocket(e,t,n)},n)}createConnection(){let e=this[U].currentSocket;if(this[U].currentSocket=void 0,!e)throw Error("No socket was returned in the `connect()` function");return e}get defaultPort(){return this[U].defaultPort??(this.protocol===`https:`?443:80)}set defaultPort(e){this[U]&&(this[U].defaultPort=e)}get protocol(){return this[U].protocol??(this.isSecureEndpoint()?`https:`:`http:`)}set protocol(e){this[U]&&(this[U].protocol=e)}};function W(...e){x.log(`[https-proxy-agent:parse-proxy-response]`,...e)}function Ut(e){return new Promise((t,n)=>{let r=0,i=[];function a(){let t=e.read();t?l(t):e.once(`readable`,a)}function o(){e.removeListener(`end`,s),e.removeListener(`error`,c),e.removeListener(`readable`,a)}function s(){o(),W(`onend`),n(/* @__PURE__ */ Error(`Proxy connection ended before receiving CONNECT response`))}function c(e){o(),W(`onerror %o`,e),n(e)}function l(s){i.push(s),r+=s.length;let c=Buffer.concat(i,r),l=c.indexOf(`\r \r `);if(l===-1){W(`have not received end of HTTP headers yet...`),a();return}let u=c.subarray(0,l).toString(`ascii`).split(`\r `),d=u.shift();if(!d)return e.destroy(),n(/* @__PURE__ */ Error(`No header received from proxy CONNECT response`));let f=d.split(` `),p=+(f[1]||0),m=f.slice(2).join(` `),h={};for(let t of u){if(!t)continue;let r=t.indexOf(`:`);if(r===-1)return e.destroy(),n(/* @__PURE__ */ Error(`Invalid header from proxy CONNECT response: "${t}"`));let i=t.slice(0,r).toLowerCase(),a=t.slice(r+1).trimStart(),o=h[i];typeof o==`string`?h[i]=[o,a]:Array.isArray(o)?o.push(a):h[i]=a}W(`got proxy server response: %o %o`,d,h),o(),t({connect:{statusCode:p,statusText:m,headers:h},buffered:c})}e.on(`error`,c),e.on(`end`,s),a()})}function G(...e){x.log(`[https-proxy-agent]`,...e)}var Wt=class extends Ht{constructor(e,t){super(t),this.options={},this.proxy=typeof e==`string`?new URL(e):e,this.proxyHeaders=t?.headers??{},G(`Creating new HttpsProxyAgent instance: %o`,this.proxy.href);let n=(this.proxy.hostname||this.proxy.host).replace(/^\[|\]$/g,``),r=this.proxy.port?parseInt(this.proxy.port,10):this.proxy.protocol===`https:`?443:80;this.connectOpts={ALPNProtocols:[`http/1.1`],...t?Kt(t,`headers`):null,host:n,port:r}}async connect(e,t){let{proxy:n}=this;if(!t.host)throw TypeError(`No "host" provided`);let r;if(n.protocol===`https:`){G("Creating `tls.Socket`: %o",this.connectOpts);let e=this.connectOpts.servername||this.connectOpts.host;r=u.connect({...this.connectOpts,servername:e&&a.isIP(e)?void 0:e})}else G("Creating `net.Socket`: %o",this.connectOpts),r=a.connect(this.connectOpts);let i=typeof this.proxyHeaders==`function`?this.proxyHeaders():{...this.proxyHeaders},o=a.isIPv6(t.host)?`[${t.host}]`:t.host,s=`CONNECT ${o}:${t.port} HTTP/1.1\r\n`;if(n.username||n.password){let e=`${decodeURIComponent(n.username)}:${decodeURIComponent(n.password)}`;i[`Proxy-Authorization`]=`Basic ${Buffer.from(e).toString(`base64`)}`}i.Host=`${o}:${t.port}`,i[`Proxy-Connection`]||(i[`Proxy-Connection`]=this.keepAlive?`Keep-Alive`:`close`);for(let e of Object.keys(i))s+=`${e}: ${i[e]}\r\n`;let c=Ut(r);r.write(`${s}\r\n`);let{connect:l,buffered:d}=await c;if(e.emit(`proxyConnect`,l),this.emit(`proxyConnect`,l,e),l.statusCode===200){if(e.once(`socket`,Gt),t.secureEndpoint){G(`Upgrading socket connection to TLS`);let e=t.servername||t.host;return u.connect({...Kt(t,`host`,`path`,`port`),socket:r,servername:a.isIP(e)?void 0:e})}return r}r.destroy();let f=new a.Socket({writable:!1});return f.readable=!0,e.once(`socket`,e=>{G(`Replaying proxy buffer for failed request`),e.push(d),e.push(null)}),f}};Wt.protocols=[`http`,`https`];function Gt(e){e.resume()}function Kt(e,...t){let n={},r;for(r in e)t.includes(r)||(n[r]=e[r]);return n}function qt(e){return new c({read(){this.push(e),this.push(null)}})}function Jt(e){let t;try{t=new URL(e.url)}catch{return v(()=>{console.warn(`[@sentry/node]: Invalid dsn or tunnel option, will not send any events. The tunnel option must be a full URL when used.`)}),Nt(e,()=>Promise.resolve({}))}let n=t.protocol===`https:`?s:o,r=Yt(t,{proxy:e.proxy,keepAlive:e.keepAlive});return Nt(e,Zt(e,e.httpModule??n,r))}function Yt(e,t={}){let n=e.protocol===`https:`,r=t.proxy===!1?void 0:Xt(e,t.proxy||(n?process.env.https_proxy:void 0)||process.env.http_proxy);return r?new Wt(r):new(n?s:o).Agent({keepAlive:t.keepAlive??!0,maxSockets:30,timeout:2e3})}function Xt(e,t){let{no_proxy:n}=process.env;if(!n?.split(`,`).some(t=>e.host.endsWith(t)||e.hostname.endsWith(t)))return t}function Zt(e,t,n){let{hostname:r,pathname:i,port:a,protocol:o,search:s}=new URL(e.url);return function(c){let u=d=>new Promise((f,p)=>{mt(()=>{let m=qt(c.body),h={...e.headers};c.body.length>32768&&(h[`content-encoding`]=`gzip`,m=m.pipe(l()));let g=r.startsWith(`[`),_=t.request({method:`POST`,agent:n,headers:h,hostname:g?r.slice(1,-1):r,path:`${i}${s}`,port:a,protocol:o,ca:e.caCerts},e=>{e.on(`data`,()=>{}),e.on(`end`,()=>{}),e.setEncoding(`utf8`);let t=e.headers[`retry-after`]??null,n=e.headers[`x-sentry-rate-limits`]??null;f({statusCode:e.statusCode,headers:{"retry-after":t,"x-sentry-rate-limits":Array.isArray(n)?n[0]||null:n}})});_.on(`error`,e=>{d&&_.reusedSocket&&e.code===`ECONNRESET`?f(u(!1)):p(e)}),m.pipe(_)})});return u(!0)}}const K=n;let q,J=0,Y={};function X(e){K.debug&&console.log(`[ANR Worker] ${e}`)}const Z=Jt({url:Tt(K.dsn,K.tunnel,K.sdkMetadata.sdk),recordDroppedEvent:()=>{}});async function Qt(){if(q){X(`Sending abnormal session`),I(q,{status:`abnormal`,abnormal_mechanism:`anr_foreground`,release:K.release,environment:K.environment});let e=_t(q,K.dsn,K.sdkMetadata,K.tunnel);X(JSON.stringify(e)),await Z.send(e);try{t?.postMessage(`session-ended`)}catch{}}}X(`Started`);function $t(e){if(!e)return;let t=oe(e);if(K.appRootPath)for(let e of t)e.filename&&(e.filename=A(e.filename,K.appRootPath));return t}function en(e){if(Object.keys(Y).length===0)return;let t=K.appRootPath?{}:Y;if(K.appRootPath)for(let[e,n]of Object.entries(Y))t[A(e,K.appRootPath)]=n;let n=/* @__PURE__ */ new Map;for(let r of e.exception?.values||[])for(let e of r.stacktrace?.frames||[]){let r=e.abs_path||e.filename;r&&t[r]&&n.set(r,t[r])}if(n.size>0){let t=[];for(let[e,r]of n.entries())t.push({type:`sourcemap`,code_file:e,debug_id:r});e.debug_meta={images:t}}}function tn(e,t){if($e(e,t),!e.contexts?.trace){let{traceId:n,parentSpanId:r,propagationSpanId:i}=t.propagationContext;e.contexts={trace:{trace_id:n,span_id:i||Re(),parent_span_id:r},...e.contexts}}}async function Q(e,t){if(J>=K.maxAnrEvents)return;J+=1,await Qt(),X(`Sending event`);let n={event_id:M(),contexts:K.contexts,release:K.release,environment:K.environment,dist:K.dist,platform:`node`,level:`error`,exception:{values:[{type:`ApplicationNotResponding`,value:`Application Not Responding for at least ${K.anrThreshold} ms`,stacktrace:{frames:$t(e)},mechanism:{type:`ANR`}}]},tags:K.staticTags};t&&tn(n,t),en(n);let r=vt(n,K.dsn,K.sdkMetadata,K.tunnel);X(JSON.stringify(r)),await Z.send(r),await Z.flush(2e3),J>=K.maxAnrEvents&&setTimeout(()=>{process.exit(0)},5e3)}let $;if(K.captureStackTrace){X(`Connecting to debugger`);let t=new e;t.connectToMainThread(),X(`Connected to debugger`);let n=/* @__PURE__ */ new Map;t.on(`Debugger.scriptParsed`,e=>{n.set(e.params.scriptId,e.params.url)}),t.on(`Debugger.paused`,e=>{if(e.params.reason===`other`)try{X(`Debugger paused`);let r=[...e.params.callFrames],i=K.appRootPath?Vt(K.appRootPath):()=>void 0,a=r.map(e=>zt(e,n.get(e.location.scriptId),i)),o=setTimeout(()=>{Q(a).then(null,()=>{X(`Sending ANR event failed.`)})},5e3);t.post(`Runtime.evaluate`,{expression:`global.__SENTRY_GET_SCOPES__();`,silent:!0,returnByValue:!0},(e,n)=>{e&&X(`Error executing script: '${e.message}'`),clearTimeout(o);let r=n?.result?n.result.value:void 0;t.post(`Debugger.resume`),t.post(`Debugger.disable`),Q(a,r).then(null,()=>{X(`Sending ANR event failed.`)})})}catch(e){throw t.post(`Debugger.resume`),t.post(`Debugger.disable`),e}}),$=()=>{try{t.post(`Debugger.enable`,()=>{t.post(`Debugger.pause`)})}catch{}}}function nn(){let e=process.hrtime.bigint();return{getTimeMs:()=>Number((process.hrtime.bigint()-e)/1000000n),reset:()=>{e=process.hrtime.bigint()}}}function rn(){X(`Watchdog timeout`),$?(X(`Pausing debugger to capture stack trace`),$()):(X(`Capturing event without a stack trace`),Q().then(null,()=>{X(`Sending ANR event failed on watchdog timeout.`)}))}const{poll:an}=Rt(nn,K.pollInterval,K.anrThreshold,rn);t?.on(`message`,e=>{e.session&&(q=Pe(e.session)),e.debugImages&&(Y=e.debugImages),an()}),t?.postMessage(`worker-ready`);