@datadog/mobile-react-native 1.0.0-rc6 → 1.0.0-rc9

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 (131) hide show
  1. package/DatadogSDKReactNative.podspec +1 -1
  2. package/README.md +2 -0
  3. package/android/build.gradle +1 -1
  4. package/ios/Sources/DdSdk.swift +6 -3
  5. package/lib/commonjs/DdSdkReactNative.js +7 -3
  6. package/lib/commonjs/DdSdkReactNative.js.map +1 -1
  7. package/lib/commonjs/DdSdkReactNativeConfiguration.js +2 -0
  8. package/lib/commonjs/DdSdkReactNativeConfiguration.js.map +1 -1
  9. package/lib/commonjs/InternalLog.js +5 -0
  10. package/lib/commonjs/InternalLog.js.map +1 -1
  11. package/lib/commonjs/index.js +8 -0
  12. package/lib/commonjs/index.js.map +1 -1
  13. package/lib/commonjs/rum/instrumentation/resourceTracking/DdRumResourceTracking.js +73 -0
  14. package/lib/commonjs/rum/instrumentation/resourceTracking/DdRumResourceTracking.js.map +1 -0
  15. package/lib/commonjs/rum/instrumentation/{TraceIdentifier.js → resourceTracking/domain/distributedTracing.js} +40 -1
  16. package/lib/commonjs/rum/instrumentation/resourceTracking/domain/distributedTracing.js.map +1 -0
  17. package/lib/commonjs/rum/instrumentation/resourceTracking/domain/firstPartyHosts.js +46 -0
  18. package/lib/commonjs/rum/instrumentation/resourceTracking/domain/firstPartyHosts.js.map +1 -0
  19. package/lib/commonjs/rum/instrumentation/resourceTracking/domain/interfaces/RequestProxy.js +25 -0
  20. package/lib/commonjs/rum/instrumentation/resourceTracking/domain/interfaces/RequestProxy.js.map +1 -0
  21. package/lib/commonjs/rum/instrumentation/resourceTracking/domain/interfaces/RumResource.js +2 -0
  22. package/lib/commonjs/rum/instrumentation/{DdRumXhr.js.map → resourceTracking/domain/interfaces/RumResource.js.map} +0 -0
  23. package/lib/commonjs/rum/instrumentation/resourceTracking/implementation/DatadogRumResource/ResourceReporter.js +57 -0
  24. package/lib/commonjs/rum/instrumentation/resourceTracking/implementation/DatadogRumResource/ResourceReporter.js.map +1 -0
  25. package/lib/commonjs/rum/instrumentation/resourceTracking/implementation/DatadogRumResource/internalDevResourceBlocklist.js +49 -0
  26. package/lib/commonjs/rum/instrumentation/resourceTracking/implementation/DatadogRumResource/internalDevResourceBlocklist.js.map +1 -0
  27. package/lib/commonjs/rum/instrumentation/resourceTracking/implementation/DatadogRumResource/resourceTiming.js +45 -0
  28. package/lib/commonjs/rum/instrumentation/resourceTracking/implementation/DatadogRumResource/resourceTiming.js.map +1 -0
  29. package/lib/commonjs/rum/instrumentation/resourceTracking/implementation/URLHostParser.js +42 -0
  30. package/lib/commonjs/rum/instrumentation/resourceTracking/implementation/URLHostParser.js.map +1 -0
  31. package/lib/commonjs/rum/instrumentation/resourceTracking/implementation/XHRProxy.js +167 -0
  32. package/lib/commonjs/rum/instrumentation/resourceTracking/implementation/XHRProxy.js.map +1 -0
  33. package/lib/commonjs/rum/instrumentation/resourceTracking/implementation/responseSize.js +97 -0
  34. package/lib/commonjs/rum/instrumentation/resourceTracking/implementation/responseSize.js.map +1 -0
  35. package/lib/commonjs/version.js +1 -1
  36. package/lib/commonjs/version.js.map +1 -1
  37. package/lib/module/DdSdkReactNative.js +6 -2
  38. package/lib/module/DdSdkReactNative.js.map +1 -1
  39. package/lib/module/DdSdkReactNativeConfiguration.js +2 -0
  40. package/lib/module/DdSdkReactNativeConfiguration.js.map +1 -1
  41. package/lib/module/InternalLog.js +6 -0
  42. package/lib/module/InternalLog.js.map +1 -1
  43. package/lib/module/index.js +2 -1
  44. package/lib/module/index.js.map +1 -1
  45. package/lib/module/rum/instrumentation/resourceTracking/DdRumResourceTracking.js +61 -0
  46. package/lib/module/rum/instrumentation/resourceTracking/DdRumResourceTracking.js.map +1 -0
  47. package/lib/module/rum/instrumentation/{TraceIdentifier.js → resourceTracking/domain/distributedTracing.js} +35 -1
  48. package/lib/module/rum/instrumentation/resourceTracking/domain/distributedTracing.js.map +1 -0
  49. package/lib/module/rum/instrumentation/resourceTracking/domain/firstPartyHosts.js +29 -0
  50. package/lib/module/rum/instrumentation/resourceTracking/domain/firstPartyHosts.js.map +1 -0
  51. package/lib/module/rum/instrumentation/resourceTracking/domain/interfaces/RequestProxy.js +16 -0
  52. package/lib/module/rum/instrumentation/resourceTracking/domain/interfaces/RequestProxy.js.map +1 -0
  53. package/lib/module/rum/instrumentation/resourceTracking/domain/interfaces/RumResource.js +2 -0
  54. package/lib/module/rum/instrumentation/{DdRumXhr.js.map → resourceTracking/domain/interfaces/RumResource.js.map} +0 -0
  55. package/lib/module/rum/instrumentation/resourceTracking/implementation/DatadogRumResource/ResourceReporter.js +50 -0
  56. package/lib/module/rum/instrumentation/resourceTracking/implementation/DatadogRumResource/ResourceReporter.js.map +1 -0
  57. package/lib/module/rum/instrumentation/resourceTracking/implementation/DatadogRumResource/internalDevResourceBlocklist.js +40 -0
  58. package/lib/module/rum/instrumentation/resourceTracking/implementation/DatadogRumResource/internalDevResourceBlocklist.js.map +1 -0
  59. package/lib/module/rum/instrumentation/resourceTracking/implementation/DatadogRumResource/resourceTiming.js +36 -0
  60. package/lib/module/rum/instrumentation/resourceTracking/implementation/DatadogRumResource/resourceTiming.js.map +1 -0
  61. package/lib/module/rum/instrumentation/resourceTracking/implementation/URLHostParser.js +30 -0
  62. package/lib/module/rum/instrumentation/resourceTracking/implementation/URLHostParser.js.map +1 -0
  63. package/lib/module/rum/instrumentation/resourceTracking/implementation/XHRProxy.js +151 -0
  64. package/lib/module/rum/instrumentation/resourceTracking/implementation/XHRProxy.js.map +1 -0
  65. package/lib/module/rum/instrumentation/resourceTracking/implementation/responseSize.js +86 -0
  66. package/lib/module/rum/instrumentation/resourceTracking/implementation/responseSize.js.map +1 -0
  67. package/lib/module/version.js +1 -1
  68. package/lib/module/version.js.map +1 -1
  69. package/lib/typescript/DdSdkReactNativeConfiguration.d.ts +1 -0
  70. package/lib/typescript/InternalLog.d.ts +5 -0
  71. package/lib/typescript/index.d.ts +2 -1
  72. package/lib/typescript/rum/instrumentation/resourceTracking/DdRumResourceTracking.d.ts +15 -0
  73. package/lib/typescript/rum/instrumentation/resourceTracking/domain/distributedTracing.d.ts +18 -0
  74. package/lib/typescript/rum/instrumentation/resourceTracking/domain/firstPartyHosts.d.ts +6 -0
  75. package/lib/typescript/rum/instrumentation/resourceTracking/domain/interfaces/RequestProxy.d.ts +8 -0
  76. package/lib/typescript/rum/instrumentation/resourceTracking/domain/interfaces/RumResource.d.ts +19 -0
  77. package/lib/typescript/rum/instrumentation/resourceTracking/implementation/DatadogRumResource/ResourceReporter.d.ts +8 -0
  78. package/lib/typescript/rum/instrumentation/resourceTracking/implementation/DatadogRumResource/internalDevResourceBlocklist.d.ts +6 -0
  79. package/lib/typescript/rum/instrumentation/resourceTracking/implementation/DatadogRumResource/resourceTiming.d.ts +17 -0
  80. package/lib/typescript/rum/instrumentation/resourceTracking/implementation/URLHostParser.d.ts +6 -0
  81. package/lib/typescript/rum/instrumentation/resourceTracking/implementation/XHRProxy.d.ts +25 -0
  82. package/lib/typescript/rum/instrumentation/resourceTracking/implementation/responseSize.d.ts +3 -0
  83. package/lib/typescript/version.d.ts +1 -1
  84. package/package.json +4 -3
  85. package/src/DdSdkReactNative.tsx +8 -4
  86. package/src/DdSdkReactNativeConfiguration.tsx +1 -0
  87. package/src/InternalLog.tsx +5 -0
  88. package/src/__tests__/DdSdkReactNative.test.tsx +42 -24
  89. package/src/__tests__/rum/instrumentation/DdEventsInterceptor.test.tsx +1 -1
  90. package/src/__tests__/rum/instrumentation/DdRumUserInteractionTracking.test.tsx +1 -1
  91. package/src/index.tsx +2 -0
  92. package/src/rum/instrumentation/resourceTracking/DdRumResourceTracking.tsx +67 -0
  93. package/src/rum/instrumentation/resourceTracking/__tests__/DdRumResourceTracking.test.ts +79 -0
  94. package/src/{__tests__/rum/instrumentation → rum/instrumentation/resourceTracking/__tests__}/__utils__/XMLHttpRequestMock.ts +0 -0
  95. package/src/{__tests__/rum/instrumentation/TraceIdentifier.test.tsx → rum/instrumentation/resourceTracking/domain/__tests__/distributedTracing.test.ts} +1 -1
  96. package/src/rum/instrumentation/resourceTracking/domain/distributedTracing.tsx +87 -0
  97. package/src/rum/instrumentation/resourceTracking/domain/firstPartyHosts.ts +45 -0
  98. package/src/rum/instrumentation/resourceTracking/domain/interfaces/RequestProxy.ts +15 -0
  99. package/src/rum/instrumentation/resourceTracking/domain/interfaces/RumResource.ts +26 -0
  100. package/src/rum/instrumentation/resourceTracking/implementation/DatadogRumResource/ResourceReporter.ts +78 -0
  101. package/src/rum/instrumentation/resourceTracking/implementation/DatadogRumResource/__tests__/ResourceReporter.test.ts +83 -0
  102. package/src/rum/instrumentation/resourceTracking/implementation/DatadogRumResource/__tests__/__utils__/ResourceMockFactory.ts +45 -0
  103. package/src/rum/instrumentation/resourceTracking/implementation/DatadogRumResource/__tests__/internalDevResourceBlocklist.test.ts +69 -0
  104. package/src/rum/instrumentation/resourceTracking/implementation/DatadogRumResource/internalDevResourceBlocklist.ts +50 -0
  105. package/src/rum/instrumentation/resourceTracking/implementation/DatadogRumResource/resourceTiming.ts +70 -0
  106. package/src/rum/instrumentation/resourceTracking/implementation/URLHostParser.ts +30 -0
  107. package/src/rum/instrumentation/resourceTracking/implementation/XHRProxy.ts +197 -0
  108. package/src/rum/instrumentation/resourceTracking/implementation/__tests__/URLHostParser.test.ts +40 -0
  109. package/src/{__tests__/rum/instrumentation/DdRumResourceTracking.test.tsx → rum/instrumentation/resourceTracking/implementation/__tests__/XHRProxy.test.ts} +178 -69
  110. package/src/rum/instrumentation/resourceTracking/implementation/responseSize.ts +83 -0
  111. package/src/version.ts +1 -1
  112. package/lib/commonjs/internal.js +0 -14
  113. package/lib/commonjs/internal.js.map +0 -1
  114. package/lib/commonjs/rum/instrumentation/DdRumResourceTracking.js +0 -298
  115. package/lib/commonjs/rum/instrumentation/DdRumResourceTracking.js.map +0 -1
  116. package/lib/commonjs/rum/instrumentation/DdRumXhr.js +0 -2
  117. package/lib/commonjs/rum/instrumentation/TraceIdentifier.js.map +0 -1
  118. package/lib/module/internal.js +0 -2
  119. package/lib/module/internal.js.map +0 -1
  120. package/lib/module/rum/instrumentation/DdRumResourceTracking.js +0 -276
  121. package/lib/module/rum/instrumentation/DdRumResourceTracking.js.map +0 -1
  122. package/lib/module/rum/instrumentation/DdRumXhr.js +0 -2
  123. package/lib/module/rum/instrumentation/TraceIdentifier.js.map +0 -1
  124. package/lib/typescript/internal.d.ts +0 -1
  125. package/lib/typescript/rum/instrumentation/DdRumResourceTracking.d.ts +0 -31
  126. package/lib/typescript/rum/instrumentation/DdRumXhr.d.ts +0 -23
  127. package/lib/typescript/rum/instrumentation/TraceIdentifier.d.ts +0 -1
  128. package/src/internal.tsx +0 -1
  129. package/src/rum/instrumentation/DdRumResourceTracking.tsx +0 -361
  130. package/src/rum/instrumentation/DdRumXhr.tsx +0 -33
  131. package/src/rum/instrumentation/TraceIdentifier.tsx +0 -34
