@datadog/mobile-react-native 1.0.0-beta4 → 1.0.0-rc4

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 (103) hide show
  1. package/DatadogSDKReactNative.podspec +1 -1
  2. package/README.md +73 -1
  3. package/android/build.gradle +2 -3
  4. package/android/src/main/java/com/datadog/reactnative/DdRum.kt +25 -24
  5. package/android/src/main/java/com/datadog/reactnative/DdTrace.kt +6 -6
  6. package/ios/Sources/DdRum.m +10 -9
  7. package/ios/Sources/DdRum.swift +24 -24
  8. package/ios/Sources/DdTrace.m +2 -2
  9. package/ios/Sources/DdTrace.swift +6 -6
  10. package/ios/Sources/QueueHolder.swift +1 -1
  11. package/lib/commonjs/DdSdkReactNative.js +57 -0
  12. package/lib/commonjs/DdSdkReactNative.js.map +1 -1
  13. package/lib/commonjs/DdSdkReactNativeConfiguration.js +8 -0
  14. package/lib/commonjs/DdSdkReactNativeConfiguration.js.map +1 -1
  15. package/lib/commonjs/NativeSdkVerbosity.js +26 -0
  16. package/lib/commonjs/NativeSdkVerbosity.js.map +1 -0
  17. package/lib/commonjs/ProxyConfiguration.js +53 -0
  18. package/lib/commonjs/ProxyConfiguration.js.map +1 -0
  19. package/lib/commonjs/Timer.js +99 -0
  20. package/lib/commonjs/Timer.js.map +1 -0
  21. package/lib/commonjs/TrackingConsent.js +6 -0
  22. package/lib/commonjs/TrackingConsent.js.map +1 -1
  23. package/lib/commonjs/foundation.js +88 -8
  24. package/lib/commonjs/foundation.js.map +1 -1
  25. package/lib/commonjs/index.js +14 -0
  26. package/lib/commonjs/index.js.map +1 -1
  27. package/lib/commonjs/rum/instrumentation/DdEventsInterceptor.js +51 -11
  28. package/lib/commonjs/rum/instrumentation/DdEventsInterceptor.js.map +1 -1
  29. package/lib/commonjs/rum/instrumentation/DdRumErrorTracking.js +38 -6
  30. package/lib/commonjs/rum/instrumentation/DdRumErrorTracking.js.map +1 -1
  31. package/lib/commonjs/rum/instrumentation/DdRumResourceTracking.js +103 -18
  32. package/lib/commonjs/rum/instrumentation/DdRumResourceTracking.js.map +1 -1
  33. package/lib/commonjs/types.js.map +1 -1
  34. package/lib/commonjs/version.js +10 -0
  35. package/lib/commonjs/version.js.map +1 -0
  36. package/lib/module/DdSdkReactNative.js +56 -1
  37. package/lib/module/DdSdkReactNative.js.map +1 -1
  38. package/lib/module/DdSdkReactNativeConfiguration.js +9 -1
  39. package/lib/module/DdSdkReactNativeConfiguration.js.map +1 -1
  40. package/lib/module/NativeSdkVerbosity.js +18 -0
  41. package/lib/module/NativeSdkVerbosity.js.map +1 -0
  42. package/lib/module/ProxyConfiguration.js +46 -0
  43. package/lib/module/ProxyConfiguration.js.map +1 -0
  44. package/lib/module/Timer.js +90 -0
  45. package/lib/module/Timer.js.map +1 -0
  46. package/lib/module/TrackingConsent.js +6 -0
  47. package/lib/module/TrackingConsent.js.map +1 -1
  48. package/lib/module/foundation.js +89 -3
  49. package/lib/module/foundation.js.map +1 -1
  50. package/lib/module/index.js +2 -1
  51. package/lib/module/index.js.map +1 -1
  52. package/lib/module/rum/instrumentation/DdEventsInterceptor.js +51 -11
  53. package/lib/module/rum/instrumentation/DdEventsInterceptor.js.map +1 -1
  54. package/lib/module/rum/instrumentation/DdRumErrorTracking.js +37 -6
  55. package/lib/module/rum/instrumentation/DdRumErrorTracking.js.map +1 -1
  56. package/lib/module/rum/instrumentation/DdRumResourceTracking.js +96 -18
  57. package/lib/module/rum/instrumentation/DdRumResourceTracking.js.map +1 -1
  58. package/lib/module/types.js.map +1 -1
  59. package/lib/module/version.js +3 -0
  60. package/lib/module/version.js.map +1 -0
  61. package/lib/typescript/DdSdkReactNative.d.ts +11 -0
  62. package/lib/typescript/DdSdkReactNativeConfiguration.d.ts +6 -0
  63. package/lib/typescript/NativeSdkVerbosity.d.ts +9 -0
  64. package/lib/typescript/ProxyConfiguration.d.ts +56 -0
  65. package/lib/typescript/Timer.d.ts +20 -0
  66. package/lib/typescript/index.d.ts +2 -1
  67. package/lib/typescript/rum/instrumentation/DdEventsInterceptor.d.ts +2 -0
  68. package/lib/typescript/rum/instrumentation/DdRumErrorTracking.d.ts +2 -0
  69. package/lib/typescript/rum/instrumentation/DdRumResourceTracking.d.ts +4 -0
  70. package/lib/typescript/rum/instrumentation/DdRumXhr.d.ts +2 -2
  71. package/lib/typescript/types.d.ts +25 -24
  72. package/lib/typescript/version.d.ts +1 -0
  73. package/package.json +12 -13
  74. package/src/DdSdkReactNative.tsx +47 -0
  75. package/src/DdSdkReactNativeConfiguration.tsx +7 -1
  76. package/src/NativeSdkVerbosity.tsx +15 -0
  77. package/src/ProxyConfiguration.tsx +37 -0
  78. package/src/Timer.ts +96 -0
  79. package/src/TrackingConsent.tsx +6 -0
  80. package/src/__tests__/DdRumWrapper.test.tsx +91 -0
  81. package/src/__tests__/DdSdkReactNative.test.tsx +541 -0
  82. package/src/__tests__/Timer.test.ts +145 -0
  83. package/src/__tests__/rum/instrumentation/DdEventsInterceptor.test.tsx +222 -0
  84. package/src/__tests__/rum/instrumentation/DdRumErrorTracking.test.tsx +314 -0
  85. package/src/__tests__/rum/instrumentation/DdRumResourceTracking.test.tsx +677 -0
  86. package/src/__tests__/rum/instrumentation/DdRumUserInteractionTracking.test.tsx +188 -0
  87. package/src/__tests__/rum/instrumentation/TraceIdentifier.test.tsx +33 -0
  88. package/src/foundation.tsx +83 -3
  89. package/src/index.tsx +3 -2
  90. package/src/rum/instrumentation/DdEventsInterceptor.tsx +40 -10
  91. package/src/rum/instrumentation/DdRumErrorTracking.tsx +56 -25
  92. package/src/rum/instrumentation/DdRumResourceTracking.tsx +92 -22
  93. package/src/rum/instrumentation/DdRumXhr.tsx +6 -5
  94. package/src/types.tsx +25 -24
  95. package/src/version.ts +2 -0
  96. package/android/.project +0 -17
  97. package/android/.settings/org.eclipse.buildship.core.prefs +0 -13
  98. package/android/gradle/wrapper/gradle-wrapper.jar +0 -0
  99. package/android/gradle/wrapper/gradle-wrapper.properties +0 -6
  100. package/android/gradlew +0 -185
  101. package/android/gradlew.bat +0 -104
  102. package/ios/DdSdkReactNative.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist +0 -8
  103. package/ios/Tests/ModulesTest.swift +0 -43
