@datadog/mobile-react-native 1.1.5 → 1.2.0-beta2

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 (160) hide show
  1. package/DatadogSDKReactNative.podspec +2 -2
  2. package/README.md +18 -14
  3. package/android/build.gradle +28 -3
  4. package/android/detekt.yml +572 -0
  5. package/android/src/main/kotlin/com/datadog/reactnative/DatadogSDKWrapper.kt +12 -0
  6. package/android/src/main/kotlin/com/datadog/reactnative/DatadogWrapper.kt +15 -0
  7. package/android/src/main/kotlin/com/datadog/reactnative/DdSdk.kt +143 -8
  8. package/android/src/main/kotlin/com/datadog/reactnative/DdSdkConfiguration.kt +25 -1
  9. package/android/src/main/kotlin/com/datadog/reactnative/DdSdkConfigurationExt.kt +31 -1
  10. package/android/src/main/kotlin/com/datadog/reactnative/VitalFrameCallback.kt +41 -0
  11. package/android/src/test/kotlin/com/datadog/reactnative/DdRumTest.kt +7 -2
  12. package/android/src/test/kotlin/com/datadog/reactnative/DdSdkTest.kt +429 -27
  13. package/android/src/test/kotlin/com/datadog/reactnative/DdTraceTest.kt +5 -1
  14. package/android/src/test/kotlin/com/datadog/tools/unit/DdSdkConfigurationExt.kt +40 -1
  15. package/android/src/test/kotlin/com/datadog/tools/unit/GenericAssert.kt +21 -1
  16. package/android/src/test/kotlin/com/datadog/tools/unit/MapExt.kt +1 -1
  17. package/android/src/test/kotlin/com/datadog/tools/unit/forge/BaseConfigurator.kt +1 -0
  18. package/android/src/test/kotlin/com/datadog/tools/unit/forge/DdSdkConfigurationForgeryFactory.kt +22 -2
  19. package/android/src/test/kotlin/com/datadog/tools/unit/forge/PackageInfoForgeryFactory.kt +2 -3
  20. package/android/src/test/kotlin/com/datadog/tools/unit/forge/TelemetryConfigurationEventForgeryFactory.kt +94 -0
  21. package/datadog-sourcemaps.gradle +85 -28
  22. package/ios/Sources/Attributes.swift +0 -4
  23. package/ios/Sources/DdSdk.m +10 -0
  24. package/ios/Sources/DdSdk.swift +113 -10
  25. package/ios/Sources/DdSdkConfiguration.swift +38 -1
  26. package/ios/Sources/JSRefreshRateListener.swift +86 -0
  27. package/ios/Sources/QueueHolder.swift +7 -0
  28. package/ios/Sources/RNDdSdkConfiguration.swift +25 -1
  29. package/lib/commonjs/DatadogProvider/Buffer/BoundedBuffer.js +173 -0
  30. package/lib/commonjs/DatadogProvider/Buffer/BoundedBuffer.js.map +1 -0
  31. package/lib/commonjs/DatadogProvider/Buffer/BufferSingleton.js +32 -0
  32. package/lib/commonjs/DatadogProvider/Buffer/BufferSingleton.js.map +1 -0
  33. package/lib/commonjs/DatadogProvider/Buffer/DatadogBuffer.js +29 -0
  34. package/lib/commonjs/DatadogProvider/Buffer/DatadogBuffer.js.map +1 -0
  35. package/lib/commonjs/DatadogProvider/Buffer/PassThroughBuffer.js +28 -0
  36. package/lib/commonjs/DatadogProvider/Buffer/PassThroughBuffer.js.map +1 -0
  37. package/lib/commonjs/DatadogProvider/Buffer/bufferNativeCall.js +32 -0
  38. package/lib/commonjs/DatadogProvider/Buffer/bufferNativeCall.js.map +1 -0
  39. package/lib/commonjs/DatadogProvider/DatadogProvider.js +101 -0
  40. package/lib/commonjs/DatadogProvider/DatadogProvider.js.map +1 -0
  41. package/lib/commonjs/DdSdkReactNative.js +140 -59
  42. package/lib/commonjs/DdSdkReactNative.js.map +1 -1
  43. package/lib/commonjs/DdSdkReactNativeConfiguration.js +166 -9
  44. package/lib/commonjs/DdSdkReactNativeConfiguration.js.map +1 -1
  45. package/lib/commonjs/errorUtils.js +69 -0
  46. package/lib/commonjs/errorUtils.js.map +1 -0
  47. package/lib/commonjs/foundation.js +19 -12
  48. package/lib/commonjs/foundation.js.map +1 -1
  49. package/lib/commonjs/index.js +20 -0
  50. package/lib/commonjs/index.js.map +1 -1
  51. package/lib/commonjs/longTasksUtils.js +40 -0
  52. package/lib/commonjs/longTasksUtils.js.map +1 -0
  53. package/lib/commonjs/nativeModulesTypes.js.map +1 -1
  54. package/lib/commonjs/rum/instrumentation/DdRumErrorTracking.js +8 -45
  55. package/lib/commonjs/rum/instrumentation/DdRumErrorTracking.js.map +1 -1
  56. package/lib/commonjs/rum/instrumentation/DdRumUserInteractionTracking.js +16 -1
  57. package/lib/commonjs/rum/instrumentation/DdRumUserInteractionTracking.js.map +1 -1
  58. package/lib/commonjs/rum/instrumentation/getJsxRuntime.js +1 -1
  59. package/lib/commonjs/rum/instrumentation/getJsxRuntime.js.map +1 -1
  60. package/lib/commonjs/rum/instrumentation/resourceTracking/domain/distributedTracing.js +2 -1
  61. package/lib/commonjs/rum/instrumentation/resourceTracking/domain/distributedTracing.js.map +1 -1
  62. package/lib/commonjs/rum/instrumentation/resourceTracking/implementation/DatadogRumResource/ResourceReporter.js +2 -1
  63. package/lib/commonjs/rum/instrumentation/resourceTracking/implementation/DatadogRumResource/ResourceReporter.js.map +1 -1
  64. package/lib/commonjs/types.js +6 -1
  65. package/lib/commonjs/types.js.map +1 -1
  66. package/lib/commonjs/version.js +1 -1
  67. package/lib/commonjs/version.js.map +1 -1
  68. package/lib/module/DatadogProvider/Buffer/BoundedBuffer.js +163 -0
  69. package/lib/module/DatadogProvider/Buffer/BoundedBuffer.js.map +1 -0
  70. package/lib/module/DatadogProvider/Buffer/BufferSingleton.js +26 -0
  71. package/lib/module/DatadogProvider/Buffer/BufferSingleton.js.map +1 -0
  72. package/lib/module/DatadogProvider/Buffer/DatadogBuffer.js +20 -0
  73. package/lib/module/DatadogProvider/Buffer/DatadogBuffer.js.map +1 -0
  74. package/lib/module/DatadogProvider/Buffer/PassThroughBuffer.js +23 -0
  75. package/lib/module/DatadogProvider/Buffer/PassThroughBuffer.js.map +1 -0
  76. package/lib/module/DatadogProvider/Buffer/bufferNativeCall.js +16 -0
  77. package/lib/module/DatadogProvider/Buffer/bufferNativeCall.js.map +1 -0
  78. package/lib/module/DatadogProvider/DatadogProvider.js +82 -0
  79. package/lib/module/DatadogProvider/DatadogProvider.js.map +1 -0
  80. package/lib/module/DdSdkReactNative.js +132 -57
  81. package/lib/module/DdSdkReactNative.js.map +1 -1
  82. package/lib/module/DdSdkReactNativeConfiguration.js +154 -8
  83. package/lib/module/DdSdkReactNativeConfiguration.js.map +1 -1
  84. package/lib/module/errorUtils.js +54 -0
  85. package/lib/module/errorUtils.js.map +1 -0
  86. package/lib/module/foundation.js +18 -12
  87. package/lib/module/foundation.js.map +1 -1
  88. package/lib/module/index.js +3 -2
  89. package/lib/module/index.js.map +1 -1
  90. package/lib/module/longTasksUtils.js +31 -0
  91. package/lib/module/longTasksUtils.js.map +1 -0
  92. package/lib/module/nativeModulesTypes.js.map +1 -1
  93. package/lib/module/rum/instrumentation/DdRumErrorTracking.js +5 -42
  94. package/lib/module/rum/instrumentation/DdRumErrorTracking.js.map +1 -1
  95. package/lib/module/rum/instrumentation/DdRumUserInteractionTracking.js +14 -1
  96. package/lib/module/rum/instrumentation/DdRumUserInteractionTracking.js.map +1 -1
  97. package/lib/module/rum/instrumentation/getJsxRuntime.js +1 -1
  98. package/lib/module/rum/instrumentation/getJsxRuntime.js.map +1 -1
  99. package/lib/module/rum/instrumentation/resourceTracking/domain/distributedTracing.js +2 -1
  100. package/lib/module/rum/instrumentation/resourceTracking/domain/distributedTracing.js.map +1 -1
  101. package/lib/module/rum/instrumentation/resourceTracking/implementation/DatadogRumResource/ResourceReporter.js +2 -1
  102. package/lib/module/rum/instrumentation/resourceTracking/implementation/DatadogRumResource/ResourceReporter.js.map +1 -1
  103. package/lib/module/types.js +6 -1
  104. package/lib/module/types.js.map +1 -1
  105. package/lib/module/version.js +1 -1
  106. package/lib/module/version.js.map +1 -1
  107. package/lib/typescript/DatadogProvider/Buffer/BoundedBuffer.d.ts +15 -0
  108. package/lib/typescript/DatadogProvider/Buffer/BufferSingleton.d.ts +7 -0
  109. package/lib/typescript/DatadogProvider/Buffer/DatadogBuffer.d.ts +20 -0
  110. package/lib/typescript/DatadogProvider/Buffer/PassThroughBuffer.d.ts +7 -0
  111. package/lib/typescript/DatadogProvider/Buffer/bufferNativeCall.d.ts +3 -0
  112. package/lib/typescript/DatadogProvider/DatadogProvider.d.ts +26 -0
  113. package/lib/typescript/DdSdkReactNative.d.ts +18 -3
  114. package/lib/typescript/DdSdkReactNativeConfiguration.d.ts +114 -0
  115. package/lib/typescript/errorUtils.d.ts +12 -0
  116. package/lib/typescript/index.d.ts +3 -2
  117. package/lib/typescript/longTasksUtils.d.ts +6 -0
  118. package/lib/typescript/nativeModulesTypes.d.ts +12 -0
  119. package/lib/typescript/rum/instrumentation/DdRumErrorTracking.d.ts +0 -2
  120. package/lib/typescript/rum/instrumentation/DdRumUserInteractionTracking.d.ts +3 -0
  121. package/lib/typescript/rum/instrumentation/resourceTracking/domain/distributedTracing.d.ts +1 -0
  122. package/lib/typescript/rum/instrumentation/resourceTracking/domain/interfaces/RumResource.d.ts +1 -1
  123. package/lib/typescript/types.d.ts +16 -1
  124. package/lib/typescript/version.d.ts +1 -1
  125. package/package.json +3 -2
  126. package/src/DatadogProvider/Buffer/BoundedBuffer.ts +209 -0
  127. package/src/DatadogProvider/Buffer/BufferSingleton.ts +26 -0
  128. package/src/DatadogProvider/Buffer/DatadogBuffer.ts +34 -0
  129. package/src/DatadogProvider/Buffer/PassThroughBuffer.ts +16 -0
  130. package/src/DatadogProvider/Buffer/__tests__/BoundedBuffer.test.ts +202 -0
  131. package/src/DatadogProvider/Buffer/__tests__/BufferSingleton.test.ts +50 -0
  132. package/src/DatadogProvider/Buffer/bufferNativeCall.ts +24 -0
  133. package/src/DatadogProvider/DatadogProvider.tsx +122 -0
  134. package/src/DatadogProvider/__tests__/__utils__/renderWithProvider.tsx +111 -0
  135. package/src/DatadogProvider/__tests__/initialization.test.tsx +182 -0
  136. package/src/DatadogProvider/__tests__/initializationModes.test.tsx +174 -0
  137. package/src/DdSdkReactNative.tsx +206 -109
  138. package/src/DdSdkReactNativeConfiguration.tsx +225 -8
  139. package/src/__tests__/DdRumWrapper.test.tsx +3 -27
  140. package/src/__tests__/DdSdkReactNative.test.tsx +57 -13
  141. package/src/__tests__/DdSdkReactNativeConfiguration.test.ts +181 -0
  142. package/src/__tests__/foundation.test.ts +11 -2
  143. package/src/__tests__/longTasksUtils.ts +23 -0
  144. package/src/__tests__/rum/instrumentation/DdRumUserInteractionTracking.test.tsx +18 -4
  145. package/src/errorUtils.ts +58 -0
  146. package/src/foundation.tsx +15 -12
  147. package/src/index.tsx +9 -1
  148. package/src/longTasksUtils.ts +30 -0
  149. package/src/nativeModulesTypes.ts +14 -0
  150. package/src/rum/instrumentation/DdRumErrorTracking.tsx +9 -46
  151. package/src/rum/instrumentation/DdRumUserInteractionTracking.tsx +11 -1
  152. package/src/rum/instrumentation/getJsxRuntime.ts +1 -1
  153. package/src/rum/instrumentation/resourceTracking/__tests__/DdRumResourceTracking.test.ts +2 -0
  154. package/src/rum/instrumentation/resourceTracking/domain/distributedTracing.tsx +3 -1
  155. package/src/rum/instrumentation/resourceTracking/domain/interfaces/RumResource.ts +1 -1
  156. package/src/rum/instrumentation/resourceTracking/implementation/DatadogRumResource/ResourceReporter.ts +2 -1
  157. package/src/rum/instrumentation/resourceTracking/implementation/DatadogRumResource/__tests__/ResourceReporter.test.ts +2 -0
  158. package/src/rum/instrumentation/resourceTracking/implementation/__tests__/XHRProxy.test.ts +12 -47
  159. package/src/types.tsx +11 -1
  160. package/src/version.ts +1 -1