@@ -0,0 +1,86 @@
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 { InternalLog } from '../../../../InternalLog';
7
+ import { SdkVerbosity } from '../../../../SdkVerbosity';
8
+ const MISSING_RESOURCE_SIZE = -1;
9
+ export const RESOURCE_SIZE_ERROR_MESSAGE = "Couldn't get resource size, because an error occured: ";
10
+
11
+ function byteLength(str) {
12
+ // This is a weird trick, but it works.
13
+ // Output is the same as TextEncoder.encode(...).length
14
+ return unescape(encodeURI(str)).length;
15
+ }
16
+
17
+ function getResponseContentLengthFromHeader(xhr) {
18
+ var _xhr$getResponseHeade;
19
+
20
+ const contentLengthHeader = parseInt((_xhr$getResponseHeade = xhr.getResponseHeader('Content-Length')) !== null && _xhr$getResponseHeade !== void 0 ? _xhr$getResponseHeade : '', 10);
21
+
22
+ if (!isNaN(contentLengthHeader)) {
23
+ return contentLengthHeader;
24
+ }
25
+
26
+ return null;
27
+ }
28
+
29
+ export function calculateResponseSize(xhr) {
30
+ const contentLengthHeader = getResponseContentLengthFromHeader(xhr);
31
+
32
+ if (contentLengthHeader != null) {
33
+ return contentLengthHeader;
34
+ }
35
+
36
+ const response = xhr.response;
37
+
38
+ if (!response) {
39
+ return MISSING_RESOURCE_SIZE;
40
+ }
41
+
42
+ let size;
43
+
44
+ try {
45
+ switch (xhr.responseType) {
46
+ case '':
47
+ case 'text':
48
+ // String
49
+ size = byteLength(response);
50
+ break;
51
+
52
+ case 'blob':
53
+ size = response.size;
54
+ break;
55
+
56
+ case 'arraybuffer':
57
+ size = response.byteLength;
58
+ break;
59
+
60
+ case 'document':
61
+ // currently not supported by RN as of 0.66
62
+ // HTML Document or XML Document
63
+ break;
64
+
65
+ case 'json':
66
+ // plain JS object
67
+ // original size was lost, because this is the object which was parsed.
68
+ // We can only convert back to the string and calculate the size,
69
+ // which will roughly match original.
70
+ size = byteLength(JSON.stringify(response));
71
+ break;
72
+
73
+ default:
74
+ break;
75
+ }
76
+ } catch (e) {
77
+ InternalLog.log(`${RESOURCE_SIZE_ERROR_MESSAGE}${e}`, SdkVerbosity.ERROR);
78
+ }
79
+
80
+ if (typeof size !== 'number') {
81
+ return MISSING_RESOURCE_SIZE;
82
+ }
83
+
84
+ return size;
85
+ }
86
+ //# sourceMappingURL=responseSize.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["responseSize.ts"],"names":["InternalLog","SdkVerbosity","MISSING_RESOURCE_SIZE","RESOURCE_SIZE_ERROR_MESSAGE","byteLength","str","unescape","encodeURI","length","getResponseContentLengthFromHeader","xhr","contentLengthHeader","parseInt","getResponseHeader","isNaN","calculateResponseSize","response","size","responseType","JSON","stringify","e","log","ERROR"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AAEA,SAASA,WAAT,QAA4B,yBAA5B;AACA,SAASC,YAAT,QAA6B,0BAA7B;AAEA,MAAMC,qBAAqB,GAAG,CAAC,CAA/B;AACA,OAAO,MAAMC,2BAA2B,GACpC,wDADG;;AAGP,SAASC,UAAT,CAAoBC,GAApB,EAAyC;AACrC;AACA;AACA,SAAOC,QAAQ,CAACC,SAAS,CAACF,GAAD,CAAV,CAAR,CAAyBG,MAAhC;AACH;;AAED,SAASC,kCAAT,CACIC,GADJ,EAEiB;AAAA;;AACb,QAAMC,mBAAmB,GAAGC,QAAQ,0BAChCF,GAAG,CAACG,iBAAJ,CAAsB,gBAAtB,CADgC,yEACW,EADX,EAEhC,EAFgC,CAApC;;AAIA,MAAI,CAACC,KAAK,CAACH,mBAAD,CAAV,EAAiC;AAC7B,WAAOA,mBAAP;AACH;;AACD,SAAO,IAAP;AACH;;AAED,OAAO,SAASI,qBAAT,CAA+BL,GAA/B,EAA4D;AAC/D,QAAMC,mBAAmB,GAAGF,kCAAkC,CAACC,GAAD,CAA9D;;AACA,MAAIC,mBAAmB,IAAI,IAA3B,EAAiC;AAC7B,WAAOA,mBAAP;AACH;;AAED,QAAMK,QAAQ,GAAGN,GAAG,CAACM,QAArB;;AACA,MAAI,CAACA,QAAL,EAAe;AACX,WAAOd,qBAAP;AACH;;AAED,MAAIe,IAAJ;;AACA,MAAI;AACA,YAAQP,GAAG,CAACQ,YAAZ;AACI,WAAK,EAAL;AACA,WAAK,MAAL;AACI;AACAD,QAAAA,IAAI,GAAGb,UAAU,CAACY,QAAD,CAAjB;AACA;;AACJ,WAAK,MAAL;AACIC,QAAAA,IAAI,GAAGD,QAAQ,CAACC,IAAhB;AACA;;AACJ,WAAK,aAAL;AACIA,QAAAA,IAAI,GAAGD,QAAQ,CAACZ,UAAhB;AACA;;AACJ,WAAK,UAAL;AACI;AACA;AACA;;AACJ,WAAK,MAAL;AACI;AACA;AACA;AACA;AACAa,QAAAA,IAAI,GAAGb,UAAU,CAACe,IAAI,CAACC,SAAL,CAAeJ,QAAf,CAAD,CAAjB;AACA;;AACJ;AACI;AAxBR;AA0BH,GA3BD,CA2BE,OAAOK,CAAP,EAAU;AACRrB,IAAAA,WAAW,CAACsB,GAAZ,CACK,GAAEnB,2BAA4B,GAAEkB,CAAE,EADvC,EAEIpB,YAAY,CAACsB,KAFjB;AAIH;;AAED,MAAI,OAAON,IAAP,KAAgB,QAApB,EAA8B;AAC1B,WAAOf,qBAAP;AACH;;AACD,SAAOe,IAAP;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 { InternalLog } from '../../../../InternalLog';\nimport { SdkVerbosity } from '../../../../SdkVerbosity';\n\nconst MISSING_RESOURCE_SIZE = -1;\nexport const RESOURCE_SIZE_ERROR_MESSAGE =\n \"Couldn't get resource size, because an error occured: \";\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(\n xhr: XMLHttpRequest\n): number | null {\n const contentLengthHeader = parseInt(\n xhr.getResponseHeader('Content-Length') ?? '',\n 10\n );\n if (!isNaN(contentLengthHeader)) {\n return contentLengthHeader;\n }\n return null;\n}\n\nexport function calculateResponseSize(xhr: XMLHttpRequest): number {\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 InternalLog.log(\n `${RESOURCE_SIZE_ERROR_MESSAGE}${e}`,\n SdkVerbosity.ERROR\n );\n }\n\n if (typeof size !== 'number') {\n return MISSING_RESOURCE_SIZE;\n }\n return size;\n}\n"]}
@@ -1,3 +1,3 @@
1
1
  // generated by genversion
