UNPKG

dd-trace

Version:

Datadog APM tracing client for JavaScript

1 lines 13.3 kB
(()=>{"use strict";var e,t,i={};i.d=(e,t)=>{for(var s in t)i.o(t,s)&&!i.o(e,s)&&Object.defineProperty(e,s,{enumerable:!0,get:t[s]})},i.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),i.r=e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})};var s={};i.r(s),i.d(s,{Function:()=>A,Label:()=>L,Line:()=>U,Location:()=>V,Mapping:()=>v,Profile:()=>P,Sample:()=>N,StringTable:()=>I,ValueType:()=>S,emptyTableToken:()=>k});var n=function(e,t,i,s){if("a"===i&&!s)throw TypeError("Private accessor was defined without a getter");if("function"==typeof t?e!==t||!s:!t.has(e))throw TypeError("Cannot read private member from an object whose class did not declare it");return"m"===i?s:"a"===i?s.call(e):s?s.value:t.get(e)};let r=2n**32n-1n,a=0x100000000-1,o=0x100000000-1+1,h="undefined"==typeof Buffer?e=>new TextEncoder().encode(e):e=>Buffer.from(e,"utf8");function c(e){if(!e.length)return 0;let t=0;for(;t<e.length&&e[t++]>=128;);return t}function d(e,t=0){return{value:e,offset:t}}function u(e){var t,i;let s=e<0;s&&(e=-e);let n="bigint"!=typeof(t=e)?(t>>>0)%o:Number(t&r),h="bigint"!=typeof(i=e)?i/o>>>0:Number(i>>32n&r);return s&&(h=~h>>>0,n=~n>>>0,++n>a&&(n=0,++h>a&&(h=0))),[h,n]}function l(e){if(c(e)>4){if(!e.length)return BigInt(0);let t=BigInt(127&e[0]),i=0;for(;e[i++]>=128;)t|=BigInt(127&e[i])<<BigInt(7*i);return t}if(!e.length)return 0;let t=127&e[0],i=0;for(;e[i++]>=128;)t|=(127&e[i])<<7*i;return t}function f(e){let t=[],i=0;for(let s=0;s<e.length;s++)(128&e[s])==0&&(t.push(l(e.slice(i,s+1))),i=s+1);return t}function m(e,t){return null==t?[e]:(t.push(e),t)}function p(e){if(0===e||0n===e)return 0;let[t,i]=u(e),s=(i>>>28|t<<4)>>>0,n=t>>>24;return 0!==n?n<128?9:10:0!==s?s<16384?s<128?5:6:s<2097152?7:8:i<16384?i<128?1:2:i<2097152?3:4}function g(e){return void 0===e?0:"number"==typeof e||"bigint"==typeof e?p(e)||1:e.length}function y(e){let t=0;for(let i of e)t+=g(i);return t}function T(e){let t=p(e);return t?1+t:0}function b(e){let t=0;for(let i of e)t+=p(i)||1;return t?1+p(t)+t:0}function w(e){let t=g(e);return t?1+p(t)+t:0}function B(e){let t=0;for(let i of e)t+=w(i);return t}function _(e,t,i){if(0===i||0n===i)return e[t++]=0,t;let[s,n]=u(i);for(;s;)e[t++]=127&n|128,n=(n>>>7|s<<25)>>>0,s>>>=7;for(;n>127;)e[t++]=127&n|128,n>>>=7;return e[t++]=n,t}let k=Symbol();class I{constructor(i){this.strings=[],e.set(this,[]),t.set(this,new Map),i!==k&&this.dedup("")}get encodedLength(){let t=0;for(let i of n(this,e,"f"))t+=i.length;return t}_encodeToBuffer(t,i){for(let s of n(this,e,"f"))t.set(s,i),i+=s.length;return i}encode(e=new Uint8Array(this.encodedLength)){return this._encodeToBuffer(e,0),e}static _encodeStringFromUtf8(e){let t=new Uint8Array(1+e.length+(p(e.length)||1)),i=0;return t[i++]=50,i=_(t,i,e.length),e.length>0&&t.set(e,i++),t}static _encodeString(e){return I._encodeStringFromUtf8(h(e))}dedup(i){if("number"==typeof i)return i;if(!n(this,t,"f").has(i)){let s=this.strings.push(i)-1;n(this,t,"f").set(i,s),n(this,e,"f").push(I._encodeString(i))}return n(this,t,"f").get(i)}_decodeString(i){let s=new TextDecoder().decode(i);n(this,t,"f").set(s,this.strings.push(s)-1),n(this,e,"f").push(I._encodeStringFromUtf8(i))}}function F(e,t){let i={},s=0;for(;s<e.length;){let n=e[s]>>3,r=7&e[s];s++;let{offset:a,value:o}=function(e,t){switch(e){case 0:for(let e=0;e<t.length;e++)if(!(128&t[e]))return d(t.slice(0,e+1));return d(t);case 2:{let e=c(t),i=l(t);return d(t.slice(e,Number(i)+e),e)}default:throw Error(`Unrecognized value type: ${e}`)}}(r,e.slice(s));s+=o.length+a,t(i,n,o)}return i}e=new WeakMap,t=new WeakMap;class S{static create(e){return e instanceof S?e:new S(e)}constructor(e){this.type=e.type||0,this.unit=e.unit||0}get length(){return 0+T(this.type)+T(this.unit)}_encodeToBuffer(e,t=0){return this.type&&(e[t++]=8,t=_(e,t,this.type)),this.unit&&(e[t++]=16,t=_(e,t,this.unit)),t}encode(e=new Uint8Array(this.length)){return this._encodeToBuffer(e,0),e}static decodeValue(e,t,i){switch(t){case 1:e.type=l(i);break;case 2:e.unit=l(i)}}static decode(e){return new this(F(e,this.decodeValue))}}class L{static create(e){return e instanceof L?e:new L(e)}constructor(e){this.key=e.key||0,this.str=e.str||0,this.num=e.num||0,this.numUnit=e.numUnit||0}get length(){return 0+T(this.key)+T(this.str)+T(this.num)+T(this.numUnit)}_encodeToBuffer(e,t=0){return this.key&&(e[t++]=8,t=_(e,t,this.key)),this.str&&(e[t++]=16,t=_(e,t,this.str)),this.num&&(e[t++]=24,t=_(e,t,this.num)),this.numUnit&&(e[t++]=32,t=_(e,t,this.numUnit)),t}encode(e=new Uint8Array(this.length)){return this._encodeToBuffer(e,0),e}static decodeValue(e,t,i){switch(t){case 1:e.key=l(i);break;case 2:e.str=l(i);break;case 3:e.num=l(i);break;case 4:e.numUnit=l(i)}}static decode(e){return new this(F(e,this.decodeValue))}}class N{static create(e){return e instanceof N?e:new N(e)}constructor(e){this.locationId=e.locationId||[],this.value=e.value||[],this.label=(e.label||[]).map(L.create)}get length(){return 0+b(this.locationId)+b(this.value)+B(this.label)}_encodeToBuffer(e,t=0){if(this.locationId.length)for(let i of(e[t++]=10,t=_(e,t,y(this.locationId)),this.locationId))t=_(e,t,i);if(this.value.length)for(let i of(e[t++]=18,t=_(e,t,y(this.value)),this.value))t=_(e,t,i);for(let i of this.label)e[t++]=26,t=_(e,t,i.length),t=i._encodeToBuffer(e,t);return t}encode(e=new Uint8Array(this.length)){return this._encodeToBuffer(e,0),e}static decodeValue(e,t,i){switch(t){case 1:e.locationId=f(i);break;case 2:e.value=f(i);break;case 3:e.label=m(L.decode(i),e.label)}}static decode(e){return new this(F(e,this.decodeValue))}}class v{static create(e){return e instanceof v?e:new v(e)}constructor(e){this.id=e.id||0,this.memoryStart=e.memoryStart||0,this.memoryLimit=e.memoryLimit||0,this.fileOffset=e.fileOffset||0,this.filename=e.filename||0,this.buildId=e.buildId||0,this.hasFunctions=!!e.hasFunctions,this.hasFilenames=!!e.hasFilenames,this.hasLineNumbers=!!e.hasLineNumbers,this.hasInlineFrames=!!e.hasInlineFrames}get length(){return 0+T(this.id)+T(this.memoryStart)+T(this.memoryLimit)+T(this.fileOffset)+T(this.filename)+T(this.buildId)+T(+!!this.hasFunctions)+T(+!!this.hasFilenames)+T(+!!this.hasLineNumbers)+T(+!!this.hasInlineFrames)}_encodeToBuffer(e,t=0){return this.id&&(e[t++]=8,t=_(e,t,this.id)),this.memoryStart&&(e[t++]=16,t=_(e,t,this.memoryStart)),this.memoryLimit&&(e[t++]=24,t=_(e,t,this.memoryLimit)),this.fileOffset&&(e[t++]=32,t=_(e,t,this.fileOffset)),this.filename&&(e[t++]=40,t=_(e,t,this.filename)),this.buildId&&(e[t++]=48,t=_(e,t,this.buildId)),this.hasFunctions&&(e[t++]=56,t=_(e,t,1)),this.hasFilenames&&(e[t++]=64,t=_(e,t,1)),this.hasLineNumbers&&(e[t++]=72,t=_(e,t,1)),this.hasInlineFrames&&(e[t++]=80,t=_(e,t,1)),t}encode(e=new Uint8Array(this.length)){return this._encodeToBuffer(e,0),e}static decodeValue(e,t,i){switch(t){case 1:e.id=l(i);break;case 2:e.memoryStart=l(i);break;case 3:e.memoryLimit=l(i);break;case 4:e.fileOffset=l(i);break;case 5:e.filename=l(i);break;case 6:e.buildId=l(i);break;case 7:e.hasFunctions=!!l(i);break;case 8:e.hasFilenames=!!l(i);break;case 9:e.hasLineNumbers=!!l(i);break;case 10:e.hasInlineFrames=!!l(i)}}static decode(e){return new this(F(e,this.decodeValue))}}class U{static create(e){return e instanceof U?e:new U(e)}constructor(e){this.functionId=e.functionId||0,this.line=e.line||0}get length(){return 0+T(this.functionId)+T(this.line)}_encodeToBuffer(e,t=0){return this.functionId&&(e[t++]=8,t=_(e,t,this.functionId)),this.line&&(e[t++]=16,t=_(e,t,this.line)),t}encode(e=new Uint8Array(this.length)){return this._encodeToBuffer(e,0),e}static decodeValue(e,t,i){switch(t){case 1:e.functionId=l(i);break;case 2:e.line=l(i)}}static decode(e){return new this(F(e,this.decodeValue))}}class V{static create(e){return e instanceof V?e:new V(e)}constructor(e){this.id=e.id||0,this.mappingId=e.mappingId||0,this.address=e.address||0,this.line=(e.line||[]).map(U.create),this.isFolded=!!e.isFolded}get length(){return 0+T(this.id)+T(this.mappingId)+T(this.address)+B(this.line)+T(+!!this.isFolded)}_encodeToBuffer(e,t=0){for(let i of(this.id&&(e[t++]=8,t=_(e,t,this.id)),this.mappingId&&(e[t++]=16,t=_(e,t,this.mappingId)),this.address&&(e[t++]=24,t=_(e,t,this.address)),this.line))e[t++]=34,t=_(e,t,i.length),t=i._encodeToBuffer(e,t);return this.isFolded&&(e[t++]=40,t=_(e,t,1)),t}encode(e=new Uint8Array(this.length)){return this._encodeToBuffer(e,0),e}static decodeValue(e,t,i){switch(t){case 1:e.id=l(i);break;case 2:e.mappingId=l(i);break;case 3:e.address=l(i);break;case 4:e.line=m(U.decode(i),e.line);break;case 5:e.isFolded=!!l(i)}}static decode(e){return new this(F(e,this.decodeValue))}}class A{static create(e){return e instanceof A?e:new A(e)}constructor(e){this.id=e.id||0,this.name=e.name||0,this.systemName=e.systemName||0,this.filename=e.filename||0,this.startLine=e.startLine||0}get length(){return 0+T(this.id)+T(this.name)+T(this.systemName)+T(this.filename)+T(this.startLine)}_encodeToBuffer(e,t=0){return this.id&&(e[t++]=8,t=_(e,t,this.id)),this.name&&(e[t++]=16,t=_(e,t,this.name)),this.systemName&&(e[t++]=24,t=_(e,t,this.systemName)),this.filename&&(e[t++]=32,t=_(e,t,this.filename)),this.startLine&&(e[t++]=40,t=_(e,t,this.startLine)),t}encode(e=new Uint8Array(this.length)){return this._encodeToBuffer(e,0),e}static decodeValue(e,t,i){switch(t){case 1:e.id=l(i);break;case 2:e.name=l(i);break;case 3:e.systemName=l(i);break;case 4:e.filename=l(i);break;case 5:e.startLine=l(i)}}static decode(e){return new this(F(e,this.decodeValue))}}class P{constructor(e={}){this.sampleType=(e.sampleType||[]).map(S.create),this.sample=(e.sample||[]).map(N.create),this.mapping=(e.mapping||[]).map(v.create),this.location=(e.location||[]).map(V.create),this.function=(e.function||[]).map(A.create),this.stringTable=e.stringTable||new I,this.dropFrames=e.dropFrames||0,this.keepFrames=e.keepFrames||0,this.timeNanos=e.timeNanos||0,this.durationNanos=e.durationNanos||0,this.periodType=e.periodType?S.create(e.periodType):void 0,this.period=e.period||0,this.comment=e.comment||[],this.defaultSampleType=e.defaultSampleType||0}get length(){return 0+B(this.sampleType)+B(this.sample)+B(this.mapping)+B(this.location)+B(this.function)+this.stringTable.encodedLength+T(this.dropFrames)+T(this.keepFrames)+T(this.timeNanos)+T(this.durationNanos)+w(this.periodType)+T(this.period)+b(this.comment)+T(this.defaultSampleType)}_encodeSampleTypesToBuffer(e,t=0){for(let i of this.sampleType)e[t++]=10,t=_(e,t,i.length),t=i._encodeToBuffer(e,t);return t}_encodeSamplesToBuffer(e,t=0){for(let i of this.sample)e[t++]=18,t=_(e,t,i.length),t=i._encodeToBuffer(e,t);return t}_encodeMappingsToBuffer(e,t=0){for(let i of this.mapping)e[t++]=26,t=_(e,t,i.length),t=i._encodeToBuffer(e,t);return t}_encodeLocationsToBuffer(e,t=0){for(let i of this.location)e[t++]=34,t=_(e,t,i.length),t=i._encodeToBuffer(e,t);return t}_encodeFunctionsToBuffer(e,t=0){for(let i of this.function)e[t++]=42,t=_(e,t,i.length),t=i._encodeToBuffer(e,t);return t}_encodeBasicValuesToBuffer(e,t=0){if(this.dropFrames&&(e[t++]=56,t=_(e,t,this.dropFrames)),this.keepFrames&&(e[t++]=64,t=_(e,t,this.keepFrames)),this.timeNanos&&(e[t++]=72,t=_(e,t,this.timeNanos)),this.durationNanos&&(e[t++]=80,t=_(e,t,this.durationNanos)),void 0!==this.periodType&&(e[t++]=90,t=_(e,t,this.periodType.length),t=this.periodType._encodeToBuffer(e,t)),this.period&&(e[t++]=96,t=_(e,t,this.period)),this.comment.length)for(let i of(e[t++]=106,t=_(e,t,y(this.comment)),this.comment))t=_(e,t,i);return this.defaultSampleType&&(e[t++]=112,t=_(e,t,this.defaultSampleType)),t}_encodeToBuffer(e,t=0){return t=this._encodeSampleTypesToBuffer(e,t),t=this._encodeSamplesToBuffer(e,t),t=this._encodeMappingsToBuffer(e,t),t=this._encodeLocationsToBuffer(e,t),t=this._encodeFunctionsToBuffer(e,t),t=this.stringTable._encodeToBuffer(e,t),t=this._encodeBasicValuesToBuffer(e,t)}async _encodeToBufferAsync(e,t=0){return t=this._encodeSampleTypesToBuffer(e,t),await new Promise(setImmediate),t=this._encodeSamplesToBuffer(e,t),await new Promise(setImmediate),t=this._encodeMappingsToBuffer(e,t),await new Promise(setImmediate),t=this._encodeLocationsToBuffer(e,t),await new Promise(setImmediate),t=this._encodeFunctionsToBuffer(e,t),await new Promise(setImmediate),t=this.stringTable._encodeToBuffer(e,t),await new Promise(setImmediate),t=this._encodeBasicValuesToBuffer(e,t)}encode(e=new Uint8Array(this.length)){return this._encodeToBuffer(e,0),e}async encodeAsync(e=new Uint8Array(this.length)){return await this._encodeToBufferAsync(e,0),e}static decodeValue(e,t,i){switch(t){case 1:e.sampleType=m(S.decode(i),e.sampleType);break;case 2:e.sample=m(N.decode(i),e.sample);break;case 3:e.mapping=m(v.decode(i),e.mapping);break;case 4:e.location=m(V.decode(i),e.location);break;case 5:e.function=m(A.decode(i),e.function);break;case 6:void 0===e.stringTable&&(e.stringTable=new I(k)),e.stringTable._decodeString(i);break;case 7:e.dropFrames=l(i);break;case 8:e.keepFrames=l(i);break;case 9:e.timeNanos=l(i);break;case 10:e.durationNanos=l(i);break;case 11:e.periodType=S.decode(i);break;case 12:e.period=l(i);break;case 13:e.comment=f(i);break;case 14:e.defaultSampleType=l(i)}}static decode(e){return new this(F(e,this.decodeValue))}}module.exports=s})();