@datadog/mobile-react-native 1.3.1 → 1.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (82) hide show
  1. package/android/src/main/kotlin/com/datadog/reactnative/DdSdk.kt +36 -2
  2. package/android/src/main/kotlin/com/datadog/reactnative/DdSdkConfigurationExt.kt +14 -0
  3. package/android/src/test/kotlin/com/datadog/reactnative/DdSdkTest.kt +145 -5
  4. package/android/src/test/kotlin/com/datadog/tools/unit/MapExt.kt +7 -0
  5. package/ios/Sources/DdSdk.swift +2 -2
  6. package/ios/Sources/RNDdSdkConfiguration.swift +42 -0
  7. package/lib/commonjs/DdSdkReactNative.js +2 -2
  8. package/lib/commonjs/DdSdkReactNative.js.map +1 -1
  9. package/lib/commonjs/DdSdkReactNativeConfiguration.js +26 -1
  10. package/lib/commonjs/DdSdkReactNativeConfiguration.js.map +1 -1
  11. package/lib/commonjs/index.js +12 -0
  12. package/lib/commonjs/index.js.map +1 -1
  13. package/lib/commonjs/rum/instrumentation/resourceTracking/DdRumResourceTracking.js +1 -1
  14. package/lib/commonjs/rum/instrumentation/resourceTracking/DdRumResourceTracking.js.map +1 -1
  15. package/lib/commonjs/rum/instrumentation/resourceTracking/domain/distributedTracing.js +59 -41
  16. package/lib/commonjs/rum/instrumentation/resourceTracking/domain/distributedTracing.js.map +1 -1
  17. package/lib/commonjs/rum/instrumentation/resourceTracking/domain/distributedTracingHeaders.js +136 -0
  18. package/lib/commonjs/rum/instrumentation/resourceTracking/domain/distributedTracingHeaders.js.map +1 -0
  19. package/lib/commonjs/rum/instrumentation/resourceTracking/domain/firstPartyHosts.js +39 -6
  20. package/lib/commonjs/rum/instrumentation/resourceTracking/domain/firstPartyHosts.js.map +1 -1
  21. package/lib/commonjs/rum/instrumentation/resourceTracking/domain/interfaces/RequestProxy.js.map +1 -1
  22. package/lib/commonjs/rum/instrumentation/resourceTracking/implementation/DatadogRumResource/ResourceReporter.js +3 -3
  23. package/lib/commonjs/rum/instrumentation/resourceTracking/implementation/DatadogRumResource/ResourceReporter.js.map +1 -1
  24. package/lib/commonjs/rum/instrumentation/resourceTracking/implementation/XHRProxy.js +12 -21
  25. package/lib/commonjs/rum/instrumentation/resourceTracking/implementation/XHRProxy.js.map +1 -1
  26. package/lib/commonjs/rum/types.js +19 -1
  27. package/lib/commonjs/rum/types.js.map +1 -1
  28. package/lib/commonjs/version.js +1 -1
  29. package/lib/commonjs/version.js.map +1 -1
  30. package/lib/module/DdSdkReactNative.js +3 -3
  31. package/lib/module/DdSdkReactNative.js.map +1 -1
  32. package/lib/module/DdSdkReactNativeConfiguration.js +22 -0
  33. package/lib/module/DdSdkReactNativeConfiguration.js.map +1 -1
  34. package/lib/module/index.js +3 -3
  35. package/lib/module/index.js.map +1 -1
  36. package/lib/module/rum/instrumentation/resourceTracking/DdRumResourceTracking.js +2 -2
  37. package/lib/module/rum/instrumentation/resourceTracking/DdRumResourceTracking.js.map +1 -1
  38. package/lib/module/rum/instrumentation/resourceTracking/domain/distributedTracing.js +57 -35
  39. package/lib/module/rum/instrumentation/resourceTracking/domain/distributedTracing.js.map +1 -1
  40. package/lib/module/rum/instrumentation/resourceTracking/domain/distributedTracingHeaders.js +115 -0
  41. package/lib/module/rum/instrumentation/resourceTracking/domain/distributedTracingHeaders.js.map +1 -0
  42. package/lib/module/rum/instrumentation/resourceTracking/domain/firstPartyHosts.js +37 -3
  43. package/lib/module/rum/instrumentation/resourceTracking/domain/firstPartyHosts.js.map +1 -1
  44. package/lib/module/rum/instrumentation/resourceTracking/domain/interfaces/RequestProxy.js.map +1 -1
  45. package/lib/module/rum/instrumentation/resourceTracking/implementation/DatadogRumResource/ResourceReporter.js +3 -3
  46. package/lib/module/rum/instrumentation/resourceTracking/implementation/DatadogRumResource/ResourceReporter.js.map +1 -1
  47. package/lib/module/rum/instrumentation/resourceTracking/implementation/XHRProxy.js +10 -15
  48. package/lib/module/rum/instrumentation/resourceTracking/implementation/XHRProxy.js.map +1 -1
  49. package/lib/module/rum/types.js +16 -0
  50. package/lib/module/rum/types.js.map +1 -1
  51. package/lib/module/version.js +1 -1
  52. package/lib/module/version.js.map +1 -1
  53. package/lib/typescript/DdSdkReactNativeConfiguration.d.ts +11 -3
  54. package/lib/typescript/index.d.ts +3 -3
  55. package/lib/typescript/rum/instrumentation/resourceTracking/DdRumResourceTracking.d.ts +2 -1
  56. package/lib/typescript/rum/instrumentation/resourceTracking/domain/distributedTracing.d.ts +32 -6
  57. package/lib/typescript/rum/instrumentation/resourceTracking/domain/distributedTracingHeaders.d.ts +21 -0
  58. package/lib/typescript/rum/instrumentation/resourceTracking/domain/firstPartyHosts.d.ts +4 -2
  59. package/lib/typescript/rum/instrumentation/resourceTracking/domain/interfaces/RequestProxy.d.ts +6 -1
  60. package/lib/typescript/rum/instrumentation/resourceTracking/implementation/XHRProxy.d.ts +0 -5
  61. package/lib/typescript/rum/types.d.ts +17 -0
  62. package/lib/typescript/version.d.ts +1 -1
  63. package/package.json +2 -2
  64. package/src/DdSdkReactNative.tsx +8 -4
  65. package/src/DdSdkReactNativeConfiguration.tsx +36 -3
  66. package/src/__tests__/DdSdkReactNative.test.tsx +16 -4
  67. package/src/index.tsx +6 -3
  68. package/src/rum/__tests__/DdRum.test.ts +17 -1
  69. package/src/rum/instrumentation/resourceTracking/DdRumResourceTracking.tsx +6 -3
  70. package/src/rum/instrumentation/resourceTracking/__tests__/DdRumResourceTracking.test.ts +13 -2
  71. package/src/rum/instrumentation/resourceTracking/domain/__tests__/distributedTracing.test.ts +64 -24
  72. package/src/rum/instrumentation/resourceTracking/domain/__tests__/firstPartyHosts.test.ts +19 -7
  73. package/src/rum/instrumentation/resourceTracking/domain/distributedTracing.tsx +82 -40
  74. package/src/rum/instrumentation/resourceTracking/domain/distributedTracingHeaders.ts +141 -0
  75. package/src/rum/instrumentation/resourceTracking/domain/firstPartyHosts.ts +43 -7
  76. package/src/rum/instrumentation/resourceTracking/domain/interfaces/RequestProxy.ts +8 -1
  77. package/src/rum/instrumentation/resourceTracking/implementation/DatadogRumResource/ResourceReporter.ts +4 -4
  78. package/src/rum/instrumentation/resourceTracking/implementation/XHRProxy.ts +8 -23
  79. package/src/rum/instrumentation/resourceTracking/implementation/__tests__/XHRProxy.test.ts +251 -73
  80. package/src/rum/types.ts +19 -0
  81. package/src/sdk/DatadogProvider/__tests__/initializationModes.test.tsx +1 -1
  82. package/src/version.ts +1 -1
@@ -1,71 +1,93 @@
1
+ function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
2
+
1
3
  /*
2
4
  * Unless explicitly stated otherwise all files in this repository are licensed under the Apache License Version 2.0.
3
5
  * This product includes software developed at Datadog (https://www.datadoghq.com/).
4
6
  * Copyright 2016-Present Datadog, Inc.
5
7
  */
6
- import { isHostFirstParty } from './firstPartyHosts';
8
+ import { getPropagatorsForHost } from './firstPartyHosts';
7
9
  const DISCARDED_TRACE_ATTRIBUTES = {
8
10
  samplingPriorityHeader: '0',
9
11
  tracingStrategy: 'DISCARD'
10
12
  };