@@ -0,0 +1,163 @@
1
+ function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
2
+
3
+ /*
4
+ * Unless explicitly stated otherwise all files in this repository are licensed under the Apache License Version 2.0.
5
+ * This product includes software developed at Datadog (https://www.datadoghq.com/).
6
+ * Copyright 2016-Present Datadog, Inc.
7
+ */
8
+ import { InternalLog } from '../../InternalLog';
9
+ import { SdkVerbosity } from '../../SdkVerbosity';
10
+ import { getErrorStackTrace } from '../../errorUtils';
11
+ import { DdSdk } from '../../foundation';
12
+ import { DatadogBuffer } from './DatadogBuffer';
13
+ const DEFAULT_BUFFER_SIZE = 100;
14
+ export class BoundedBuffer extends DatadogBuffer {
15
+ constructor(bufferSize = DEFAULT_BUFFER_SIZE) {
16
+ super();
17
+
18
+ _defineProperty(this, "bufferSize", void 0);
19
+
20
+ _defineProperty(this, "buffer", []);
21
+
22
+ _defineProperty(this, "idTable", {});
23
+
24
+ _defineProperty(this, "telemetryBuffer", {});
25
+
26
+ _defineProperty(this, "addCallback", callback => {
27
+ if (this.buffer.length < this.bufferSize) {
28
+ this.buffer.push({
29
+ callback,
30
+ _type: 'VOID'
31
+ });
32
+ } else {
33
+ this.addTelemetryEvent('Buffer overflow', '', 'BufferOverflow');
34
+ }
35
+
36
+ return new Promise(resolve => resolve(undefined));
37
+ });
38
+
39
+ _defineProperty(this, "addCallbackReturningId", callback => {
40
+ try {
41
+ const bufferId = this.generateRandomBufferId();
42
+
43
+ if (this.buffer.length < this.bufferSize) {
44
+ this.buffer.push({
45
+ callback,
46
+ returnedBufferId: bufferId,
47
+ _type: 'RETURNING_ID'
48
+ });
49
+ this.idTable[bufferId] = null;
50
+ } else {
51
+ this.addTelemetryEvent('Buffer overflow', '', 'BufferOverflow');
52
+ }
53
+
54
+ return new Promise(resolve => resolve(bufferId));
55
+ } catch (error) {
56
+ this.addTelemetryEvent('Could not generate enough random numbers', getErrorStackTrace(error), 'RandomIdGenerationError'); // Not using InternalLog here as it is not yet instantiated
57
+
58
+ console.warn(`[Datadog] Could not generate enough random numbers for RUM buffer. Please check that Math.random is not overwritten. Math.random returns: ${Math.random()}`);
59
+ return new Promise(resolve => resolve(''));
60
+ }
61
+ });
62
+
63
+ _defineProperty(this, "addCallbackWithId", (callback, bufferId) => {
64
+ if (this.idTable[bufferId] !== undefined) {
65
+ this.buffer.push({
66
+ callback,
67
+ withBufferId: bufferId,
68
+ _type: 'WITH_ID'
69
+ });
70
+ } else {
71
+ this.addTelemetryEvent('Buffer overflow', '', 'BufferOverflow');
72
+ }
73
+
74
+ return new Promise(resolve => resolve(undefined));
75
+ });
76
+
77
+ _defineProperty(this, "drain", async () => {
78
+ for (let bufferIndex = 0; bufferIndex < this.buffer.length; bufferIndex++) {
79
+ try {
80
+ const item = this.buffer[bufferIndex];
81
+
82
+ if (item._type === 'RETURNING_ID') {
83
+ try {
84
+ // Here we want to await the callback result to make sure that it has registered the id returned
85
+ // by the callback before executing the callback needing this id.
86
+ // eslint-disable-next-line no-await-in-loop
87
+ const callbackId = await item.callback();
88
+ this.idTable[item.returnedBufferId] = callbackId;
89
+ } catch (error) {
90
+ InternalLog.log(`Error running a callback returning an id in Buffer: ${error}`, SdkVerbosity.WARN);
91
+ }
92
+
93
+ continue;
94
+ }
95
+
96
+ if (item._type === 'WITH_ID') {
97
+ const callbackId = this.idTable[item.withBufferId]; // callbackId can be `null` if the callback supposed to return the id errored. In this case, let's ignore the next callback.
98
+
99
+ if (callbackId !== null && callbackId !== undefined) {
100
+ item.callback(callbackId);
101
+ delete this.idTable[item.withBufferId];
102
+ } else {
103
+ InternalLog.log(`1 event was not sent as callback id was ${callbackId === null ? 'not set' : 'already unset'}`, SdkVerbosity.WARN);
104
+ }
105
+
106
+ continue;
107
+ }
108
+
109
+ item.callback();
110
+ } catch (error) {
111
+ InternalLog.log(`Error while draining Datadog Buffer: ${error}`, SdkVerbosity.WARN);
112
+ }
113
+ }
114
+
115
+ this.buffer = [];
116
+ this.drainTelemetry();
117
+ });
118
+
119
+ _defineProperty(this, "generateRandomBufferId", () => {
120
+ let tries = 0;
121
+
122
+ while (tries < 20) {
123
+ const hash = Math.random().toString(36).slice(2);
124
+
125
+ if (this.idTable[hash] !== undefined) {
126
+ tries++;
127
+ } else {
128
+ return hash;
129
+ }
130
+ }
131
+
132
+ throw new Error('Could not generate random Buffer id');
133
+ });
134
+
135
+ _defineProperty(this, "addTelemetryEvent", (message, stack, kind) => {
136
+ if (this.telemetryBuffer[kind]) {
137
+ this.telemetryBuffer[kind].occurences++;
138
+ } else {
139
+ this.telemetryBuffer[kind] = {
140
+ message,
141
+ stack,
142
+ kind,
143
+ occurences: 1
144
+ };
145
+ }
146
+ });
147
+
148
+ _defineProperty(this, "drainTelemetry", () => {
149
+ Object.values(this.telemetryBuffer).forEach(({
150
+ message,
151
+ stack,
152
+ kind,
153
+ occurences
154
+ }) => {
155
+ DdSdk.telemetryError(`${message} happened ${occurences} times.`, stack, kind);
156
+ });
157
+ });
158
+
159
+ this.bufferSize = bufferSize;
160
+ }
161
+
162
+ }
163
+ //# sourceMappingURL=BoundedBuffer.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["BoundedBuffer.ts"],"names":["InternalLog","SdkVerbosity","getErrorStackTrace","DdSdk","DatadogBuffer","DEFAULT_BUFFER_SIZE","BoundedBuffer","constructor","bufferSize","callback","buffer","length","push","_type","addTelemetryEvent","Promise","resolve","undefined","bufferId","generateRandomBufferId","returnedBufferId","idTable","error","console","warn","Math","random","withBufferId","bufferIndex","item","callbackId","log","WARN","drainTelemetry","tries","hash","toString","slice","Error","message","stack","kind","telemetryBuffer","occurences","Object","values","forEach","telemetryError"],"mappings":";;AAAA;AACA;AACA;AACA;AACA;AAEA,SAASA,WAAT,QAA4B,mBAA5B;AACA,SAASC,YAAT,QAA6B,oBAA7B;AACA,SAASC,kBAAT,QAAmC,kBAAnC;AACA,SAASC,KAAT,QAAsB,kBAAtB;AAEA,SAASC,aAAT,QAA8B,iBAA9B;AAEA,MAAMC,mBAAmB,GAAG,GAA5B;AAqBA,OAAO,MAAMC,aAAN,SAA4BF,aAA5B,CAA0C;AAa7CG,EAAAA,WAAW,CAACC,UAAkB,GAAGH,mBAAtB,EAA2C;AAClD;;AADkD;;AAAA,oCAXvB,EAWuB;;AAAA,qCAVG,EAUH;;AAAA,6CAFlD,EAEkD;;AAAA,yCAKvCI,QAAD,IAAmC;AAC7C,UAAI,KAAKC,MAAL,CAAYC,MAAZ,GAAqB,KAAKH,UAA9B,EAA0C;AACtC,aAAKE,MAAL,CAAYE,IAAZ,CAAiB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A0C;AACtCxC,QAAAA,KAAK,CAAC4C,cAAN,CACK,GAAER,OAAQ,aAAYI,UAAW,SADtC,EAEIH,KAFJ,EAGIC,IAHJ;AAKH,OAPL;AASH,KAhKqD;;AAElD,SAAKjC,UAAL,GAAkBA,UAAlB;AACH;;AAhB4C","sourcesContent":["/*\n * Unless explicitly stated otherwise all files in this repository are licensed under the Apache License Version 2.0.\n * This product includes software developed at Datadog (https://www.datadoghq.com/).\n * Copyright 2016-Present Datadog, Inc.\n */\n\nimport { InternalLog } from '../../InternalLog';\nimport { SdkVerbosity } from '../../SdkVerbosity';\nimport { getErrorStackTrace } from '../../errorUtils';\nimport { DdSdk } from '../../foundation';\n\nimport { DatadogBuffer } from './DatadogBuffer';\n\nconst DEFAULT_BUFFER_SIZE = 100;\n\ntype VoidCallback = {\n callback: () => Promise<void>;\n _type: 'VOID';\n};\n\ntype CallbackReturningId = {\n callback: () => Promise<string>;\n returnedBufferId: string;\n _type: 'RETURNING_ID';\n};\n\ntype CallbackWithId = {\n callback: (id: string) => Promise<void>;\n withBufferId: string;\n _type: 'WITH_ID';\n};\n\ntype BufferItem = VoidCallback | CallbackReturningId | CallbackWithId;\n\nexport class BoundedBuffer extends DatadogBuffer {\n private bufferSize: number;\n private buffer: BufferItem[] = [];\n private idTable: { [bufferId: string]: string | null } = {};\n private telemetryBuffer: {\n [kind: string]: {\n message: string;\n stack: string;\n kind: string;\n occurences: number;\n };\n } = {};\n\n constructor(bufferSize: number = DEFAULT_BUFFER_SIZE) {\n super();\n this.bufferSize = bufferSize;\n }\n\n addCallback = (callback: () => Promise<void>) => {\n if (this.buffer.length < this.bufferSize) {\n this.buffer.push({ callback, _type: 'VOID' });\n } else {\n this.addTelemetryEvent('Buffer overflow', '', 'BufferOverflow');\n }\n\n return new Promise<void>(resolve => resolve(undefined));\n };\n\n addCallbackReturningId = (callback: () => Promise<string>) => {\n try {\n const bufferId = this.generateRandomBufferId();\n if (this.buffer.length < this.bufferSize) {\n this.buffer.push({\n callback,\n returnedBufferId: bufferId,\n _type: 'RETURNING_ID'\n });\n this.idTable[bufferId] = null;\n } else {\n this.addTelemetryEvent('Buffer overflow', '', 'BufferOverflow');\n }\n\n return new Promise<string>(resolve => resolve(bufferId));\n } catch (error) {\n this.addTelemetryEvent(\n 'Could not generate enough random numbers',\n getErrorStackTrace(error),\n 'RandomIdGenerationError'\n );\n // Not using InternalLog here as it is not yet instantiated\n console.warn(\n `[Datadog] Could not generate enough random numbers for RUM buffer. Please check that Math.random is not overwritten. Math.random returns: ${Math.random()}`\n );\n\n return new Promise<string>(resolve => resolve(''));\n }\n };\n\n addCallbackWithId = (\n callback: (id: string) => Promise<void>,\n bufferId: string\n ) => {\n if (this.idTable[bufferId] !== undefined) {\n this.buffer.push({\n callback,\n withBufferId: bufferId,\n _type: 'WITH_ID'\n });\n } else {\n this.addTelemetryEvent('Buffer overflow', '', 'BufferOverflow');\n }\n\n return new Promise<void>(resolve => resolve(undefined));\n };\n\n drain = async () => {\n for (\n let bufferIndex = 0;\n bufferIndex < this.buffer.length;\n bufferIndex++\n ) {\n try {\n const item = this.buffer[bufferIndex];\n if (item._type === 'RETURNING_ID') {\n try {\n // Here we want to await the callback result to make sure that it has registered the id returned\n // by the callback before executing the callback needing this id.\n // eslint-disable-next-line no-await-in-loop\n const callbackId = await item.callback();\n this.idTable[item.returnedBufferId] = callbackId;\n } catch (error) {\n InternalLog.log(\n `Error running a callback returning an id in Buffer: ${error}`,\n SdkVerbosity.WARN\n );\n }\n continue;\n }\n\n if (item._type === 'WITH_ID') {\n const callbackId = this.idTable[item.withBufferId];\n // callbackId can be `null` if the callback supposed to return the id errored. In this case, let's ignore the next callback.\n if (callbackId !== null && callbackId !== undefined) {\n item.callback(callbackId);\n delete this.idTable[item.withBufferId];\n } else {\n InternalLog.log(\n `1 event was not sent as callback id was ${\n callbackId === null\n ? 'not set'\n : 'already unset'\n }`,\n SdkVerbosity.WARN\n );\n }\n continue;\n }\n\n item.callback();\n } catch (error) {\n InternalLog.log(\n `Error while draining Datadog Buffer: ${error}`,\n SdkVerbosity.WARN\n );\n }\n }\n\n this.buffer = [];\n\n this.drainTelemetry();\n };\n\n private generateRandomBufferId = (): string => {\n let tries = 0;\n while (tries < 20) {\n const hash = Math.random().toString(36).slice(2);\n if (this.idTable[hash] !== undefined) {\n tries++;\n } else {\n return hash;\n }\n }\n\n throw new Error('Could not generate random Buffer id');\n };\n\n private addTelemetryEvent = (\n message: string,\n stack: string,\n kind: string\n ) => {\n if (this.telemetryBuffer[kind]) {\n this.telemetryBuffer[kind].occurences++;\n } else {\n this.telemetryBuffer[kind] = {\n message,\n stack,\n kind,\n occurences: 1\n };\n }\n };\n\n private drainTelemetry = () => {\n Object.values(this.telemetryBuffer).forEach(\n ({ message, stack, kind, occurences }) => {\n DdSdk.telemetryError(\n `${message} happened ${occurences} times.`,\n stack,\n kind\n );\n }\n );\n };\n}\n"]}
@@ -0,0 +1,26 @@
1
+ function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
2
+
3
+ /*
4
+ * Unless explicitly stated otherwise all files in this repository are licensed under the Apache License Version 2.0.
5
+ * This product includes software developed at Datadog (https://www.datadoghq.com/).
6
+ * Copyright 2016-Present Datadog, Inc.
7
+ */
8
+ import { BoundedBuffer } from './BoundedBuffer';
9
+ import { PassThroughBuffer } from './PassThroughBuffer';
10
+ export class BufferSingleton {}
11
+
12
+ _defineProperty(BufferSingleton, "bufferInstance", new BoundedBuffer());
13
+
14
+ _defineProperty(BufferSingleton, "getInstance", () => {
15
+ return BufferSingleton.bufferInstance;
16
+ });
17
+
18
+ _defineProperty(BufferSingleton, "onInitialization", () => {
19
+ BufferSingleton.bufferInstance.drain();
20
+ BufferSingleton.bufferInstance = new PassThroughBuffer();
21
+ });
22
+
23
+ _defineProperty(BufferSingleton, "reset", () => {
24
+ BufferSingleton.bufferInstance = new BoundedBuffer();
25
+ });
26
+ //# sourceMappingURL=BufferSingleton.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["BufferSingleton.ts"],"names":["BoundedBuffer","PassThroughBuffer","BufferSingleton","bufferInstance","drain"],"mappings":";;AAAA;AACA;AACA;AACA;AACA;AAEA,SAASA,aAAT,QAA8B,iBAA9B;AAEA,SAASC,iBAAT,QAAkC,qBAAlC;AAEA,OAAO,MAAMC,eAAN,CAAsB;;gBAAhBA,e,oBACsC,IAAIF,aAAJ,E;;gBADtCE,e,iBAGY,MAAqB;AACtC,SAAOA,eAAe,CAACC,cAAvB;AACH,C;;gBALQD,e,sBAOiB,MAAM;AAC5BA,EAAAA,eAAe,CAACC,cAAhB,CAA+BC,KAA/B;AACAF,EAAAA,eAAe,CAACC,cAAhB,GAAiC,IAAIF,iBAAJ,EAAjC;AACH,C;;gBAVQC,e,WAYM,MAAM;AACjBA,EAAAA,eAAe,CAACC,cAAhB,GAAiC,IAAIH,aAAJ,EAAjC;AACH,C","sourcesContent":["/*\n * Unless explicitly stated otherwise all files in this repository are licensed under the Apache License Version 2.0.\n * This product includes software developed at Datadog (https://www.datadoghq.com/).\n * Copyright 2016-Present Datadog, Inc.\n */\n\nimport { BoundedBuffer } from './BoundedBuffer';\nimport type { DatadogBuffer } from './DatadogBuffer';\nimport { PassThroughBuffer } from './PassThroughBuffer';\n\nexport class BufferSingleton {\n private static bufferInstance: DatadogBuffer = new BoundedBuffer();\n\n static getInstance = (): DatadogBuffer => {\n return BufferSingleton.bufferInstance;\n };\n\n static onInitialization = () => {\n BufferSingleton.bufferInstance.drain();\n BufferSingleton.bufferInstance = new PassThroughBuffer();\n };\n\n static reset = () => {\n BufferSingleton.bufferInstance = new BoundedBuffer();\n };\n}\n"]}
@@ -0,0 +1,20 @@
1
+ function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
2
+
3
+ /*
4
+ * Unless explicitly stated otherwise all files in this repository are licensed under the Apache License Version 2.0.
5
+ * This product includes software developed at Datadog (https://www.datadoghq.com/).
6
+ * Copyright 2016-Present Datadog, Inc.
7
+ */
8
+ export class DatadogBuffer {
9
+ constructor() {
10
+ _defineProperty(this, "addCallback", void 0);
11
+
12
+ _defineProperty(this, "addCallbackReturningId", void 0);
13
+
14
+ _defineProperty(this, "addCallbackWithId", void 0);
15
+
16
+ _defineProperty(this, "drain", void 0);
17
+ }
18
+
19
+ }
20
+ //# sourceMappingURL=DatadogBuffer.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["DatadogBuffer.ts"],"names":["DatadogBuffer"],"mappings":";;AAAA;AACA;AACA;AACA;AACA;AAEA,OAAO,MAAeA,aAAf,CAA6B;AAAA;AAAA;;AAAA;;AAAA;;AAAA;AAAA;;AAAA","sourcesContent":["/*\n * Unless explicitly stated otherwise all files in this repository are licensed under the Apache License Version 2.0.\n * This product includes software developed at Datadog (https://www.datadoghq.com/).\n * Copyright 2016-Present Datadog, Inc.\n */\n\nexport abstract class DatadogBuffer {\n /**\n * Add a callback that takes no input and yields no output to the buffer.\n */\n abstract addCallback: (callback: () => Promise<void>) => Promise<void>;\n\n /**\n * Add a callback that returns an id to the buffer.\n * This method also returns an id (possibly different), to be passed to addCallbackWithId.\n */\n abstract addCallbackReturningId: (\n callback: () => Promise<string>\n ) => Promise<string>;\n\n /**\n * Add a callback that takes an id as input to the buffer.\n * This id must be obtained by calling addCallbackReturningId.\n */\n abstract addCallbackWithId: (\n callback: (id: string) => Promise<void>,\n id: string\n ) => Promise<void>;\n\n /**\n * Execute all callbacks in the buffer.\n */\n abstract drain: () => void;\n}\n"]}
@@ -0,0 +1,23 @@
1
+ function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
2
+
3
+ /*
4
+ * Unless explicitly stated otherwise all files in this repository are licensed under the Apache License Version 2.0.
5
+ * This product includes software developed at Datadog (https://www.datadoghq.com/).
6
+ * Copyright 2016-Present Datadog, Inc.
7
+ */
8
+ import { DatadogBuffer } from './DatadogBuffer';
9
+ export class PassThroughBuffer extends DatadogBuffer {
10
+ constructor(...args) {
11
+ super(...args);
12
+
13
+ _defineProperty(this, "addCallback", callback => callback());
14
+
15
+ _defineProperty(this, "addCallbackReturningId", callback => callback());
16
+
17
+ _defineProperty(this, "addCallbackWithId", (callback, id) => callback(id));
18
+
19
+ _defineProperty(this, "drain", () => undefined);
20
+ }
21
+
22
+ }
23
+ //# sourceMappingURL=PassThroughBuffer.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["PassThroughBuffer.ts"],"names":["DatadogBuffer","PassThroughBuffer","callback","id","undefined"],"mappings":";;AAAA;AACA;AACA;AACA;AACA;AAEA,SAASA,aAAT,QAA8B,iBAA9B;AAEA,OAAO,MAAMC,iBAAN,SAAgCD,aAAhC,CAA8C;AAAA;AAAA;;AAAA,yCAClCE,QAAD,IAAyBA,QAAQ,EADE;;AAAA,oDAEvBA,QAAD,IAAyBA,QAAQ,EAFT;;AAAA,+CAG7B,CAACA,QAAD,EAAgCC,EAAhC,KAChBD,QAAQ,CAACC,EAAD,CAJqC;;AAAA,mCAMzC,MAAMC,SANmC;AAAA;;AAAA","sourcesContent":["/*\n * Unless explicitly stated otherwise all files in this repository are licensed under the Apache License Version 2.0.\n * This product includes software developed at Datadog (https://www.datadoghq.com/).\n * Copyright 2016-Present Datadog, Inc.\n */\n\nimport { DatadogBuffer } from './DatadogBuffer';\n\nexport class PassThroughBuffer extends DatadogBuffer {\n addCallback = (callback: () => any) => callback();\n addCallbackReturningId = (callback: () => any) => callback();\n addCallbackWithId = (callback: (id: string) => any, id: string) =>\n callback(id);\n\n drain = () => undefined;\n}\n"]}
@@ -0,0 +1,16 @@
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 { BufferSingleton } from './BufferSingleton';
7
+ export const bufferVoidNativeCall = callback => {
8
+ return BufferSingleton.getInstance().addCallback(callback);
9
+ };
10
+ export const bufferNativeCallReturningId = callback => {
11
+ return BufferSingleton.getInstance().addCallbackReturningId(callback);
12
+ };
13
+ export const bufferNativeCallWithId = (callback, id) => {
14
+ return BufferSingleton.getInstance().addCallbackWithId(callback, id);
15
+ };
16
+ //# sourceMappingURL=bufferNativeCall.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["bufferNativeCall.ts"],"names":["BufferSingleton","bufferVoidNativeCall","callback","getInstance","addCallback","bufferNativeCallReturningId","addCallbackReturningId","bufferNativeCallWithId","id","addCallbackWithId"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AAEA,SAASA,eAAT,QAAgC,mBAAhC;AAEA,OAAO,MAAMC,oBAAoB,GAAIC,QAAD,IAAmC;AACnE,SAAOF,eAAe,CAACG,WAAhB,GAA8BC,WAA9B,CAA0CF,QAA1C,CAAP;AACH,CAFM;AAIP,OAAO,MAAMG,2BAA2B,GACpCH,QADuC,IAEtC;AACD,SAAOF,eAAe,CAACG,WAAhB,GAA8BG,sBAA9B,CAAqDJ,QAArD,CAAP;AACH,CAJM;AAMP,OAAO,MAAMK,sBAAsB,GAAG,CAClCL,QADkC,EAElCM,EAFkC,KAGjC;AACD,SAAOR,eAAe,CAACG,WAAhB,GAA8BM,iBAA9B,CAAgDP,QAAhD,EAA0DM,EAA1D,CAAP;AACH,CALM","sourcesContent":["/*\n * Unless explicitly stated otherwise all files in this repository are licensed under the Apache License Version 2.0.\n * This product includes software developed at Datadog (https://www.datadoghq.com/).\n * Copyright 2016-Present Datadog, Inc.\n */\n\nimport { BufferSingleton } from './BufferSingleton';\n\nexport const bufferVoidNativeCall = (callback: () => Promise<void>) => {\n return BufferSingleton.getInstance().addCallback(callback);\n};\n\nexport const bufferNativeCallReturningId = (\n callback: () => Promise<string>\n) => {\n return BufferSingleton.getInstance().addCallbackReturningId(callback);\n};\n\nexport const bufferNativeCallWithId = (\n callback: (id: string) => Promise<void>,\n id: string\n) => {\n return BufferSingleton.getInstance().addCallbackWithId(callback, id);\n};\n"]}
@@ -0,0 +1,82 @@
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 React from 'react';
7
+ import { DatadogProviderConfiguration, DdSdkReactNativeConfiguration } from '../DdSdkReactNativeConfiguration';
8
+ import { DdSdkReactNative } from '../DdSdkReactNative';
9
+ import { InternalLog } from '../InternalLog';
10
+ import { SdkVerbosity } from '../SdkVerbosity';
11
+ let isInitialized = false;
12
+
13
+ const isConfigurationPartial = configuration => {
14
+ if (configuration instanceof DatadogProviderConfiguration) {
15
+ return false;
16
+ }
17
+
18
+ if (configuration instanceof DdSdkReactNativeConfiguration) {
19
+ // Not using InternalLog here as it is not yet instanciated
20
+ console.warn('A DdSdkReactNativeConfiguration was passed to DatadogProvider. Please use DatadogProviderConfiguration instead.');
21
+ return false;
22
+ }
23
+
24
+ return true;
25
+ };
26
+
27
+ const initializeDatadog = async (configuration, onInitialization) => {
28
+ await DdSdkReactNative._initializeFromDatadogProvider(configuration);
29
+
30
+ if (onInitialization) {
31
+ try {
32
+ onInitialization();
33
+ } catch (error) {
34
+ InternalLog.log(`Error running onInitialization callback ${error}`, SdkVerbosity.WARN);
35
+ }
36
+ }
37
+ };
38
+ /**
39
+ * Set up the Datadog React Native SDK.
40
+ */
41
+
42
+
43
+ export const DatadogProvider = ({
44
+ children,
45
+ configuration,
46
+ onInitialization
47
+ }) => {
48
+ if (!isInitialized) {
49
+ // Here we cannot use a useEffect hook since it would be called after
50
+ // the first render. Thus, we wouldn't enable auto-instrumentation on
51
+ // the elements rendered in this first render and what happens during
52
+ // the first render.
53
+ if (isConfigurationPartial(configuration)) {
54
+ DdSdkReactNative._enableFeaturesFromDatadogProvider(configuration);
55
+
56
+ DatadogProvider.onInitialization = onInitialization;
57
+ } else {
58
+ initializeDatadog(configuration, onInitialization);
59
+ }
60
+
61
+ isInitialized = true;
62
+ }
63
+
64
+ return /*#__PURE__*/React.createElement(React.Fragment, null, children);
65
+ };
66
+ /**
67
+ * Initialize the Datadog SDK to start sending RUM events, logs and traces,
68
+ * then execute onInitialization callback if any was provided.
69
+ */
70
+
71
+ DatadogProvider.initialize = async configuration => {
72
+ await DdSdkReactNative._initializeFromDatadogProviderWithConfigurationAsync(configuration);
73
+
74
+ if (DatadogProvider.onInitialization) {
75
+ DatadogProvider.onInitialization();
76
+ }
77
+ };
78
+
79
+ export const __internalResetIsInitializedForTesting = () => {
80
+ isInitialized = false;
81
+ };
82
+ //# sourceMappingURL=DatadogProvider.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["DatadogProvider.tsx"],"names":["React","DatadogProviderConfiguration","DdSdkReactNativeConfiguration","DdSdkReactNative","InternalLog","SdkVerbosity","isInitialized","isConfigurationPartial","configuration","console","warn","initializeDatadog","onInitialization","_initializeFromDatadogProvider","error","log","WARN","DatadogProvider","children","_enableFeaturesFromDatadogProvider","initialize","_initializeFromDatadogProviderWithConfigurationAsync","__internalResetIsInitializedForTesting"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA,OAAOA,KAAP,MAAkB,OAAlB;AAGA,SACIC,4BADJ,EAEIC,6BAFJ,QAGO,kCAHP;AAQA,SAASC,gBAAT,QAAiC,qBAAjC;AACA,SAASC,WAAT,QAA4B,gBAA5B;AACA,SAASC,YAAT,QAA6B,iBAA7B;AAEA,IAAIC,aAAa,GAAG,KAApB;;AAwBA,MAAMC,sBAAsB,GACxBC,aAD2B,IAIyB;AACpD,MAAIA,aAAa,YAAYP,4BAA7B,EAA2D;AACvD,WAAO,KAAP;AACH;;AACD,MAAIO,aAAa,YAAYN,6BAA7B,EAA4D;AACxD;AACAO,IAAAA,OAAO,CAACC,IAAR,CACI,iHADJ;AAGA,WAAO,KAAP;AACH;;AACD,SAAO,IAAP;AACH,CAhBD;;AAkBA,MAAMC,iBAAiB,GAAG,OACtBH,aADsB,EAEtBI,gBAFsB,KAGrB;AACD,QAAMT,gBAAgB,CAACU,8BAAjB,CAAgDL,aAAhD,CAAN;;AACA,MAAII,gBAAJ,EAAsB;AAClB,QAAI;AACAA,MAAAA,gBAAgB;AACnB,KAFD,CAEE,OAAOE,KAAP,EAAc;AACZV,MAAAA,WAAW,CAACW,GAAZ,CACK,2CAA0CD,KAAM,EADrD,EAEIT,YAAY,CAACW,IAFjB;AAIH;AACJ;AACJ,CAfD;AAiBA;AACA;AACA;;;AACA,OAAO,MAAMC,eAAmD,GAAG,CAAC;AAChEC,EAAAA,QADgE;AAEhEV,EAAAA,aAFgE;AAGhEI,EAAAA;AAHgE,CAAD,KAI7D;AACF,MAAI,CAACN,aAAL,EAAoB;AAChB;AACA;AACA;AACA;AACA,QAAIC,sBAAsB,CAACC,aAAD,CAA1B,EAA2C;AACvCL,MAAAA,gBAAgB,CAACgB,kCAAjB,CAAoDX,aAApD;;AACAS,MAAAA,eAAe,CAACL,gBAAhB,GAAmCA,gBAAnC;AACH,KAHD,MAGO;AACHD,MAAAA,iBAAiB,CAACH,aAAD,EAAgBI,gBAAhB,CAAjB;AACH;;AACDN,IAAAA,aAAa,GAAG,IAAhB;AACH;;AAED,sBAAO,0CAAGY,QAAH,CAAP;AACH,CApBM;AAsBP;AACA;AACA;AACA;;AACAD,eAAe,CAACG,UAAhB,GAA6B,MACzBZ,aADyB,IAExB;AACD,QAAML,gBAAgB,CAACkB,oDAAjB,CACFb,aADE,CAAN;;AAGA,MAAIS,eAAe,CAACL,gBAApB,EAAsC;AAClCK,IAAAA,eAAe,CAACL,gBAAhB;AACH;AACJ,CATD;;AAWA,OAAO,MAAMU,sCAAsC,GAAG,MAAM;AACxDhB,EAAAA,aAAa,GAAG,KAAhB;AACH,CAFM","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 */\nimport React from 'react';\nimport type { PropsWithChildren } from 'react';\n\nimport {\n DatadogProviderConfiguration,\n DdSdkReactNativeConfiguration\n} from '../DdSdkReactNativeConfiguration';\nimport type {\n PartialInitializationConfiguration,\n AutoInstrumentationConfiguration\n} from '../DdSdkReactNativeConfiguration';\nimport { DdSdkReactNative } from '../DdSdkReactNative';\nimport { InternalLog } from '../InternalLog';\nimport { SdkVerbosity } from '../SdkVerbosity';\n\nlet isInitialized = false;\n\ntype Props = PropsWithChildren<{\n /**\n * If a `DatadogProviderConfiguration` instance is passed, the SDK will start tracking errors, resources and actions and sending events.\n *\n * If a `AutoInstrumentationConfiguration` object is passed, the SDK will start tracking errors, resources and actions. To start sending events, call `DatadogProvider.initialize`.\n */\n configuration:\n | DatadogProviderConfiguration\n | AutoInstrumentationConfiguration;\n /**\n * Callback to be run once the SDK starts sending events.\n */\n onInitialization?: () => void;\n}>;\n\ntype StaticProperties = {\n initialize: (\n configuration: PartialInitializationConfiguration\n ) => Promise<void>;\n onInitialization?: () => void;\n};\n\nconst isConfigurationPartial = (\n configuration:\n | DatadogProviderConfiguration\n | AutoInstrumentationConfiguration\n): configuration is AutoInstrumentationConfiguration => {\n if (configuration instanceof DatadogProviderConfiguration) {\n return false;\n }\n if (configuration instanceof DdSdkReactNativeConfiguration) {\n // Not using InternalLog here as it is not yet instanciated\n console.warn(\n 'A DdSdkReactNativeConfiguration was passed to DatadogProvider. Please use DatadogProviderConfiguration instead.'\n );\n return false;\n }\n return true;\n};\n\nconst initializeDatadog = async (\n configuration: DatadogProviderConfiguration,\n onInitialization?: () => void\n) => {\n await DdSdkReactNative._initializeFromDatadogProvider(configuration);\n if (onInitialization) {\n try {\n onInitialization();\n } catch (error) {\n InternalLog.log(\n `Error running onInitialization callback ${error}`,\n SdkVerbosity.WARN\n );\n }\n }\n};\n\n/**\n * Set up the Datadog React Native SDK.\n */\nexport const DatadogProvider: React.FC<Props> & StaticProperties = ({\n children,\n configuration,\n onInitialization\n}) => {\n if (!isInitialized) {\n // Here we cannot use a useEffect hook since it would be called after\n // the first render. Thus, we wouldn't enable auto-instrumentation on\n // the elements rendered in this first render and what happens during\n // the first render.\n if (isConfigurationPartial(configuration)) {\n DdSdkReactNative._enableFeaturesFromDatadogProvider(configuration);\n DatadogProvider.onInitialization = onInitialization;\n } else {\n initializeDatadog(configuration, onInitialization);\n }\n isInitialized = true;\n }\n\n return <>{children}</>;\n};\n\n/**\n * Initialize the Datadog SDK to start sending RUM events, logs and traces,\n * then execute onInitialization callback if any was provided.\n */\nDatadogProvider.initialize = async (\n configuration: PartialInitializationConfiguration\n) => {\n await DdSdkReactNative._initializeFromDatadogProviderWithConfigurationAsync(\n configuration\n );\n if (DatadogProvider.onInitialization) {\n DatadogProvider.onInitialization();\n }\n};\n\nexport const __internalResetIsInitializedForTesting = () => {\n isInitialized = false;\n};\n"]}
@@ -5,10 +5,14 @@ function _defineProperty(obj, key, value) { if (key in obj) { Object.definePrope
5
5
  * This product includes software developed at Datadog (https://www.datadoghq.com/).
6
6
  * Copyright 2016-Present Datadog, Inc.
7
7
  */
8
+ import { InteractionManager } from 'react-native';
9
+ import { BufferSingleton } from './DatadogProvider/Buffer/BufferSingleton';
10
+ import { DdSdkReactNativeConfiguration, buildConfigurationFromPartialConfiguration, addDefaultValuesToAutoInstrumentationConfiguration, InitializationMode } from './DdSdkReactNativeConfiguration';
8
11
  import { InternalLog } from './InternalLog';
9
12
  import { ProxyType } from './ProxyConfiguration';
10
13
  import { SdkVerbosity } from './SdkVerbosity';
11
14
  import { DdSdk } from './foundation';
15
+ import { adaptLongTaskThreshold } from './longTasksUtils';
12
16
  import { DdRumErrorTracking } from './rum/instrumentation/DdRumErrorTracking';
13
17
  import { DdRumUserInteractionTracking } from './rum/instrumentation/DdRumUserInteractionTracking';
14
18
  import { DdRumResourceTracking } from './rum/instrumentation/resourceTracking/DdRumResourceTracking';
@@ -26,74 +30,60 @@ export class DdSdkReactNative {
26
30
  * @param configuration the configuration for the SDK library
27
31
  * @returns a Promise.
28
32
  */
29
- static initialize(configuration) {
30
- return new Promise((resolve, reject) => {
31
- if (DdSdkReactNative.wasInitialized) {
32
- InternalLog.log("Can't initialize Datadog, SDK was already initialized", SdkVerbosity.WARN);
33
- resolve();
34
- return;
35
- }
36
-
37
- InternalLog.verbosity = configuration.verbosity;
38
- configuration.additionalConfig[DdSdkReactNative.DD_SOURCE_KEY] = 'react-native';
39
- configuration.additionalConfig[DdSdkReactNative.DD_SDK_VERSION] = sdkVersion;
40
- configuration.additionalConfig[DdSdkReactNative.DD_NATIVE_VIEW_TRACKING_KEY] = configuration.nativeViewTracking;
33
+ static async initialize(configuration) {
34
+ await DdSdkReactNative.initializeNativeSDK(configuration, {
35
+ initializationModeForTelemetry: 'LEGACY'
36
+ });
37
+ DdSdkReactNative.enableFeatures(configuration);
38
+ }
41
39
 
42
- if (configuration.verbosity) {
43
- configuration.additionalConfig[DdSdkReactNative.DD_SDK_VERBOSITY_KEY] = configuration.verbosity;
44
- }
40
+ /**
41
+ * FOR INTERNAL USE ONLY.
42
+ */
43
+ static async _initializeFromDatadogProvider(configuration) {
44
+ DdSdkReactNative.enableFeatures(configuration);
45
45
 
46
- if (configuration.proxyConfig) {
47
- const additionalConfig = configuration.additionalConfig;
48
- const proxyConfig = configuration.proxyConfig;
49
- additionalConfig[DdSdkReactNative.DD_PROXY_TYPE_KEY] = proxyConfig.type;
50
- additionalConfig[DdSdkReactNative.DD_PROXY_ADDRESS_KEY] = proxyConfig.address;
51
- additionalConfig[DdSdkReactNative.DD_PROXY_PORT_KEY] = proxyConfig.port;
52
-
53
- if (proxyConfig.username && proxyConfig.password) {
54
- if (proxyConfig.type === ProxyType.SOCKS) {
55
- console.warn("SOCKS proxy configuration doesn't support Basic authentication.");
56
- } else {
57
- additionalConfig[DdSdkReactNative.DD_PROXY_USERNAME_KEY] = proxyConfig.username;
58
- additionalConfig[DdSdkReactNative.DD_PROXY_PASSWORD_KEY] = proxyConfig.password;
59
- }
60
- }
61
- }
46
+ if (configuration.initializationMode === InitializationMode.SYNC) {
47
+ return DdSdkReactNative.initializeNativeSDK(configuration, {
48
+ initializationModeForTelemetry: 'SYNC'
49
+ });
50
+ }
62
51
 
63
- if (configuration.serviceName) {
64
- configuration.additionalConfig[DdSdkReactNative.DD_SERVICE_NAME] = configuration.serviceName;
65
- }
52
+ if (configuration.initializationMode === InitializationMode.ASYNC) {
53
+ return InteractionManager.runAfterInteractions(() => {
54
+ return DdSdkReactNative.initializeNativeSDK(configuration, {
55
+ initializationModeForTelemetry: 'ASYNC'
56
+ });
57
+ });
58
+ } // TODO: Remove when DdSdkReactNativeConfiguration is deprecated
66
59
 
67
- if (configuration.version) {
68
- configuration.additionalConfig[DdSdkReactNative.DD_VERSION] = `${configuration.version}${configuration.versionSuffix ? `-${configuration.versionSuffix}` : ''}`;
69
- } // If both version and version suffix are provided, we merge them into the version field.
70
- // To avoid adding it in again the native part, we only set it if the version isn't set.
71
60
 
61
+ if (configuration instanceof DdSdkReactNativeConfiguration) {
62
+ return DdSdkReactNative.initializeNativeSDK(configuration, {
63
+ initializationModeForTelemetry: 'SYNC'
64
+ });
65
+ }
66
+ }
67
+ /**
68
+ * FOR INTERNAL USE ONLY.
69
+ */
72
70
 
73
- if (configuration.versionSuffix && !configuration.version) {
74
- configuration.additionalConfig[DdSdkReactNative.DD_VERSION_SUFFIX] = `-${configuration.versionSuffix}`;
75
- }
76
71
 
77
- configuration.additionalConfig[DdSdkReactNative.DD_NATIVE_LONG_TASK_THRESHOLD_KEY] = DdSdkReactNative.NATIVE_LONG_TASK_THRESHOLD_MS;
78
- configuration.additionalConfig['_dd.first_party_hosts'] = configuration.firstPartyHosts;
79
- DdSdk.initialize(new DdSdkConfiguration(configuration.clientToken, configuration.env, configuration.applicationId, configuration.nativeCrashReportEnabled, configuration.sampleRate === undefined ? configuration.sessionSamplingRate : configuration.sampleRate, configuration.site, configuration.trackingConsent, configuration.additionalConfig)).then(() => {
80
- InternalLog.log('Datadog SDK was initialized', SdkVerbosity.INFO);
81
- DdSdkReactNative.enableFeatures(configuration);
82
- DdSdkReactNative.wasInitialized = true;
83
- resolve();
84
- }, rejection => {
85
- reject(rejection);
86
- });
87
- });
72
+ static async _enableFeaturesFromDatadogProvider(features) {
73
+ DdSdkReactNative.features = features;
74
+ DdSdkReactNative.enableFeatures(addDefaultValuesToAutoInstrumentationConfiguration(features));
88
75
  }
76
+ /**
77
+ * FOR INTERNAL USE ONLY.
78
+ */
79
+
80
+
89
81
  /**
90
82
  * Sets the global context (set of attributes) attached with all future Logs, Spans and RUM events.
91
83
  * @param attributes: The global context attributes.
92
84
  * @returns a Promise.
93
85
  */
94
86
  // eslint-disable-next-line @typescript-eslint/ban-types
95
-
96
-
97
87
  static setAttributes(attributes) {
98
88
  InternalLog.log(`Setting attributes ${JSON.stringify(attributes)}`, SdkVerbosity.DEBUG);
99
89
  return DdSdk.setAttributes(attributes);
@@ -123,6 +113,11 @@ export class DdSdkReactNative {
123
113
  }
124
114
 
125
115
  static enableFeatures(configuration) {
116
+ if (DdSdkReactNative.wasAutoInstrumented) {
117
+ InternalLog.log("Can't auto instrument Datadog, SDK was already instrumented", SdkVerbosity.WARN);
118
+ return;
119
+ }
120
+
126
121
  if (configuration.trackInteractions) {
127
122
  DdRumUserInteractionTracking.startTracking();
128
123
  }
@@ -137,6 +132,8 @@ export class DdSdkReactNative {
137
132
  if (configuration.trackErrors) {
138
133
  DdRumErrorTracking.startTracking();
139
134
  }
135
+
136
+ DdSdkReactNative.wasAutoInstrumented = true;
140
137
  }
141
138
 
142
139
  }
@@ -165,9 +162,87 @@ _defineProperty(DdSdkReactNative, "DD_PROXY_USERNAME_KEY", '_dd.proxy.username')
165
162
 
166
163
  _defineProperty(DdSdkReactNative, "DD_PROXY_PASSWORD_KEY", '_dd.proxy.password');
167
164
 
168
- _defineProperty(DdSdkReactNative, "DD_NATIVE_LONG_TASK_THRESHOLD_KEY", '_dd.long_task.threshold');
165
+ _defineProperty(DdSdkReactNative, "wasInitialized", false);
169
166
 
170
- _defineProperty(DdSdkReactNative, "NATIVE_LONG_TASK_THRESHOLD_MS", 200);
167
+ _defineProperty(DdSdkReactNative, "wasAutoInstrumented", false);
171
168
 
172
- _defineProperty(DdSdkReactNative, "wasInitialized", false);
169
+ _defineProperty(DdSdkReactNative, "features", void 0);
170
+
171
+ _defineProperty(DdSdkReactNative, "initializeNativeSDK", async (configuration, params) => {
172
+ if (DdSdkReactNative.wasInitialized) {
173
+ InternalLog.log("Can't initialize Datadog, SDK was already initialized", SdkVerbosity.WARN);
174
+
175
+ if (!__DEV__) {
176
+ DdSdk.telemetryDebug('RN SDK was already initialized in javascript');
177
+ }
178
+
179
+ return new Promise(resolve => resolve());
180
+ }
181
+
182
+ InternalLog.verbosity = configuration.verbosity;
183
+ DdSdkReactNative.buildConfiguration(configuration);
184
+ await DdSdk.initialize(new DdSdkConfiguration(configuration.clientToken, configuration.env, configuration.applicationId, configuration.nativeCrashReportEnabled, adaptLongTaskThreshold(configuration.nativeLongTaskThresholdMs), adaptLongTaskThreshold(configuration.longTaskThresholdMs), configuration.sampleRate === undefined ? configuration.sessionSamplingRate : configuration.sampleRate, configuration.site, configuration.trackingConsent, configuration.additionalConfig, configuration.telemetrySampleRate, configuration.vitalsUpdateFrequency, {
185
+ initializationType: params.initializationModeForTelemetry,
186
+ trackErrors: configuration.trackErrors,
187
+ trackInteractions: configuration.trackInteractions,
188
+ trackNetworkRequests: configuration.trackResources
189
+ }));
190
+ InternalLog.log('Datadog SDK was initialized', SdkVerbosity.INFO);
191
+ DdSdkReactNative.wasInitialized = true;
192
+ BufferSingleton.onInitialization();
193
+ });
194
+
195
+ _defineProperty(DdSdkReactNative, "_initializeFromDatadogProviderWithConfigurationAsync", async configuration => {
196
+ if (!DdSdkReactNative.features) {
197
+ InternalLog.log("Can't initialize Datadog, make sure the DatadogProvider component is mounted before calling this function", SdkVerbosity.WARN);
198
+ return new Promise(resolve => resolve());
199
+ }
200
+
201
+ return DdSdkReactNative.initializeNativeSDK(buildConfigurationFromPartialConfiguration(DdSdkReactNative.features, configuration), {
202
+ initializationModeForTelemetry: 'PARTIAL'
203
+ });
204
+ });
205
+
206
+ _defineProperty(DdSdkReactNative, "buildConfiguration", configuration => {
207
+ configuration.additionalConfig[DdSdkReactNative.DD_SOURCE_KEY] = 'react-native';
208
+ configuration.additionalConfig[DdSdkReactNative.DD_SDK_VERSION] = sdkVersion;
209
+ configuration.additionalConfig[DdSdkReactNative.DD_NATIVE_VIEW_TRACKING_KEY] = configuration.nativeViewTracking;
210
+
211
+ if (configuration.verbosity) {
212
+ configuration.additionalConfig[DdSdkReactNative.DD_SDK_VERBOSITY_KEY] = configuration.verbosity;
213
+ }
214
+
215
+ if (configuration.proxyConfig) {
216
+ const additionalConfig = configuration.additionalConfig;
217
+ const proxyConfig = configuration.proxyConfig;
218
+ additionalConfig[DdSdkReactNative.DD_PROXY_TYPE_KEY] = proxyConfig.type;
219
+ additionalConfig[DdSdkReactNative.DD_PROXY_ADDRESS_KEY] = proxyConfig.address;
220
+ additionalConfig[DdSdkReactNative.DD_PROXY_PORT_KEY] = proxyConfig.port;
221
+
222
+ if (proxyConfig.username && proxyConfig.password) {
223
+ if (proxyConfig.type === ProxyType.SOCKS) {
224
+ console.warn("SOCKS proxy configuration doesn't support Basic authentication.");
225
+ } else {
226
+ additionalConfig[DdSdkReactNative.DD_PROXY_USERNAME_KEY] = proxyConfig.username;
227
+ additionalConfig[DdSdkReactNative.DD_PROXY_PASSWORD_KEY] = proxyConfig.password;
228
+ }
229
+ }
230
+ }
231
+
232
+ if (configuration.serviceName) {
233
+ configuration.additionalConfig[DdSdkReactNative.DD_SERVICE_NAME] = configuration.serviceName;
234
+ }
235
+
236
+ if (configuration.version) {
237
+ configuration.additionalConfig[DdSdkReactNative.DD_VERSION] = `${configuration.version}${configuration.versionSuffix ? `-${configuration.versionSuffix}` : ''}`;
238
+ } // If both version and version suffix are provided, we merge them into the version field.
239
+ // To avoid adding it in again the native part, we only set it if the version isn't set.
240
+
241
+
242
+ if (configuration.versionSuffix && !configuration.version) {
243
+ configuration.additionalConfig[DdSdkReactNative.DD_VERSION_SUFFIX] = `-${configuration.versionSuffix}`;
244
+ }
245
+
246
+ configuration.additionalConfig['_dd.first_party_hosts'] = configuration.firstPartyHosts;
247
+ });
173
248
  //# sourceMappingURL=DdSdkReactNative.js.map