@@ -7,18 +7,18 @@ function _defineProperty(obj, key, value) { if (key in obj) { Object.definePrope
7
7
  */
8
8
  import { Platform } from 'react-native';
9
9
  import { DdRum } from '../../foundation';
10
+ import Timer from '../../Timer';
10
11
  import { generateTraceId } from './TraceIdentifier';
11
12
  export const TRACE_ID_HEADER_KEY = "x-datadog-trace-id";
12
13
  export const PARENT_ID_HEADER_KEY = "x-datadog-parent-id";
13
14
  export const ORIGIN_HEADER_KEY = "x-datadog-origin";
15
+ export const SAMPLING_PRIORITY_HEADER_KEY = "x-datadog-sampling-priority";
16
+ export const SAMPLED_HEADER_KEY = "x-datadog-sampled";
14
17
  export const ORIGIN_RUM = "rum";
15
- const MISSING_TIME = -1;
18
+ const RESPONSE_START_LABEL = "response_start";
19
+ const MISSING_RESOURCE_SIZE = -1;
16
20
 
17
21
  function createTimings(startTime, responseStartTime, responseEndTime) {
18
- if (startTime === MISSING_TIME || responseStartTime === MISSING_TIME) {
19
- return null;
20
- }
21
-
22
22
  const firstByte = formatTiming(startTime, startTime, responseStartTime);
23
23
  const download = formatTiming(startTime, responseStartTime, responseEndTime); // needed for iOS, simply total duration from start to end
24
24
 
@@ -48,11 +48,86 @@ function formatTiming(origin, start, end) {
48
48
  function timeToNanos(durationMs) {
49
49
  return +(durationMs * 1e6).toFixed(0);
50
50
  }
51
+
52
+ function byteLength(str) {
53
+ // This is a weird trick, but it works.
54
+ // Output is the same as TextEncoder.encode(...).length
55
+ return unescape(encodeURI(str)).length;
56
+ }
57
+
58
+ function getResponseContentLengthFromHeader(xhr) {
59
+ var _xhr$getResponseHeade;
60
+
61
+ const contentLengthHeader = parseInt((_xhr$getResponseHeade = xhr.getResponseHeader('Content-Length')) !== null && _xhr$getResponseHeade !== void 0 ? _xhr$getResponseHeade : '', 10);
62
+
63
+ if (!isNaN(contentLengthHeader)) {
64
+ return contentLengthHeader;
65
+ }
66
+
67
+ return null;
68
+ }
69
+
70
+ export function calculateResponseSize(xhr) {
71
+ const contentLengthHeader = getResponseContentLengthFromHeader(xhr);
72
+
73
+ if (contentLengthHeader != null) {
74
+ return contentLengthHeader;
75
+ }
76
+
77
+ const response = xhr.response;
78
+
79
+ if (!response) {
80
+ return MISSING_RESOURCE_SIZE;
81
+ }
82
+
83
+ let size;
84
+
85
+ try {
86
+ switch (xhr.responseType) {
87
+ case '':
88
+ case 'text':
89
+ // String
90
+ size = byteLength(response);
91
+ break;
92
+
93
+ case 'blob':
94
+ size = response.size;
95
+ break;
96
+
97
+ case 'arraybuffer':
98
+ size = response.byteLength;
99
+ break;
100
+
101
+ case 'document':
102
+ // currently not supported by RN as of 0.66
103
+ // HTML Document or XML Document
104
+ break;
105
+
106
+ case 'json':
107
+ // plain JS object
108
+ // original size was lost, because this is the object which was parsed.
109
+ // We can only convert back to the string and calculate the size,
110
+ // which will roughly match original.
111
+ size = byteLength(JSON.stringify(response));
112
+ break;
113
+
114
+ default:
115
+ break;
116
+ }
117
+ } catch (e) {
118
+ console.error("Couldn't get resource size, because of the error", e);
119
+ }
120
+
121
+ if (typeof size !== 'number') {
122
+ return MISSING_RESOURCE_SIZE;
123
+ }
124
+
125
+ return size;
126
+ }
51
127
  /**
52
128
  * Provides RUM auto-instrumentation feature to track resources (fetch, XHR, axios) as RUM events.
53
129
  */
54
130
 
55
-
56
131
  export class DdRumResourceTracking {
57
132
  /**
58
133
  * Starts tracking resources and sends a RUM Resource event every time a network request is detected.
@@ -101,10 +176,9 @@ export class DdRumResourceTracking {
101
176
  const traceId = generateTraceId();
102
177
  this._datadog_xhr = {
103
178
  method,
104
- startTime: MISSING_TIME,
105
- responseStartTime: MISSING_TIME,
106
179
  url: url,
107
180
  reported: false,
181
+ timer: new Timer(),
108
182
  spanId: spanId,
109
183
  traceId: traceId
110
184
  }; // eslint-disable-next-line prefer-rest-params
@@ -119,10 +193,13 @@ export class DdRumResourceTracking {
119
193
  xhrType.prototype.send = function () {
120
194
  if (this._datadog_xhr) {
121
195
  // keep track of start time
122
- this._datadog_xhr.startTime = Date.now();
196
+ this._datadog_xhr.timer.start();
197
+
123
198
  this.setRequestHeader(TRACE_ID_HEADER_KEY, this._datadog_xhr.traceId);
124
199
  this.setRequestHeader(PARENT_ID_HEADER_KEY, this._datadog_xhr.spanId);
125
200
  this.setRequestHeader(ORIGIN_HEADER_KEY, ORIGIN_RUM);
201
+ this.setRequestHeader(SAMPLING_PRIORITY_HEADER_KEY, "1");
202
+ this.setRequestHeader(SAMPLED_HEADER_KEY, "1");
126
203
  }
127
204
 
128
205
  DdRumResourceTracking.proxyOnReadyStateChange(this, xhrType); // eslint-disable-next-line prefer-rest-params
@@ -140,8 +217,8 @@ export class DdRumResourceTracking {
140
217
  DdRumResourceTracking.reportXhr(xhrProxy);
141
218
  xhrProxy._datadog_xhr.reported = true;
142
219
  }
143
- } else if (xhrProxy.readyState === xhrType.HEADERS_RECEIVED && xhrProxy._datadog_xhr.responseStartTime === MISSING_TIME) {
144
- xhrProxy._datadog_xhr.responseStartTime = Date.now();
220
+ } else if (xhrProxy.readyState === xhrType.HEADERS_RECEIVED) {
221
+ xhrProxy._datadog_xhr.timer.recordTick(RESPONSE_START_LABEL);
145
222
  }
146
223
 
147
224
  if (originalOnreadystatechange) {
@@ -152,16 +229,17 @@ export class DdRumResourceTracking {
152
229
  }
153
230
 
154
231
  static reportXhr(xhrProxy) {
232
+ const responseSize = calculateResponseSize(xhrProxy);
155
233
  const context = xhrProxy._datadog_xhr;
156
- const key = context.startTime + "/" + context.method + "/" + context.startTime;
157
- const responseEndTime = Date.now();
158
- DdRum.startResource(key, context.method, context.url, context.startTime, {
234
+ const key = context.timer.startTime + "/" + context.method;
235
+ context.timer.stop();
236
+ DdRum.startResource(key, context.method, context.url, {
159
237
  "_dd.span_id": context.spanId,
160
238
  "_dd.trace_id": context.traceId
161
- }).then(() => {
162
- DdRum.stopResource(key, xhrProxy.status, "xhr", responseEndTime, {
163
- "_dd.resource_timings": createTimings(context.startTime, context.responseStartTime, responseEndTime)
164
- });
239
+ }, context.timer.startTime).then(() => {
240
+ DdRum.stopResource(key, xhrProxy.status, "xhr", responseSize, {
241
+ "_dd.resource_timings": context.timer.hasTickFor(RESPONSE_START_LABEL) ? createTimings(context.timer.startTime, context.timer.timeAt(RESPONSE_START_LABEL), context.timer.stopTime) : null
242
+ }, context.timer.stopTime);
165
243
  });
166
244
  }
167
245
 
@@ -1 +1 @@
1
- {"version":3,"sources":["DdRumResourceTracking.tsx"],"names":["Platform","DdRum","generateTraceId","TRACE_ID_HEADER_KEY","PARENT_ID_HEADER_KEY","ORIGIN_HEADER_KEY","ORIGIN_RUM","MISSING_TIME","createTimings","startTime","responseStartTime","responseEndTime","firstByte","formatTiming","download","fetch","origin","start","end","duration","timeToNanos","OS","durationMs","toFixed","DdRumResourceTracking","startTracking","startTrackingInternal","XMLHttpRequest","xhrType","isTracking","originalXhrOpen","prototype","open","originalXhrSend","send","proxyXhr","stopTracking","proxyOpen","proxySend","method","url","spanId","traceId","_datadog_xhr","reported","apply","arguments","Date","now","setRequestHeader","proxyOnReadyStateChange","xhrProxy","originalOnreadystatechange","onreadystatechange","readyState","DONE","reportXhr","HEADERS_RECEIVED","context","key","startResource","then","stopResource","status"],"mappings":";;AAAA;AACA;AACA;AACA;AACA;AAEA,SAASA,QAAT,QAAyB,cAAzB;AACA,SAASC,KAAT,QAAsB,kBAAtB;AAEA,SAASC,eAAT,QAAgC,mBAAhC;AAEA,OAAO,MAAMC,mBAAmB,GAAG,oBAA5B;AACP,OAAO,MAAMC,oBAAoB,GAAG,qBAA7B;AACP,OAAO,MAAMC,iBAAiB,GAAG,kBAA1B;AACP,OAAO,MAAMC,UAAU,GAAG,KAAnB;AAEP,MAAMC,YAAY,GAAG,CAAC,CAAtB;;AAuBA,SAASC,aAAT,CAAuBC,SAAv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AT,CAAsBjC,iBAAtB,GAA0CqC,IAAI,CAACC,GAAL,EAA1C;AACD;;AAED,UAAII,0BAAJ,EAAgC;AAC9B;AACAA,QAAAA,0BAA0B,CAACP,KAA3B,CAAiCM,QAAjC,EAA2CL,SAA3C;AACD;AACF,KAfD;AAgBD;;AAEuB,SAATU,SAAS,CAACL,QAAD,EAA2B;AAEjD,UAAMO,OAAO,GAAGP,QAAQ,CAACR,YAAzB;AAEA,UAAMgB,GAAG,GAAGD,OAAO,CAACjD,SAAR,GAAoB,GAApB,GACRiD,OAAO,CAACnB,MADA,GACS,GADT,GAERmB,OAAO,CAACjD,SAFZ;AAIA,UAAME,eAAe,GAAGoC,IAAI,CAACC,GAAL,EAAxB;AAEA/C,IAAAA,KAAK,CAAC2D,aAAN,CACED,GADF,EAEED,OAAO,CAACnB,MAFV,EAGEmB,OAAO,CAAClB,GAHV,EAIEkB,OAAO,CAACjD,SAJV,EAKE;AACE,qBAAeiD,OAAO,CAACjB,MADzB;AAEE,sBAAgBiB,OAAO,CAAChB;AAF1B,KALF,EASEmB,IATF,CASO,MAAM;AACX5D,MAAAA,KAAK,CAAC6D,YAAN,CACEH,GADF,EAEER,QAAQ,CAACY,MAFX,EAGE,KAHF,EAIEpD,eAJF,EAKE;AACE,gCAAwBH,aAAa,CAACkD,OAAO,CAACjD,SAAT,EAAoBiD,OAAO,CAAChD,iBAA5B,EAA+CC,eAA/C;AADvC,OALF;AAQD,KAlBD;AAmBD;;AAvIgC;;gBAAtBa,qB,gBAEiB,K;;gBAFjBA,qB;;gBAAAA,qB","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 { Platform } from 'react-native';\nimport { DdRum } from '../../foundation'\nimport type { DdRumXhr } from './DdRumXhr'\nimport { generateTraceId } from './TraceIdentifier';\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 ORIGIN_RUM = \"rum\"\n\nconst MISSING_TIME = -1\n\ninterface Timing {\n /**\n * Time relative (absolute in case of iOS) to some point, in ns.\n */\n startTime: number\n /**\n * Duration in ns.\n */\n duration: number\n}\n\ninterface ResourceTimings {\n // unlike in Performance API it is not the time until request\n // starts (requestStart, before it can be connect, SSL, DNS),\n // but the time until the response is first seen\n firstByte: Timing,\n download: Timing,\n // required by iOS, total timing from the beginning to the end\n fetch: Timing\n}\n\nfunction createTimings(startTime: number,\n responseStartTime: number, responseEndTime: number): ResourceTimings | null {\n\n if (startTime === MISSING_TIME || responseStartTime === MISSING_TIME) {\n return null\n }\n\n const firstByte = formatTiming(startTime, startTime, responseStartTime)\n const download = formatTiming(startTime, responseStartTime, responseEndTime)\n // needed for iOS, simply total duration from start to end\n const fetch = formatTiming(startTime, startTime, responseEndTime)\n\n return {\n firstByte,\n download,\n fetch\n }\n}\n\n/**\n * @param origin Start time (absolute) of the request\n * @param start Start time (absolute) of the timing\n * @param end End time (absolute) of the timing\n */\nfunction formatTiming(origin: number, start: number, end: number): Timing {\n return {\n duration: timeToNanos(end - start),\n // if it is Android, startTime should be relative to the origin,\n // if it is iOS - absolute (unix timestamp)\n startTime: Platform.OS === 'ios' ? timeToNanos(start) : timeToNanos(start - origin)\n }\n}\n\nfunction timeToNanos(durationMs: number): number {\n return +(durationMs * 1e6).toFixed(0)\n}\n\n/**\n* Provides RUM auto-instrumentation feature to track resources (fetch, XHR, axios) as RUM events.\n*/\nexport class DdRumResourceTracking {\n\n private static isTracking = false\n\n private static originalXhrOpen: any\n private static originalXhrSend: any\n\n /**\n * Starts tracking resources and sends a RUM Resource event every time a network request is detected.\n */\n static startTracking(): void {\n DdRumResourceTracking.startTrackingInternal(XMLHttpRequest);\n }\n\n /**\n * Starts tracking resources and sends a RUM Resource event every time a fetch or XHR call is detected.\n */\n // eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types\n static startTrackingInternal(xhrType: any): void {\n // extra safety to avoid proxying the XHR class twice\n if (DdRumResourceTracking.isTracking) {\n return\n }\n\n DdRumResourceTracking.originalXhrOpen = xhrType.prototype.open;\n DdRumResourceTracking.originalXhrSend = xhrType.prototype.send;\n\n DdRumResourceTracking.proxyXhr(xhrType)\n }\n\n\n static stopTracking(): void {\n if (DdRumResourceTracking.isTracking) {\n DdRumResourceTracking.isTracking = false;\n XMLHttpRequest.prototype.open = DdRumResourceTracking.originalXhrOpen;\n XMLHttpRequest.prototype.send = DdRumResourceTracking.originalXhrSend;\n }\n }\n\n // eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types\n static proxyXhr(xhrType: any): void {\n this.proxyOpen(xhrType);\n this.proxySend(xhrType);\n }\n\n private static proxyOpen(xhrType: any): void {\n const originalXhrOpen = this.originalXhrOpen;\n xhrType.prototype.open = function (this: DdRumXhr, method: string, url: string) {\n // Keep track of the method and url\n // start time is tracked by the `send` method\n const spanId = generateTraceId()\n const traceId = generateTraceId()\n this._datadog_xhr = {\n method,\n startTime: MISSING_TIME,\n responseStartTime: MISSING_TIME,\n url: url,\n reported: false,\n spanId: spanId,\n traceId: traceId\n }\n // eslint-disable-next-line prefer-rest-params\n return originalXhrOpen.apply(this, arguments as any)\n }\n }\n\n private static proxySend(xhrType: any): void {\n const originalXhrSend = this.originalXhrSend;\n xhrType.prototype.send = function (this: DdRumXhr) {\n\n if (this._datadog_xhr) {\n // keep track of start time\n this._datadog_xhr.startTime = Date.now()\n this.setRequestHeader(TRACE_ID_HEADER_KEY, this._datadog_xhr.traceId)\n this.setRequestHeader(PARENT_ID_HEADER_KEY, this._datadog_xhr.spanId)\n this.setRequestHeader(ORIGIN_HEADER_KEY, ORIGIN_RUM)\n\n }\n\n DdRumResourceTracking.proxyOnReadyStateChange(this, xhrType);\n\n // eslint-disable-next-line prefer-rest-params\n return originalXhrSend.apply(this, arguments as any);\n }\n }\n\n private static proxyOnReadyStateChange(xhrProxy: DdRumXhr, xhrType: any): void {\n const originalOnreadystatechange = xhrProxy.onreadystatechange\n xhrProxy.onreadystatechange = function () {\n if (xhrProxy.readyState === xhrType.DONE) {\n if (!xhrProxy._datadog_xhr.reported) {\n DdRumResourceTracking.reportXhr(xhrProxy);\n xhrProxy._datadog_xhr.reported = true;\n }\n } else if (xhrProxy.readyState === xhrType.HEADERS_RECEIVED\n && xhrProxy._datadog_xhr.responseStartTime === MISSING_TIME) {\n xhrProxy._datadog_xhr.responseStartTime = Date.now()\n }\n\n if (originalOnreadystatechange) {\n // eslint-disable-next-line prefer-rest-params\n originalOnreadystatechange.apply(xhrProxy, arguments as any)\n }\n }\n }\n\n private static reportXhr(xhrProxy: DdRumXhr): void {\n\n const context = xhrProxy._datadog_xhr\n\n const key = context.startTime + \"/\"\n + context.method + \"/\"\n + context.startTime\n\n const responseEndTime = Date.now()\n\n DdRum.startResource(\n key,\n context.method,\n context.url,\n context.startTime,\n {\n \"_dd.span_id\": context.spanId,\n \"_dd.trace_id\": context.traceId\n }\n ).then(() => {\n DdRum.stopResource(\n key,\n xhrProxy.status,\n \"xhr\",\n responseEndTime,\n {\n \"_dd.resource_timings\": createTimings(context.startTime, context.responseStartTime, responseEndTime),\n });\n })\n }\n\n}\n"]}
1
+ {"version":3,"sources":["DdRumResourceTracking.tsx"],"names":["Platform","DdRum","Timer","generateTraceId","TRACE_ID_HEADER_KEY","PARENT_ID_HEADER_KEY","ORIGIN_HEADER_KEY","SAMPLING_PRIORITY_HEADER_KEY","SAMPLED_HEADER_KEY","ORIGIN_RUM","RESPONSE_START_LABEL","MISSING_RESOURCE_SIZE","createTimings","startTime","responseStartTime","responseEndTime","firstByte","formatTiming","download","fetch","origin","start","end","duration","timeToNanos","OS","durationMs","toFixed","byteLength","str","unescape","encodeURI","length","getResponseContentLengthFromHeader","xhr","contentLengthHeader","parseInt","getResponseHeader","isNaN","calculateResponseSize","response","size","responseType","JSON","stringify","e","console","error","DdRumResourceTracking","startTracking","startTrackingInternal","XMLHttpRequest","xhrType","isTracking","originalXhrOpen","prototype","open","originalXhrSend","send","proxyXhr","stopTracking","proxyOpen","proxySend","method","url","spanId","traceId","_datadog_xhr","reported","timer","apply","arguments","setRequestHeader","proxyOnReadyStateChange","xhrProxy","originalOnreadystatechange","onreadystatechange","readyState","DONE","reportXhr","HEADERS_RECEIVED","recordTick","responseSize","context","key","stop","startResource","then","stopResource","status","hasTickFor","timeAt","stopTime"],"mappings":";;AAAA;AACA;AACA;AACA;AACA;AAEA,SAASA,QAAT,QAAyB,cAAzB;AACA,SAASC,KAAT,QAAsB,kBAAtB;AACA,OAAOC,KAAP,MAAkB,aAAlB;AAEA,SAASC,eAAT,QAAgC,mBAAhC;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,kBAAkB,GAAG,mBAA3B;AACP,OAAO,MAAMC,UAAU,GAAG,KAAnB;AAEP,MAAMC,oBAAoB,GAAG,gBAA7B;AACA,MAAMC,qBAAqB,GAAG,CAAC,CAA/B;;AAuBA,SAASC,aAAT,CAAuBC,SAAvB,EACEC,iBADF,EAC6BC,eAD7B,EACuE;AAErE,QAAMC,SAAS,GAAGC,YAAY,CAACJ,SAAD,EAAYA,SAAZ,EAAuBC,iBAAvB,CAA9B;AACA,QAAMI,QAAQ,GAAGD,YAAY,CAACJ,SAAD,EAAYC,iBAAZ,EAA+BC,eAA/B,CAA7B,CAHqE,CAIrE;;AACA,QAAMI,KAAK,GAAGF,YAAY,CAACJ,SAAD,EAAYA,SAAZ,EAAuBE,eAAvB,CAA1B;AAEA,SAAO;AACLC,IAAAA,SADK;AAELE,IAAAA,QAFK;AAGLC,IAAAA;AAHK,GAAP;AAKD;AAED;AACA;AACA;AACA;AACA;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,CAAcxD,SAAd,GAA0B,GAA1B,GAAgCsE,OAAO,CAACpB,MAApD;AAEAoB,IAAAA,OAAO,CAACd,KAAR,CAAcgB,IAAd;AAEApF,IAAAA,KAAK,CAACqF,aAAN,CACEF,GADF,EAEED,OAAO,CAACpB,MAFV,EAGEoB,OAAO,CAACnB,GAHV,EAIE;AACE,qBAAemB,OAAO,CAAClB,MADzB;AAEE,sBAAgBkB,OAAO,CAACjB;AAF1B,KAJF,EAQEiB,OAAO,CAACd,KAAR,CAAcxD,SARhB,EASE0E,IATF,CASO,MAAM;AACXtF,MAAAA,KAAK,CAACuF,YAAN,CACEJ,GADF,EAEEV,QAAQ,CAACe,MAFX,EAGE,KAHF,EAIEP,YAJF,EAKE;AACE,gCAAwBC,OAAO,CAACd,KAAR,CAAcqB,UAAd,CAAyBhF,oBAAzB,IACtBE,aAAa,CACXuE,OAAO,CAACd,KAAR,CAAcxD,SADH,EAEXsE,OAAO,CAACd,KAAR,CAAcsB,MAAd,CAAqBjF,oBAArB,CAFW,EAGXyE,OAAO,CAACd,KAAR,CAAcuB,QAHH,CADS,GAKlB;AANR,OALF,EAaET,OAAO,CAACd,KAAR,CAAcuB,QAbhB;AAeD,KAzBD;AA0BD;;AA7IgC;;gBAAtB5C,qB,gBAEiB,K;;gBAFjBA,qB;;gBAAAA,qB","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 { Platform } from 'react-native';\nimport { DdRum } from '../../foundation'\nimport Timer from '../../Timer';\nimport type { DdRumXhr } from './DdRumXhr'\nimport { generateTraceId } from './TraceIdentifier';\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 SAMPLED_HEADER_KEY = \"x-datadog-sampled\"\nexport const ORIGIN_RUM = \"rum\"\n\nconst RESPONSE_START_LABEL = \"response_start\"\nconst MISSING_RESOURCE_SIZE = -1\n\ninterface Timing {\n /**\n * Time relative (absolute in case of iOS) to some point, in ns.\n */\n startTime: number\n /**\n * Duration in ns.\n */\n duration: number\n}\n\ninterface ResourceTimings {\n // unlike in Performance API it is not the time until request\n // starts (requestStart, before it can be connect, SSL, DNS),\n // but the time until the response is first seen\n firstByte: Timing,\n download: Timing,\n // required by iOS, total timing from the beginning to the end\n fetch: Timing\n}\n\nfunction createTimings(startTime: number,\n responseStartTime: number, responseEndTime: number): ResourceTimings {\n\n const firstByte = formatTiming(startTime, startTime, responseStartTime)\n const download = formatTiming(startTime, responseStartTime, responseEndTime)\n // needed for iOS, simply total duration from start to end\n const fetch = formatTiming(startTime, startTime, responseEndTime)\n\n return {\n firstByte,\n download,\n fetch\n }\n}\n\n/**\n * @param origin Start time (absolute) of the request\n * @param start Start time (absolute) of the timing\n * @param end End time (absolute) of the timing\n */\nfunction formatTiming(origin: number, start: number, end: number): Timing {\n return {\n duration: timeToNanos(end - start),\n // if it is Android, startTime should be relative to the origin,\n // if it is iOS - absolute (unix timestamp)\n startTime: Platform.OS === 'ios' ? timeToNanos(start) : timeToNanos(start - origin)\n }\n}\n\nfunction timeToNanos(durationMs: number): number {\n return +(durationMs * 1e6).toFixed(0)\n}\n\nfunction byteLength(str: string): number {\n // This is a weird trick, but it works.\n // Output is the same as TextEncoder.encode(...).length\n return unescape(encodeURI(str)).length;\n}\n\nfunction getResponseContentLengthFromHeader(xhr: XMLHttpRequest): number | null {\n const contentLengthHeader = parseInt(xhr.getResponseHeader('Content-Length') ?? '', 10);\n if (!isNaN(contentLengthHeader)) {\n return contentLengthHeader;\n }\n return null;\n}\n\nexport function calculateResponseSize(xhr: XMLHttpRequest): number {\n\n const contentLengthHeader = getResponseContentLengthFromHeader(xhr);\n if (contentLengthHeader != null) {\n return contentLengthHeader as number;\n }\n\n const response = xhr.response\n if (!response) {\n return MISSING_RESOURCE_SIZE;\n }\n\n let size;\n try {\n switch (xhr.responseType) {\n case '':\n case 'text':\n // String\n size = byteLength(response);\n break;\n case 'blob':\n size = response.size;\n break;\n case 'arraybuffer':\n size = response.byteLength;\n break;\n case 'document':\n // currently not supported by RN as of 0.66\n // HTML Document or XML Document\n break;\n case 'json':\n // plain JS object\n // original size was lost, because this is the object which was parsed.\n // We can only convert back to the string and calculate the size,\n // which will roughly match original.\n size = byteLength(JSON.stringify(response))\n break;\n default:\n break;\n }\n } catch (e) {\n console.error(\"Couldn't get resource size, because of the error\", e);\n }\n\n if (typeof size !== 'number') {\n return MISSING_RESOURCE_SIZE;\n }\n return size;\n}\n\n/**\n* Provides RUM auto-instrumentation feature to track resources (fetch, XHR, axios) as RUM events.\n*/\nexport class DdRumResourceTracking {\n\n private static isTracking = false\n\n private static originalXhrOpen: any\n private static originalXhrSend: any\n\n /**\n * Starts tracking resources and sends a RUM Resource event every time a network request is detected.\n */\n static startTracking(): void {\n DdRumResourceTracking.startTrackingInternal(XMLHttpRequest);\n }\n\n /**\n * Starts tracking resources and sends a RUM Resource event every time a fetch or XHR call is detected.\n */\n // eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types\n static startTrackingInternal(xhrType: any): void {\n // extra safety to avoid proxying the XHR class twice\n if (DdRumResourceTracking.isTracking) {\n return\n }\n\n DdRumResourceTracking.originalXhrOpen = xhrType.prototype.open;\n DdRumResourceTracking.originalXhrSend = xhrType.prototype.send;\n\n DdRumResourceTracking.proxyXhr(xhrType)\n }\n\n\n static stopTracking(): void {\n if (DdRumResourceTracking.isTracking) {\n DdRumResourceTracking.isTracking = false;\n XMLHttpRequest.prototype.open = DdRumResourceTracking.originalXhrOpen;\n XMLHttpRequest.prototype.send = DdRumResourceTracking.originalXhrSend;\n }\n }\n\n // eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types\n static proxyXhr(xhrType: any): void {\n this.proxyOpen(xhrType);\n this.proxySend(xhrType);\n }\n\n private static proxyOpen(xhrType: any): void {\n const originalXhrOpen = this.originalXhrOpen;\n xhrType.prototype.open = function (this: DdRumXhr, method: string, url: string) {\n // Keep track of the method and url\n // start time is tracked by the `send` method\n const spanId = generateTraceId()\n const traceId = generateTraceId()\n this._datadog_xhr = {\n method,\n url: url,\n reported: false,\n timer: new Timer(),\n spanId: spanId,\n traceId: traceId\n }\n // eslint-disable-next-line prefer-rest-params\n return originalXhrOpen.apply(this, arguments as any)\n }\n }\n\n private static proxySend(xhrType: any): void {\n const originalXhrSend = this.originalXhrSend;\n xhrType.prototype.send = function (this: DdRumXhr) {\n\n if (this._datadog_xhr) {\n // keep track of start time\n this._datadog_xhr.timer.start()\n this.setRequestHeader(TRACE_ID_HEADER_KEY, this._datadog_xhr.traceId)\n this.setRequestHeader(PARENT_ID_HEADER_KEY, this._datadog_xhr.spanId)\n this.setRequestHeader(ORIGIN_HEADER_KEY, ORIGIN_RUM)\n this.setRequestHeader(SAMPLING_PRIORITY_HEADER_KEY, \"1\")\n this.setRequestHeader(SAMPLED_HEADER_KEY, \"1\")\n }\n\n DdRumResourceTracking.proxyOnReadyStateChange(this, xhrType);\n\n // eslint-disable-next-line prefer-rest-params\n return originalXhrSend.apply(this, arguments as any);\n }\n }\n\n private static proxyOnReadyStateChange(xhrProxy: DdRumXhr, xhrType: any): void {\n const originalOnreadystatechange = xhrProxy.onreadystatechange\n xhrProxy.onreadystatechange = function () {\n if (xhrProxy.readyState === xhrType.DONE) {\n if (!xhrProxy._datadog_xhr.reported) {\n DdRumResourceTracking.reportXhr(xhrProxy);\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\n private static reportXhr(xhrProxy: DdRumXhr): void {\n\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 DdRum.startResource(\n key,\n context.method,\n context.url,\n {\n \"_dd.span_id\": context.spanId,\n \"_dd.trace_id\": context.traceId\n },\n context.timer.startTime\n ).then(() => {\n DdRum.stopResource(\n key,\n xhrProxy.status,\n \"xhr\",\n responseSize,\n {\n \"_dd.resource_timings\": context.timer.hasTickFor(RESPONSE_START_LABEL) ?\n createTimings(\n context.timer.startTime,\n context.timer.timeAt(RESPONSE_START_LABEL),\n context.timer.stopTime\n ) : null\n },\n context.timer.stopTime\n );\n })\n }\n\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"sources":["types.tsx"],"names":["DdSdkConfiguration","constructor","clientToken","env","applicationId","nativeCrashReportEnabled","sampleRate","site","trackingConsent","additionalConfig"],"mappings":"AAAA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA,OAAO,MAAMA,kBAAN,CAAyB;AAC9BC,EAAAA,WAAW,CACAC,WADA,EAEAC,GAFA,EAGAC,aAHA,EAIAC,wBAJA,EAKAC,UALA,EAMAC,IANA,EAOAC,eAPA,EAQAC,gBARA,EAST;AAAA,SARSP,WAQT,GARSA,WAQT;AAAA,SAPSC,GAOT,GAPSA,GAOT;AAAA,SANSC,aAMT,GANSA,aAMT;AAAA,SALSC,wBAKT,GALSA,wBAKT;AAAA,SAJSC,UAIT,GAJSA,UAIT;AAAA,SAHSC,IAGT,GAHSA,IAGT;AAAA,SAFSC,eAET,GAFSA,eAET;AAAA,SADSC,gBACT,GADSA,gBACT;AAAE;;AAV0B;AAahC;AACA;AACA","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 * A configuration object to initialize Datadog's features.\n */\nexport class DdSdkConfiguration {\n constructor(\n readonly clientToken: string,\n readonly env: string,\n readonly applicationId: string,\n readonly nativeCrashReportEnabled: boolean,\n readonly sampleRate: number,\n readonly site: string,\n readonly trackingConsent: string,\n readonly additionalConfig: object\n ) {}\n}\n\n/**\n * The entry point to initialize Datadog's features.\n */\nexport type DdSdkType = {\n /**\n * Initializes Datadog's features.\n * @param configuration: The configuration to use.\n */\n initialize(configuration: DdSdkConfiguration): Promise<void>;\n\n /**\n * Sets the global context (set of attributes) attached with all future Logs, Spans and RUM events.\n * @param attributes: The global context attributes.\n */\n setAttributes(attributes: object): Promise<void>;\n\n /**\n * Set the user information.\n * @param user: The user object (use builtin attributes: 'id', 'email', 'name', and/or any custom attribute).\n */\n setUser(user: object): Promise<void>;\n\n /**\n * Set the tracking consent regarding the data collection.\n * @param trackingConsent: Consent, which can take one of the following values: 'pending', 'granted', 'not_granted'.\n */\n setTrackingConsent(trackingConsent: string): Promise<void>;\n\n};\n\n/**\n * The entry point to use Datadog's Logs feature.\n */\nexport type DdLogsType = {\n /**\n * Send a log with level debug.\n * @param message: The message to send.\n * @param context: The additional context to send.\n */\n debug(message: string, context: object): Promise<void>;\n\n /**\n * Send a log with level info.\n * @param message: The message to send.\n * @param context: The additional context to send.\n */\n info(message: string, context: object): Promise<void>;\n\n /**\n * Send a log with level warn.\n * @param message: The message to send.\n * @param context: The additional context to send.\n */\n warn(message: string, context: object): Promise<void>;\n\n /**\n * Send a log with level error.\n * @param message: The message to send.\n * @param context: The additional context to send.\n */\n error(message: string, context: object): Promise<void>;\n\n};\n\n/**\n * The entry point to use Datadog's Trace feature.\n */\nexport type DdTraceType = {\n /**\n * Start a span, and returns a unique identifier for the span.\n * @param operation: The operation name of the span.\n * @param timestampMs: The timestamp when the operation started (in milliseconds).\n * @param context: The additional context to send.\n */\n startSpan(operation: string, timestampMs: number, context: object): Promise<string>;\n\n /**\n * Finish a started span.\n * @param spanId: The unique identifier of the span.\n * @param timestampMs: The timestamp when the operation stopped (in milliseconds).\n * @param context: The additional context to send.\n */\n finishSpan(spanId: string, timestampMs: number, context: object): Promise<void>;\n\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 timestampMs: The timestamp when the view started (in milliseconds).\n * @param context: The additional context to send.\n */\n startView(key: string, name: string, timestampMs: number, context: object): Promise<void>;\n\n /**\n * Stop tracking a RUM View.\n * @param key: The view unique key identifier.\n * @param timestampMs: The timestamp when the view stopped (in milliseconds).\n * @param context: The additional context to send.\n */\n stopView(key: string, timestampMs: number, context: object): Promise<void>;\n\n /**\n * Start tracking a RUM Action.\n * @param type: The action type (tap, scroll, swipe, click, custom).\n * @param name: The action name.\n * @param timestampMs: The timestamp when the action started (in milliseconds).\n * @param context: The additional context to send.\n */\n startAction(type: string, name: string, timestampMs: number, context: object): Promise<void>;\n\n /**\n * Stop tracking the ongoing RUM Action.\n * @param timestampMs: The timestamp when the action stopped (in milliseconds).\n * @param context: The additional context to send.\n */\n stopAction(timestampMs: number, context: object): Promise<void>;\n\n /**\n * Add a RUM Action.\n * @param type: The action type (tap, scroll, swipe, click, custom).\n * @param name: The action name.\n * @param timestampMs: The timestamp when the action occurred (in milliseconds).\n * @param context: The additional context to send.\n */\n addAction(type: string, name: string, timestampMs: number, context: object): 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 timestampMs: The timestamp when the resource started (in milliseconds).\n * @param context: The additional context to send.\n */\n startResource(key: string, method: string, url: string, timestampMs: number, context: object): 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 timestampMs: The timestamp when the resource stopped (in milliseconds).\n * @param context: The additional context to send.\n */\n stopResource(key: string, statusCode: number, kind: string, timestampMs: number, context: object): Promise<void>;\n\n /**\n * Add a RUM Error.\n * @param message: The error message.\n * @param source: The error source (network, source, console, logger, …).\n * @param stacktrace: The error stacktrace.\n * @param timestampMs: The timestamp when the error occurred (in milliseconds).\n * @param context: The additional context to send.\n */\n addError(message: string, source: string, stacktrace: string, timestampMs: number, context: object): 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"]}
1
+ {"version":3,"sources":["types.tsx"],"names":["DdSdkConfiguration","constructor","clientToken","env","applicationId","nativeCrashReportEnabled","sampleRate","site","trackingConsent","additionalConfig"],"mappings":"AAAA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA,OAAO,MAAMA,kBAAN,CAAyB;AAC9BC,EAAAA,WAAW,CACAC,WADA,EAEAC,GAFA,EAGAC,aAHA,EAIAC,wBAJA,EAKAC,UALA,EAMAC,IANA,EAOAC,eAPA,EAQAC,gBARA,EAST;AAAA,SARSP,WAQT,GARSA,WAQT;AAAA,SAPSC,GAOT,GAPSA,GAOT;AAAA,SANSC,aAMT,GANSA,aAMT;AAAA,SALSC,wBAKT,GALSA,wBAKT;AAAA,SAJSC,UAIT,GAJSA,UAIT;AAAA,SAHSC,IAGT,GAHSA,IAGT;AAAA,SAFSC,eAET,GAFSA,eAET;AAAA,SADSC,gBACT,GADSA,gBACT;AAAE;;AAV0B;AAahC;AACA;AACA","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 * A configuration object to initialize Datadog's features.\n */\nexport class DdSdkConfiguration {\n constructor(\n readonly clientToken: string,\n readonly env: string,\n readonly applicationId: string,\n readonly nativeCrashReportEnabled: boolean,\n readonly sampleRate: number,\n readonly site: string,\n readonly trackingConsent: string,\n readonly additionalConfig: object\n ) {}\n}\n\n/**\n * The entry point to initialize Datadog's features.\n */\nexport type DdSdkType = {\n /**\n * Initializes Datadog's features.\n * @param configuration: The configuration to use.\n */\n initialize(configuration: DdSdkConfiguration): Promise<void>;\n\n /**\n * Sets the global context (set of attributes) attached with all future Logs, Spans and RUM events.\n * @param attributes: The global context attributes.\n */\n setAttributes(attributes: object): Promise<void>;\n\n /**\n * Set the user information.\n * @param user: The user object (use builtin attributes: 'id', 'email', 'name', and/or any custom attribute).\n */\n setUser(user: object): Promise<void>;\n\n /**\n * Set the tracking consent regarding the data collection.\n * @param trackingConsent: Consent, which can take one of the following values: 'pending', 'granted', 'not_granted'.\n */\n setTrackingConsent(trackingConsent: string): Promise<void>;\n\n};\n\n/**\n * The entry point to use Datadog's Logs feature.\n */\nexport type DdLogsType = {\n /**\n * Send a log with level debug.\n * @param message: The message to send.\n * @param context: The additional context to send.\n */\n debug(message: string, context?: object): Promise<void>;\n\n /**\n * Send a log with level info.\n * @param message: The message to send.\n * @param context: The additional context to send.\n */\n info(message: string, context?: object): Promise<void>;\n\n /**\n * Send a log with level warn.\n * @param message: The message to send.\n * @param context: The additional context to send.\n */\n warn(message: string, context?: object): Promise<void>;\n\n /**\n * Send a log with level error.\n * @param message: The message to send.\n * @param context: The additional context to send.\n */\n error(message: string, context?: object): Promise<void>;\n\n};\n\n/**\n * The entry point to use Datadog's Trace feature.\n */\nexport type DdTraceType = {\n /**\n * Start a span, and returns a unique identifier for the span.\n * @param operation: The operation name of the span.\n * @param context: The additional context to send.\n * @param timestampMs: The timestamp when the operation started (in milliseconds). If not provided, current timestamp will be used.\n */\n startSpan(operation: string, context?: object, timestampMs?: number): Promise<string>;\n\n /**\n * Finish a started span.\n * @param spanId: The unique identifier of the span.\n * @param context: The additional context to send.\n * @param timestampMs: The timestamp when the operation stopped (in milliseconds). If not provided, current timestamp will be used.\n */\n finishSpan(spanId: string, context?: object, timestampMs?: number): Promise<void>;\n\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(key: string, name: string, context?: object, timestampMs?: number): 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(key: string, context?: object, timestampMs?: number): Promise<void>;\n\n /**\n * Start tracking a RUM Action.\n * @param type: The action type (tap, scroll, swipe, click, 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(type: string, name: string, context?: object, timestampMs?: number): Promise<void>;\n\n /**\n * Stop tracking the ongoing RUM Action.\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, click, 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(type: string, name: string, context?: object, timestampMs?: number): 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(key: string, method: string, url: string, context?: object, timestampMs?: number): 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(key: string, statusCode: number, kind: string, size?: number, context?: object, timestampMs?: number): Promise<void>;\n\n /**\n * Add a RUM Error.\n * @param message: The error message.\n * @param source: The error source (network, source, console, logger, …).\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(message: string, source: string, stacktrace: string, context?: object, timestampMs?: number): 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"]}
@@ -0,0 +1,3 @@
1
+ // generated by genversion
2
+ export const version = '1.0.0-rc4';
3
+ //# sourceMappingURL=version.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["version.ts"],"names":["version"],"mappings":"AAAA;AACA,OAAO,MAAMA,OAAO,GAAG,WAAhB","sourcesContent":["// generated by genversion\nexport const version = '1.0.0-rc4';\n"]}
@@ -5,6 +5,17 @@ import type { TrackingConsent } from "./TrackingConsent";
5
5
  */
6
6
  export declare class DdSdkReactNative {
7
7
  private static readonly DD_SOURCE_KEY;
8
+ private static readonly DD_SDK_VERSION;
9
+ private static readonly DD_SERVICE_NAME;
10
+ private static readonly DD_SDK_VERBOSITY_KEY;
11
+ private static readonly DD_NATIVE_VIEW_TRACKING_KEY;
12
+ private static readonly DD_PROXY_TYPE_KEY;
13
+ private static readonly DD_PROXY_ADDRESS_KEY;
14
+ private static readonly DD_PROXY_PORT_KEY;
15
+ private static readonly DD_PROXY_USERNAME_KEY;
16
+ private static readonly DD_PROXY_PASSWORD_KEY;
17
+ private static readonly DD_NATIVE_LONG_TASK_THRESHOLD_KEY;
18
+ private static readonly NATIVE_LONG_TASK_THRESHOLD_MS;
8
19
  private static wasInitialized;
9
20
  /**
10
21
  * Initializes the Datadog SDK.
@@ -1,4 +1,6 @@
1
1
  import { TrackingConsent } from './TrackingConsent';
2
+ import type { NativeSdkVerbosity } from './NativeSdkVerbosity';
3
+ import type { ProxyConfiguration } from './ProxyConfiguration';
2
4
  /**
3
5
  * The SDK configuration class.
4
6
  * It will be used to configure the SDK functionality at initialization.
@@ -14,6 +16,10 @@ export declare class DdSdkReactNativeConfiguration {
14
16
  nativeCrashReportEnabled: boolean;
15
17
  sampleRate: number;
16
18
  site: string;
19
+ verbosity: NativeSdkVerbosity | undefined;
20
+ nativeViewTracking: boolean;
21
+ proxyConfig?: ProxyConfiguration;
22
+ serviceName?: string;
17
23
  additionalConfig: {
18
24
  [k: string]: any;
19
25
  };
@@ -0,0 +1,9 @@
1
+ /**
2
+ * Enum specifying possible consent options for DD SDK.
3
+ */
4
+ export declare enum NativeSdkVerbosity {
5
+ DEBUG = "debug",
6
+ INFO = "info",
7
+ WARN = "warn",
8
+ ERROR = "error"
9
+ }
@@ -0,0 +1,56 @@
1
+ /**
2
+ * Proxy server configuration.
3
+ */
4
+ declare class ProxyConfiguration {
5
+ /**
6
+ * Proxy type.
7
+ */
8
+ readonly type: ProxyType;
9
+ /**
10
+ * Proxy address. Can be either in the IP address format, ex. "1.1.1.1", or hostname, ex. "example.com".
11
+ */
12
+ readonly address: string;
13
+ /**
14
+ * Proxy port.
15
+ */
16
+ readonly port: number;
17
+ /**
18
+ * Username for Basic authentication scheme.
19
+ *
20
+ * Note: "SOCKS + authentication" scheme is not supported.
21
+ */
22
+ readonly username?: string | undefined;
23
+ /**
24
+ * Password for Basic authentication scheme.
25
+ */
26
+ readonly password?: string | undefined;
27
+ constructor(
28
+ /**
29
+ * Proxy type.
30
+ */
31
+ type: ProxyType,
32
+ /**
33
+ * Proxy address. Can be either in the IP address format, ex. "1.1.1.1", or hostname, ex. "example.com".
34
+ */
35
+ address: string,
36
+ /**
37
+ * Proxy port.
38
+ */
39
+ port: number,
40
+ /**
41
+ * Username for Basic authentication scheme.
42
+ *
43
+ * Note: "SOCKS + authentication" scheme is not supported.
44
+ */
45
+ username?: string | undefined,
46
+ /**
47
+ * Password for Basic authentication scheme.
48
+ */
49
+ password?: string | undefined);
50
+ }
51
+ declare enum ProxyType {
52
+ HTTP = "http",
53
+ HTTPS = "https",
54
+ SOCKS = "socks"
55
+ }
56
+ export { ProxyConfiguration, ProxyType };
@@ -0,0 +1,20 @@
1
+ /**
2
+ * Simple timer which records time ticks. Shouldn't be re-used once stopped.
3
+ * All timestamps/durations returned are in milliseconds.
4
+ */
5
+ export default class Timer {
6
+ private times;
7
+ get startTime(): number;
8
+ get stopTime(): number;
9
+ start(): void;
10
+ stop(): void;
11
+ recordTick(label: string): void;
12
+ hasTickFor(label: string): boolean;
13
+ durationBetween(startLabel: string, endLabel: string): number;
14
+ timeAt(label: string): number;
15
+ reset(): void;
16
+ private durationBetweenTicks;
17
+ private performanceNow;
18
+ private canUsePerformanceNow;
19
+ private checkLabelExists;
20
+ }
@@ -1,5 +1,6 @@
1
1
  import { DdLogs, DdTrace, DdRum } from './foundation';
2
2
  import { DdSdkReactNativeConfiguration } from './DdSdkReactNativeConfiguration';
3
3
  import { DdSdkReactNative } from './DdSdkReactNative';
4
+ import { ProxyConfiguration, ProxyType } from './ProxyConfiguration';
4
5
  import { TrackingConsent } from './TrackingConsent';
5
- export { DdLogs, DdTrace, DdRum, DdSdkReactNativeConfiguration, DdSdkReactNative, TrackingConsent };
6
+ export { DdLogs, DdTrace, DdRum, DdSdkReactNativeConfiguration, DdSdkReactNative, ProxyConfiguration, ProxyType, TrackingConsent };
@@ -5,6 +5,8 @@ export declare class DdEventsInterceptor implements EventsInterceptor {
5
5
  interceptOnPress(...args: any[]): void;
6
6
  private handleTargetEvent;
7
7
  private resolveTargetName;
8
+ private resolveElementTypeName;
9
+ private findClosestActionLabel;
8
10
  }
9
11
  /**
10
12
  * Describe the type of a RUM Action.
@@ -3,6 +3,7 @@
3
3
  */
4
4
  export declare class DdRumErrorTracking {
5
5
  private static isTracking;
6
+ private static isInDefaultErrorHandler;
6
7
  private static defaultErrorHandler;
7
8
  private static defaultConsoleError;
8
9
  /**
@@ -11,5 +12,6 @@ export declare class DdRumErrorTracking {
11
12
  static startTracking(): void;
12
13
  static onGlobalError(error: any, isFatal?: boolean): void;
13
14
  static onConsoleError(...params: unknown[]): void;
15
+ private static getErrorMessage;
14
16
  private static getErrorStackTrace;
15
17
  }
@@ -1,7 +1,11 @@
1
+ /// <reference types="react-native" />
1
2
  export declare const TRACE_ID_HEADER_KEY = "x-datadog-trace-id";
2
3
  export declare const PARENT_ID_HEADER_KEY = "x-datadog-parent-id";
3
4
  export declare const ORIGIN_HEADER_KEY = "x-datadog-origin";
5
+ export declare const SAMPLING_PRIORITY_HEADER_KEY = "x-datadog-sampling-priority";
6
+ export declare const SAMPLED_HEADER_KEY = "x-datadog-sampled";
4
7
  export declare const ORIGIN_RUM = "rum";
8
+ export declare function calculateResponseSize(xhr: XMLHttpRequest): number;
5
9
  /**
6
10
  * Provides RUM auto-instrumentation feature to track resources (fetch, XHR, axios) as RUM events.
7
11
  */
@@ -1,13 +1,13 @@
1
1
  /// <reference types="react-native" />
2
+ import type Timer from "../../Timer";
2
3
  export interface DdRumXhr extends XMLHttpRequest {
3
4
  _datadog_xhr: DdRumXhrContext;
4
5
  }
5
6
  export interface DdRumXhrContext {
6
7
  method: string;
7
8
  url: string;
8
- startTime: number;
9
- responseStartTime: number;
10
9
  reported: boolean;
10
+ timer: Timer;
11
11
  spanId: string;
12
12
  traceId: string;
13
13
  }
@@ -46,25 +46,25 @@ export declare type DdLogsType = {
46
46
  * @param message: The message to send.
47
47
  * @param context: The additional context to send.
48
48
  */
49
- debug(message: string, context: object): Promise<void>;
49
+ debug(message: string, context?: object): Promise<void>;
50
50
  /**
51
51
  * Send a log with level info.
52
52
  * @param message: The message to send.
53
53
  * @param context: The additional context to send.
54
54
  */
55
- info(message: string, context: object): Promise<void>;
55
+ info(message: string, context?: object): Promise<void>;
56
56
  /**
57
57
  * Send a log with level warn.
58
58
  * @param message: The message to send.
59
59
  * @param context: The additional context to send.
60
60
  */
61
- warn(message: string, context: object): Promise<void>;
61
+ warn(message: string, context?: object): Promise<void>;
62
62
  /**
63
63
  * Send a log with level error.
64
64
  * @param message: The message to send.
65
65
  * @param context: The additional context to send.
66
66
  */
67
- error(message: string, context: object): Promise<void>;
67
+ error(message: string, context?: object): Promise<void>;
68
68
  };
69
69
  /**
70
70
  * The entry point to use Datadog's Trace feature.
@@ -73,17 +73,17 @@ export declare type DdTraceType = {
73
73
  /**
74
74
  * Start a span, and returns a unique identifier for the span.
75
75
  * @param operation: The operation name of the span.
76
- * @param timestampMs: The timestamp when the operation started (in milliseconds).
77
76
  * @param context: The additional context to send.
77
+ * @param timestampMs: The timestamp when the operation started (in milliseconds). If not provided, current timestamp will be used.
78
78
  */
79
- startSpan(operation: string, timestampMs: number, context: object): Promise<string>;
79
+ startSpan(operation: string, context?: object, timestampMs?: number): Promise<string>;
80
80
  /**
81
81
  * Finish a started span.
82
82
  * @param spanId: The unique identifier of the span.
83
- * @param timestampMs: The timestamp when the operation stopped (in milliseconds).
84
83
  * @param context: The additional context to send.
84
+ * @param timestampMs: The timestamp when the operation stopped (in milliseconds). If not provided, current timestamp will be used.
85
85
  */
86
- finishSpan(spanId: string, timestampMs: number, context: object): Promise<void>;
86
+ finishSpan(spanId: string, context?: object, timestampMs?: number): Promise<void>;
87
87
  };
88
88
  /**
89
89
  * The entry point to use Datadog's RUM feature.
@@ -93,66 +93,67 @@ export declare type DdRumType = {
93
93
  * Start tracking a RUM View.
94
94
  * @param key: The view unique key identifier.
95
95
  * @param name: The view name.
96
- * @param timestampMs: The timestamp when the view started (in milliseconds).
97
96
  * @param context: The additional context to send.
97
+ * @param timestampMs: The timestamp when the view started (in milliseconds). If not provided, current timestamp will be used.
98
98
  */
99
- startView(key: string, name: string, timestampMs: number, context: object): Promise<void>;
99
+ startView(key: string, name: string, context?: object, timestampMs?: number): Promise<void>;
100
100
  /**
101
101
  * Stop tracking a RUM View.
102
102
  * @param key: The view unique key identifier.
103
- * @param timestampMs: The timestamp when the view stopped (in milliseconds).
104
103
  * @param context: The additional context to send.
104
+ * @param timestampMs: The timestamp when the view stopped (in milliseconds). If not provided, current timestamp will be used.
105
105
  */
106
- stopView(key: string, timestampMs: number, context: object): Promise<void>;
106
+ stopView(key: string, context?: object, timestampMs?: number): Promise<void>;
107
107
  /**
108
108
  * Start tracking a RUM Action.
109
109
  * @param type: The action type (tap, scroll, swipe, click, custom).
110
110
  * @param name: The action name.
111
- * @param timestampMs: The timestamp when the action started (in milliseconds).
112
111
  * @param context: The additional context to send.
112
+ * @param timestampMs: The timestamp when the action started (in milliseconds). If not provided, current timestamp will be used.
113
113
  */
114
- startAction(type: string, name: string, timestampMs: number, context: object): Promise<void>;
114
+ startAction(type: string, name: string, context?: object, timestampMs?: number): Promise<void>;
115
115
  /**
116
116
  * Stop tracking the ongoing RUM Action.
117
- * @param timestampMs: The timestamp when the action stopped (in milliseconds).
118
117
  * @param context: The additional context to send.
118
+ * @param timestampMs: The timestamp when the action stopped (in milliseconds). If not provided, current timestamp will be used.
119
119
  */
120
- stopAction(timestampMs: number, context: object): Promise<void>;
120
+ stopAction(context?: object, timestampMs?: number): Promise<void>;
121
121
  /**
122
122
  * Add a RUM Action.
123
123
  * @param type: The action type (tap, scroll, swipe, click, custom).
124
124
  * @param name: The action name.
125
- * @param timestampMs: The timestamp when the action occurred (in milliseconds).
126
125
  * @param context: The additional context to send.
126
+ * @param timestampMs: The timestamp when the action occurred (in milliseconds). If not provided, current timestamp will be used.
127
127
  */
128
- addAction(type: string, name: string, timestampMs: number, context: object): Promise<void>;
128
+ addAction(type: string, name: string, context?: object, timestampMs?: number): Promise<void>;
129
129
  /**
130
130
  * Start tracking a RUM Resource.
131
131
  * @param key: The resource unique key identifier.
132
132
  * @param method: The resource method (GET, POST, …).
133
133
  * @param url: The resource url.
134
- * @param timestampMs: The timestamp when the resource started (in milliseconds).
135
134
  * @param context: The additional context to send.
135
+ * @param timestampMs: The timestamp when the resource started (in milliseconds). If not provided, current timestamp will be used.
136
136
  */
137
- startResource(key: string, method: string, url: string, timestampMs: number, context: object): Promise<void>;
137
+ startResource(key: string, method: string, url: string, context?: object, timestampMs?: number): Promise<void>;
138
138
  /**
139
139
  * Stop tracking a RUM Resource.
140
140
  * @param key: The resource unique key identifier.
141
141
  * @param statusCode: The resource status code.
142
142
  * @param kind: The resource's kind (xhr, document, image, css, font, …).
143
- * @param timestampMs: The timestamp when the resource stopped (in milliseconds).
143
+ * @param size: The resource size in bytes. If size is unknown, use -1.
144
144
  * @param context: The additional context to send.
145
+ * @param timestampMs: The timestamp when the resource stopped (in milliseconds). If not provided, current timestamp will be used.
145
146
  */
146
- stopResource(key: string, statusCode: number, kind: string, timestampMs: number, context: object): Promise<void>;
147
+ stopResource(key: string, statusCode: number, kind: string, size?: number, context?: object, timestampMs?: number): Promise<void>;
147
148
  /**
148
149
  * Add a RUM Error.
149
150
  * @param message: The error message.
150
151
  * @param source: The error source (network, source, console, logger, …).
151
152
  * @param stacktrace: The error stacktrace.
152
- * @param timestampMs: The timestamp when the error occurred (in milliseconds).
153
153
  * @param context: The additional context to send.
154
+ * @param timestampMs: The timestamp when the error occurred (in milliseconds). If not provided, current timestamp will be used.
154
155
  */
155
- addError(message: string, source: string, stacktrace: string, timestampMs: number, context: object): Promise<void>;
156
+ addError(message: string, source: string, stacktrace: string, context?: object, timestampMs?: number): Promise<void>;
156
157
  /**
157
158
  * 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.
158
159
  * @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.
@@ -0,0 +1 @@
1
+ export declare const version = "1.0.0-rc4";