11
13
  export const getTracingAttributes = ({
12
14
  hostname,
13
- firstPartyHostsRegex,
15
+ firstPartyHostsRegexMap,
14
16
  tracingSamplingRate
15
17
  }) => {
16
18
  if (hostname === null) {
17
19
  return DISCARDED_TRACE_ATTRIBUTES;
18
20
  }
19
21
 
20
- if (isHostFirstParty(hostname, firstPartyHostsRegex)) {
21
- return generateTracingAttributesWithSampling(tracingSamplingRate);
22
+ const propagatorsForHost = getPropagatorsForHost(hostname, firstPartyHostsRegexMap);
23
+
24
+ if (propagatorsForHost) {
25
+ return generateTracingAttributesWithSampling(tracingSamplingRate, propagatorsForHost);
22
26
  }
23
27
 
24
28
  return DISCARDED_TRACE_ATTRIBUTES;
25
29
  };
26
30
 
27
- const generateTracingAttributesWithSampling = tracingSamplingRate => {
28
- if (Math.random() * 100 <= tracingSamplingRate) {
29
- return {
30
- traceId: generateTraceId(),
31
- spanId: generateTraceId(),
32
- samplingPriorityHeader: '1',
33
- tracingStrategy: 'KEEP',
34
- rulePsr: tracingSamplingRate / 100
35
- };
36
- }
37
-
38
- return DISCARDED_TRACE_ATTRIBUTES;
31
+ const generateTracingAttributesWithSampling = (tracingSamplingRate, propagatorTypes) => {
32
+ const isSampled = Math.random() * 100 <= tracingSamplingRate;
33
+ const tracingAttributes = {
34
+ traceId: new TraceIdentifier(),
35
+ spanId: new TraceIdentifier(),
36
+ samplingPriorityHeader: isSampled ? '1' : '0',
37
+ tracingStrategy: 'KEEP',
38
+ rulePsr: tracingSamplingRate / 100,
39
+ propagatorTypes
40
+ };
41
+ return tracingAttributes;
39
42
  };
43
+ /**
44
+ * Using branded types will ensure we don't accidentally use
45
+ * traceId for spanId when generating headers.
46
+ */
47
+
48
+
40
49
  /*
41
- * This code was inspired from browser-sdk at (https://github.com/DataDog/browser-sdk/blob/master/packages/rum-core/src/domain/tracing/tracer.ts#L107)
50
+ * This code was inspired from browser-sdk at (https://github.com/DataDog/browser-sdk/blob/0e9722d5b06f6d49264bc82cd254a207d647d66c/packages/rum-core/src/domain/tracing/tracer.ts#L190)
42
51
  */
52
+ const MAX_32_BITS_NUMBER = 4294967295; // 2^32-1
53
+
54
+ const MAX_31_BITS_NUMBER = 2147483647; // 2^31-1
55
+
56
+ export class TraceIdentifier {
57
+ constructor() {
58
+ _defineProperty(this, "low", void 0);
59
+
60
+ _defineProperty(this, "high", void 0);
43
61
 
62
+ _defineProperty(this, "toString", radix => {
63
+ let low = this.low;
64
+ let high = this.high;
65
+ let str = '';
44
66
 
45
- export function generateTraceId() {
46
- const radix = 10;
47
- const MAX_32_BITS_NUMBER = 4294967295; // 2^32-1
67
+ while (high > 0 || low > 0) {
68
+ const mod = high % radix * (MAX_32_BITS_NUMBER + 1) + low;
69
+ high = Math.floor(high / radix);
70
+ low = Math.floor(mod / radix);
71
+ str = (mod % radix).toString(radix) + str;
72
+ }
48
73
 
49
- let low = Math.floor(Math.random() * MAX_32_BITS_NUMBER);
50
- let high = Math.floor(Math.random() * MAX_32_BITS_NUMBER);
51
- let str = '';
74
+ return str;
75
+ });
52
76
 
53
- while (high > 0 && low > 0) {
54
- // Create an intermediate value with the same modulo as the combined high and low value
55
- // but requiring 36 bits max (32 for the low value + 4 for the high part)
56
- const modH = high % radix;
57
- const temp = (modH << 32) + low;
58
- const digit = temp % radix; // update the high value
77
+ _defineProperty(this, "toPaddedString", (radix, length) => {
78
+ const traceId = this.toString(radix);
59
79
 
60
- high = (high - modH) / radix; // we reuse the modH to avoid the need of a floor op
61
- // the low value reuses the previous temp value to account for the "missing mod" in the high update
80
+ if (traceId.length > length) {
81
+ return traceId;
82
+ }
62
83
 
63
- low = (temp - digit) / radix; // we reuse the digit to avoid the need of a floor op
64
- // update the string from right to left
84
+ return Array(length - traceId.length + 1).join('0') + traceId;
85
+ });
65
86
 
66
- str = digit.toString() + str;
87
+ // We need to have a 63 bits number max
88
+ this.high = Math.floor(Math.random() * MAX_31_BITS_NUMBER);
89
+ this.low = Math.floor(Math.random() * MAX_32_BITS_NUMBER);
67
90
  }
68
91
 
69
- return str;
70
92
  }
71
93
  //# sourceMappingURL=distributedTracing.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["distributedTracing.tsx"],"names":["isHostFirstParty","DISCARDED_TRACE_ATTRIBUTES","samplingPriorityHeader","tracingStrategy","getTracingAttributes","hostname","firstPartyHostsRegex","tracingSamplingRate","generateTracingAttributesWithSampling","Math","random","traceId","generateTraceId","spanId","rulePsr","radix","MAX_32_BITS_NUMBER","low","floor","high","str","modH","temp","digit","toString"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AAGA,SAASA,gBAAT,QAAiC,mBAAjC;AAiBA,MAAMC,0BAA0D,GAAG;AAC/DC,EAAAA,sBAAsB,EAAE,GADuC;AAE/DC,EAAAA,eAAe,EAAE;AAF8C,CAAnE;AAKA,OAAO,MAAMC,oBAAoB,GAAG,CAAC;AACjCC,EAAAA,QADiC;AA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AI,GAAG,CAACA,IAAI,GAAGE,IAAR,IAAgBN,KAAvB,CARwB,CAQM;AAC9B;;AACAE,IAAAA,GAAG,GAAG,CAACK,IAAI,GAAGC,KAAR,IAAiBR,KAAvB,CAVwB,CAUM;AAE9B;;AACAK,IAAAA,GAAG,GAAGG,KAAK,CAACC,QAAN,KAAmBJ,GAAzB;AACH;;AACD,SAAOA,GAAP;AACH","sourcesContent":["/*\n * Unless explicitly stated otherwise all files in this repository are licensed under the Apache License Version 2.0.\n * This product includes software developed at Datadog (https://www.datadoghq.com/).\n * Copyright 2016-Present Datadog, Inc.\n */\n\nimport type { Hostname } from './firstPartyHosts';\nimport { isHostFirstParty } from './firstPartyHosts';\n\nexport type DdRumResourceTracingAttributes =\n | {\n tracingStrategy: 'KEEP';\n traceId: string;\n spanId: string;\n samplingPriorityHeader: '1';\n rulePsr: number;\n }\n | {\n tracingStrategy: 'DISCARD';\n traceId?: void;\n spanId?: void;\n samplingPriorityHeader: '0';\n };\n\nconst DISCARDED_TRACE_ATTRIBUTES: DdRumResourceTracingAttributes = {\n samplingPriorityHeader: '0',\n tracingStrategy: 'DISCARD'\n};\n\nexport const getTracingAttributes = ({\n hostname,\n firstPartyHostsRegex,\n tracingSamplingRate\n}: {\n hostname: Hostname | null;\n firstPartyHostsRegex: RegExp;\n tracingSamplingRate: number;\n}): DdRumResourceTracingAttributes => {\n if (hostname === null) {\n return DISCARDED_TRACE_ATTRIBUTES;\n }\n if (isHostFirstParty(hostname, firstPartyHostsRegex)) {\n return generateTracingAttributesWithSampling(tracingSamplingRate);\n }\n return DISCARDED_TRACE_ATTRIBUTES;\n};\n\nconst generateTracingAttributesWithSampling = (\n tracingSamplingRate: number\n): DdRumResourceTracingAttributes => {\n if (Math.random() * 100 <= tracingSamplingRate) {\n return {\n traceId: generateTraceId(),\n spanId: generateTraceId(),\n samplingPriorityHeader: '1',\n tracingStrategy: 'KEEP',\n rulePsr: tracingSamplingRate / 100\n };\n }\n return DISCARDED_TRACE_ATTRIBUTES;\n};\n\n/*\n * This code was inspired from browser-sdk at (https://github.com/DataDog/browser-sdk/blob/master/packages/rum-core/src/domain/tracing/tracer.ts#L107)\n */\nexport function generateTraceId(): string {\n const radix = 10;\n const MAX_32_BITS_NUMBER = 4294967295; // 2^32-1\n let low: number = Math.floor(Math.random() * MAX_32_BITS_NUMBER);\n let high: number = Math.floor(Math.random() * MAX_32_BITS_NUMBER);\n let str = '';\n\n while (high > 0 && low > 0) {\n // Create an intermediate value with the same modulo as the combined high and low value\n // but requiring 36 bits max (32 for the low value + 4 for the high part)\n const modH = high % radix;\n const temp = (modH << 32) + low;\n const digit = temp % radix;\n\n // update the high value\n high = (high - modH) / radix; // we reuse the modH to avoid the need of a floor op\n // the low value reuses the previous temp value to account for the \"missing mod\" in the high update\n low = (temp - digit) / radix; // we reuse the digit to avoid the need of a floor op\n\n // update the string from right to left\n str = digit.toString() + str;\n }\n return str;\n}\n"]}
1
+ {"version":3,"sources":["distributedTracing.tsx"],"names":["getPropagatorsForHost","DISCARDED_TRACE_ATTRIBUTES","samplingPriorityHeader","tracingStrategy","getTracingAttributes","hostname","firstPartyHostsRegexMap","tracingSamplingRate","propagatorsForHost","generateTracingAttributesWithSampling","propagatorTypes","isSampled","Math","random","tracingAttributes","traceId","TraceIdentifier","spanId","rulePsr","MAX_32_BITS_NUMBER","MAX_31_BITS_NUMBER","constructor","radix","low","high","str","mod","floor","toString","length","Array","join"],"mappings":";;AAAA;AACA;AACA;AACA;AACA;AAKA,SAASA,qBAAT,QAAsC,mBAAtC;AAmBA,MAAMC,0BAA0D,GAAG;AAC/DC,EAAAA,sBAAsB,EAAE,GADuC;AAE/DC,EAAAA,eAAe,EAAE;AAF8C,CAAnE;AAKA,OAAO,MAAMC,oBAAoB,GAAG,CAAC;AACjCC,EAAAA,QADiC;AAEjCC,EAAAA,uBAFiC;AAGjCC,EAAAA;AAHiC,CAAD,KAQE;AAClC,MAAIF,QAAQ,KAAK,IAAjB,EAAuB;AACnB,WAAO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L,CAAWH,IAAI,GAAGF,KAAlB,CAAP;AACAC,QAAAA,GAAG,GAAGX,IAAI,CAACe,KAAL,CAAWD,GAAG,GAAGJ,KAAjB,CAAN;AACAG,QAAAA,GAAG,GAAG,CAACC,GAAG,GAAGJ,KAAP,EAAcM,QAAd,CAAuBN,KAAvB,IAAgCG,GAAtC;AACH;;AACD,aAAOA,GAAP;AACH,KAlBa;;AAAA,4CA2BG,CAACH,KAAD,EAAgBO,MAAhB,KAAmC;AAChD,YAAMd,OAAO,GAAG,KAAKa,QAAL,CAAcN,KAAd,CAAhB;;AACA,UAAIP,OAAO,CAACc,MAAR,GAAiBA,MAArB,EAA6B;AACzB,eAAOd,OAAP;AACH;;AACD,aAAOe,KAAK,CAACD,MAAM,GAAGd,OAAO,CAACc,MAAjB,GAA0B,CAA3B,CAAL,CAAmCE,IAAnC,CAAwC,GAAxC,IAA+ChB,OAAtD;AACH,KAjCa;;AACV;AACA,SAAKS,IAAL,GAAYZ,IAAI,CAACe,KAAL,CAAWf,IAAI,CAACC,MAAL,KAAgBO,kBAA3B,CAAZ;AACA,SAAKG,GAAL,GAAWX,IAAI,CAACe,KAAL,CAAWf,IAAI,CAACC,MAAL,KAAgBM,kBAA3B,CAAX;AACH;;AARwB","sourcesContent":["/*\n * Unless explicitly stated otherwise all files in this repository are licensed under the Apache License Version 2.0.\n * This product includes software developed at Datadog (https://www.datadoghq.com/).\n * Copyright 2016-Present Datadog, Inc.\n */\n\nimport type { PropagatorType } from '../../../types';\n\nimport type { Hostname } from './firstPartyHosts';\nimport { getPropagatorsForHost } from './firstPartyHosts';\nimport type { RegexMap } from './interfaces/RequestProxy';\n\nexport type DdRumResourceTracingAttributes =\n | {\n tracingStrategy: 'KEEP';\n traceId: TraceId;\n spanId: SpanId;\n samplingPriorityHeader: '1' | '0';\n rulePsr: number;\n propagatorTypes: PropagatorType[];\n }\n | {\n tracingStrategy: 'DISCARD';\n traceId?: void;\n spanId?: void;\n samplingPriorityHeader: '0';\n };\n\nconst DISCARDED_TRACE_ATTRIBUTES: DdRumResourceTracingAttributes = {\n samplingPriorityHeader: '0',\n tracingStrategy: 'DISCARD'\n};\n\nexport const getTracingAttributes = ({\n hostname,\n firstPartyHostsRegexMap,\n tracingSamplingRate\n}: {\n hostname: Hostname | null;\n firstPartyHostsRegexMap: RegexMap;\n tracingSamplingRate: number;\n}): DdRumResourceTracingAttributes => {\n if (hostname === null) {\n return DISCARDED_TRACE_ATTRIBUTES;\n }\n const propagatorsForHost = getPropagatorsForHost(\n hostname,\n firstPartyHostsRegexMap\n );\n if (propagatorsForHost) {\n return generateTracingAttributesWithSampling(\n tracingSamplingRate,\n propagatorsForHost\n );\n }\n return DISCARDED_TRACE_ATTRIBUTES;\n};\n\nconst generateTracingAttributesWithSampling = (\n tracingSamplingRate: number,\n propagatorTypes: PropagatorType[]\n): DdRumResourceTracingAttributes => {\n const isSampled = Math.random() * 100 <= tracingSamplingRate;\n const tracingAttributes: DdRumResourceTracingAttributes = {\n traceId: new TraceIdentifier() as TraceId,\n spanId: new TraceIdentifier() as SpanId,\n samplingPriorityHeader: isSampled ? '1' : '0',\n tracingStrategy: 'KEEP',\n rulePsr: tracingSamplingRate / 100,\n propagatorTypes\n };\n\n return tracingAttributes;\n};\n\n/**\n * Using branded types will ensure we don't accidentally use\n * traceId for spanId when generating headers.\n */\nexport type TraceId = TraceIdentifier & {\n _brand: 'traceId';\n};\n\nexport type SpanId = TraceIdentifier & {\n _brand: 'spanId';\n};\n\n/*\n * This code was inspired from browser-sdk at (https://github.com/DataDog/browser-sdk/blob/0e9722d5b06f6d49264bc82cd254a207d647d66c/packages/rum-core/src/domain/tracing/tracer.ts#L190)\n */\nconst MAX_32_BITS_NUMBER = 4294967295; // 2^32-1\nconst MAX_31_BITS_NUMBER = 2147483647; // 2^31-1\nexport class TraceIdentifier {\n private low: number;\n private high: number;\n\n constructor() {\n // We need to have a 63 bits number max\n this.high = Math.floor(Math.random() * MAX_31_BITS_NUMBER);\n this.low = Math.floor(Math.random() * MAX_32_BITS_NUMBER);\n }\n\n toString = (radix: number) => {\n let low = this.low;\n let high = this.high;\n let str = '';\n\n while (high > 0 || low > 0) {\n const mod = (high % radix) * (MAX_32_BITS_NUMBER + 1) + low;\n high = Math.floor(high / radix);\n low = Math.floor(mod / radix);\n str = (mod % radix).toString(radix) + str;\n }\n return str;\n };\n\n /**\n * This function pads the trace with `0`.\n * It should not be used with a `length` lower than the trace, as we return the full trace in this case.\n * @param radix radix for the trace\n * @param length minimum length\n * @returns padded string\n */\n toPaddedString = (radix: number, length: number) => {\n const traceId = this.toString(radix);\n if (traceId.length > length) {\n return traceId;\n }\n return Array(length - traceId.length + 1).join('0') + traceId;\n };\n}\n"]}
@@ -0,0 +1,115 @@
1
+ /*
2
+ * Unless explicitly stated otherwise all files in this repository are licensed under the Apache License Version 2.0.
3
+ * This product includes software developed at Datadog (https://www.datadoghq.com/).
4
+ * Copyright 2016-Present Datadog, Inc.
5
+ */
6
+ import { PropagatorType } from '../../../types';
7
+ export const SAMPLING_PRIORITY_HEADER_KEY = 'x-datadog-sampling-priority';
8
+ /**
9
+ * Datadog headers
10
+ */
11
+
12
+ export const ORIGIN_HEADER_KEY = 'x-datadog-origin';
13
+ export const ORIGIN_RUM = 'rum';
14
+ export const TRACE_ID_HEADER_KEY = 'x-datadog-trace-id';
15
+ export const PARENT_ID_HEADER_KEY = 'x-datadog-parent-id';
16
+ /**
17
+ * OTel headers
18
+ */
19
+
20
+ export const TRACECONTEXT_HEADER_KEY = 'traceparent';
21
+ export const B3_HEADER_KEY = 'b3';
22
+ export const B3_MULTI_TRACE_ID_HEADER_KEY = 'X-B3-TraceId';
23
+ export const B3_MULTI_SPAN_ID_HEADER_KEY = 'X-B3-SpanId';
24
+ export const B3_MULTI_SAMPLED_HEADER_KEY = 'X-B3-Sampled';
25
+ export const getTracingHeaders = tracingAttributes => {
26
+ const headers = [];
27
+
28
+ if (tracingAttributes.tracingStrategy === 'DISCARD') {
29
+ return headers;
30
+ }
31
+
32
+ tracingAttributes.propagatorTypes.forEach(propagator => {
33
+ switch (propagator) {
34
+ case PropagatorType.DATADOG:
35
+ {
36
+ headers.push({
37
+ header: ORIGIN_HEADER_KEY,
38
+ value: ORIGIN_RUM
39
+ }, {
40
+ header: SAMPLING_PRIORITY_HEADER_KEY,
41
+ value: tracingAttributes.samplingPriorityHeader
42
+ }, {
43
+ header: TRACE_ID_HEADER_KEY,
44
+ value: tracingAttributes.traceId.toString(10)
45
+ }, {
46
+ header: PARENT_ID_HEADER_KEY,
47
+ value: tracingAttributes.spanId.toString(10)
48
+ });
49
+ break;
50
+ }
51
+
52
+ case PropagatorType.TRACECONTEXT:
53
+ {
54
+ headers.push({
55
+ header: TRACECONTEXT_HEADER_KEY,
56
+ value: generateTraceContextHeader({
57
+ version: '00',
58
+ traceId: tracingAttributes.traceId,
59
+ parentId: tracingAttributes.spanId,
60
+ isSampled: tracingAttributes.samplingPriorityHeader === '1'
61
+ })
62
+ });
63
+ break;
64
+ }
65
+
66
+ case PropagatorType.B3:
67
+ {
68
+ headers.push({
69
+ header: B3_HEADER_KEY,
70
+ value: generateB3Header({
71
+ traceId: tracingAttributes.traceId,
72
+ spanId: tracingAttributes.spanId,
73
+ isSampled: tracingAttributes.samplingPriorityHeader === '1'
74
+ })
75
+ });
76
+ break;
77
+ }
78
+
79
+ case PropagatorType.B3MULTI:
80
+ {
81
+ headers.push({
82
+ header: B3_MULTI_TRACE_ID_HEADER_KEY,
83
+ value: tracingAttributes.traceId.toPaddedString(16, 32)
84
+ }, {
85
+ header: B3_MULTI_SPAN_ID_HEADER_KEY,
86
+ value: tracingAttributes.spanId.toPaddedString(16, 16)
87
+ }, {
88
+ header: B3_MULTI_SAMPLED_HEADER_KEY,
89
+ value: tracingAttributes.samplingPriorityHeader
90
+ });
91
+ }
92
+ }
93
+ });
94
+ return headers;
95
+ };
96
+
97
+ const generateTraceContextHeader = ({
98
+ version,
99
+ traceId,
100
+ parentId,
101
+ isSampled
102
+ }) => {
103
+ const flags = isSampled ? '01' : '00';
104
+ return `${version}-${traceId.toPaddedString(16, 32)}-${parentId.toPaddedString(16, 16)}-${flags}`;
105
+ };
106
+
107
+ const generateB3Header = ({
108
+ traceId,
109
+ spanId,
110
+ isSampled
111
+ }) => {
112
+ const flags = isSampled ? '1' : '0';
113
+ return `${traceId.toPaddedString(16, 32)}-${spanId.toPaddedString(16, 16)}-${flags}`;
114
+ };
115
+ //# sourceMappingURL=distributedTracingHeaders.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["distributedTracingHeaders.ts"],"names":["PropagatorType","SAMPLING_PRIORITY_HEADER_KEY","ORIGIN_HEADER_KEY","ORIGIN_RUM","TRACE_ID_HEADER_KEY","PARENT_ID_HEADER_KEY","TRACECONTEXT_HEADER_KEY","B3_HEADER_KEY","B3_MULTI_TRACE_ID_HEADER_KEY","B3_MULTI_SPAN_ID_HEADER_KEY","B3_MULTI_SAMPLED_HEADER_KEY","getTracingHeaders","tracingAttributes","headers","tracingStrategy","propagatorTypes","forEach","propagator","DATADOG","push","header","value","samplingPriorityHeader","traceId","toString","spanId","TRACECONTEXT","generateTraceContextHeader","version","parentId","isSampled","B3","generateB3Header","B3MULTI","toPaddedString","flags"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AAEA,SAASA,cAAT,QAA+B,gBAA/B;AAQA,OAAO,MAAMC,4BAA4B,GAAG,6BAArC;AACP;AACA;AACA;;AACA,OAAO,MAAMC,iBAAiB,GAAG,kBAA1B;AACP,OAAO,MAAMC,UAAU,GAAG,KAAnB;AACP,OAAO,MAAMC,mBAAmB,GAAG,oBAA5B;AACP,OAAO,MAAMC,oBAAoB,GAAG,qBAA7B;AACP;AACA;AACA;;AACA,OAAO,MAAMC,uBAAuB,GAAG,aAAhC;AACP,OAAO,MAAMC,aAAa,GAAG,IAAtB;AACP,OAAO,MAAMC,4BAA4B,GAAG,cAArC;AACP,OAAO,MAAMC,2BAA2B,GAAG,aAApC;AACP,OAAO,MAAMC,2BAA2B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sB;AAEtBE,EAAAA,MAFsB;AAGtBK,EAAAA;AAHsB,CAAD,KAQnB;AACF,QAAMK,KAAK,GAAGL,SAAS,GAAG,GAAH,GAAS,GAAhC;AACA,SAAQ,GAAEP,OAAO,CAACW,cAAR,CAAuB,EAAvB,EAA2B,EAA3B,CAA+B,IAAGT,MAAM,CAACS,cAAP,CACxC,EADwC,EAExC,EAFwC,CAG1C,IAAGC,KAAM,EAHX;AAIH,CAdD","sourcesContent":["/*\n * Unless explicitly stated otherwise all files in this repository are licensed under the Apache License Version 2.0.\n * This product includes software developed at Datadog (https://www.datadoghq.com/).\n * Copyright 2016-Present Datadog, Inc.\n */\n\nimport { PropagatorType } from '../../../types';\n\nimport type {\n DdRumResourceTracingAttributes,\n SpanId,\n TraceId\n} from './distributedTracing';\n\nexport const SAMPLING_PRIORITY_HEADER_KEY = 'x-datadog-sampling-priority';\n/**\n * Datadog headers\n */\nexport const ORIGIN_HEADER_KEY = 'x-datadog-origin';\nexport const ORIGIN_RUM = 'rum';\nexport const TRACE_ID_HEADER_KEY = 'x-datadog-trace-id';\nexport const PARENT_ID_HEADER_KEY = 'x-datadog-parent-id';\n/**\n * OTel headers\n */\nexport const TRACECONTEXT_HEADER_KEY = 'traceparent';\nexport const B3_HEADER_KEY = 'b3';\nexport const B3_MULTI_TRACE_ID_HEADER_KEY = 'X-B3-TraceId';\nexport const B3_MULTI_SPAN_ID_HEADER_KEY = 'X-B3-SpanId';\nexport const B3_MULTI_SAMPLED_HEADER_KEY = 'X-B3-Sampled';\n\nexport const getTracingHeaders = (\n tracingAttributes: DdRumResourceTracingAttributes\n): { header: string; value: string }[] => {\n const headers: { header: string; value: string }[] = [];\n if (tracingAttributes.tracingStrategy === 'DISCARD') {\n return headers;\n }\n tracingAttributes.propagatorTypes.forEach(propagator => {\n switch (propagator) {\n case PropagatorType.DATADOG: {\n headers.push(\n {\n header: ORIGIN_HEADER_KEY,\n value: ORIGIN_RUM\n },\n {\n header: SAMPLING_PRIORITY_HEADER_KEY,\n value: tracingAttributes.samplingPriorityHeader\n },\n {\n header: TRACE_ID_HEADER_KEY,\n value: tracingAttributes.traceId.toString(10)\n },\n {\n header: PARENT_ID_HEADER_KEY,\n value: tracingAttributes.spanId.toString(10)\n }\n );\n break;\n }\n case PropagatorType.TRACECONTEXT: {\n headers.push({\n header: TRACECONTEXT_HEADER_KEY,\n value: generateTraceContextHeader({\n version: '00',\n traceId: tracingAttributes.traceId,\n parentId: tracingAttributes.spanId,\n isSampled:\n tracingAttributes.samplingPriorityHeader === '1'\n })\n });\n break;\n }\n case PropagatorType.B3: {\n headers.push({\n header: B3_HEADER_KEY,\n value: generateB3Header({\n traceId: tracingAttributes.traceId,\n spanId: tracingAttributes.spanId,\n isSampled:\n tracingAttributes.samplingPriorityHeader === '1'\n })\n });\n break;\n }\n case PropagatorType.B3MULTI: {\n headers.push(\n {\n header: B3_MULTI_TRACE_ID_HEADER_KEY,\n value: tracingAttributes.traceId.toPaddedString(16, 32)\n },\n {\n header: B3_MULTI_SPAN_ID_HEADER_KEY,\n value: tracingAttributes.spanId.toPaddedString(16, 16)\n },\n {\n header: B3_MULTI_SAMPLED_HEADER_KEY,\n value: tracingAttributes.samplingPriorityHeader\n }\n );\n }\n }\n });\n\n return headers;\n};\n\nconst generateTraceContextHeader = ({\n version,\n traceId,\n parentId,\n isSampled\n}: {\n version: string;\n traceId: TraceId;\n parentId: SpanId;\n isSampled: boolean;\n}) => {\n const flags = isSampled ? '01' : '00';\n return `${version}-${traceId.toPaddedString(\n 16,\n 32\n )}-${parentId.toPaddedString(16, 16)}-${flags}`;\n};\n\nconst generateB3Header = ({\n traceId,\n spanId,\n isSampled\n}: {\n traceId: TraceId;\n spanId: SpanId;\n isSampled: boolean;\n}) => {\n const flags = isSampled ? '1' : '0';\n return `${traceId.toPaddedString(16, 32)}-${spanId.toPaddedString(\n 16,\n 16\n )}-${flags}`;\n};\n"]}
@@ -12,7 +12,31 @@ const escapeRegExp = string => {
12
12
  return string.replace(/[.*+?^${}()|[\]\\]/g, '\\$&'); // $& means the whole matched string
13
13
  };
14
14
 
15
- export const firstPartyHostsRegexBuilder = firstPartyHosts => {
15
+ export const firstPartyHostsRegexMapBuilder = firstPartyHosts => {
16
+ const hostsMap = {
17
+ datadog: [],
18
+ tracecontext: [],
19
+ b3: [],
20
+ b3multi: []
21
+ };
22
+ firstPartyHosts.forEach(host => {
23
+ host.propagatorTypes.forEach(propagatorType => {
24
+ hostsMap[propagatorType].push(host.match);
25
+ });
26
+ });
27
+ const regexMap = [];
28
+ Object.entries(hostsMap).forEach(([propagatorType, hosts]) => {
29
+ if (hosts.length > 0) {
30
+ regexMap.push({
31
+ propagatorType: propagatorType,
32
+ regex: firstPartyHostsRegexBuilder(hosts)
33
+ });
34
+ }
35
+ });
36
+ return regexMap;
37
+ };
38
+
39
+ const firstPartyHostsRegexBuilder = firstPartyHosts => {
16
40
  if (firstPartyHosts.length === 0) {
17
41
  return NO_MATCH_REGEX;
18
42
  }
@@ -28,7 +52,17 @@ export const firstPartyHostsRegexBuilder = firstPartyHosts => {
28
52
  return NO_MATCH_REGEX;
29
53
  }
30
54
  };
31
- export const isHostFirstParty = (hostname, firstPartyHostsRegex) => {
32
- return firstPartyHostsRegex.test(hostname);
55
+
56
+ export const getPropagatorsForHost = (hostname, firstPartyHostsRegexMap) => {
57
+ const matchedPropagatorTypes = [];
58
+ firstPartyHostsRegexMap.forEach(({
59
+ regex,
60
+ propagatorType
61
+ }) => {
62
+ if (regex.test(hostname)) {
63
+ matchedPropagatorTypes.push(propagatorType);
64
+ }
65
+ });
66
+ return matchedPropagatorTypes.length > 0 ? matchedPropagatorTypes : null;
33
67
  };
34
68
  //# sourceMappingURL=firstPartyHosts.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["firstPartyHosts.ts"],"names":["InternalLog","SdkVerbosity","NO_MATCH_REGEX","RegExp","escapeRegExp","string","replace","firstPartyHostsRegexBuilder","firstPartyHosts","length","firstPartyHostsRegex","map","host","join","test","e","log","JSON","stringify","WARN","isHostFirstParty","hostname"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AAEA,SAASA,WAAT,QAA4B,yBAA5B;AACA,SAASC,YAAT,QAA6B,0BAA7B;AAIA;AACA,OAAO,MAAMC,cAAc,GAAG,IAAIC,MAAJ,CAAW,IAAX,CAAvB,C,CAEP;;AACA,MAAMC,YAAY,GAAIC,MAAD,IAAoB;AACrC,SAAOA,MAAM,CAACC,OAAP,CAAe,qBAAf,EAAsC,MAAtC,CAAP,CADqC,CACiB;AACzD,CAFD;;AAIA,OAAO,MAAMC,2BAA2B,GACpCC,eADuC,IAE9B;AACT,MAAIA,eAAe,CAACC,MAAhB,KAA2B,CAA/B,EAAkC;AAC9B,WAAOP,cAAP;AACH;;AACD,MAAI;AACA;AACA;AACA,UAAMQ,oBAAoB,GAAG,IAAIP,MAAJ,CACxB,aAAYK,eAAe,CACvBG,GADQ,CACJC,IAAI,IAAK,GAAER,YAAY,CAACQ,IAAD,CAAO,GAD1B,EAERC,IAFQ,CAEH,GAFG,CAEE,GAHU,CAA7B;AAKAH,IAAAA,oBAAoB,CAACI,IAArB,CAA0B,yBAA1B;AACA,WAAOJ,oBAAP;AACH,GAVD,CAUE,OAAOK,CAAP,EAAU;AACRf,IAAAA,WAAW,CAACgB,GAAZ,CACK,kCAAiCC,IAAI,CAACC,SAAL,CAC9BV,eAD8B,CAEhC,wCAHN,EAIIP,YAAY,CAACkB,IAJjB;AAMA,WAAOjB,cAAP;AACH;AACJ,CAzBM;AA2BP,OAAO,MAAMkB,gBAAgB,GAAG,CAC5BC,QAD4B,EAE5BX,oBAF4B,KAGlB;AACV,SAAOA,oBAAoB,CAACI,IAArB,CAA0BO,QAA1B,CAAP;AACH,CALM","sourcesContent":["/*\n * Unless explicitly stated otherwise all files in this repository are licensed under the Apache License Version 2.0.\n * This product includes software developed at Datadog (https://www.datadoghq.com/).\n * Copyright 2016-Present Datadog, Inc.\n */\n\nimport { InternalLog } from '../../../../InternalLog';\nimport { SdkVerbosity } from '../../../../SdkVerbosity';\n\nexport type Hostname = { _type: 'Hostname' } & string;\n\n// This regex does not match anything\nexport const NO_MATCH_REGEX = new RegExp('a^');\n\n// From https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Regular_Expressions\nconst escapeRegExp = (string: string) => {\n return string.replace(/[.*+?^${}()|[\\]\\\\]/g, '\\\\$&'); // $& means the whole matched string\n};\n\nexport const firstPartyHostsRegexBuilder = (\n firstPartyHosts: string[]\n): RegExp => {\n if (firstPartyHosts.length === 0) {\n return NO_MATCH_REGEX;\n }\n try {\n // A regexp for matching hosts, e.g. when `hosts` is \"example.com\", it will match\n // \"example.com\", \"api.example.com\", but not \"foo.com\".\n const firstPartyHostsRegex = new RegExp(\n `^(.*\\\\.)*(${firstPartyHosts\n .map(host => `${escapeRegExp(host)}$`)\n .join('|')})`\n );\n firstPartyHostsRegex.test('test_the_regex_is_valid');\n return firstPartyHostsRegex;\n } catch (e) {\n InternalLog.log(\n `Invalid first party hosts list ${JSON.stringify(\n firstPartyHosts\n )}. Regular expressions are not allowed.`,\n SdkVerbosity.WARN\n );\n return NO_MATCH_REGEX;\n }\n};\n\nexport const isHostFirstParty = (\n hostname: Hostname,\n firstPartyHostsRegex: RegExp\n): boolean => {\n return firstPartyHostsRegex.test(hostname);\n};\n"]}
1
+ {"version":3,"sources":["firstPartyHosts.ts"],"names":["InternalLog","SdkVerbosity","NO_MATCH_REGEX","RegExp","escapeRegExp","string","replace","firstPartyHostsRegexMapBuilder","firstPartyHosts","hostsMap","datadog","tracecontext","b3","b3multi","forEach","host","propagatorTypes","propagatorType","push","match","regexMap","Object","entries","hosts","length","regex","firstPartyHostsRegexBuilder","firstPartyHostsRegex","map","join","test","e","log","JSON","stringify","WARN","getPropagatorsForHost","hostname","firstPartyHostsRegexMap","matchedPropagatorTypes"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AAEA,SAASA,WAAT,QAA4B,yBAA5B;AACA,SAASC,YAAT,QAA6B,0BAA7B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AJ,CACxB,aAAYK,eAAe,CACvBoB,GADQ,CACJb,IAAI,IAAK,GAAEX,YAAY,CAACW,IAAD,CAAO,GAD1B,EAERc,IAFQ,CAEH,GAFG,CAEE,GAHU,CAA7B;AAKAF,IAAAA,oBAAoB,CAACG,IAArB,CAA0B,yBAA1B;AACA,WAAOH,oBAAP;AACH,GAVD,CAUE,OAAOI,CAAP,EAAU;AACR/B,IAAAA,WAAW,CAACgC,GAAZ,CACK,kCAAiCC,IAAI,CAACC,SAAL,CAC9B1B,eAD8B,CAEhC,wCAHN,EAIIP,YAAY,CAACkC,IAJjB;AAMA,WAAOjC,cAAP;AACH;AACJ,CAvBD;;AAyBA,OAAO,MAAMkC,qBAAqB,GAAG,CACjCC,QADiC,EAEjCC,uBAFiC,KAGP;AAC1B,QAAMC,sBAAwC,GAAG,EAAjD;AACAD,EAAAA,uBAAuB,CAACxB,OAAxB,CAAgC,CAAC;AAAEW,IAAAA,KAAF;AAASR,IAAAA;AAAT,GAAD,KAA+B;AAC3D,QAAIQ,KAAK,CAACK,IAAN,CAAWO,QAAX,CAAJ,EAA0B;AACtBE,MAAAA,sBAAsB,CAACrB,IAAvB,CAA4BD,cAA5B;AACH;AACJ,GAJD;AAKA,SAAOsB,sBAAsB,CAACf,MAAvB,GAAgC,CAAhC,GAAoCe,sBAApC,GAA6D,IAApE;AACH,CAXM","sourcesContent":["/*\n * Unless explicitly stated otherwise all files in this repository are licensed under the Apache License Version 2.0.\n * This product includes software developed at Datadog (https://www.datadoghq.com/).\n * Copyright 2016-Present Datadog, Inc.\n */\n\nimport { InternalLog } from '../../../../InternalLog';\nimport { SdkVerbosity } from '../../../../SdkVerbosity';\nimport type { FirstPartyHost, PropagatorType } from '../../../types';\n\nimport type { RegexMap } from './interfaces/RequestProxy';\n\nexport type Hostname = { _type: 'Hostname' } & string;\n\n// This regex does not match anything\nexport const NO_MATCH_REGEX = new RegExp('a^');\n\n// From https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Regular_Expressions\nconst escapeRegExp = (string: string) => {\n return string.replace(/[.*+?^${}()|[\\]\\\\]/g, '\\\\$&'); // $& means the whole matched string\n};\n\nexport const firstPartyHostsRegexMapBuilder = (\n firstPartyHosts: FirstPartyHost[]\n): RegexMap => {\n const hostsMap: Record<PropagatorType, string[]> = {\n datadog: [],\n tracecontext: [],\n b3: [],\n b3multi: []\n };\n\n firstPartyHosts.forEach(host => {\n host.propagatorTypes.forEach(propagatorType => {\n hostsMap[propagatorType].push(host.match);\n });\n });\n\n const regexMap: { regex: RegExp; propagatorType: PropagatorType }[] = [];\n Object.entries(hostsMap).forEach(([propagatorType, hosts]) => {\n if (hosts.length > 0) {\n regexMap.push({\n propagatorType: propagatorType as PropagatorType,\n regex: firstPartyHostsRegexBuilder(hosts)\n });\n }\n });\n\n return regexMap;\n};\n\nconst firstPartyHostsRegexBuilder = (firstPartyHosts: string[]): RegExp => {\n if (firstPartyHosts.length === 0) {\n return NO_MATCH_REGEX;\n }\n try {\n // A regexp for matching hosts, e.g. when `hosts` is \"example.com\", it will match\n // \"example.com\", \"api.example.com\", but not \"foo.com\".\n const firstPartyHostsRegex = new RegExp(\n `^(.*\\\\.)*(${firstPartyHosts\n .map(host => `${escapeRegExp(host)}$`)\n .join('|')})`\n );\n firstPartyHostsRegex.test('test_the_regex_is_valid');\n return firstPartyHostsRegex;\n } catch (e) {\n InternalLog.log(\n `Invalid first party hosts list ${JSON.stringify(\n firstPartyHosts\n )}. Regular expressions are not allowed.`,\n SdkVerbosity.WARN\n );\n return NO_MATCH_REGEX;\n }\n};\n\nexport const getPropagatorsForHost = (\n hostname: Hostname,\n firstPartyHostsRegexMap: RegexMap\n): PropagatorType[] | null => {\n const matchedPropagatorTypes: PropagatorType[] = [];\n firstPartyHostsRegexMap.forEach(({ regex, propagatorType }) => {\n if (regex.test(hostname)) {\n matchedPropagatorTypes.push(propagatorType);\n }\n });\n return matchedPropagatorTypes.length > 0 ? matchedPropagatorTypes : null;\n};\n"]}
@@ -1 +1 @@
1
- {"version":3,"sources":["RequestProxy.ts"],"names":["RequestProxy"],"mappings":";;AAAA;AACA;AACA;AACA;AACA;AAOA,OAAO,MAAeA,YAAf,CAA4B;AAAA;AAAA;;AAAA;AAAA;;AAAA","sourcesContent":["/*\n * Unless explicitly stated otherwise all files in this repository are licensed under the Apache License Version 2.0.\n * This product includes software developed at Datadog (https://www.datadoghq.com/).\n * Copyright 2016-Present Datadog, Inc.\n */\n\nexport interface RequestProxyOptions {\n tracingSamplingRate: number;\n firstPartyHostsRegex: RegExp;\n}\n\nexport abstract class RequestProxy {\n abstract onTrackingStart: (context: RequestProxyOptions) => void;\n abstract onTrackingStop: () => void;\n}\n"]}
1
+ {"version":3,"sources":["RequestProxy.ts"],"names":["RequestProxy"],"mappings":";;AAAA;AACA;AACA;AACA;AACA;AAcA,OAAO,MAAeA,YAAf,CAA4B;AAAA;AAAA;;AAAA;AAAA;;AAAA","sourcesContent":["/*\n * Unless explicitly stated otherwise all files in this repository are licensed under the Apache License Version 2.0.\n * This product includes software developed at Datadog (https://www.datadoghq.com/).\n * Copyright 2016-Present Datadog, Inc.\n */\n\nimport type { PropagatorType } from '../../../../types';\n\nexport interface RequestProxyOptions {\n tracingSamplingRate: number;\n firstPartyHostsRegexMap: RegexMap;\n}\n\nexport type RegexMap = {\n regex: RegExp;\n propagatorType: PropagatorType;\n}[];\n\nexport abstract class RequestProxy {\n abstract onTrackingStart: (context: RequestProxyOptions) => void;\n abstract onTrackingStop: () => void;\n}\n"]}
@@ -31,9 +31,9 @@ export class ResourceReporter {
31
31
  }
32
32
 
33
33
  const formatResourceStartContext = tracingAttributes => {
34
- return tracingAttributes.tracingStrategy === 'DISCARD' ? undefined : {
35
- '_dd.span_id': tracingAttributes.spanId,
36
- '_dd.trace_id': tracingAttributes.traceId,
34
+ return tracingAttributes.samplingPriorityHeader === '0' ? undefined : {
35
+ '_dd.span_id': tracingAttributes.spanId.toString(10),
36
+ '_dd.trace_id': tracingAttributes.traceId.toString(10),
37
37
  '_dd.rule_psr': tracingAttributes.rulePsr
38
38
  };
39
39
  };
@@ -1 +1 @@
1
- {"version":3,"sources":["ResourceReporter.ts"],"names":["DdRum","createTimings","ResourceReporter","constructor","resourceMappers","resource","modifiedResource","mapper","mappers","reportResource","formatResourceStartContext","tracingAttributes","tracingStrategy","undefined","spanId","traceId","rulePsr","formatResourceStopContext","timings","responseStartTime","startTime","stopTime","startResource","key","request","method","url","stopResource","response","statusCode","kind","size","resourceContext"],"mappings":";;AAAA;AACA;AACA;AACA;AACA;AAEA,SAASA,KAAT,QAAsB,mBAAtB;AAGA,SAASC,aAAT,QAA8B,kBAA9B;AAIA,OAAO,MAAMC,gBAAN,CAAuB;AAG1BC,EAAAA,WAAW,CAACC,eAAD,EAAoC;AAAA;;AAAA,4CAI7BC,QAAD,IAA2B;AACxC,UAAIC,gBAAoC,GAAGD,QAA3C;;AAEA,WAAK,MAAME,MAAX,IAAqB,KAAKC,OAA1B,EAAmC;AAC/BF,QAAAA,gBAAgB,GAAGC,MAAM,CAACF,QAAD,CAAzB;;AACA,YAAIC,gBAAgB,KAAK,IAAzB,EAA+B;AAC3B;AACH;AACJ;;AAEDG,MAAAA,cAAc,CAACH,gBAAD,CAAd;AACH,KAf8C;;AAC3C,SAAKE,OAAL,GAAeJ,eAAf;AACH;;AALyB;;AAqB9B,MAAMM,0BAA0B,GAC5BC,iBAD+B,IAEO;AACtC,SAAOA,iBAAiB,CAACC,eAAlB,KAAsC,SAAtC,GACDC,SADC,GAED;AACI,mBAAeF,iBAAiB,CAACG,MADrC;AAEI,oBAAgBH,iBAAiB,CAACI,OAFtC;AAGI,oBAAgBJ,iBAAiB,CAACK;AAHtC,GAFN;AAOH,CAVD;;AAYA,MAAMC,yBAAyB,GAC3BC,OAD8B,IAEJ;AAC1B,SAAO;AACH,4BACIA,OAAO,CAACC,iBAAR,KAA8BN,SAA9B,GACMZ,aAAa,CACTiB,OAAO,CAACE,SADC,EAETF,OAAO,CAACC,iBAFC,EAGTD,OAAO,CAACG,QAHC,CADnB,GAMM;AARP,GAAP;AAUH,CAbD;;AAeA,MAAMZ,cAAc,GAAG,MAAOJ,QAAP,IAAiC;AACpD,QAAML,KAAK,CAACsB,aAAN,CACFjB,QAAQ,CAACkB,GADP,EAEFlB,QAAQ,CAACmB,OAAT,CAAiBC,MAFf,EAGFpB,QAAQ,CAACmB,OAAT,CAAiBE,GAHf,EAIFhB,0BAA0B,CAACL,QAAQ,CAACM,iBAAV,CAJxB,EAKFN,QAAQ,CAACa,OAAT,CAAiBE,SALf,CAAN;AAQApB,EAAAA,KAAK,CAAC2B,YAAN,CACItB,QAAQ,CAACkB,GADb,EAEIlB,QAAQ,CAACuB,QAAT,CAAkBC,UAFtB,EAGIxB,QAAQ,CAACmB,OAAT,CAAiBM,IAHrB,EAIIzB,QAAQ,CAACuB,QAAT,CAAkBG,IAJtB,EAKId,yBAAyB,CAACZ,QAAQ,CAACa,OAAV,CAL7B,EAMIb,QAAQ,CAACa,OAAT,CAAiBG,QANrB,EAOIhB,QAAQ,CAAC2B,eAPb;AASH,CAlBD","sourcesContent":["/*\n * Unless explicitly stated otherwise all files in this repository are licensed under the Apache License Version 2.0.\n * This product includes software developed at Datadog (https://www.datadoghq.com/).\n * Copyright 2016-Present Datadog, Inc.\n */\n\nimport { DdRum } from '../../../../DdRum';\nimport type { RUMResource } from '../../domain/interfaces/RumResource';\n\nimport { createTimings } from './resourceTiming';\n\ntype ResourceMapper = (resource: RUMResource) => RUMResource | null;\n\nexport class ResourceReporter {\n private mappers: ResourceMapper[];\n\n constructor(resourceMappers: ResourceMapper[]) {\n this.mappers = resourceMappers;\n }\n\n reportResource = (resource: RUMResource) => {\n let modifiedResource: RUMResource | null = resource;\n\n for (const mapper of this.mappers) {\n modifiedResource = mapper(resource);\n if (modifiedResource === null) {\n return;\n }\n }\n\n reportResource(modifiedResource);\n };\n}\n\nconst formatResourceStartContext = (\n tracingAttributes: RUMResource['tracingAttributes']\n): Record<string, unknown> | undefined => {\n return tracingAttributes.tracingStrategy === 'DISCARD'\n ? undefined\n : {\n '_dd.span_id': tracingAttributes.spanId,\n '_dd.trace_id': tracingAttributes.traceId,\n '_dd.rule_psr': tracingAttributes.rulePsr\n };\n};\n\nconst formatResourceStopContext = (\n timings: RUMResource['timings']\n): Record<string, unknown> => {\n return {\n '_dd.resource_timings':\n timings.responseStartTime !== undefined\n ? createTimings(\n timings.startTime,\n timings.responseStartTime,\n timings.stopTime\n )\n : null\n };\n};\n\nconst reportResource = async (resource: RUMResource) => {\n await DdRum.startResource(\n resource.key,\n resource.request.method,\n resource.request.url,\n formatResourceStartContext(resource.tracingAttributes),\n resource.timings.startTime\n );\n\n DdRum.stopResource(\n resource.key,\n resource.response.statusCode,\n resource.request.kind,\n resource.response.size,\n formatResourceStopContext(resource.timings),\n resource.timings.stopTime,\n resource.resourceContext\n );\n};\n"]}
1
+ {"version":3,"sources":["ResourceReporter.ts"],"names":["DdRum","createTimings","ResourceReporter","constructor","resourceMappers","resource","modifiedResource","mapper","mappers","reportResource","formatResourceStartContext","tracingAttributes","samplingPriorityHeader","undefined","spanId","toString","traceId","rulePsr","formatResourceStopContext","timings","responseStartTime","startTime","stopTime","startResource","key","request","method","url","stopResource","response","statusCode","kind","size","resourceContext"],"mappings":";;AAAA;AACA;AACA;AACA;AACA;AAEA,SAASA,KAAT,QAAsB,mBAAtB;AAGA,SAASC,aAAT,QAA8B,kBAA9B;AAIA,OAAO,MAAMC,gBAAN,CAAuB;AAG1BC,EAAAA,WAAW,CAACC,eAAD,EAAoC;AAAA;;AAAA,4CAI7BC,QAAD,IAA2B;AACxC,UAAIC,gBAAoC,GAAGD,QAA3C;;AAEA,WAAK,MAAME,MAAX,IAAqB,KAAKC,OAA1B,EAAmC;AAC/BF,QAAAA,gBAAgB,GAAGC,MAAM,CAACF,QAAD,CAAzB;;AACA,YAAIC,gBAAgB,KAAK,IAAzB,EAA+B;AAC3B;AACH;AACJ;;AAEDG,MAAAA,cAAc,CAACH,gBAAD,CA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*\n * Unless explicitly stated otherwise all files in this repository are licensed under the Apache License Version 2.0.\n * This product includes software developed at Datadog (https://www.datadoghq.com/).\n * Copyright 2016-Present Datadog, Inc.\n */\n\nimport { DdRum } from '../../../../DdRum';\nimport type { RUMResource } from '../../domain/interfaces/RumResource';\n\nimport { createTimings } from './resourceTiming';\n\ntype ResourceMapper = (resource: RUMResource) => RUMResource | null;\n\nexport class ResourceReporter {\n private mappers: ResourceMapper[];\n\n constructor(resourceMappers: ResourceMapper[]) {\n this.mappers = resourceMappers;\n }\n\n reportResource = (resource: RUMResource) => {\n let modifiedResource: RUMResource | null = resource;\n\n for (const mapper of this.mappers) {\n modifiedResource = mapper(resource);\n if (modifiedResource === null) {\n return;\n }\n }\n\n reportResource(modifiedResource);\n };\n}\n\nconst formatResourceStartContext = (\n tracingAttributes: RUMResource['tracingAttributes']\n): Record<string, string | number> | undefined => {\n return tracingAttributes.samplingPriorityHeader === '0'\n ? undefined\n : {\n '_dd.span_id': tracingAttributes.spanId.toString(10),\n '_dd.trace_id': tracingAttributes.traceId.toString(10),\n '_dd.rule_psr': tracingAttributes.rulePsr\n };\n};\n\nconst formatResourceStopContext = (\n timings: RUMResource['timings']\n): Record<string, unknown> => {\n return {\n '_dd.resource_timings':\n timings.responseStartTime !== undefined\n ? createTimings(\n timings.startTime,\n timings.responseStartTime,\n timings.stopTime\n )\n : null\n };\n};\n\nconst reportResource = async (resource: RUMResource) => {\n await DdRum.startResource(\n resource.key,\n resource.request.method,\n resource.request.url,\n formatResourceStartContext(resource.tracingAttributes),\n resource.timings.startTime\n );\n\n DdRum.stopResource(\n resource.key,\n resource.response.statusCode,\n resource.request.kind,\n resource.response.size,\n formatResourceStopContext(resource.timings),\n resource.timings.stopTime,\n resource.resourceContext\n );\n};\n"]}
@@ -6,15 +6,11 @@ function _defineProperty(obj, key, value) { if (key in obj) { Object.definePrope
6
6
  * Copyright 2016-Present Datadog, Inc.
7
7
  */
8
8
  import Timer from '../../../../Timer';
9
+ import { getTracingHeaders } from '../domain/distributedTracingHeaders';
9
10
  import { getTracingAttributes } from '../domain/distributedTracing';
10
11
  import { RequestProxy } from '../domain/interfaces/RequestProxy';
11
12
  import { URLHostParser } from './URLHostParser';
12
13
  import { calculateResponseSize } from './responseSize';
13
- export const TRACE_ID_HEADER_KEY = 'x-datadog-trace-id';
14
- export const PARENT_ID_HEADER_KEY = 'x-datadog-parent-id';
15
- export const ORIGIN_HEADER_KEY = 'x-datadog-origin';
16
- export const SAMPLING_PRIORITY_HEADER_KEY = 'x-datadog-sampling-priority';
17
- export const ORIGIN_RUM = 'rum';
18
14
  const RESPONSE_START_LABEL = 'response_start';
19
15
 
20
16
  /**
@@ -55,7 +51,7 @@ const proxyOpen = ({
55
51
  xhrType
56
52
  }, context) => {
57
53
  const originalXhrOpen = xhrType.prototype.open;
58
- const firstPartyHostsRegex = context.firstPartyHostsRegex;
54
+ const firstPartyHostsRegexMap = context.firstPartyHostsRegexMap;
59
55
  const tracingSamplingRate = context.tracingSamplingRate;
60
56
 
61
57
  xhrType.prototype.open = function (method, url) {
@@ -69,7 +65,7 @@ const proxyOpen = ({
69
65
  timer: new Timer(),
70
66
  tracingAttributes: getTracingAttributes({
71
67
  hostname,
72
- firstPartyHostsRegex,
68
+ firstPartyHostsRegexMap,
73
69
  tracingSamplingRate
74
70
  })
75
71
  }; // eslint-disable-next-line prefer-rest-params
@@ -87,14 +83,13 @@ const proxySend = providers => {
87
83
  // keep track of start time
88
84
  this._datadog_xhr.timer.start();
89
85
 
90
- this.setRequestHeader(ORIGIN_HEADER_KEY, ORIGIN_RUM);
91
- const tracingAttributes = this._datadog_xhr.tracingAttributes;
92
- this.setRequestHeader(SAMPLING_PRIORITY_HEADER_KEY, tracingAttributes.samplingPriorityHeader);
93
-
94
- if (tracingAttributes.tracingStrategy !== 'DISCARD') {
95
- this.setRequestHeader(TRACE_ID_HEADER_KEY, tracingAttributes.traceId);
96
- this.setRequestHeader(PARENT_ID_HEADER_KEY, tracingAttributes.spanId);
97
- }
86
+ const tracingHeaders = getTracingHeaders(this._datadog_xhr.tracingAttributes);
87
+ tracingHeaders.forEach(({
88
+ header,
89
+ value
90
+ }) => {
91
+ this.setRequestHeader(header, value);
92
+ });
98
93
  }
99
94
 
100
95
  proxyOnReadyStateChange(this, providers); // eslint-disable-next-line prefer-rest-params
@@ -1 +1 @@
1
- {"version":3,"sources":["XHRProxy.ts"],"names":["Timer","getTracingAttributes","RequestProxy","URLHostParser","calculateResponseSize","TRACE_ID_HEADER_KEY","PARENT_ID_HEADER_KEY","ORIGIN_HEADER_KEY","SAMPLING_PRIORITY_HEADER_KEY","ORIGIN_RUM","RESPONSE_START_LABEL","XHRProxy","constructor","providers","context","originalXhrOpen","xhrType","prototype","open","originalXhrSend","send","proxyRequests","proxyOpen","proxySend","firstPartyHostsRegex","tracingSamplingRate","method","url","hostname","_datadog_xhr","reported","timer","tracingAttributes","apply","arguments","start","setRequestHeader","samplingPriorityHeader","tracingStrategy","traceId","spanId","proxyOnReadyStateChange","xhrProxy","originalOnreadystatechange","onreadystatechange","readyState","DONE","reportXhr","resourceReporter","HEADERS_RECEIVED","recordTick","responseSize","key","startTime","stop","reportResource","request","kind","response","statusCode","status","size","timings","stopTime","responseStartTime","hasTickFor","timeAt","undefined","resourceContext"],"mappings":";;AAAA;AACA;AACA;AACA;AACA;AAEA,OAAOA,KAAP,MAAkB,mBAAlB;AAEA,SAASC,oBAAT,QAAqC,8BAArC;AAEA,SAASC,YAAT,QAA6B,mCAA7B;AAGA,SAASC,aAAT,QAA8B,iBAA9B;AACA,SAASC,qBAAT,QAAsC,gBAAtC;AAEA,OAAO,MAAMC,mBAAmB,GAAG,oBAA5B;AACP,OAAO,MAAMC,oBAAoB,GAAG,qBAA7B;AACP,OAAO,MAAMC,iBAAiB,GAAG,kBAA1B;AACP,OAAO,MAAMC,4BAA4B,GAAG,6BAArC;AACP,OAAO,MAAMC,UAAU,GAAG,KAAnB;AAEP,MAAMC,oBAAoB,GAAG,gBAA7B;;A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AAO,EAAE;AACL9B,MAAAA,MAAM,EAAEZ,OAAO,CAACY,MADX;AAELC,MAAAA,GAAG,EAAEb,OAAO,CAACa,GAFR;AAGL8B,MAAAA,IAAI,EAAE;AAHD,KAFmB;AAO5BzB,IAAAA,iBAAiB,EAAElB,OAAO,CAACkB,iBAPC;AAQ5B0B,IAAAA,QAAQ,EAAE;AACNC,MAAAA,UAAU,EAAEjB,QAAQ,CAACkB,MADf;AAENC,MAAAA,IAAI,EAAEV;AAFA,KARkB;AAY5BW,IAAAA,OAAO,EAAE;AACLT,MAAAA,SAAS,EAAEvC,OAAO,CAACiB,KAAR,CAAcsB,SADpB;AAELU,MAAAA,QAAQ,EAAEjD,OAAO,CAACiB,KAAR,CAAcgC,QAFnB;AAGLC,MAAAA,iBAAiB,EAAElD,OAAO,CAACiB,KAAR,CAAckC,UAAd,CAAyBvD,oBAAzB,IACbI,OAAO,CAACiB,KAAR,CAAcmC,MAAd,CAAqBxD,oBAArB,CADa,GAEbyD;AALD,KAZmB;AAmB5BC,IAAAA,eAAe,EAAE1B;AAnBW,GAAhC;AAqBH,CAjCD","sourcesContent":["/*\n * Unless explicitly stated otherwise all files in this repository are licensed under the Apache License Version 2.0.\n * This product includes software developed at Datadog (https://www.datadoghq.com/).\n * Copyright 2016-Present Datadog, Inc.\n */\n\nimport Timer from '../../../../Timer';\nimport type { DdRumResourceTracingAttributes } from '../domain/distributedTracing';\nimport { getTracingAttributes } from '../domain/distributedTracing';\nimport type { RequestProxyOptions } from '../domain/interfaces/RequestProxy';\nimport { RequestProxy } from '../domain/interfaces/RequestProxy';\n\nimport type { ResourceReporter } from './DatadogRumResource/ResourceReporter';\nimport { URLHostParser } from './URLHostParser';\nimport { calculateResponseSize } from './responseSize';\n\nexport const TRACE_ID_HEADER_KEY = 'x-datadog-trace-id';\nexport const PARENT_ID_HEADER_KEY = 'x-datadog-parent-id';\nexport const ORIGIN_HEADER_KEY = 'x-datadog-origin';\nexport const SAMPLING_PRIORITY_HEADER_KEY = 'x-datadog-sampling-priority';\nexport const ORIGIN_RUM = 'rum';\n\nconst RESPONSE_START_LABEL = 'response_start';\n\ninterface DdRumXhr extends XMLHttpRequest {\n _datadog_xhr: DdRumXhrContext;\n}\n\ninterface DdRumXhrContext {\n method: string;\n url: string;\n reported: boolean;\n timer: Timer;\n tracingAttributes: DdRumResourceTracingAttributes;\n}\n\ninterface XHRProxyProviders {\n xhrType: typeof XMLHttpRequest;\n resourceReporter: ResourceReporter;\n}\n\n/**\n * Proxies XMLHTTPRequest to track resources.\n */\nexport class XHRProxy extends RequestProxy {\n private providers: XHRProxyProviders;\n private static originalXhrOpen: typeof XMLHttpRequest.prototype.open;\n private static originalXhrSend: typeof XMLHttpRequest.prototype.send;\n\n constructor(providers: XHRProxyProviders) {\n super();\n this.providers = providers;\n }\n\n onTrackingStart = (context: RequestProxyOptions) => {\n XHRProxy.originalXhrOpen = this.providers.xhrType.prototype.open;\n XHRProxy.originalXhrSend = this.providers.xhrType.prototype.send;\n proxyRequests(this.providers, context);\n };\n\n onTrackingStop = () => {\n this.providers.xhrType.prototype.open = XHRProxy.originalXhrOpen;\n this.providers.xhrType.prototype.send = XHRProxy.originalXhrSend;\n };\n}\n\nconst proxyRequests = (\n providers: XHRProxyProviders,\n context: RequestProxyOptions\n): void => {\n proxyOpen(providers, context);\n proxySend(providers);\n};\n\nconst proxyOpen = (\n { xhrType }: XHRProxyProviders,\n context: RequestProxyOptions\n): void => {\n const originalXhrOpen = xhrType.prototype.open;\n const firstPartyHostsRegex = context.firstPartyHostsRegex;\n const tracingSamplingRate = context.tracingSamplingRate;\n\n xhrType.prototype.open = function (\n this: DdRumXhr,\n method: string,\n url: string\n ) {\n const hostname = URLHostParser(url);\n // Keep track of the method and url\n // start time is tracked by the `send` method\n this._datadog_xhr = {\n method,\n url,\n reported: false,\n timer: new Timer(),\n tracingAttributes: getTracingAttributes({\n hostname,\n firstPartyHostsRegex,\n tracingSamplingRate\n })\n };\n // eslint-disable-next-line prefer-rest-params\n return originalXhrOpen.apply(this, arguments as any);\n };\n};\n\nconst proxySend = (providers: XHRProxyProviders): void => {\n const xhrType = providers.xhrType;\n const originalXhrSend = xhrType.prototype.send;\n\n xhrType.prototype.send = function (this: DdRumXhr) {\n if (this._datadog_xhr) {\n // keep track of start time\n this._datadog_xhr.timer.start();\n this.setRequestHeader(ORIGIN_HEADER_KEY, ORIGIN_RUM);\n\n const tracingAttributes = this._datadog_xhr.tracingAttributes;\n this.setRequestHeader(\n SAMPLING_PRIORITY_HEADER_KEY,\n tracingAttributes.samplingPriorityHeader\n );\n if (tracingAttributes.tracingStrategy !== 'DISCARD') {\n this.setRequestHeader(\n TRACE_ID_HEADER_KEY,\n tracingAttributes.traceId\n );\n this.setRequestHeader(\n PARENT_ID_HEADER_KEY,\n tracingAttributes.spanId\n );\n }\n }\n\n proxyOnReadyStateChange(this, providers);\n\n // eslint-disable-next-line prefer-rest-params\n return originalXhrSend.apply(this, arguments as any);\n };\n};\n\nconst proxyOnReadyStateChange = (\n xhrProxy: DdRumXhr,\n providers: XHRProxyProviders\n): void => {\n const xhrType = providers.xhrType;\n const originalOnreadystatechange = xhrProxy.onreadystatechange;\n\n xhrProxy.onreadystatechange = function () {\n if (xhrProxy.readyState === xhrType.DONE) {\n if (!xhrProxy._datadog_xhr.reported) {\n reportXhr(xhrProxy, providers.resourceReporter);\n xhrProxy._datadog_xhr.reported = true;\n }\n } else if (xhrProxy.readyState === xhrType.HEADERS_RECEIVED) {\n xhrProxy._datadog_xhr.timer.recordTick(RESPONSE_START_LABEL);\n }\n\n if (originalOnreadystatechange) {\n // eslint-disable-next-line prefer-rest-params\n originalOnreadystatechange.apply(xhrProxy, arguments as any);\n }\n };\n};\n\nconst reportXhr = async (\n xhrProxy: DdRumXhr,\n resourceReporter: ResourceReporter\n): Promise<void> => {\n const responseSize = calculateResponseSize(xhrProxy);\n\n const context = xhrProxy._datadog_xhr;\n\n const key = `${context.timer.startTime}/${context.method}`;\n\n context.timer.stop();\n\n resourceReporter.reportResource({\n key,\n request: {\n method: context.method,\n url: context.url,\n kind: 'xhr'\n },\n tracingAttributes: context.tracingAttributes,\n response: {\n statusCode: xhrProxy.status,\n size: responseSize\n },\n timings: {\n startTime: context.timer.startTime,\n stopTime: context.timer.stopTime,\n responseStartTime: context.timer.hasTickFor(RESPONSE_START_LABEL)\n ? context.timer.timeAt(RESPONSE_START_LABEL)\n : undefined\n },\n resourceContext: xhrProxy\n });\n};\n"]}
1
+ {"version":3,"sources":["XHRProxy.ts"],"names":["Timer","getTracingHeaders","getTracingAttributes","RequestProxy","URLHostParser","calculateResponseSize","RESPONSE_START_LABEL","XHRProxy","constructor","providers","context","originalXhrOpen","xhrType","prototype","open","originalXhrSend","send","proxyRequests","proxyOpen","proxySend","firstPartyHostsRegexMap","tracingSamplingRate","method","url","hostname","_datadog_xhr","reported","timer","tracingAttributes","apply","arguments","start","tracingHeaders","forEach","header","value","setRequestHeader","proxyOnReadyStateChange","xhrProxy","originalOnreadystatechange","onreadystatechange","readyState","DONE","reportXhr","resourceReporter","HEADERS_RECEIVED","recordTick","responseSize","key","startTime","stop","reportResource","request","kind","response","statusCode","status","size","timings","stopTime","responseStartTime","hasTickFor","timeAt","undefined","resourceContext"],"mappings":";;AAAA;AACA;AACA;AACA;AACA;AAEA,OAAOA,KAAP,MAAkB,mBAAlB;AACA,SAASC,iBAAT,QAAkC,qCAAlC;AAEA,SAASC,oBAAT,QAAqC,8BAArC;AAEA,SAASC,YAAT,QAA6B,mCAA7B;AAGA,SAASC,aAAT,QAA8B,iBAA9B;AACA,SAASC,qBAAT,QAAsC,gBAAtC;AAEA,MAAMC,oBAAoB,GAAG,gBAA7B;;AAmBA;AACA;AACA;AACA,OAAO,MAAMC,QAAN,SAAuBJ,YAAvB,CAAoC;AAKvCK,EAAAA,WAAW,CAACC,SAAD,EAA+B;AACtC;;AADsC;;AAAA,6CAKvBC,OAAD,IAAkC;AAChDH,MAAAA,QAAQ,CAACI,eAAT,GAA2B,KAAKF,SA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OAAO,EAAE;AACLT,MAAAA,SAAS,EAAEvC,OAAO,CAACiB,KAAR,CAAcsB,SADpB;AAELU,MAAAA,QAAQ,EAAEjD,OAAO,CAACiB,KAAR,CAAcgC,QAFnB;AAGLC,MAAAA,iBAAiB,EAAElD,OAAO,CAACiB,KAAR,CAAckC,UAAd,CAAyBvD,oBAAzB,IACbI,OAAO,CAACiB,KAAR,CAAcmC,MAAd,CAAqBxD,oBAArB,CADa,GAEbyD;AALD,KAZmB;AAmB5BC,IAAAA,eAAe,EAAE1B;AAnBW,GAAhC;AAqBH,CAjCD","sourcesContent":["/*\n * Unless explicitly stated otherwise all files in this repository are licensed under the Apache License Version 2.0.\n * This product includes software developed at Datadog (https://www.datadoghq.com/).\n * Copyright 2016-Present Datadog, Inc.\n */\n\nimport Timer from '../../../../Timer';\nimport { getTracingHeaders } from '../domain/distributedTracingHeaders';\nimport type { DdRumResourceTracingAttributes } from '../domain/distributedTracing';\nimport { getTracingAttributes } from '../domain/distributedTracing';\nimport type { RequestProxyOptions } from '../domain/interfaces/RequestProxy';\nimport { RequestProxy } from '../domain/interfaces/RequestProxy';\n\nimport type { ResourceReporter } from './DatadogRumResource/ResourceReporter';\nimport { URLHostParser } from './URLHostParser';\nimport { calculateResponseSize } from './responseSize';\n\nconst RESPONSE_START_LABEL = 'response_start';\n\ninterface DdRumXhr extends XMLHttpRequest {\n _datadog_xhr: DdRumXhrContext;\n}\n\ninterface DdRumXhrContext {\n method: string;\n url: string;\n reported: boolean;\n timer: Timer;\n tracingAttributes: DdRumResourceTracingAttributes;\n}\n\ninterface XHRProxyProviders {\n xhrType: typeof XMLHttpRequest;\n resourceReporter: ResourceReporter;\n}\n\n/**\n * Proxies XMLHTTPRequest to track resources.\n */\nexport class XHRProxy extends RequestProxy {\n private providers: XHRProxyProviders;\n private static originalXhrOpen: typeof XMLHttpRequest.prototype.open;\n private static originalXhrSend: typeof XMLHttpRequest.prototype.send;\n\n constructor(providers: XHRProxyProviders) {\n super();\n this.providers = providers;\n }\n\n onTrackingStart = (context: RequestProxyOptions) => {\n XHRProxy.originalXhrOpen = this.providers.xhrType.prototype.open;\n XHRProxy.originalXhrSend = this.providers.xhrType.prototype.send;\n proxyRequests(this.providers, context);\n };\n\n onTrackingStop = () => {\n this.providers.xhrType.prototype.open = XHRProxy.originalXhrOpen;\n this.providers.xhrType.prototype.send = XHRProxy.originalXhrSend;\n };\n}\n\nconst proxyRequests = (\n providers: XHRProxyProviders,\n context: RequestProxyOptions\n): void => {\n proxyOpen(providers, context);\n proxySend(providers);\n};\n\nconst proxyOpen = (\n { xhrType }: XHRProxyProviders,\n context: RequestProxyOptions\n): void => {\n const originalXhrOpen = xhrType.prototype.open;\n const firstPartyHostsRegexMap = context.firstPartyHostsRegexMap;\n const tracingSamplingRate = context.tracingSamplingRate;\n\n xhrType.prototype.open = function (\n this: DdRumXhr,\n method: string,\n url: string\n ) {\n const hostname = URLHostParser(url);\n // Keep track of the method and url\n // start time is tracked by the `send` method\n this._datadog_xhr = {\n method,\n url,\n reported: false,\n timer: new Timer(),\n tracingAttributes: getTracingAttributes({\n hostname,\n firstPartyHostsRegexMap,\n tracingSamplingRate\n })\n };\n // eslint-disable-next-line prefer-rest-params\n return originalXhrOpen.apply(this, arguments as any);\n };\n};\n\nconst proxySend = (providers: XHRProxyProviders): void => {\n const xhrType = providers.xhrType;\n const originalXhrSend = xhrType.prototype.send;\n\n xhrType.prototype.send = function (this: DdRumXhr) {\n if (this._datadog_xhr) {\n // keep track of start time\n this._datadog_xhr.timer.start();\n\n const tracingHeaders = getTracingHeaders(\n this._datadog_xhr.tracingAttributes\n );\n tracingHeaders.forEach(({ header, value }) => {\n this.setRequestHeader(header, value);\n });\n }\n\n proxyOnReadyStateChange(this, providers);\n\n // eslint-disable-next-line prefer-rest-params\n return originalXhrSend.apply(this, arguments as any);\n };\n};\n\nconst proxyOnReadyStateChange = (\n xhrProxy: DdRumXhr,\n providers: XHRProxyProviders\n): void => {\n const xhrType = providers.xhrType;\n const originalOnreadystatechange = xhrProxy.onreadystatechange;\n\n xhrProxy.onreadystatechange = function () {\n if (xhrProxy.readyState === xhrType.DONE) {\n if (!xhrProxy._datadog_xhr.reported) {\n reportXhr(xhrProxy, providers.resourceReporter);\n xhrProxy._datadog_xhr.reported = true;\n }\n } else if (xhrProxy.readyState === xhrType.HEADERS_RECEIVED) {\n xhrProxy._datadog_xhr.timer.recordTick(RESPONSE_START_LABEL);\n }\n\n if (originalOnreadystatechange) {\n // eslint-disable-next-line prefer-rest-params\n originalOnreadystatechange.apply(xhrProxy, arguments as any);\n }\n };\n};\n\nconst reportXhr = async (\n xhrProxy: DdRumXhr,\n resourceReporter: ResourceReporter\n): Promise<void> => {\n const responseSize = calculateResponseSize(xhrProxy);\n\n const context = xhrProxy._datadog_xhr;\n\n const key = `${context.timer.startTime}/${context.method}`;\n\n context.timer.stop();\n\n resourceReporter.reportResource({\n key,\n request: {\n method: context.method,\n url: context.url,\n kind: 'xhr'\n },\n tracingAttributes: context.tracingAttributes,\n response: {\n statusCode: xhrProxy.status,\n size: responseSize\n },\n timings: {\n startTime: context.timer.startTime,\n stopTime: context.timer.stopTime,\n responseStartTime: context.timer.hasTickFor(RESPONSE_START_LABEL)\n ? context.timer.timeAt(RESPONSE_START_LABEL)\n : undefined\n },\n resourceContext: xhrProxy\n });\n};\n"]}
@@ -22,6 +22,13 @@ export let RumActionType;
22
22
  })(RumActionType || (RumActionType = {}));
23
23
 
24
24
  export let ErrorSource;
25
+ /**
26
+ * Type of instrumentation on the host.
27
+ * - DATADOG: Datadog’s propagator (`x-datadog-*`)
28
+ * - TRACECONTEXT: W3C Trace Context (`traceparent`)
29
+ * - B3: B3 single header (`b3`)
30
+ * - B3MULTI: B3 multiple headers (`X-B3-*`)
31
+ */
25
32
 
26
33
  (function (ErrorSource) {
27
34
  ErrorSource["NETWORK"] = "NETWORK";
@@ -30,4 +37,13 @@ export let ErrorSource;
30
37
  ErrorSource["WEBVIEW"] = "WEBVIEW";
31
38
  ErrorSource["CUSTOM"] = "CUSTOM";
32
39
  })(ErrorSource || (ErrorSource = {}));
40
+
41
+ export let PropagatorType;
42
+
43
+ (function (PropagatorType) {
44
+ PropagatorType["DATADOG"] = "datadog";
45
+ PropagatorType["TRACECONTEXT"] = "tracecontext";
46
+ PropagatorType["B3"] = "b3";
47
+ PropagatorType["B3MULTI"] = "b3multi";
48
+ })(PropagatorType || (PropagatorType = {}));
33
49
  //# sourceMappingURL=types.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["types.ts"],"names":["RumActionType","ErrorSource"],"mappings":"AAAA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;;AA0IA;AACA;AACA;AACA,WAAYA,aAAZ;;WAAYA,a;AAAAA,EAAAA,a;AAAAA,EAAAA,a;AAAAA,EAAAA,a;AAAAA,EAAAA,a;AAAAA,EAAAA,a;GAAAA,a,KAAAA,a;;AA0BZ,WAAYC,WAAZ;;WAAYA,W;AAAAA,EAAAA,W;AAAAA,EAAAA,W;AAAAA,EAAAA,W;AAAAA,EAAAA,W;AAAAA,EAAAA,W;GAAAA,W,KAAAA,W","sourcesContent":["/*\n * Unless explicitly stated otherwise all files in this repository are licensed under the Apache License Version 2.0.\n * This product includes software developed at Datadog (https://www.datadoghq.com/).\n * Copyright 2016-Present Datadog, Inc.\n */\n\n/**\n * The entry point to use Datadog's RUM feature.\n */\nexport type DdRumType = {\n /**\n * Start tracking a RUM View.\n * @param key: The view unique key identifier.\n * @param name: The view name.\n * @param context: The additional context to send.\n * @param timestampMs: The timestamp when the view started (in milliseconds). If not provided, current timestamp will be used.\n */\n startView(\n key: string,\n name: string,\n context?: object,\n timestampMs?: number\n ): Promise<void>;\n\n /**\n * Stop tracking a RUM View.\n * @param key: The view unique key identifier.\n * @param context: The additional context to send.\n * @param timestampMs: The timestamp when the view stopped (in milliseconds). If not provided, current timestamp will be used.\n */\n stopView(\n key: string,\n context?: object,\n timestampMs?: number\n ): Promise<void>;\n\n /**\n * Start tracking a RUM Action.\n * @param type: The action type (tap, scroll, swipe, back, custom).\n * @param name: The action name.\n * @param context: The additional context to send.\n * @param timestampMs: The timestamp when the action started (in milliseconds). If not provided, current timestamp will be used.\n */\n startAction(\n type: RumActionType,\n name: string,\n context?: object,\n timestampMs?: number\n ): Promise<void>;\n\n /**\n * Stop tracking the ongoing RUM Action.\n * @param type: The action type (tap, scroll, swipe, back, custom).\n * @param name: The action name.\n * @param context: The additional context to send.\n * @param timestampMs: The timestamp when the action stopped (in milliseconds). If not provided, current timestamp will be used.\n */\n stopAction(\n type: RumActionType,\n name: string,\n context?: object,\n timestampMs?: number\n ): Promise<void>;\n\n /**\n * Stop tracking the ongoing RUM Action.\n *\n * Warning: using this function signature can lead to inconsistent behaviors on iOS and Android when multiple actions are started in parallel.\n *\n * @deprecated add the `type` and `name` of the action as first two arguments.\n * @param context: The additional context to send.\n * @param timestampMs: The timestamp when the action stopped (in milliseconds). If not provided, current timestamp will be used.\n */\n stopAction(context?: object, timestampMs?: number): Promise<void>;\n\n /**\n * Add a RUM Action.\n * @param type: The action type (tap, scroll, swipe, back, custom).\n * @param name: The action name.\n * @param context: The additional context to send.\n * @param timestampMs: The timestamp when the action occurred (in milliseconds). If not provided, current timestamp will be used.\n */\n addAction(\n type: RumActionType,\n name: string,\n context?: object,\n timestampMs?: number\n ): Promise<void>;\n\n /**\n * Start tracking a RUM Resource.\n * @param key: The resource unique key identifier.\n * @param method: The resource method (GET, POST, …).\n * @param url: The resource url.\n * @param context: The additional context to send.\n * @param timestampMs: The timestamp when the resource started (in milliseconds). If not provided, current timestamp will be used.\n */\n startResource(\n key: string,\n method: string,\n url: string,\n context?: object,\n timestampMs?: number\n ): Promise<void>;\n\n /**\n * Stop tracking a RUM Resource.\n * @param key: The resource unique key identifier.\n * @param statusCode: The resource status code.\n * @param kind: The resource's kind (xhr, document, image, css, font, …).\n * @param size: The resource size in bytes. If size is unknown, use -1.\n * @param context: The additional context to send.\n * @param timestampMs: The timestamp when the resource stopped (in milliseconds). If not provided, current timestamp will be used.\n */\n stopResource(\n key: string,\n statusCode: number,\n kind: ResourceKind,\n size?: number,\n context?: object,\n timestampMs?: number\n ): Promise<void>;\n\n /**\n * Add a RUM Error.\n * @param message: The error message.\n * @param source: The error source (network, source, console, webview, custom).\n * @param stacktrace: The error stacktrace.\n * @param context: The additional context to send.\n * @param timestampMs: The timestamp when the error occurred (in milliseconds). If not provided, current timestamp will be used.\n */\n addError(\n message: string,\n source: ErrorSource,\n stacktrace: string,\n context?: object,\n timestampMs?: number\n ): Promise<void>;\n\n /**\n * Adds a specific timing in the active View. The timing duration will be computed as the difference between the time the View was started and the time this function was called.\n * @param name: The name of the new custom timing attribute. Timings can be nested up to 8 levels deep. Names using more than 8 levels will be sanitized by SDK.\n */\n addTiming(name: string): Promise<void>;\n};\n\n/**\n * Describe the type of a RUM Action.\n */\nexport enum RumActionType {\n /** User tapped on a widget. */\n TAP = 'TAP',\n /** User scrolled a view. */\n SCROLL = 'SCROLL',\n /** User swiped on a view. */\n SWIPE = 'SWIPE',\n /** User pressed hardware back button (Android only). */\n BACK = 'BACK',\n /** A custom action. */\n CUSTOM = 'CUSTOM'\n}\n\nexport type ResourceKind =\n | 'image'\n | 'xhr'\n | 'beacon'\n | 'css'\n | 'document'\n | 'fetch'\n | 'font'\n | 'js'\n | 'media'\n | 'other'\n | 'native';\n\nexport enum ErrorSource {\n NETWORK = 'NETWORK',\n SOURCE = 'SOURCE',\n CONSOLE = 'CONSOLE',\n WEBVIEW = 'WEBVIEW',\n CUSTOM = 'CUSTOM'\n}\n"]}
1
+ {"version":3,"sources":["types.ts"],"names":["RumActionType","ErrorSource","PropagatorType"],"mappings":"AAAA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;;AA0IA;AACA;AACA;AACA,WAAYA,aAAZ;;WAAYA,a;AAAAA,EAAAA,a;AAAAA,EAAAA,a;AAAAA,EAAAA,a;AAAAA,EAAAA,a;AAAAA,EAAAA,a;GAAAA,a,KAAAA,a;;AA0BZ,WAAYC,WAAZ;AAQA;AACA;AACA;AACA;AACA;AACA;AACA;;WAdYA,W;AAAAA,EAAAA,W;AAAAA,EAAAA,W;AAAAA,EAAAA,W;AAAAA,EAAAA,W;AAAAA,EAAAA,W;GAAAA,W,KAAAA,W;;AAeZ,WAAYC,cAAZ;;WAAYA,c;AAAAA,EAAAA,c;AAAAA,EAAAA,c;AAAAA,EAAAA,c;AAAAA,EAAAA,c;GAAAA,c,KAAAA,c","sourcesContent":["/*\n * Unless explicitly stated otherwise all files in this repository are licensed under the Apache License Version 2.0.\n * This product includes software developed at Datadog (https://www.datadoghq.com/).\n * Copyright 2016-Present Datadog, Inc.\n */\n\n/**\n * The entry point to use Datadog's RUM feature.\n */\nexport type DdRumType = {\n /**\n * Start tracking a RUM View.\n * @param key: The view unique key identifier.\n * @param name: The view name.\n * @param context: The additional context to send.\n * @param timestampMs: The timestamp when the view started (in milliseconds). If not provided, current timestamp will be used.\n */\n startView(\n key: string,\n name: string,\n context?: object,\n timestampMs?: number\n ): Promise<void>;\n\n /**\n * Stop tracking a RUM View.\n * @param key: The view unique key identifier.\n * @param context: The additional context to send.\n * @param timestampMs: The timestamp when the view stopped (in milliseconds). If not provided, current timestamp will be used.\n */\n stopView(\n key: string,\n context?: object,\n timestampMs?: number\n ): Promise<void>;\n\n /**\n * Start tracking a RUM Action.\n * @param type: The action type (tap, scroll, swipe, back, custom).\n * @param name: The action name.\n * @param context: The additional context to send.\n * @param timestampMs: The timestamp when the action started (in milliseconds). If not provided, current timestamp will be used.\n */\n startAction(\n type: RumActionType,\n name: string,\n context?: object,\n timestampMs?: number\n ): Promise<void>;\n\n /**\n * Stop tracking the ongoing RUM Action.\n * @param type: The action type (tap, scroll, swipe, back, custom).\n * @param name: The action name.\n * @param context: The additional context to send.\n * @param timestampMs: The timestamp when the action stopped (in milliseconds). If not provided, current timestamp will be used.\n */\n stopAction(\n type: RumActionType,\n name: string,\n context?: object,\n timestampMs?: number\n ): Promise<void>;\n\n /**\n * Stop tracking the ongoing RUM Action.\n *\n * Warning: using this function signature can lead to inconsistent behaviors on iOS and Android when multiple actions are started in parallel.\n *\n * @deprecated add the `type` and `name` of the action as first two arguments.\n * @param context: The additional context to send.\n * @param timestampMs: The timestamp when the action stopped (in milliseconds). If not provided, current timestamp will be used.\n */\n stopAction(context?: object, timestampMs?: number): Promise<void>;\n\n /**\n * Add a RUM Action.\n * @param type: The action type (tap, scroll, swipe, back, custom).\n * @param name: The action name.\n * @param context: The additional context to send.\n * @param timestampMs: The timestamp when the action occurred (in milliseconds). If not provided, current timestamp will be used.\n */\n addAction(\n type: RumActionType,\n name: string,\n context?: object,\n timestampMs?: number\n ): Promise<void>;\n\n /**\n * Start tracking a RUM Resource.\n * @param key: The resource unique key identifier.\n * @param method: The resource method (GET, POST, …).\n * @param url: The resource url.\n * @param context: The additional context to send.\n * @param timestampMs: The timestamp when the resource started (in milliseconds). If not provided, current timestamp will be used.\n */\n startResource(\n key: string,\n method: string,\n url: string,\n context?: object,\n timestampMs?: number\n ): Promise<void>;\n\n /**\n * Stop tracking a RUM Resource.\n * @param key: The resource unique key identifier.\n * @param statusCode: The resource status code.\n * @param kind: The resource's kind (xhr, document, image, css, font, …).\n * @param size: The resource size in bytes. If size is unknown, use -1.\n * @param context: The additional context to send.\n * @param timestampMs: The timestamp when the resource stopped (in milliseconds). If not provided, current timestamp will be used.\n */\n stopResource(\n key: string,\n statusCode: number,\n kind: ResourceKind,\n size?: number,\n context?: object,\n timestampMs?: number\n ): Promise<void>;\n\n /**\n * Add a RUM Error.\n * @param message: The error message.\n * @param source: The error source (network, source, console, webview, custom).\n * @param stacktrace: The error stacktrace.\n * @param context: The additional context to send.\n * @param timestampMs: The timestamp when the error occurred (in milliseconds). If not provided, current timestamp will be used.\n */\n addError(\n message: string,\n source: ErrorSource,\n stacktrace: string,\n context?: object,\n timestampMs?: number\n ): Promise<void>;\n\n /**\n * Adds a specific timing in the active View. The timing duration will be computed as the difference between the time the View was started and the time this function was called.\n * @param name: The name of the new custom timing attribute. Timings can be nested up to 8 levels deep. Names using more than 8 levels will be sanitized by SDK.\n */\n addTiming(name: string): Promise<void>;\n};\n\n/**\n * Describe the type of a RUM Action.\n */\nexport enum RumActionType {\n /** User tapped on a widget. */\n TAP = 'TAP',\n /** User scrolled a view. */\n SCROLL = 'SCROLL',\n /** User swiped on a view. */\n SWIPE = 'SWIPE',\n /** User pressed hardware back button (Android only). */\n BACK = 'BACK',\n /** A custom action. */\n CUSTOM = 'CUSTOM'\n}\n\nexport type ResourceKind =\n | 'image'\n | 'xhr'\n | 'beacon'\n | 'css'\n | 'document'\n | 'fetch'\n | 'font'\n | 'js'\n | 'media'\n | 'other'\n | 'native';\n\nexport enum ErrorSource {\n NETWORK = 'NETWORK',\n SOURCE = 'SOURCE',\n CONSOLE = 'CONSOLE',\n WEBVIEW = 'WEBVIEW',\n CUSTOM = 'CUSTOM'\n}\n\n/**\n * Type of instrumentation on the host.\n * - DATADOG: Datadog’s propagator (`x-datadog-*`)\n * - TRACECONTEXT: W3C Trace Context (`traceparent`)\n * - B3: B3 single header (`b3`)\n * - B3MULTI: B3 multiple headers (`X-B3-*`)\n */\nexport enum PropagatorType {\n DATADOG = 'datadog',\n TRACECONTEXT = 'tracecontext',\n B3 = 'b3',\n B3MULTI = 'b3multi'\n}\n\nexport type FirstPartyHost = {\n match: string;\n propagatorTypes: PropagatorType[];\n};\n"]}