@datadog/mobile-react-native 1.1.3 → 1.2.0-beta1
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.
- package/README.md +18 -14
- package/android/src/main/kotlin/com/datadog/reactnative/DatadogSDKWrapper.kt +8 -0
- package/android/src/main/kotlin/com/datadog/reactnative/DatadogWrapper.kt +10 -0
- package/android/src/main/kotlin/com/datadog/reactnative/DdSdk.kt +25 -0
- package/android/src/main/kotlin/com/datadog/reactnative/DdSdkConfiguration.kt +2 -0
- package/android/src/main/kotlin/com/datadog/reactnative/DdSdkConfigurationExt.kt +2 -0
- package/android/src/test/kotlin/com/datadog/reactnative/DdSdkTest.kt +52 -0
- package/android/src/test/kotlin/com/datadog/tools/unit/DdSdkConfigurationExt.kt +7 -0
- package/android/src/test/kotlin/com/datadog/tools/unit/forge/DdSdkConfigurationForgeryFactory.kt +1 -0
- package/ios/Sources/DdSdk.m +10 -0
- package/ios/Sources/DdSdk.swift +17 -0
- package/ios/Sources/DdSdkConfiguration.swift +4 -0
- package/ios/Sources/RNDdSdkConfiguration.swift +2 -0
- package/lib/commonjs/DatadogProvider/Buffer/BoundedBuffer.js +173 -0
- package/lib/commonjs/DatadogProvider/Buffer/BoundedBuffer.js.map +1 -0
- package/lib/commonjs/DatadogProvider/Buffer/BufferSingleton.js +32 -0
- package/lib/commonjs/DatadogProvider/Buffer/BufferSingleton.js.map +1 -0
- package/lib/commonjs/DatadogProvider/Buffer/DatadogBuffer.js +29 -0
- package/lib/commonjs/DatadogProvider/Buffer/DatadogBuffer.js.map +1 -0
- package/lib/commonjs/DatadogProvider/Buffer/PassThroughBuffer.js +28 -0
- package/lib/commonjs/DatadogProvider/Buffer/PassThroughBuffer.js.map +1 -0
- package/lib/commonjs/DatadogProvider/Buffer/bufferNativeCall.js +32 -0
- package/lib/commonjs/DatadogProvider/Buffer/bufferNativeCall.js.map +1 -0
- package/lib/commonjs/DatadogProvider/DatadogProvider.js +101 -0
- package/lib/commonjs/DatadogProvider/DatadogProvider.js.map +1 -0
- package/lib/commonjs/DdSdkReactNative.js +138 -56
- package/lib/commonjs/DdSdkReactNative.js.map +1 -1
- package/lib/commonjs/DdSdkReactNativeConfiguration.js +102 -9
- package/lib/commonjs/DdSdkReactNativeConfiguration.js.map +1 -1
- package/lib/commonjs/errorUtils.js +60 -0
- package/lib/commonjs/errorUtils.js.map +1 -0
- package/lib/commonjs/foundation.js +19 -12
- package/lib/commonjs/foundation.js.map +1 -1
- package/lib/commonjs/index.js +20 -0
- package/lib/commonjs/index.js.map +1 -1
- package/lib/commonjs/nativeModulesTypes.js.map +1 -1
- package/lib/commonjs/rum/instrumentation/DdRumErrorTracking.js +8 -45
- package/lib/commonjs/rum/instrumentation/DdRumErrorTracking.js.map +1 -1
- package/lib/commonjs/rum/instrumentation/DdRumUserInteractionTracking.js +19 -9
- package/lib/commonjs/rum/instrumentation/DdRumUserInteractionTracking.js.map +1 -1
- package/lib/commonjs/rum/instrumentation/getJsxRuntime.js +55 -0
- package/lib/commonjs/rum/instrumentation/getJsxRuntime.js.map +1 -0
- package/lib/commonjs/types.js +2 -1
- package/lib/commonjs/types.js.map +1 -1
- package/lib/commonjs/version.js +1 -1
- package/lib/commonjs/version.js.map +1 -1
- package/lib/module/DatadogProvider/Buffer/BoundedBuffer.js +163 -0
- package/lib/module/DatadogProvider/Buffer/BoundedBuffer.js.map +1 -0
- package/lib/module/DatadogProvider/Buffer/BufferSingleton.js +26 -0
- package/lib/module/DatadogProvider/Buffer/BufferSingleton.js.map +1 -0
- package/lib/module/DatadogProvider/Buffer/DatadogBuffer.js +20 -0
- package/lib/module/DatadogProvider/Buffer/DatadogBuffer.js.map +1 -0
- package/lib/module/DatadogProvider/Buffer/PassThroughBuffer.js +23 -0
- package/lib/module/DatadogProvider/Buffer/PassThroughBuffer.js.map +1 -0
- package/lib/module/DatadogProvider/Buffer/bufferNativeCall.js +16 -0
- package/lib/module/DatadogProvider/Buffer/bufferNativeCall.js.map +1 -0
- package/lib/module/DatadogProvider/DatadogProvider.js +82 -0
- package/lib/module/DatadogProvider/DatadogProvider.js.map +1 -0
- package/lib/module/DdSdkReactNative.js +130 -54
- package/lib/module/DdSdkReactNative.js.map +1 -1
- package/lib/module/DdSdkReactNativeConfiguration.js +91 -8
- package/lib/module/DdSdkReactNativeConfiguration.js.map +1 -1
- package/lib/module/errorUtils.js +45 -0
- package/lib/module/errorUtils.js.map +1 -0
- package/lib/module/foundation.js +18 -12
- package/lib/module/foundation.js.map +1 -1
- package/lib/module/index.js +3 -2
- package/lib/module/index.js.map +1 -1
- package/lib/module/nativeModulesTypes.js.map +1 -1
- package/lib/module/rum/instrumentation/DdRumErrorTracking.js +5 -42
- package/lib/module/rum/instrumentation/DdRumErrorTracking.js.map +1 -1
- package/lib/module/rum/instrumentation/DdRumUserInteractionTracking.js +16 -9
- package/lib/module/rum/instrumentation/DdRumUserInteractionTracking.js.map +1 -1
- package/lib/module/rum/instrumentation/getJsxRuntime.js +45 -0
- package/lib/module/rum/instrumentation/getJsxRuntime.js.map +1 -0
- package/lib/module/types.js +2 -1
- package/lib/module/types.js.map +1 -1
- package/lib/module/version.js +1 -1
- package/lib/module/version.js.map +1 -1
- package/lib/typescript/DatadogProvider/Buffer/BoundedBuffer.d.ts +15 -0
- package/lib/typescript/DatadogProvider/Buffer/BufferSingleton.d.ts +7 -0
- package/lib/typescript/DatadogProvider/Buffer/DatadogBuffer.d.ts +20 -0
- package/lib/typescript/DatadogProvider/Buffer/PassThroughBuffer.d.ts +7 -0
- package/lib/typescript/DatadogProvider/Buffer/bufferNativeCall.d.ts +3 -0
- package/lib/typescript/DatadogProvider/DatadogProvider.d.ts +26 -0
- package/lib/typescript/DdSdkReactNative.d.ts +23 -1
- package/lib/typescript/DdSdkReactNativeConfiguration.d.ts +63 -0
- package/lib/typescript/errorUtils.d.ts +4 -0
- package/lib/typescript/index.d.ts +3 -2
- package/lib/typescript/nativeModulesTypes.d.ts +12 -0
- package/lib/typescript/rum/instrumentation/DdRumErrorTracking.d.ts +0 -2
- package/lib/typescript/rum/instrumentation/DdRumUserInteractionTracking.d.ts +3 -0
- package/lib/typescript/rum/instrumentation/getJsxRuntime.d.ts +1 -0
- package/lib/typescript/types.d.ts +2 -1
- package/lib/typescript/version.d.ts +1 -1
- package/package.json +2 -2
- package/src/DatadogProvider/Buffer/BoundedBuffer.ts +209 -0
- package/src/DatadogProvider/Buffer/BufferSingleton.ts +26 -0
- package/src/DatadogProvider/Buffer/DatadogBuffer.ts +34 -0
- package/src/DatadogProvider/Buffer/PassThroughBuffer.ts +16 -0
- package/src/DatadogProvider/Buffer/__tests__/BoundedBuffer.test.ts +202 -0
- package/src/DatadogProvider/Buffer/__tests__/BufferSingleton.test.ts +50 -0
- package/src/DatadogProvider/Buffer/bufferNativeCall.ts +24 -0
- package/src/DatadogProvider/DatadogProvider.tsx +122 -0
- package/src/DatadogProvider/__tests__/__utils__/renderWithProvider.tsx +111 -0
- package/src/DatadogProvider/__tests__/initialization.test.tsx +174 -0
- package/src/DatadogProvider/__tests__/initializationModes.test.tsx +174 -0
- package/src/DdSdkReactNative.tsx +205 -105
- package/src/DdSdkReactNativeConfiguration.tsx +160 -8
- package/src/__tests__/DdRumWrapper.test.tsx +3 -27
- package/src/__tests__/DdSdkReactNative.test.tsx +1 -0
- package/src/__tests__/DdSdkReactNativeConfiguration.test.ts +168 -0
- package/src/__tests__/foundation.test.ts +11 -2
- package/src/__tests__/rum/instrumentation/DdRumUserInteractionTracking.test.tsx +18 -4
- package/src/errorUtils.ts +50 -0
- package/src/foundation.tsx +15 -12
- package/src/index.tsx +9 -1
- package/src/nativeModulesTypes.ts +14 -0
- package/src/rum/instrumentation/DdRumErrorTracking.tsx +9 -46
- package/src/rum/instrumentation/DdRumUserInteractionTracking.tsx +13 -9
- package/src/rum/instrumentation/getJsxRuntime.ts +43 -0
- package/src/rum/instrumentation/resourceTracking/__tests__/DdRumResourceTracking.test.ts +2 -0
- package/src/rum/instrumentation/resourceTracking/implementation/DatadogRumResource/__tests__/ResourceReporter.test.ts +2 -0
- package/src/rum/instrumentation/resourceTracking/implementation/__tests__/XHRProxy.test.ts +3 -0
- package/src/types.tsx +2 -1
- package/src/version.ts +1 -1
package/README.md
CHANGED
|
@@ -34,11 +34,11 @@ To ensure the safety of your data, you must use a client token. You cannot use o
|
|
|
34
34
|
|
|
35
35
|
```js
|
|
36
36
|
import {
|
|
37
|
-
|
|
38
|
-
|
|
37
|
+
DatadogProvider,
|
|
38
|
+
DatadogProviderConfiguration
|
|
39
39
|
} from '@datadog/mobile-react-native';
|
|
40
40
|
|
|
41
|
-
const
|
|
41
|
+
const datadogConfiguration = new DatadogProviderConfiguration(
|
|
42
42
|
'<CLIENT_TOKEN>',
|
|
43
43
|
'<ENVIRONMENT_NAME>',
|
|
44
44
|
'<RUM_APPLICATION_ID>',
|
|
@@ -47,23 +47,27 @@ const config = new DdSdkReactNativeConfiguration(
|
|
|
47
47
|
true // track Errors
|
|
48
48
|
);
|
|
49
49
|
// Optional: Select your Datadog website (one of "US1", "US3", "US5", EU1", or "US1_FED"). Default is "US1".
|
|
50
|
-
|
|
50
|
+
datadogConfiguration.site = 'US1';
|
|
51
51
|
// Optional: enable or disable native crash reports
|
|
52
|
-
|
|
52
|
+
datadogConfiguration.nativeCrashReportEnabled = true;
|
|
53
53
|
// Optional: sample RUM sessions (here, 80% of session will be sent to Datadog. Default = 100%)
|
|
54
|
-
|
|
54
|
+
datadogConfiguration.sessionSamplingRate = 80;
|
|
55
55
|
// Optional: sample tracing integrations for network calls between your app and your backend (here, 80% of calls to your instrumented backend will be linked from the RUM view to the APM view. Default = 20%)
|
|
56
56
|
// You need to specify the hosts of your backends to enable tracing with these backends
|
|
57
|
-
|
|
58
|
-
|
|
57
|
+
datadogConfiguration.resourceTracingSamplingRate = 80;
|
|
58
|
+
datadogConfiguration.firstPartyHosts = ['example.com']; // matches 'example.com' and subdomains like 'api.example.com'
|
|
59
59
|
// Optional: set the reported service name (by default, it'll use the package name / bundleIdentifier of your Android / iOS app respectively)
|
|
60
|
-
|
|
60
|
+
datadogConfiguration.serviceName = 'com.example.reactnative';
|
|
61
61
|
// Optional: let the SDK print internal logs (above or equal to the provided level. Default = undefined (meaning no logs))
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
62
|
+
datadogConfiguration.verbosity = SdkVerbosity.WARN;
|
|
63
|
+
|
|
64
|
+
export default function App() {
|
|
65
|
+
return (
|
|
66
|
+
<DatadogProvider configuration={datadogConfiguration}>
|
|
67
|
+
<Navigation />
|
|
68
|
+
</DatadogProvider>
|
|
69
|
+
);
|
|
70
|
+
}
|
|
67
71
|
```
|
|
68
72
|
|
|
69
73
|
### Track view navigation
|
|
@@ -51,4 +51,12 @@ internal class DatadogSDKWrapper : DatadogWrapper {
|
|
|
51
51
|
override fun setTrackingConsent(trackingConsent: TrackingConsent) {
|
|
52
52
|
Datadog.setTrackingConsent(trackingConsent)
|
|
53
53
|
}
|
|
54
|
+
|
|
55
|
+
override fun telemetryDebug(message: String) {
|
|
56
|
+
Datadog._internal._telemetry.debug(message)
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
override fun telemetryError(message: String, stack: String?, kind: String?) {
|
|
60
|
+
Datadog._internal._telemetry.error(message, stack, kind)
|
|
61
|
+
}
|
|
54
62
|
}
|
|
@@ -83,4 +83,14 @@ interface DatadogWrapper {
|
|
|
83
83
|
* Sets tracking consent.
|
|
84
84
|
*/
|
|
85
85
|
fun setTrackingConsent(trackingConsent: TrackingConsent)
|
|
86
|
+
|
|
87
|
+
/**
|
|
88
|
+
* Sends telemetry debug event
|
|
89
|
+
*/
|
|
90
|
+
fun telemetryDebug(message: String)
|
|
91
|
+
|
|
92
|
+
/**
|
|
93
|
+
* Sends telemetry error
|
|
94
|
+
*/
|
|
95
|
+
fun telemetryError(message: String, stack: String?, kind: String?)
|
|
86
96
|
}
|
|
@@ -95,6 +95,28 @@ class DdSdk(
|
|
|
95
95
|
promise.resolve(null)
|
|
96
96
|
}
|
|
97
97
|
|
|
98
|
+
/**
|
|
99
|
+
* Sends a telemetry debug event.
|
|
100
|
+
* @param message Debug message.
|
|
101
|
+
*/
|
|
102
|
+
@ReactMethod
|
|
103
|
+
fun telemetryDebug(message: String, promise: Promise) {
|
|
104
|
+
datadog.telemetryDebug(message)
|
|
105
|
+
promise.resolve(null)
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
/**
|
|
109
|
+
* Sends a telemetry error event.
|
|
110
|
+
* @param message Error message.
|
|
111
|
+
* @param stack Error stack.
|
|
112
|
+
* @param kind Error kind.
|
|
113
|
+
*/
|
|
114
|
+
@ReactMethod
|
|
115
|
+
fun telemetryError(message: String, stack: String, kind: String, promise: Promise) {
|
|
116
|
+
datadog.telemetryError(message, stack, kind)
|
|
117
|
+
promise.resolve(null)
|
|
118
|
+
}
|
|
119
|
+
|
|
98
120
|
// endregion
|
|
99
121
|
|
|
100
122
|
// region Internal
|
|
@@ -156,6 +178,9 @@ class DdSdk(
|
|
|
156
178
|
|
|
157
179
|
configBuilder.useSite(buildSite(configuration.site))
|
|
158
180
|
|
|
181
|
+
val telemetrySampleRate = (configuration.telemetrySampleRate as? Number)?.toFloat()
|
|
182
|
+
telemetrySampleRate?.let { configBuilder.sampleTelemetry(it) }
|
|
183
|
+
|
|
159
184
|
val viewTracking = configuration.additionalConfig?.get(DD_NATIVE_VIEW_TRACKING) as? Boolean
|
|
160
185
|
if (viewTracking == true) {
|
|
161
186
|
// Use sensible default
|
|
@@ -15,6 +15,7 @@ package com.datadog.reactnative
|
|
|
15
15
|
* @param sampleRate The sample rate (between 0 and 100) of RUM sessions kept.
|
|
16
16
|
* @param site The Datadog site of your organization (can be 'US', 'EU' or 'GOV', default is 'US').
|
|
17
17
|
* @param trackingConsent Consent, which can take one of the following values: 'pending', 'granted', 'not_granted'.
|
|
18
|
+
* @param telemetrySampleRate The sample rate (between 0 and 100) of telemetry events.
|
|
18
19
|
* @param additionalConfig Additional configuration parameters.
|
|
19
20
|
*/
|
|
20
21
|
data class DdSdkConfiguration(
|
|
@@ -25,5 +26,6 @@ data class DdSdkConfiguration(
|
|
|
25
26
|
val sampleRate: Double? = null,
|
|
26
27
|
val site: String? = null,
|
|
27
28
|
val trackingConsent: String? = null,
|
|
29
|
+
val telemetrySampleRate: Double? = null,
|
|
28
30
|
val additionalConfig: Map<String, Any?>? = null
|
|
29
31
|
)
|
|
@@ -18,6 +18,7 @@ internal fun ReadableMap.asDdSdkConfiguration(): DdSdkConfiguration {
|
|
|
18
18
|
sampleRate = getDouble("sampleRate"),
|
|
19
19
|
site = getString("site"),
|
|
20
20
|
trackingConsent = getString("trackingConsent"),
|
|
21
|
+
telemetrySampleRate = getDouble("telemetrySampleRate"),
|
|
21
22
|
additionalConfig = getMap("additionalConfig")?.toHashMap()
|
|
22
23
|
)
|
|
23
24
|
}
|
|
@@ -31,6 +32,7 @@ internal fun DdSdkConfiguration.toReadableMap(): ReadableMap {
|
|
|
31
32
|
sampleRate?.let { map.putDouble("sampleRate", it) }
|
|
32
33
|
site?.let { map.putString("site", it) }
|
|
33
34
|
trackingConsent?.let { map.putString("trackingConsent", it) }
|
|
35
|
+
telemetrySampleRate?.let { map.putDouble("telemetrySampleRate", it) }
|
|
34
36
|
additionalConfig?.let { map.putMap("additionalConfig", it.toWritableMap()) }
|
|
35
37
|
return map
|
|
36
38
|
}
|
|
@@ -291,6 +291,58 @@ internal class DdSdkTest {
|
|
|
291
291
|
|
|
292
292
|
// endregion
|
|
293
293
|
|
|
294
|
+
// region initialize / telemetry sample rate
|
|
295
|
+
|
|
296
|
+
@Test
|
|
297
|
+
fun `𝕄 initialize native with telemetry sample rate SDK 𝕎 initialize() {}`() {
|
|
298
|
+
// Given
|
|
299
|
+
val credentialCaptor = argumentCaptor<Credentials>()
|
|
300
|
+
val configCaptor = argumentCaptor<Configuration>()
|
|
301
|
+
val expectedTelemetrySampleRate = fakeConfiguration.telemetrySampleRate?.toFloat() ?: 20f
|
|
302
|
+
|
|
303
|
+
// When
|
|
304
|
+
testedBridgeSdk.initialize(fakeConfiguration.toReadableJavaOnlyMap(), mockPromise)
|
|
305
|
+
|
|
306
|
+
// Then
|
|
307
|
+
inOrder(mockDatadog) {
|
|
308
|
+
verify(mockDatadog).initialize(
|
|
309
|
+
same(mockContext),
|
|
310
|
+
credentialCaptor.capture(),
|
|
311
|
+
configCaptor.capture(),
|
|
312
|
+
any()
|
|
313
|
+
)
|
|
314
|
+
verify(mockDatadog).registerRumMonitor(any())
|
|
315
|
+
}
|
|
316
|
+
assertThat(configCaptor.firstValue)
|
|
317
|
+
.hasField("coreConfig") {
|
|
318
|
+
it.hasFieldEqualTo("needsClearTextHttp", false)
|
|
319
|
+
it.hasFieldEqualTo("firstPartyHosts", emptyList<String>())
|
|
320
|
+
it.hasFieldEqualTo("batchSize", BatchSize.MEDIUM)
|
|
321
|
+
it.hasFieldEqualTo("uploadFrequency", UploadFrequency.AVERAGE)
|
|
322
|
+
}
|
|
323
|
+
.hasField("logsConfig") {
|
|
324
|
+
it.hasFieldEqualTo("plugins", emptyList<DatadogPlugin>())
|
|
325
|
+
}
|
|
326
|
+
.hasField("tracesConfig") {
|
|
327
|
+
it.hasFieldEqualTo("plugins", emptyList<DatadogPlugin>())
|
|
328
|
+
}
|
|
329
|
+
.hasField("rumConfig") {
|
|
330
|
+
it.hasFieldEqualTo("plugins", emptyList<DatadogPlugin>())
|
|
331
|
+
it.hasFieldEqualTo("telemetrySamplingRate", expectedTelemetrySampleRate)
|
|
332
|
+
}
|
|
333
|
+
.hasFieldEqualTo(
|
|
334
|
+
"additionalConfig",
|
|
335
|
+
fakeConfiguration.additionalConfig?.filterValues { it != null }.orEmpty()
|
|
336
|
+
)
|
|
337
|
+
val credentials = credentialCaptor.firstValue
|
|
338
|
+
assertThat(credentials.clientToken).isEqualTo(fakeConfiguration.clientToken)
|
|
339
|
+
assertThat(credentials.envName).isEqualTo(fakeConfiguration.env)
|
|
340
|
+
assertThat(credentials.rumApplicationId).isEqualTo(fakeConfiguration.applicationId)
|
|
341
|
+
assertThat(credentials.variant).isEqualTo("")
|
|
342
|
+
}
|
|
343
|
+
|
|
344
|
+
// endregion
|
|
345
|
+
|
|
294
346
|
// region initialize / additionalConfig
|
|
295
347
|
|
|
296
348
|
@Test
|
|
@@ -26,6 +26,13 @@ fun DdSdkConfiguration.toReadableJavaOnlyMap(): ReadableMap {
|
|
|
26
26
|
// ReadableMap#getDouble which doesn't allow having null value
|
|
27
27
|
map["sampleRate"] = 100f
|
|
28
28
|
}
|
|
29
|
+
if (telemetrySampleRate != null) {
|
|
30
|
+
map["telemetrySampleRate"] = telemetrySampleRate
|
|
31
|
+
} else {
|
|
32
|
+
// we have to put something, because ReadableMap.asDdSdkConfiguration() will call
|
|
33
|
+
// ReadableMap#getDouble which doesn't allow having null value
|
|
34
|
+
map["telemetrySampleRate"] = 20f
|
|
35
|
+
}
|
|
29
36
|
site?.let { map.put("site", it) }
|
|
30
37
|
trackingConsent?.let { map.put("trackingConsent", it) }
|
|
31
38
|
additionalConfig?.let { map.put("additionalConfig", it.toReadableMap()) }
|
package/android/src/test/kotlin/com/datadog/tools/unit/forge/DdSdkConfigurationForgeryFactory.kt
CHANGED
|
@@ -19,6 +19,7 @@ class DdSdkConfigurationForgeryFactory : ForgeryFactory<DdSdkConfiguration> {
|
|
|
19
19
|
applicationId = forge.aNullable { getForgery<UUID>().toString() },
|
|
20
20
|
nativeCrashReportEnabled = forge.aNullable { aBool() },
|
|
21
21
|
sampleRate = forge.aNullable { aDouble(0.0, 100.0) },
|
|
22
|
+
telemetrySampleRate = forge.aNullable { aDouble(0.0, 100.0) },
|
|
22
23
|
site = forge.aNullable { anElementFrom("US", "EU", "GOV") },
|
|
23
24
|
additionalConfig = forge.aMap {
|
|
24
25
|
forge.anAsciiString() to forge.anElementFrom(
|
package/ios/Sources/DdSdk.m
CHANGED
|
@@ -24,4 +24,14 @@ RCT_EXTERN_METHOD(setTrackingConsent:(NSString)trackingConsent
|
|
|
24
24
|
withResolver:(RCTPromiseResolveBlock)resolve
|
|
25
25
|
withRejecter:(RCTPromiseRejectBlock)reject)
|
|
26
26
|
|
|
27
|
+
RCT_EXTERN_METHOD(telemetryDebug:(NSString)message
|
|
28
|
+
withResolver:(RCTPromiseResolveBlock)resolve
|
|
29
|
+
withRejecter:(RCTPromiseRejectBlock)reject)
|
|
30
|
+
|
|
31
|
+
RCT_EXTERN_METHOD(telemetryError:(NSString)message
|
|
32
|
+
withStack:(NSString)stack
|
|
33
|
+
withKind:(NSString)kind
|
|
34
|
+
withResolver:(RCTPromiseResolveBlock)resolve
|
|
35
|
+
withRejecter:(RCTPromiseRejectBlock)reject)
|
|
36
|
+
|
|
27
37
|
@end
|
package/ios/Sources/DdSdk.swift
CHANGED
|
@@ -43,6 +43,7 @@ class RNDdSdk: NSObject {
|
|
|
43
43
|
// Initializing the SDK twice results in Global.rum and
|
|
44
44
|
// Global.sharedTracer to be set to no-op instances
|
|
45
45
|
consolePrint("Datadog SDK is already initialized, skipping initialization.")
|
|
46
|
+
Datadog._internal._telemtry.debug(id: "datadog_react_native: RN SDK was already initialized in native", message: "RN SDK was already initialized in native")
|
|
46
47
|
resolve(nil)
|
|
47
48
|
return
|
|
48
49
|
}
|
|
@@ -87,6 +88,18 @@ class RNDdSdk: NSObject {
|
|
|
87
88
|
Datadog.set(trackingConsent: buildTrackingConsent(consent: trackingConsent))
|
|
88
89
|
resolve(nil)
|
|
89
90
|
}
|
|
91
|
+
|
|
92
|
+
@objc(telemetryDebug:withResolver:withRejecter:)
|
|
93
|
+
func telemetryDebug(message: NSString, resolve:RCTPromiseResolveBlock, reject:RCTPromiseRejectBlock) -> Void {
|
|
94
|
+
Datadog._internal._telemtry.debug(id: "datadog_react_native:\(message)", message: message as String)
|
|
95
|
+
resolve(nil)
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
@objc(telemetryError:withStack:withKind:withResolver:withRejecter:)
|
|
99
|
+
func telemetryDebug(message: NSString, stack: NSString, kind: NSString, resolve:RCTPromiseResolveBlock, reject:RCTPromiseRejectBlock) -> Void {
|
|
100
|
+
Datadog._internal._telemtry.error(id: "datadog_react_native:\(String(describing: kind)):\(message)", message: message as String, kind: kind as? String, stack: stack as? String)
|
|
101
|
+
resolve(nil)
|
|
102
|
+
}
|
|
90
103
|
|
|
91
104
|
func buildConfiguration(configuration: DdSdkConfiguration, defaultAppVersion: String = getDefaultAppVersion()) -> Datadog.Configuration {
|
|
92
105
|
let ddConfigBuilder: Datadog.Configuration.Builder
|
|
@@ -119,6 +132,10 @@ class RNDdSdk: NSObject {
|
|
|
119
132
|
_ = ddConfigBuilder.set(endpoint: .us1)
|
|
120
133
|
}
|
|
121
134
|
|
|
135
|
+
if var telemetrySampleRate = (configuration.telemetrySampleRate as? NSNumber)?.floatValue {
|
|
136
|
+
_ = ddConfigBuilder.set(sampleTelemetry: telemetrySampleRate)
|
|
137
|
+
}
|
|
138
|
+
|
|
122
139
|
let additionalConfig = configuration.additionalConfig
|
|
123
140
|
|
|
124
141
|
if var additionalConfiguration = additionalConfig as? [String: Any] {
|
|
@@ -16,6 +16,7 @@ import Foundation
|
|
|
16
16
|
- sampleRate: The sample rate (between 0 and 100) of RUM sessions kept.
|
|
17
17
|
- site: The Datadog site of your organization (can be 'US1', 'US1_FED', 'US3', 'US5', or 'EU1', default is 'US1').
|
|
18
18
|
- trackingConsent: Consent, which can take one of the following values: 'pending', 'granted', 'not_granted'.
|
|
19
|
+
- telemetrySampleRate: The sample rate (between 0 and 100) of telemetry events.
|
|
19
20
|
- additionalConfig: Additional configuration parameters.
|
|
20
21
|
*/
|
|
21
22
|
@objc(DdSdkConfiguration)
|
|
@@ -27,6 +28,7 @@ public class DdSdkConfiguration: NSObject {
|
|
|
27
28
|
public var sampleRate: Double? = nil
|
|
28
29
|
public var site: NSString? = nil
|
|
29
30
|
public var trackingConsent: NSString? = nil
|
|
31
|
+
public var telemetrySampleRate: Double? = nil
|
|
30
32
|
public var additionalConfig: NSDictionary? = nil
|
|
31
33
|
|
|
32
34
|
public init(
|
|
@@ -37,6 +39,7 @@ public class DdSdkConfiguration: NSObject {
|
|
|
37
39
|
sampleRate: Double?,
|
|
38
40
|
site: NSString?,
|
|
39
41
|
trackingConsent: NSString?,
|
|
42
|
+
telemetrySampleRate: Double?,
|
|
40
43
|
additionalConfig: NSDictionary?
|
|
41
44
|
) {
|
|
42
45
|
self.clientToken = clientToken
|
|
@@ -46,6 +49,7 @@ public class DdSdkConfiguration: NSObject {
|
|
|
46
49
|
self.sampleRate = sampleRate
|
|
47
50
|
self.site = site
|
|
48
51
|
self.trackingConsent = trackingConsent
|
|
52
|
+
self.telemetrySampleRate = telemetrySampleRate
|
|
49
53
|
self.additionalConfig = additionalConfig
|
|
50
54
|
}
|
|
51
55
|
}
|
|
@@ -16,6 +16,7 @@ extension NSDictionary {
|
|
|
16
16
|
let sampleRate = object(forKey: "sampleRate") as? Double
|
|
17
17
|
let site = object(forKey: "site") as? NSString
|
|
18
18
|
let trackingConsent = object(forKey: "trackingConsent") as? NSString
|
|
19
|
+
let telemetrySampleRate = object(forKey: "telemetrySampleRate") as? Double
|
|
19
20
|
let additionalConfig = object(forKey: "additionalConfig") as? NSDictionary
|
|
20
21
|
return DdSdkConfiguration(
|
|
21
22
|
clientToken: (clientToken != nil) ? clientToken! : String(),
|
|
@@ -25,6 +26,7 @@ extension NSDictionary {
|
|
|
25
26
|
sampleRate: sampleRate,
|
|
26
27
|
site: site,
|
|
27
28
|
trackingConsent: trackingConsent,
|
|
29
|
+
telemetrySampleRate: telemetrySampleRate,
|
|
28
30
|
additionalConfig: additionalConfig
|
|
29
31
|
)
|
|
30
32
|
}
|
|
@@ -0,0 +1,173 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.BoundedBuffer = void 0;
|
|
7
|
+
|
|
8
|
+
var _InternalLog = require("../../InternalLog");
|
|
9
|
+
|
|
10
|
+
var _SdkVerbosity = require("../../SdkVerbosity");
|
|
11
|
+
|
|
12
|
+
var _errorUtils = require("../../errorUtils");
|
|
13
|
+
|
|
14
|
+
var _foundation = require("../../foundation");
|
|
15
|
+
|
|
16
|
+
var _DatadogBuffer = require("./DatadogBuffer");
|
|
17
|
+
|
|
18
|
+
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; }
|
|
19
|
+
|
|
20
|
+
const DEFAULT_BUFFER_SIZE = 100;
|
|
21
|
+
|
|
22
|
+
class BoundedBuffer extends _DatadogBuffer.DatadogBuffer {
|
|
23
|
+
constructor(bufferSize = DEFAULT_BUFFER_SIZE) {
|
|
24
|
+
super();
|
|
25
|
+
|
|
26
|
+
_defineProperty(this, "bufferSize", void 0);
|
|
27
|
+
|
|
28
|
+
_defineProperty(this, "buffer", []);
|
|
29
|
+
|
|
30
|
+
_defineProperty(this, "idTable", {});
|
|
31
|
+
|
|
32
|
+
_defineProperty(this, "telemetryBuffer", {});
|
|
33
|
+
|
|
34
|
+
_defineProperty(this, "addCallback", callback => {
|
|
35
|
+
if (this.buffer.length < this.bufferSize) {
|
|
36
|
+
this.buffer.push({
|
|
37
|
+
callback,
|
|
38
|
+
_type: 'VOID'
|
|
39
|
+
});
|
|
40
|
+
} else {
|
|
41
|
+
this.addTelemetryEvent('Buffer overflow', '', 'BufferOverflow');
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
return new Promise(resolve => resolve(undefined));
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
_defineProperty(this, "addCallbackReturningId", callback => {
|
|
48
|
+
try {
|
|
49
|
+
const bufferId = this.generateRandomBufferId();
|
|
50
|
+
|
|
51
|
+
if (this.buffer.length < this.bufferSize) {
|
|
52
|
+
this.buffer.push({
|
|
53
|
+
callback,
|
|
54
|
+
returnedBufferId: bufferId,
|
|
55
|
+
_type: 'RETURNING_ID'
|
|
56
|
+
});
|
|
57
|
+
this.idTable[bufferId] = null;
|
|
58
|
+
} else {
|
|
59
|
+
this.addTelemetryEvent('Buffer overflow', '', 'BufferOverflow');
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
return new Promise(resolve => resolve(bufferId));
|
|
63
|
+
} catch (error) {
|
|
64
|
+
this.addTelemetryEvent('Could not generate enough random numbers', (0, _errorUtils.getErrorStackTrace)(error), 'RandomIdGenerationError'); // Not using InternalLog here as it is not yet instantiated
|
|
65
|
+
|
|
66
|
+
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()}`);
|
|
67
|
+
return new Promise(resolve => resolve(''));
|
|
68
|
+
}
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
_defineProperty(this, "addCallbackWithId", (callback, bufferId) => {
|
|
72
|
+
if (this.idTable[bufferId] !== undefined) {
|
|
73
|
+
this.buffer.push({
|
|
74
|
+
callback,
|
|
75
|
+
withBufferId: bufferId,
|
|
76
|
+
_type: 'WITH_ID'
|
|
77
|
+
});
|
|
78
|
+
} else {
|
|
79
|
+
this.addTelemetryEvent('Buffer overflow', '', 'BufferOverflow');
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
return new Promise(resolve => resolve(undefined));
|
|
83
|
+
});
|
|
84
|
+
|
|
85
|
+
_defineProperty(this, "drain", async () => {
|
|
86
|
+
for (let bufferIndex = 0; bufferIndex < this.buffer.length; bufferIndex++) {
|
|
87
|
+
try {
|
|
88
|
+
const item = this.buffer[bufferIndex];
|
|
89
|
+
|
|
90
|
+
if (item._type === 'RETURNING_ID') {
|
|
91
|
+
try {
|
|
92
|
+
// Here we want to await the callback result to make sure that it has registered the id returned
|
|
93
|
+
// by the callback before executing the callback needing this id.
|
|
94
|
+
// eslint-disable-next-line no-await-in-loop
|
|
95
|
+
const callbackId = await item.callback();
|
|
96
|
+
this.idTable[item.returnedBufferId] = callbackId;
|
|
97
|
+
} catch (error) {
|
|
98
|
+
_InternalLog.InternalLog.log(`Error running a callback returning an id in Buffer: ${error}`, _SdkVerbosity.SdkVerbosity.WARN);
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
continue;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
if (item._type === 'WITH_ID') {
|
|
105
|
+
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.
|
|
106
|
+
|
|
107
|
+
if (callbackId !== null && callbackId !== undefined) {
|
|
108
|
+
item.callback(callbackId);
|
|
109
|
+
delete this.idTable[item.withBufferId];
|
|
110
|
+
} else {
|
|
111
|
+
_InternalLog.InternalLog.log(`1 event was not sent as callback id was ${callbackId === null ? 'not set' : 'already unset'}`, _SdkVerbosity.SdkVerbosity.WARN);
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
continue;
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
item.callback();
|
|
118
|
+
} catch (error) {
|
|
119
|
+
_InternalLog.InternalLog.log(`Error while draining Datadog Buffer: ${error}`, _SdkVerbosity.SdkVerbosity.WARN);
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
this.buffer = [];
|
|
124
|
+
this.drainTelemetry();
|
|
125
|
+
});
|
|
126
|
+
|
|
127
|
+
_defineProperty(this, "generateRandomBufferId", () => {
|
|
128
|
+
let tries = 0;
|
|
129
|
+
|
|
130
|
+
while (tries < 20) {
|
|
131
|
+
const hash = Math.random().toString(36).slice(2);
|
|
132
|
+
|
|
133
|
+
if (this.idTable[hash] !== undefined) {
|
|
134
|
+
tries++;
|
|
135
|
+
} else {
|
|
136
|
+
return hash;
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
throw new Error('Could not generate random Buffer id');
|
|
141
|
+
});
|
|
142
|
+
|
|
143
|
+
_defineProperty(this, "addTelemetryEvent", (message, stack, kind) => {
|
|
144
|
+
if (this.telemetryBuffer[kind]) {
|
|
145
|
+
this.telemetryBuffer[kind].occurences++;
|
|
146
|
+
} else {
|
|
147
|
+
this.telemetryBuffer[kind] = {
|
|
148
|
+
message,
|
|
149
|
+
stack,
|
|
150
|
+
kind,
|
|
151
|
+
occurences: 1
|
|
152
|
+
};
|
|
153
|
+
}
|
|
154
|
+
});
|
|
155
|
+
|
|
156
|
+
_defineProperty(this, "drainTelemetry", () => {
|
|
157
|
+
Object.values(this.telemetryBuffer).forEach(({
|
|
158
|
+
message,
|
|
159
|
+
stack,
|
|
160
|
+
kind,
|
|
161
|
+
occurences
|
|
162
|
+
}) => {
|
|
163
|
+
_foundation.DdSdk.telemetryError(`${message} happened ${occurences} times.`, stack, kind);
|
|
164
|
+
});
|
|
165
|
+
});
|
|
166
|
+
|
|
167
|
+
this.bufferSize = bufferSize;
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
exports.BoundedBuffer = BoundedBuffer;
|
|
173
|
+
//# sourceMappingURL=BoundedBuffer.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["BoundedBuffer.ts"],"names":["DEFAULT_BUFFER_SIZE","BoundedBuffer","DatadogBuffer","constructor","bufferSize","callback","buffer","length","push","_type","addTelemetryEvent","Promise","resolve","undefined","bufferId","generateRandomBufferId","returnedBufferId","idTable","error","console","warn","Math","random","withBufferId","bufferIndex","item","callbackId","InternalLog","log","SdkVerbosity","WARN","drainTelemetry","tries","hash","toString","slice","Error","message","stack","kind","telemetryBuffer","occurences","Object","values","forEach","DdSdk","telemetryError"],"mappings":";;;;;;;AAMA;;AACA;;AACA;;AACA;;AAEA;;;;AAEA,MAAMA,mBAAmB,GAAG,GAA5B;;AAqBO,MAAMC,aAAN,SAA4BC,4BAA5B,CAA0C;AAa7CC,EAAAA,WAAW,CAACC,UAAkB,GAAGJ,mBAAtB,EAA2C;AAClD;;AADkD;;AAAA,oCAXvB,EAWuB;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I,OAApC,CACI,CAAC;AAAEP,QAAAA,OAAF;AAAWC,QAAAA,KAAX;AAAkBC,QAAAA,IAAlB;AAAwBE,QAAAA;AAAxB,OAAD,KAA0C;AACtCI,0BAAMC,cAAN,CACK,GAAET,OAAQ,aAAYI,UAAW,SADtC,EAEIH,KAFJ,EAGIC,IAHJ;AAKH,OAPL;AASH,KAhKqD;;AAElD,SAAKnC,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,32 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.BufferSingleton = void 0;
|
|
7
|
+
|
|
8
|
+
var _BoundedBuffer = require("./BoundedBuffer");
|
|
9
|
+
|
|
10
|
+
var _PassThroughBuffer = require("./PassThroughBuffer");
|
|
11
|
+
|
|
12
|
+
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; }
|
|
13
|
+
|
|
14
|
+
class BufferSingleton {}
|
|
15
|
+
|
|
16
|
+
exports.BufferSingleton = BufferSingleton;
|
|
17
|
+
|
|
18
|
+
_defineProperty(BufferSingleton, "bufferInstance", new _BoundedBuffer.BoundedBuffer());
|
|
19
|
+
|
|
20
|
+
_defineProperty(BufferSingleton, "getInstance", () => {
|
|
21
|
+
return BufferSingleton.bufferInstance;
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
_defineProperty(BufferSingleton, "onInitialization", () => {
|
|
25
|
+
BufferSingleton.bufferInstance.drain();
|
|
26
|
+
BufferSingleton.bufferInstance = new _PassThroughBuffer.PassThroughBuffer();
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
_defineProperty(BufferSingleton, "reset", () => {
|
|
30
|
+
BufferSingleton.bufferInstance = new _BoundedBuffer.BoundedBuffer();
|
|
31
|
+
});
|
|
32
|
+
//# sourceMappingURL=BufferSingleton.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["BufferSingleton.ts"],"names":["BufferSingleton","BoundedBuffer","bufferInstance","drain","PassThroughBuffer"],"mappings":";;;;;;;AAMA;;AAEA;;;;AAEO,MAAMA,eAAN,CAAsB;;;;gBAAhBA,e,oBACsC,IAAIC,4BAAJ,E;;gBADtCD,e,iBAGY,MAAqB;AACtC,SAAOA,eAAe,CAACE,cAAvB;AACH,C;;gBALQF,e,sBAOiB,MAAM;AAC5BA,EAAAA,eAAe,CAACE,cAAhB,CAA+BC,KAA/B;AACAH,EAAAA,eAAe,CAACE,cAAhB,GAAiC,IAAIE,oCAAJ,EAAjC;AACH,C;;gBAVQJ,e,WAYM,MAAM;AACjBA,EAAAA,eAAe,CAACE,cAAhB,GAAiC,IAAID,4BAAJ,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,29 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.DatadogBuffer = void 0;
|
|
7
|
+
|
|
8
|
+
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; }
|
|
9
|
+
|
|
10
|
+
/*
|
|
11
|
+
* Unless explicitly stated otherwise all files in this repository are licensed under the Apache License Version 2.0.
|
|
12
|
+
* This product includes software developed at Datadog (https://www.datadoghq.com/).
|
|
13
|
+
* Copyright 2016-Present Datadog, Inc.
|
|
14
|
+
*/
|
|
15
|
+
class DatadogBuffer {
|
|
16
|
+
constructor() {
|
|
17
|
+
_defineProperty(this, "addCallback", void 0);
|
|
18
|
+
|
|
19
|
+
_defineProperty(this, "addCallbackReturningId", void 0);
|
|
20
|
+
|
|
21
|
+
_defineProperty(this, "addCallbackWithId", void 0);
|
|
22
|
+
|
|
23
|
+
_defineProperty(this, "drain", void 0);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
exports.DatadogBuffer = DatadogBuffer;
|
|
29
|
+
//# sourceMappingURL=DatadogBuffer.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["DatadogBuffer.ts"],"names":["DatadogBuffer"],"mappings":";;;;;;;;;AAAA;AACA;AACA;AACA;AACA;AAEO,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,28 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.PassThroughBuffer = void 0;
|
|
7
|
+
|
|
8
|
+
var _DatadogBuffer = require("./DatadogBuffer");
|
|
9
|
+
|
|
10
|
+
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; }
|
|
11
|
+
|
|
12
|
+
class PassThroughBuffer extends _DatadogBuffer.DatadogBuffer {
|
|
13
|
+
constructor(...args) {
|
|
14
|
+
super(...args);
|
|
15
|
+
|
|
16
|
+
_defineProperty(this, "addCallback", callback => callback());
|
|
17
|
+
|
|
18
|
+
_defineProperty(this, "addCallbackReturningId", callback => callback());
|
|
19
|
+
|
|
20
|
+
_defineProperty(this, "addCallbackWithId", (callback, id) => callback(id));
|
|
21
|
+
|
|
22
|
+
_defineProperty(this, "drain", () => undefined);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
exports.PassThroughBuffer = PassThroughBuffer;
|
|
28
|
+
//# sourceMappingURL=PassThroughBuffer.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["PassThroughBuffer.ts"],"names":["PassThroughBuffer","DatadogBuffer","callback","id","undefined"],"mappings":";;;;;;;AAMA;;;;AAEO,MAAMA,iBAAN,SAAgCC,4BAAhC,CAA8C;AAAA;AAAA;;AAAA,yCAClCC,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"]}
|