2
- export const version = '1.0.0-rc6';
2
+ export const version = '1.0.0-rc9';
3
3
  //# sourceMappingURL=version.js.map
@@ -1 +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-rc6';\n"]}
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-rc9';\n"]}
@@ -31,6 +31,7 @@ export declare class DdSdkReactNativeConfiguration {
31
31
  nativeViewTracking: boolean;
32
32
  proxyConfig?: ProxyConfiguration;
33
33
  serviceName?: string;
34
+ firstPartyHosts: string[];
34
35
  additionalConfig: {
35
36
  [k: string]: any;
36
37
  };
@@ -1,4 +1,9 @@
1
1
  import { SdkVerbosity } from './SdkVerbosity';
2
+ /**
3
+ * /!\ DO NOT USE THIS IN YOUR APP /!\\
4
+ *
5
+ * This logger is only for debugging the Datadog SDK.
6
+ */
2
7
  export declare class InternalLog {
3
8
  private static levelMap;
4
9
  static verbosity: SdkVerbosity | undefined;
@@ -1,7 +1,8 @@
1
1
  import { DdSdkReactNativeConfiguration } from './DdSdkReactNativeConfiguration';
2
2
  import { DdSdkReactNative } from './DdSdkReactNative';
3
+ import { InternalLog } from './InternalLog';
3
4
  import { ProxyConfiguration, ProxyType } from './ProxyConfiguration';
4
5
  import { SdkVerbosity } from './SdkVerbosity';
5
6
  import { TrackingConsent } from './TrackingConsent';
6
7
  import { DdLogs, DdTrace, DdRum } from './foundation';
7
- export { DdLogs, DdTrace, DdRum, DdSdkReactNativeConfiguration, DdSdkReactNative, ProxyConfiguration, ProxyType, TrackingConsent, SdkVerbosity };
8
+ export { DdLogs, DdTrace, DdRum, DdSdkReactNativeConfiguration, DdSdkReactNative, InternalLog, ProxyConfiguration, ProxyType, TrackingConsent, SdkVerbosity };
@@ -0,0 +1,15 @@
1
+ /**
2
+ * Provides RUM auto-instrumentation feature to track resources (fetch, XHR, axios) as RUM events.
3
+ */
4
+ export declare class DdRumResourceTracking {
5
+ private static isTracking;
6
+ private static requestProxy;
7
+ /**
8
+ * Starts tracking resources and sends a RUM Resource event every time a network request is detected.
9
+ */
10
+ static startTracking({ tracingSamplingRate, firstPartyHosts }: {
11
+ tracingSamplingRate: number;
12
+ firstPartyHosts: string[];
13
+ }): void;
14
+ static stopTracking(): void;
15
+ }
@@ -0,0 +1,18 @@
1
+ import type { Hostname } from './firstPartyHosts';
2
+ export declare type DdRumResourceTracingAttributes = {
3
+ tracingStrategy: 'KEEP';
4
+ traceId: string;
5
+ spanId: string;
6
+ samplingPriorityHeader: '1';
7
+ } | {
8
+ tracingStrategy: 'DISCARD';
9
+ traceId?: void;
10
+ spanId?: void;
11
+ samplingPriorityHeader: '0';
12
+ };
13
+ export declare const getTracingAttributes: ({ hostname, firstPartyHostsRegex, tracingSamplingRate }: {
14
+ hostname: Hostname | null;
15
+ firstPartyHostsRegex: RegExp;
16
+ tracingSamplingRate: number;
17
+ }) => DdRumResourceTracingAttributes;
18
+ export declare function generateTraceId(): string;
@@ -0,0 +1,6 @@
1
+ export declare type Hostname = {
2
+ _type: 'Hostname';
3
+ } & string;
4
+ export declare const NO_MATCH_REGEX: RegExp;
5
+ export declare const firstPartyHostsRegexBuilder: (firstPartyHosts: string[]) => RegExp;
6
+ export declare const isHostFirstParty: (hostname: Hostname, firstPartyHostsRegex: RegExp) => boolean;
@@ -0,0 +1,8 @@
1
+ export interface RequestProxyOptions {
2
+ tracingSamplingRate: number;
3
+ firstPartyHostsRegex: RegExp;
4
+ }
5
+ export declare abstract class RequestProxy {
6
+ abstract onTrackingStart: (context: RequestProxyOptions) => void;
7
+ abstract onTrackingStop: () => void;
8
+ }
@@ -0,0 +1,19 @@
1
+ import type { DdRumResourceTracingAttributes } from '../distributedTracing';
2
+ export interface RUMResource {
3
+ key: string;
4
+ request: {
5
+ method: string;
6
+ url: string;
7
+ kind: string;
8
+ };
9
+ tracingAttributes: DdRumResourceTracingAttributes;
10
+ response: {
11
+ statusCode: number;
12
+ size: number;
13
+ };
14
+ timings: {
15
+ startTime: number;
16
+ stopTime: number;
17
+ responseStartTime?: number;
18
+ };
19
+ }
@@ -0,0 +1,8 @@
1
+ import type { RUMResource } from '../../domain/interfaces/RumResource';
2
+ declare type ResourceMapper = (resource: RUMResource) => RUMResource | null;
3
+ export declare class ResourceReporter {
4
+ private mappers;
5
+ constructor(resourceMappers: ResourceMapper[]);
6
+ reportResource: (resource: RUMResource) => void;
7
+ }
8
+ export {};
@@ -0,0 +1,6 @@
1
+ import type { RUMResource } from '../../domain/interfaces/RumResource';
2
+ /**
3
+ * Filters RN symbolicate calls and Expo logs calls that happen only in dev.
4
+ * @param resource RUMResource
5
+ */
6
+ export declare const filterDevResource: (resource: RUMResource) => RUMResource | null;
@@ -0,0 +1,17 @@
1
+ interface Timing {
2
+ /**
3
+ * Time relative (absolute in case of iOS) to some point, in ns.
4
+ */
5
+ startTime: number;
6
+ /**
7
+ * Duration in ns.
8
+ */
9
+ duration: number;
10
+ }
11
+ interface ResourceTimings {
12
+ firstByte: Timing;
13
+ download: Timing;
14
+ fetch: Timing;
15
+ }
16
+ export declare function createTimings(startTime: number, responseStartTime: number, responseEndTime: number): ResourceTimings;
17
+ export {};
@@ -0,0 +1,6 @@
1
+ import type { Hostname } from '../domain/firstPartyHosts';
2
+ /**
3
+ * Returns the host from an URL.
4
+ * @returns the host (without the port) or null if could not cast the URL as host
5
+ */
6
+ export declare const URLHostParser: (url: string) => Hostname | null;
@@ -0,0 +1,25 @@
1
+ /// <reference types="react-native" />
2
+ import type { RequestProxyOptions } from '../domain/interfaces/RequestProxy';
3
+ import { RequestProxy } from '../domain/interfaces/RequestProxy';
4
+ import type { ResourceReporter } from './DatadogRumResource/ResourceReporter';
5
+ export declare const TRACE_ID_HEADER_KEY = "x-datadog-trace-id";
6
+ export declare const PARENT_ID_HEADER_KEY = "x-datadog-parent-id";
7
+ export declare const ORIGIN_HEADER_KEY = "x-datadog-origin";
8
+ export declare const SAMPLING_PRIORITY_HEADER_KEY = "x-datadog-sampling-priority";
9
+ export declare const ORIGIN_RUM = "rum";
10
+ interface XHRProxyProviders {
11
+ xhrType: typeof XMLHttpRequest;
12
+ resourceReporter: ResourceReporter;
13
+ }
14
+ /**
15
+ * Proxies XMLHTTPRequest to track resources.
16
+ */
17
+ export declare class XHRProxy extends RequestProxy {
18
+ private providers;
19
+ private static originalXhrOpen;
20
+ private static originalXhrSend;
21
+ constructor(providers: XHRProxyProviders);
22
+ onTrackingStart: (context: RequestProxyOptions) => void;
23
+ onTrackingStop: () => void;
24
+ }
25
+ export {};
@@ -0,0 +1,3 @@
1
+ /// <reference types="react-native" />
2
+ export declare const RESOURCE_SIZE_ERROR_MESSAGE = "Couldn't get resource size, because an error occured: ";
3
+ export declare function calculateResponseSize(xhr: XMLHttpRequest): number;
@@ -1 +1 @@
1
- export declare const version = "1.0.0-rc6";
1
+ export declare const version = "1.0.0-rc9";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@datadog/mobile-react-native",
3
- "version": "1.0.0-rc6",
3
+ "version": "1.0.0-rc9",
4
4
  "description": "A client-side React Native module to interact with Datadog",
5
5
  "keywords": [
6
6
  "datadog",
@@ -53,7 +53,8 @@
53
53
  "<rootDir>/lib/"
54
54
  ],
55
55
  "setupFiles": [
56
- "./../../node_modules/react-native-gesture-handler/jestSetup.js"
56
+ "./../../node_modules/react-native-gesture-handler/jestSetup.js",
57
+ "./../../jest.setup.js"
57
58
  ],
58
59
  "transformIgnorePatterns": []
59
60
  },
@@ -71,5 +72,5 @@
71
72
  ]
