dd-trace
Version:
Datadog APM tracing client for JavaScript
1 lines • 16.3 kB
JavaScript
(()=>{"use strict";var e,t,r={};r.d=(e,t)=>{for(var i in t)r.o(t,i)&&!r.o(e,i)&&Object.defineProperty(e,i,{enumerable:!0,get:t[i]})},r.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),r.r=e=>{"u">typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})};var i={};r.r(i),r.d(i,{Function:()=>Function,Label:()=>Label,Line:()=>Line,Location:()=>Location,Mapping:()=>Mapping,Profile:()=>Profile,Sample:()=>Sample,StringTable:()=>StringTable,ValueType:()=>ValueType,emptyTableToken:()=>c});var __classPrivateFieldGet=function(e,t,r,i){if("a"===r&&!i)throw TypeError("Private accessor was defined without a getter");if("function"==typeof t?e!==t||!i:!t.has(e))throw TypeError("Cannot read private member from an object whose class did not declare it");return"m"===r?i:"a"===r?i.call(e):i?i.value:t.get(e)};let s=2n**32n-1n,n=0x100000000-1,a=0x100000000-1+1,o="u"<typeof Buffer?e=>new TextEncoder().encode(e):e=>Buffer.from(e,"utf8");function countNumberBytes(e){if(!e.length)return 0;let t=0;for(;t<e.length&&e[t++]>=128;);return t}function decodeBigNumber(e){if(!e.length)return BigInt(0);let t=BigInt(127&e[0]),r=0;for(;e[r++]>=128;)t|=BigInt(127&e[r])<<BigInt(7*r);return t}function makeValue(e,t=0){return{value:e,offset:t}}function getValue(e,t){switch(e){case u:for(let e=0;e<t.length;e++)if(!(128&t[e]))return makeValue(t.slice(0,e+1));return makeValue(t);case d:{let e=countNumberBytes(t),r=decodeNumber(t);return makeValue(t.slice(e,Number(r)+e),e)}default:throw Error(`Unrecognized value type: ${e}`)}}function lowBits(e){return"bigint"!=typeof e?(e>>>0)%a:Number(e&s)}function highBits(e){return"bigint"!=typeof e?e/a>>>0:Number(e>>32n&s)}function long(e){let t=e<0;t&&(e=-e);let r=lowBits(e),i=highBits(e);return t&&(i=~i>>>0,r=~r>>>0,++r>n&&(r=0,++i>n&&(i=0))),[i,r]}let u=0,d=2;function decodeNumber(e){if(countNumberBytes(e)>4)return decodeBigNumber(e);if(!e.length)return 0;let t=127&e[0],r=0;for(;e[r++]>=128;)t|=(127&e[r])<<7*r;return t}function decodeNumbers(e){let t=[],r=0;for(let i=0;i<e.length;i++)(128&e[i])==0&&(t.push(decodeNumber(e.slice(r,i+1))),r=i+1);return t}function push(e,t){return null==t?[e]:(t.push(e),t)}function measureNumber(e){if(0===e||0n===e)return 0;let[t,r]=long(e),i=(r>>>28|t<<4)>>>0,s=t>>>24;return 0!==s?s<128?9:10:0!==i?i<16384?i<128?5:6:i<2097152?7:8:r<16384?r<128?1:2:r<2097152?3:4}function measureValue(e){return void 0===e?0:"number"==typeof e||"bigint"==typeof e?measureNumber(e)||1:e.length}function measureArray(e){let t=0;for(let r of e)t+=measureValue(r);return t}function measureNumberField(e){let t=measureNumber(e);return t?1+t:0}function measureNumberArrayField(e){let t=0;for(let r of e)t+=measureNumber(r)||1;return t?1+measureNumber(t)+t:0}function measureLengthDelimField(e){let t=measureValue(e);return t?1+measureNumber(t)+t:0}function measureLengthDelimArrayField(e){let t=0;for(let r of e)t+=measureLengthDelimField(r);return t}function encodeNumber(e,t,r){if(0===r||0n===r)return e[t++]=0,t;let[i,s]=long(r);for(;i;)e[t++]=127&s|128,s=(s>>>7|i<<25)>>>0,i>>>=7;for(;s>127;)e[t++]=127&s|128,s>>>=7;return e[t++]=s,t}let c=Symbol();let StringTable=class StringTable{constructor(r){this.strings=[],e.set(this,[]),t.set(this,new Map),r!==c&&this.dedup("")}get encodedLength(){let t=0;for(let r of __classPrivateFieldGet(this,e,"f"))t+=r.length;return t}_encodeToBuffer(t,r){for(let i of __classPrivateFieldGet(this,e,"f"))t.set(i,r),r+=i.length;return r}encode(e=new Uint8Array(this.encodedLength)){return this._encodeToBuffer(e,0),e}static _encodeStringFromUtf8(e){let t=new Uint8Array(1+e.length+(measureNumber(e.length)||1)),r=0;return t[r++]=50,r=encodeNumber(t,r,e.length),e.length>0&&t.set(e,r++),t}static _encodeString(e){return StringTable._encodeStringFromUtf8(o(e))}dedup(r){if("number"==typeof r)return r;if(!__classPrivateFieldGet(this,t,"f").has(r)){let i=this.strings.push(r)-1;__classPrivateFieldGet(this,t,"f").set(r,i),__classPrivateFieldGet(this,e,"f").push(StringTable._encodeString(r))}return __classPrivateFieldGet(this,t,"f").get(r)}_decodeString(r){let i=new TextDecoder().decode(r);__classPrivateFieldGet(this,t,"f").set(i,this.strings.push(i)-1),__classPrivateFieldGet(this,e,"f").push(StringTable._encodeStringFromUtf8(r))}};function decode(e,t){let r={},i=0;for(;i<e.length;){let s=e[i]>>3,n=7&e[i];i++;let{offset:a,value:o}=getValue(n,e.slice(i));i+=o.length+a,t(r,s,o)}return r}e=new WeakMap,t=new WeakMap;let ValueType=class ValueType{static create(e){return e instanceof ValueType?e:new ValueType(e)}constructor(e){this.type=e.type||0,this.unit=e.unit||0}get length(){return 0+measureNumberField(this.type)+measureNumberField(this.unit)}_encodeToBuffer(e,t=0){return this.type&&(e[t++]=8,t=encodeNumber(e,t,this.type)),this.unit&&(e[t++]=16,t=encodeNumber(e,t,this.unit)),t}encode(e=new Uint8Array(this.length)){return this._encodeToBuffer(e,0),e}static decodeValue(e,t,r){switch(t){case 1:e.type=decodeNumber(r);break;case 2:e.unit=decodeNumber(r)}}static decode(e){return new this(decode(e,this.decodeValue))}};let Label=class Label{static create(e){return e instanceof Label?e:new Label(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+measureNumberField(this.key)+measureNumberField(this.str)+measureNumberField(this.num)+measureNumberField(this.numUnit)}_encodeToBuffer(e,t=0){return this.key&&(e[t++]=8,t=encodeNumber(e,t,this.key)),this.str&&(e[t++]=16,t=encodeNumber(e,t,this.str)),this.num&&(e[t++]=24,t=encodeNumber(e,t,this.num)),this.numUnit&&(e[t++]=32,t=encodeNumber(e,t,this.numUnit)),t}encode(e=new Uint8Array(this.length)){return this._encodeToBuffer(e,0),e}static decodeValue(e,t,r){switch(t){case 1:e.key=decodeNumber(r);break;case 2:e.str=decodeNumber(r);break;case 3:e.num=decodeNumber(r);break;case 4:e.numUnit=decodeNumber(r)}}static decode(e){return new this(decode(e,this.decodeValue))}};let Sample=class Sample{static create(e){return e instanceof Sample?e:new Sample(e)}constructor(e){this.locationId=e.locationId||[],this.value=e.value||[],this.label=(e.label||[]).map(Label.create)}get length(){return 0+measureNumberArrayField(this.locationId)+measureNumberArrayField(this.value)+measureLengthDelimArrayField(this.label)}_encodeToBuffer(e,t=0){if(this.locationId.length)for(let r of(e[t++]=10,t=encodeNumber(e,t,measureArray(this.locationId)),this.locationId))t=encodeNumber(e,t,r);if(this.value.length)for(let r of(e[t++]=18,t=encodeNumber(e,t,measureArray(this.value)),this.value))t=encodeNumber(e,t,r);for(let r of this.label)e[t++]=26,t=encodeNumber(e,t,r.length),t=r._encodeToBuffer(e,t);return t}encode(e=new Uint8Array(this.length)){return this._encodeToBuffer(e,0),e}static decodeValue(e,t,r){switch(t){case 1:e.locationId=decodeNumbers(r);break;case 2:e.value=decodeNumbers(r);break;case 3:e.label=push(Label.decode(r),e.label)}}static decode(e){return new this(decode(e,this.decodeValue))}};let Mapping=class Mapping{static create(e){return e instanceof Mapping?e:new Mapping(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+measureNumberField(this.id)+measureNumberField(this.memoryStart)+measureNumberField(this.memoryLimit)+measureNumberField(this.fileOffset)+measureNumberField(this.filename)+measureNumberField(this.buildId)+measureNumberField(+!!this.hasFunctions)+measureNumberField(+!!this.hasFilenames)+measureNumberField(+!!this.hasLineNumbers)+measureNumberField(+!!this.hasInlineFrames)}_encodeToBuffer(e,t=0){return this.id&&(e[t++]=8,t=encodeNumber(e,t,this.id)),this.memoryStart&&(e[t++]=16,t=encodeNumber(e,t,this.memoryStart)),this.memoryLimit&&(e[t++]=24,t=encodeNumber(e,t,this.memoryLimit)),this.fileOffset&&(e[t++]=32,t=encodeNumber(e,t,this.fileOffset)),this.filename&&(e[t++]=40,t=encodeNumber(e,t,this.filename)),this.buildId&&(e[t++]=48,t=encodeNumber(e,t,this.buildId)),this.hasFunctions&&(e[t++]=56,t=encodeNumber(e,t,1)),this.hasFilenames&&(e[t++]=64,t=encodeNumber(e,t,1)),this.hasLineNumbers&&(e[t++]=72,t=encodeNumber(e,t,1)),this.hasInlineFrames&&(e[t++]=80,t=encodeNumber(e,t,1)),t}encode(e=new Uint8Array(this.length)){return this._encodeToBuffer(e,0),e}static decodeValue(e,t,r){switch(t){case 1:e.id=decodeNumber(r);break;case 2:e.memoryStart=decodeNumber(r);break;case 3:e.memoryLimit=decodeNumber(r);break;case 4:e.fileOffset=decodeNumber(r);break;case 5:e.filename=decodeNumber(r);break;case 6:e.buildId=decodeNumber(r);break;case 7:e.hasFunctions=!!decodeNumber(r);break;case 8:e.hasFilenames=!!decodeNumber(r);break;case 9:e.hasLineNumbers=!!decodeNumber(r);break;case 10:e.hasInlineFrames=!!decodeNumber(r)}}static decode(e){return new this(decode(e,this.decodeValue))}};let Line=class Line{static create(e){return e instanceof Line?e:new Line(e)}constructor(e){this.functionId=e.functionId||0,this.line=e.line||0}get length(){return 0+measureNumberField(this.functionId)+measureNumberField(this.line)}_encodeToBuffer(e,t=0){return this.functionId&&(e[t++]=8,t=encodeNumber(e,t,this.functionId)),this.line&&(e[t++]=16,t=encodeNumber(e,t,this.line)),t}encode(e=new Uint8Array(this.length)){return this._encodeToBuffer(e,0),e}static decodeValue(e,t,r){switch(t){case 1:e.functionId=decodeNumber(r);break;case 2:e.line=decodeNumber(r)}}static decode(e){return new this(decode(e,this.decodeValue))}};let Location=class Location{static create(e){return e instanceof Location?e:new Location(e)}constructor(e){this.id=e.id||0,this.mappingId=e.mappingId||0,this.address=e.address||0,this.line=(e.line||[]).map(Line.create),this.isFolded=!!e.isFolded}get length(){return 0+measureNumberField(this.id)+measureNumberField(this.mappingId)+measureNumberField(this.address)+measureLengthDelimArrayField(this.line)+measureNumberField(+!!this.isFolded)}_encodeToBuffer(e,t=0){for(let r of(this.id&&(e[t++]=8,t=encodeNumber(e,t,this.id)),this.mappingId&&(e[t++]=16,t=encodeNumber(e,t,this.mappingId)),this.address&&(e[t++]=24,t=encodeNumber(e,t,this.address)),this.line))e[t++]=34,t=encodeNumber(e,t,r.length),t=r._encodeToBuffer(e,t);return this.isFolded&&(e[t++]=40,t=encodeNumber(e,t,1)),t}encode(e=new Uint8Array(this.length)){return this._encodeToBuffer(e,0),e}static decodeValue(e,t,r){switch(t){case 1:e.id=decodeNumber(r);break;case 2:e.mappingId=decodeNumber(r);break;case 3:e.address=decodeNumber(r);break;case 4:e.line=push(Line.decode(r),e.line);break;case 5:e.isFolded=!!decodeNumber(r)}}static decode(e){return new this(decode(e,this.decodeValue))}};let Function=class Function{static create(e){return e instanceof Function?e:new Function(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+measureNumberField(this.id)+measureNumberField(this.name)+measureNumberField(this.systemName)+measureNumberField(this.filename)+measureNumberField(this.startLine)}_encodeToBuffer(e,t=0){return this.id&&(e[t++]=8,t=encodeNumber(e,t,this.id)),this.name&&(e[t++]=16,t=encodeNumber(e,t,this.name)),this.systemName&&(e[t++]=24,t=encodeNumber(e,t,this.systemName)),this.filename&&(e[t++]=32,t=encodeNumber(e,t,this.filename)),this.startLine&&(e[t++]=40,t=encodeNumber(e,t,this.startLine)),t}encode(e=new Uint8Array(this.length)){return this._encodeToBuffer(e,0),e}static decodeValue(e,t,r){switch(t){case 1:e.id=decodeNumber(r);break;case 2:e.name=decodeNumber(r);break;case 3:e.systemName=decodeNumber(r);break;case 4:e.filename=decodeNumber(r);break;case 5:e.startLine=decodeNumber(r)}}static decode(e){return new this(decode(e,this.decodeValue))}};let Profile=class Profile{constructor(e={}){this.sampleType=(e.sampleType||[]).map(ValueType.create),this.sample=(e.sample||[]).map(Sample.create),this.mapping=(e.mapping||[]).map(Mapping.create),this.location=(e.location||[]).map(Location.create),this.function=(e.function||[]).map(Function.create),this.stringTable=e.stringTable||new StringTable,this.dropFrames=e.dropFrames||0,this.keepFrames=e.keepFrames||0,this.timeNanos=e.timeNanos||0,this.durationNanos=e.durationNanos||0,this.periodType=e.periodType?ValueType.create(e.periodType):void 0,this.period=e.period||0,this.comment=e.comment||[],this.defaultSampleType=e.defaultSampleType||0}get length(){return 0+measureLengthDelimArrayField(this.sampleType)+measureLengthDelimArrayField(this.sample)+measureLengthDelimArrayField(this.mapping)+measureLengthDelimArrayField(this.location)+measureLengthDelimArrayField(this.function)+this.stringTable.encodedLength+measureNumberField(this.dropFrames)+measureNumberField(this.keepFrames)+measureNumberField(this.timeNanos)+measureNumberField(this.durationNanos)+measureLengthDelimField(this.periodType)+measureNumberField(this.period)+measureNumberArrayField(this.comment)+measureNumberField(this.defaultSampleType)}_encodeSampleTypesToBuffer(e,t=0){for(let r of this.sampleType)e[t++]=10,t=encodeNumber(e,t,r.length),t=r._encodeToBuffer(e,t);return t}_encodeSamplesToBuffer(e,t=0){for(let r of this.sample)e[t++]=18,t=encodeNumber(e,t,r.length),t=r._encodeToBuffer(e,t);return t}_encodeMappingsToBuffer(e,t=0){for(let r of this.mapping)e[t++]=26,t=encodeNumber(e,t,r.length),t=r._encodeToBuffer(e,t);return t}_encodeLocationsToBuffer(e,t=0){for(let r of this.location)e[t++]=34,t=encodeNumber(e,t,r.length),t=r._encodeToBuffer(e,t);return t}_encodeFunctionsToBuffer(e,t=0){for(let r of this.function)e[t++]=42,t=encodeNumber(e,t,r.length),t=r._encodeToBuffer(e,t);return t}_encodeBasicValuesToBuffer(e,t=0){if(this.dropFrames&&(e[t++]=56,t=encodeNumber(e,t,this.dropFrames)),this.keepFrames&&(e[t++]=64,t=encodeNumber(e,t,this.keepFrames)),this.timeNanos&&(e[t++]=72,t=encodeNumber(e,t,this.timeNanos)),this.durationNanos&&(e[t++]=80,t=encodeNumber(e,t,this.durationNanos)),void 0!==this.periodType&&(e[t++]=90,t=encodeNumber(e,t,this.periodType.length),t=this.periodType._encodeToBuffer(e,t)),this.period&&(e[t++]=96,t=encodeNumber(e,t,this.period)),this.comment.length)for(let r of(e[t++]=106,t=encodeNumber(e,t,measureArray(this.comment)),this.comment))t=encodeNumber(e,t,r);return this.defaultSampleType&&(e[t++]=112,t=encodeNumber(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,r){switch(t){case 1:e.sampleType=push(ValueType.decode(r),e.sampleType);break;case 2:e.sample=push(Sample.decode(r),e.sample);break;case 3:e.mapping=push(Mapping.decode(r),e.mapping);break;case 4:e.location=push(Location.decode(r),e.location);break;case 5:e.function=push(Function.decode(r),e.function);break;case 6:void 0===e.stringTable&&(e.stringTable=new StringTable(c)),e.stringTable._decodeString(r);break;case 7:e.dropFrames=decodeNumber(r);break;case 8:e.keepFrames=decodeNumber(r);break;case 9:e.timeNanos=decodeNumber(r);break;case 10:e.durationNanos=decodeNumber(r);break;case 11:e.periodType=ValueType.decode(r);break;case 12:e.period=decodeNumber(r);break;case 13:e.comment=decodeNumbers(r);break;case 14:e.defaultSampleType=decodeNumber(r)}}static decode(e){return new this(decode(e,this.decodeValue))}};module.exports=i})();