72
73
  ]
73
74
  },
74
- "gitHead": "db2b48ab61c67e64567b91fc5d858473bf64d448"
75
+ "gitHead": "552457ced3fc826cb42120402eb9e98f80228890"
75
76
  }
@@ -11,8 +11,8 @@ import { SdkVerbosity } from './SdkVerbosity';
11
11
  import type { TrackingConsent } from './TrackingConsent';
12
12
  import { DdSdk } from './foundation';
13
13
  import { DdRumErrorTracking } from './rum/instrumentation/DdRumErrorTracking';
14
- import { DdRumResourceTracking } from './rum/instrumentation/DdRumResourceTracking';
15
14
  import { DdRumUserInteractionTracking } from './rum/instrumentation/DdRumUserInteractionTracking';
15
+ import { DdRumResourceTracking } from './rum/instrumentation/resourceTracking/DdRumResourceTracking';
16
16
  import { DdSdkConfiguration } from './types';
17
17
  import { version as sdkVersion } from './version';
18
18
 
@@ -110,6 +110,9 @@ export class DdSdkReactNative {
110
110
  DdSdkReactNative.DD_NATIVE_LONG_TASK_THRESHOLD_KEY
111
111
  ] = DdSdkReactNative.NATIVE_LONG_TASK_THRESHOLD_MS;
112
112
 
113
+ configuration.additionalConfig['_dd.first_party_hosts'] =
114
+ configuration.firstPartyHosts;
115
+
113
116
  DdSdk.initialize(
114
117
  new DdSdkConfiguration(
115
118
  configuration.clientToken,
@@ -186,9 +189,10 @@ export class DdSdkReactNative {
186
189
  }
187
190
 
188
191
  if (configuration.trackResources) {
189
- DdRumResourceTracking.startTracking(
190
- configuration.resourceTracingSamplingRate
191
- );
192
+ DdRumResourceTracking.startTracking({
193
+ tracingSamplingRate: configuration.resourceTracingSamplingRate,
194
+ firstPartyHosts: configuration.firstPartyHosts
195
+ });
192
196
  }
193
197
 
194
198
  if (configuration.trackErrors) {
@@ -31,6 +31,7 @@ export class DdSdkReactNativeConfiguration {
31
31
  public nativeViewTracking: boolean = false;
32
32
  public proxyConfig?: ProxyConfiguration = undefined;
33
33
  public serviceName?: string = undefined;
34
+ public firstPartyHosts: string[] = [];
34
35
 
35
36
  public additionalConfig: { [k: string]: any } = {};
36
37
 
@@ -6,6 +6,11 @@
6
6
 
7
7
  import { SdkVerbosity } from './SdkVerbosity';
8
8
 
9
+ /**
10
+ * /!\ DO NOT USE THIS IN YOUR APP /!\\
11
+ *
12
+ * This logger is only for debugging the Datadog SDK.
13
+ */
9
14
  export class InternalLog {
10
15
  private static levelMap = new Map<SdkVerbosity, number>([
11
16
  [SdkVerbosity.DEBUG, 1],
@@ -13,8 +13,8 @@ import { SdkVerbosity } from '../SdkVerbosity';
13
13
  import { TrackingConsent } from '../TrackingConsent';
14
14
  import { DdSdk } from '../foundation';
15
15
  import { DdRumErrorTracking } from '../rum/instrumentation/DdRumErrorTracking';
16
- import { DdRumResourceTracking } from '../rum/instrumentation/DdRumResourceTracking';
17
16
  import { DdRumUserInteractionTracking } from '../rum/instrumentation/DdRumUserInteractionTracking';
17
+ import { DdRumResourceTracking } from '../rum/instrumentation/resourceTracking/DdRumResourceTracking';
18
18
  import type { DdSdkConfiguration } from '../types';
19
19
  import { version as sdkVersion } from '../version';
20
20
 
@@ -28,13 +28,16 @@ jest.mock('../rum/instrumentation/DdRumUserInteractionTracking', () => {
28
28
  };
29
29
  });
30
30
 
31
- jest.mock('../rum/instrumentation/DdRumResourceTracking', () => {
32
- return {
33
- DdRumResourceTracking: {
34
- startTracking: jest.fn().mockImplementation(() => {})
35
- }
36
- };
37
- });
31
+ jest.mock(
32
+ '../rum/instrumentation/resourceTracking/DdRumResourceTracking',
33
+ () => {
34
+ return {
35
+ DdRumResourceTracking: {
36
+ startTracking: jest.fn().mockImplementation(() => {})
37
+ }
38
+ };
39
+ }
40
+ );
38
41
 
39
42
  jest.mock('../rum/instrumentation/DdRumErrorTracking', () => {
40
43
  return {
@@ -94,7 +97,8 @@ describe('DdSdkReactNative', () => {
94
97
  '_dd.source': 'react-native',
95
98
  '_dd.sdk_version': sdkVersion,
96
99
  '_dd.native_view_tracking': false,
97
- '_dd.long_task.threshold': 200
100
+ '_dd.long_task.threshold': 200,
101
+ '_dd.first_party_hosts': []
98
102
  });
99
103
  });
100
104
 
@@ -130,7 +134,8 @@ describe('DdSdkReactNative', () => {
130
134
  '_dd.source': 'react-native',
131
135
  '_dd.sdk_version': sdkVersion,
132
136
  '_dd.native_view_tracking': false,
133
- '_dd.long_task.threshold': 200
137
+ '_dd.long_task.threshold': 200,
138
+ '_dd.first_party_hosts': []
134
139
  });
135
140
 
136
141
  expect(DdSdkReactNative['wasInitialized']).toBe(false);
@@ -174,7 +179,8 @@ describe('DdSdkReactNative', () => {
174
179
  '_dd.source': 'react-native',
175
180
  '_dd.sdk_version': sdkVersion,
176
181
  '_dd.native_view_tracking': false,
177
- '_dd.long_task.threshold': 200
182
+ '_dd.long_task.threshold': 200,
183
+ '_dd.first_party_hosts': []
178
184
  });
179
185
  });
180
186
 
@@ -208,7 +214,8 @@ describe('DdSdkReactNative', () => {
208
214
  '_dd.source': 'react-native',
209
215
  '_dd.sdk_version': sdkVersion,
210
216
  '_dd.native_view_tracking': false,
211
- '_dd.long_task.threshold': 200
217
+ '_dd.long_task.threshold': 200,
218
+ '_dd.first_party_hosts': []
212
219
  });
213
220
  });
214
221
 
@@ -264,7 +271,8 @@ describe('DdSdkReactNative', () => {
264
271
  '_dd.proxy.type': proxyType,
265
272
  '_dd.proxy.address': proxyAddress,
266
273
  '_dd.proxy.port': proxyPort,
267
- '_dd.long_task.threshold': 200
274
+ '_dd.long_task.threshold': 200,
275
+ '_dd.first_party_hosts': []
268
276
  });
269
277
  expect(spyConsoleWarn).toHaveBeenCalledTimes(1);
270
278
  } finally {
@@ -370,7 +378,8 @@ describe('DdSdkReactNative', () => {
370
378
  '_dd.source': 'react-native',
371
379
  '_dd.sdk_version': sdkVersion,
372
380
  '_dd.native_view_tracking': false,
373
- '_dd.long_task.threshold': 200
381
+ '_dd.long_task.threshold': 200,
382
+ '_dd.first_party_hosts': []
374
383
  });
375
384
  expect(
376
385
  DdRumUserInteractionTracking.startTracking
@@ -390,6 +399,7 @@ describe('DdSdkReactNative', () => {
390
399
  true
391
400
  );
392
401
  configuration.resourceTracingSamplingRate = 42;
402
+ configuration.firstPartyHosts = ['api.example.com'];
393
403
 
394
404
  NativeModules.DdSdk.initialize.mockResolvedValue(null);
395
405
 
@@ -407,14 +417,16 @@ describe('DdSdkReactNative', () => {
407
417
  '_dd.source': 'react-native',
408
418
  '_dd.sdk_version': sdkVersion,
409
419
  '_dd.native_view_tracking': false,
410
- '_dd.long_task.threshold': 200
420
+ '_dd.long_task.threshold': 200,
421
+ '_dd.first_party_hosts': ['api.example.com']
411
422
  });
412
423
  expect(DdRumResourceTracking.startTracking).toHaveBeenCalledTimes(
413
424
  1
414
425
  );
415
- expect(DdRumResourceTracking.startTracking).toHaveBeenCalledWith(
416
- 42
417
- );
426
+ expect(DdRumResourceTracking.startTracking).toHaveBeenCalledWith({
427
+ tracingSamplingRate: 42,
428
+ firstPartyHosts: ['api.example.com']
429
+ });
418
430
  });
419
431
 
420
432
  it('enables error tracking feature when initialize { error tracking config enabled }', async () => {
@@ -448,7 +460,8 @@ describe('DdSdkReactNative', () => {
448
460
  '_dd.source': 'react-native',
449
461
  '_dd.sdk_version': sdkVersion,
450
462
  '_dd.native_view_tracking': false,
451
- '_dd.long_task.threshold': 200
463
+ '_dd.long_task.threshold': 200,
464
+ '_dd.first_party_hosts': []
452
465
  });
453
466
  expect(DdRumErrorTracking.startTracking).toHaveBeenCalledTimes(1);
454
467
  });
@@ -486,7 +499,8 @@ describe('DdSdkReactNative', () => {
486
499
  '_dd.sdk_version': sdkVersion,
487
500
  '_dd.service_name': fakeServiceName,
488
501
  '_dd.native_view_tracking': false,
489
- '_dd.long_task.threshold': 200
502
+ '_dd.long_task.threshold': 200,
503
+ '_dd.first_party_hosts': []
490
504
  });
491
505
  expect(DdRumErrorTracking.startTracking).toHaveBeenCalledTimes(1);
492
506
  });
@@ -523,7 +537,8 @@ describe('DdSdkReactNative', () => {
523
537
  '_dd.sdk_version': sdkVersion,
524
538
  '_dd.sdk_verbosity': SdkVerbosity.DEBUG,
525
539
  '_dd.native_view_tracking': false,
526
- '_dd.long_task.threshold': 200
540
+ '_dd.long_task.threshold': 200,
541
+ '_dd.first_party_hosts': []
527
542
  });
528
543
  expect(DdRumErrorTracking.startTracking).toHaveBeenCalledTimes(1);
529
544
  });
@@ -559,7 +574,8 @@ describe('DdSdkReactNative', () => {
559
574
  '_dd.source': 'react-native',
560
575
  '_dd.sdk_version': sdkVersion,
561
576
  '_dd.native_view_tracking': true,
562
- '_dd.long_task.threshold': 200
577
+ '_dd.long_task.threshold': 200,
578
+ '_dd.first_party_hosts': []
563
579
  });
564
580
  expect(DdRumErrorTracking.startTracking).toHaveBeenCalledTimes(1);
565
581
  });
@@ -657,7 +673,8 @@ describe('DdSdkReactNative', () => {
657
673
  '_dd.proxy.type': proxyType,
658
674
  '_dd.proxy.address': proxyAddress,
659
675
  '_dd.proxy.port': proxyPort,
660
- '_dd.long_task.threshold': 200
676
+ '_dd.long_task.threshold': 200,
677
+ '_dd.first_party_hosts': []
661
678
  });
662
679
  });
663
680
  }
@@ -717,7 +734,8 @@ describe('DdSdkReactNative', () => {
717
734
  '_dd.proxy.port': proxyPort,
718
735
  '_dd.proxy.username': proxyUsername,
719
736
  '_dd.proxy.password': proxyPassword,
720
- '_dd.long_task.threshold': 200
737
+ '_dd.long_task.threshold': 200,
738
+ '_dd.first_party_hosts': []
721
739
  });
722
740
  });
723
741
  }
@@ -31,7 +31,7 @@ jest.mock('../../../InternalLog', () => {
31
31
  });
32
32
 
33
33
  // Silence the warning https://github.com/facebook/react-native/issues/11094#issuecomment-263240420
34
- jest.mock('react-native/Libraries/Animated/src/NativeAnimatedHelper');
34
+ jest.mock('react-native/Libraries/Animated/NativeAnimatedHelper');
35
35
  jest.useFakeTimers();
36
36
 
37
37
  let testedEventsInterceptor: DdEventsInterceptor;
@@ -31,7 +31,7 @@ const styles = StyleSheet.create({
31
31
  jest.mock('../../../rum/instrumentation/DdEventsInterceptor');
32
32
 
33
33
  // Silence the warning https://github.com/facebook/react-native/issues/11094#issuecomment-263240420
34
- jest.mock('react-native/Libraries/Animated/src/NativeAnimatedHelper');
34
+ jest.mock('react-native/Libraries/Animated/NativeAnimatedHelper');
35
35
  jest.useFakeTimers();
36
36
 
37
37
  let originalMethod: typeof React.createElement;
package/src/index.tsx CHANGED
@@ -6,6 +6,7 @@
6
6
 
7
7
  import { DdSdkReactNativeConfiguration } from './DdSdkReactNativeConfiguration';
8
8
  import { DdSdkReactNative } from './DdSdkReactNative';
9
+ import { InternalLog } from './InternalLog';
9
10
  import { ProxyConfiguration, ProxyType } from './ProxyConfiguration';
10
11
  import { SdkVerbosity } from './SdkVerbosity';
11
12
  import { TrackingConsent } from './TrackingConsent';
@@ -17,6 +18,7 @@ export {
17
18
  DdRum,
18
19
  DdSdkReactNativeConfiguration,
19
20
  DdSdkReactNative,
21
+ InternalLog,
20
22
  ProxyConfiguration,
21
23
  ProxyType,
22
24
  TrackingConsent,