@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.
- package/DatadogSDKReactNative.podspec +2 -2
- package/README.md +18 -14
- package/android/build.gradle +28 -3
- package/android/detekt.yml +572 -0
- package/android/src/main/kotlin/com/datadog/reactnative/DatadogSDKWrapper.kt +12 -0
- package/android/src/main/kotlin/com/datadog/reactnative/DatadogWrapper.kt +15 -0
- package/android/src/main/kotlin/com/datadog/reactnative/DdSdk.kt +143 -8
- package/android/src/main/kotlin/com/datadog/reactnative/DdSdkConfiguration.kt +25 -1
- package/android/src/main/kotlin/com/datadog/reactnative/DdSdkConfigurationExt.kt +31 -1
- package/android/src/main/kotlin/com/datadog/reactnative/VitalFrameCallback.kt +41 -0
- package/android/src/test/kotlin/com/datadog/reactnative/DdRumTest.kt +7 -2
- package/android/src/test/kotlin/com/datadog/reactnative/DdSdkTest.kt +429 -27
- package/android/src/test/kotlin/com/datadog/reactnative/DdTraceTest.kt +5 -1
- package/android/src/test/kotlin/com/datadog/tools/unit/DdSdkConfigurationExt.kt +40 -1
- package/android/src/test/kotlin/com/datadog/tools/unit/GenericAssert.kt +21 -1
- package/android/src/test/kotlin/com/datadog/tools/unit/MapExt.kt +1 -1
- package/android/src/test/kotlin/com/datadog/tools/unit/forge/BaseConfigurator.kt +1 -0
- package/android/src/test/kotlin/com/datadog/tools/unit/forge/DdSdkConfigurationForgeryFactory.kt +22 -2
- package/android/src/test/kotlin/com/datadog/tools/unit/forge/PackageInfoForgeryFactory.kt +2 -3
- package/android/src/test/kotlin/com/datadog/tools/unit/forge/TelemetryConfigurationEventForgeryFactory.kt +94 -0
- package/datadog-sourcemaps.gradle +85 -28
- package/ios/Sources/Attributes.swift +0 -4
- package/ios/Sources/DdSdk.m +10 -0
- package/ios/Sources/DdSdk.swift +113 -10
- package/ios/Sources/DdSdkConfiguration.swift +38 -1
- package/ios/Sources/JSRefreshRateListener.swift +86 -0
- package/ios/Sources/QueueHolder.swift +7 -0
- package/ios/Sources/RNDdSdkConfiguration.swift +25 -1
- 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 +140 -59
- package/lib/commonjs/DdSdkReactNative.js.map +1 -1
- package/lib/commonjs/DdSdkReactNativeConfiguration.js +166 -9
- package/lib/commonjs/DdSdkReactNativeConfiguration.js.map +1 -1
- package/lib/commonjs/errorUtils.js +69 -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/longTasksUtils.js +40 -0
- package/lib/commonjs/longTasksUtils.js.map +1 -0
- 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 +16 -1
- package/lib/commonjs/rum/instrumentation/DdRumUserInteractionTracking.js.map +1 -1
- package/lib/commonjs/rum/instrumentation/getJsxRuntime.js +1 -1
- package/lib/commonjs/rum/instrumentation/getJsxRuntime.js.map +1 -1
- package/lib/commonjs/rum/instrumentation/resourceTracking/domain/distributedTracing.js +2 -1
- package/lib/commonjs/rum/instrumentation/resourceTracking/domain/distributedTracing.js.map +1 -1
- package/lib/commonjs/rum/instrumentation/resourceTracking/implementation/DatadogRumResource/ResourceReporter.js +2 -1
- package/lib/commonjs/rum/instrumentation/resourceTracking/implementation/DatadogRumResource/ResourceReporter.js.map +1 -1
- package/lib/commonjs/types.js +6 -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 +132 -57
- package/lib/module/DdSdkReactNative.js.map +1 -1
- package/lib/module/DdSdkReactNativeConfiguration.js +154 -8
- package/lib/module/DdSdkReactNativeConfiguration.js.map +1 -1
- package/lib/module/errorUtils.js +54 -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/longTasksUtils.js +31 -0
- package/lib/module/longTasksUtils.js.map +1 -0
- 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 +14 -1
- package/lib/module/rum/instrumentation/DdRumUserInteractionTracking.js.map +1 -1
- package/lib/module/rum/instrumentation/getJsxRuntime.js +1 -1
- package/lib/module/rum/instrumentation/getJsxRuntime.js.map +1 -1
- package/lib/module/rum/instrumentation/resourceTracking/domain/distributedTracing.js +2 -1
- package/lib/module/rum/instrumentation/resourceTracking/domain/distributedTracing.js.map +1 -1
- package/lib/module/rum/instrumentation/resourceTracking/implementation/DatadogRumResource/ResourceReporter.js +2 -1
- package/lib/module/rum/instrumentation/resourceTracking/implementation/DatadogRumResource/ResourceReporter.js.map +1 -1
- package/lib/module/types.js +6 -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 +18 -3
- package/lib/typescript/DdSdkReactNativeConfiguration.d.ts +114 -0
- package/lib/typescript/errorUtils.d.ts +12 -0
- package/lib/typescript/index.d.ts +3 -2
- package/lib/typescript/longTasksUtils.d.ts +6 -0
- 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/resourceTracking/domain/distributedTracing.d.ts +1 -0
- package/lib/typescript/rum/instrumentation/resourceTracking/domain/interfaces/RumResource.d.ts +1 -1
- package/lib/typescript/types.d.ts +16 -1
- package/lib/typescript/version.d.ts +1 -1
- package/package.json +3 -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 +182 -0
- package/src/DatadogProvider/__tests__/initializationModes.test.tsx +174 -0
- package/src/DdSdkReactNative.tsx +206 -109
- package/src/DdSdkReactNativeConfiguration.tsx +225 -8
- package/src/__tests__/DdRumWrapper.test.tsx +3 -27
- package/src/__tests__/DdSdkReactNative.test.tsx +57 -13
- package/src/__tests__/DdSdkReactNativeConfiguration.test.ts +181 -0
- package/src/__tests__/foundation.test.ts +11 -2
- package/src/__tests__/longTasksUtils.ts +23 -0
- package/src/__tests__/rum/instrumentation/DdRumUserInteractionTracking.test.tsx +18 -4
- package/src/errorUtils.ts +58 -0
- package/src/foundation.tsx +15 -12
- package/src/index.tsx +9 -1
- package/src/longTasksUtils.ts +30 -0
- package/src/nativeModulesTypes.ts +14 -0
- package/src/rum/instrumentation/DdRumErrorTracking.tsx +9 -46
- package/src/rum/instrumentation/DdRumUserInteractionTracking.tsx +11 -1
- package/src/rum/instrumentation/getJsxRuntime.ts +1 -1
- package/src/rum/instrumentation/resourceTracking/__tests__/DdRumResourceTracking.test.ts +2 -0
- package/src/rum/instrumentation/resourceTracking/domain/distributedTracing.tsx +3 -1
- package/src/rum/instrumentation/resourceTracking/domain/interfaces/RumResource.ts +1 -1
- package/src/rum/instrumentation/resourceTracking/implementation/DatadogRumResource/ResourceReporter.ts +2 -1
- package/src/rum/instrumentation/resourceTracking/implementation/DatadogRumResource/__tests__/ResourceReporter.test.ts +2 -0
- package/src/rum/instrumentation/resourceTracking/implementation/__tests__/XHRProxy.test.ts +12 -47
- package/src/types.tsx +11 -1
- package/src/version.ts +1 -1
|
@@ -13,9 +13,12 @@ import Foundation
|
|
|
13
13
|
- env: The application’s environment, for example: prod, pre-prod, staging, etc.
|
|
14
14
|
- applicationId: The RUM application ID.
|
|
15
15
|
- nativeCrashReportEnabled: Whether the SDK should track native (pure iOS or pure Android) crashes (default is false).
|
|
16
|
+
- nativeLongTaskThresholdMs: The threshold for native long tasks reporting in milliseconds.
|
|
17
|
+
- longTaskThresholdMs: The threshold for javascript long tasks reporting in milliseconds.
|
|
16
18
|
- sampleRate: The sample rate (between 0 and 100) of RUM sessions kept.
|
|
17
19
|
- site: The Datadog site of your organization (can be 'US1', 'US1_FED', 'US3', 'US5', or 'EU1', default is 'US1').
|
|
18
20
|
- trackingConsent: Consent, which can take one of the following values: 'pending', 'granted', 'not_granted'.
|
|
21
|
+
- telemetrySampleRate: The sample rate (between 0 and 100) of telemetry events.
|
|
19
22
|
- additionalConfig: Additional configuration parameters.
|
|
20
23
|
*/
|
|
21
24
|
@objc(DdSdkConfiguration)
|
|
@@ -24,28 +27,62 @@ public class DdSdkConfiguration: NSObject {
|
|
|
24
27
|
public var env: String = ""
|
|
25
28
|
public var applicationId: String? = nil
|
|
26
29
|
public var nativeCrashReportEnabled: Bool? = nil
|
|
30
|
+
public var nativeLongTaskThresholdMs: Double? = nil
|
|
31
|
+
public var longTaskThresholdMs: Double = 0.0
|
|
27
32
|
public var sampleRate: Double? = nil
|
|
28
33
|
public var site: NSString? = nil
|
|
29
34
|
public var trackingConsent: NSString? = nil
|
|
35
|
+
public var telemetrySampleRate: Double? = nil
|
|
36
|
+
public var vitalsUpdateFrequency: NSString? = nil
|
|
30
37
|
public var additionalConfig: NSDictionary? = nil
|
|
38
|
+
public var configurationForTelemetry: ConfigurationForTelemetry? = nil
|
|
31
39
|
|
|
32
40
|
public init(
|
|
33
41
|
clientToken: String,
|
|
34
42
|
env: String,
|
|
35
43
|
applicationId: String?,
|
|
36
44
|
nativeCrashReportEnabled: Bool?,
|
|
45
|
+
nativeLongTaskThresholdMs: Double?,
|
|
46
|
+
longTaskThresholdMs: Double,
|
|
37
47
|
sampleRate: Double?,
|
|
38
48
|
site: NSString?,
|
|
39
49
|
trackingConsent: NSString?,
|
|
40
|
-
|
|
50
|
+
telemetrySampleRate: Double?,
|
|
51
|
+
vitalsUpdateFrequency: NSString?,
|
|
52
|
+
additionalConfig: NSDictionary?,
|
|
53
|
+
configurationForTelemetry: ConfigurationForTelemetry?
|
|
41
54
|
) {
|
|
42
55
|
self.clientToken = clientToken
|
|
43
56
|
self.env = env
|
|
44
57
|
self.applicationId = applicationId
|
|
45
58
|
self.nativeCrashReportEnabled = nativeCrashReportEnabled
|
|
59
|
+
self.nativeLongTaskThresholdMs = nativeLongTaskThresholdMs
|
|
60
|
+
self.longTaskThresholdMs = longTaskThresholdMs
|
|
46
61
|
self.sampleRate = sampleRate
|
|
47
62
|
self.site = site
|
|
48
63
|
self.trackingConsent = trackingConsent
|
|
64
|
+
self.telemetrySampleRate = telemetrySampleRate
|
|
65
|
+
self.vitalsUpdateFrequency = vitalsUpdateFrequency
|
|
49
66
|
self.additionalConfig = additionalConfig
|
|
67
|
+
self.configurationForTelemetry = configurationForTelemetry
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
public class ConfigurationForTelemetry: NSObject {
|
|
72
|
+
public var initializationType: NSString?
|
|
73
|
+
public var trackErrors: Bool?
|
|
74
|
+
public var trackInteractions: Bool?
|
|
75
|
+
public var trackNetworkRequests: Bool?
|
|
76
|
+
|
|
77
|
+
public init(
|
|
78
|
+
initializationType: NSString?,
|
|
79
|
+
trackErrors: Bool?,
|
|
80
|
+
trackInteractions: Bool?,
|
|
81
|
+
trackNetworkRequests: Bool?
|
|
82
|
+
) {
|
|
83
|
+
self.initializationType = initializationType
|
|
84
|
+
self.trackErrors = trackErrors
|
|
85
|
+
self.trackInteractions = trackInteractions
|
|
86
|
+
self.trackNetworkRequests = trackNetworkRequests
|
|
50
87
|
}
|
|
51
88
|
}
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Unless explicitly stated otherwise all files in this repository are licensed under the Apache License Version 2.0.
|
|
3
|
+
* This product includes software developed at Datadog (https://www.datadoghq.com/).
|
|
4
|
+
* Copyright 2016-Present Datadog, Inc.
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
import Foundation
|
|
8
|
+
|
|
9
|
+
typealias frame_time_callback = (Double) -> Void
|
|
10
|
+
|
|
11
|
+
internal protocol RefreshRateListener {
|
|
12
|
+
func start()
|
|
13
|
+
func stop()
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
internal protocol RefreshRateMonitor {
|
|
17
|
+
func startMonitoring(jsQueue: DispatchQueueType, frameTimeCallback: @escaping frame_time_callback)
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
internal final class JSRefreshRateMonitor: RefreshRateMonitor {
|
|
21
|
+
private var refreshRateListener: RefreshRateListener
|
|
22
|
+
|
|
23
|
+
init() {
|
|
24
|
+
self.refreshRateListener = NoOpRefreshRateListener()
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
public func startMonitoring(jsQueue: DispatchQueueType, frameTimeCallback: @escaping frame_time_callback) {
|
|
28
|
+
self.refreshRateListener = JSRefreshRateListener(jsQueue: jsQueue, frameTimeCallback: frameTimeCallback)
|
|
29
|
+
self.refreshRateListener.start()
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
func appWillResignActive() {
|
|
33
|
+
self.refreshRateListener.stop()
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
func appDidBecomeActive() {
|
|
37
|
+
self.refreshRateListener.start()
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
class func requiresMainQueueSetup() -> Bool {
|
|
41
|
+
return true
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
private final class NoOpRefreshRateListener: RefreshRateListener {
|
|
46
|
+
init() {}
|
|
47
|
+
func start() {}
|
|
48
|
+
func stop() {}
|
|
49
|
+
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
private final class JSRefreshRateListener: RefreshRateListener {
|
|
53
|
+
private var jsQueue: DispatchQueueType
|
|
54
|
+
private var frameTimeCallback: frame_time_callback
|
|
55
|
+
private var lastFrameTimestamp: TimeInterval = -1
|
|
56
|
+
private var jsDisplayLink: CADisplayLink?
|
|
57
|
+
|
|
58
|
+
init(jsQueue: DispatchQueueType, frameTimeCallback: @escaping frame_time_callback) {
|
|
59
|
+
self.jsQueue = jsQueue
|
|
60
|
+
self.frameTimeCallback = frameTimeCallback
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
public func start() {
|
|
64
|
+
jsQueue.async {
|
|
65
|
+
self.jsDisplayLink?.invalidate()
|
|
66
|
+
self.jsDisplayLink = CADisplayLink(target: self, selector: #selector(self.onFrameTick))
|
|
67
|
+
self.jsDisplayLink?.add(to: .current, forMode: .common)
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
public func stop() {
|
|
72
|
+
jsQueue.async {
|
|
73
|
+
self.jsDisplayLink?.invalidate()
|
|
74
|
+
self.jsDisplayLink = nil
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
@objc func onFrameTick(displayLink: CADisplayLink) {
|
|
79
|
+
let frameTimestamp = displayLink.timestamp
|
|
80
|
+
if lastFrameTimestamp != -1 {
|
|
81
|
+
let frameDuration = frameTimestamp - lastFrameTimestamp
|
|
82
|
+
frameTimeCallback(frameDuration)
|
|
83
|
+
}
|
|
84
|
+
lastFrameTimestamp = frameTimestamp
|
|
85
|
+
}
|
|
86
|
+
}
|
|
@@ -5,6 +5,7 @@
|
|
|
5
5
|
*/
|
|
6
6
|
|
|
7
7
|
import Foundation
|
|
8
|
+
import React
|
|
8
9
|
|
|
9
10
|
internal let sharedQueue = DispatchQueue(label: "dd-react-native-sdk")
|
|
10
11
|
|
|
@@ -17,3 +18,9 @@ extension DispatchQueue: DispatchQueueType {
|
|
|
17
18
|
async(group: nil, qos: .unspecified, flags: [], execute: work)
|
|
18
19
|
}
|
|
19
20
|
}
|
|
21
|
+
|
|
22
|
+
extension RCTBridge: DispatchQueueType {
|
|
23
|
+
func async(execute work: @escaping @convention(block) () -> Void) {
|
|
24
|
+
self.dispatchBlock(work, queue: RCTJSThread)
|
|
25
|
+
}
|
|
26
|
+
}
|
|
@@ -13,19 +13,43 @@ extension NSDictionary {
|
|
|
13
13
|
let env = object(forKey: "env") as? String
|
|
14
14
|
let applicationId = object(forKey: "applicationId") as? String
|
|
15
15
|
let nativeCrashReportEnabled = object(forKey: "nativeCrashReportEnabled") as? Bool
|
|
16
|
+
let nativeLongTaskThresholdMs = object(forKey: "nativeLongTaskThresholdMs") as? Double
|
|
17
|
+
let longTaskThresholdMs = object(forKey: "longTaskThresholdMs") as? Double
|
|
16
18
|
let sampleRate = object(forKey: "sampleRate") as? Double
|
|
17
19
|
let site = object(forKey: "site") as? NSString
|
|
18
20
|
let trackingConsent = object(forKey: "trackingConsent") as? NSString
|
|
21
|
+
let telemetrySampleRate = object(forKey: "telemetrySampleRate") as? Double
|
|
22
|
+
let vitalsUpdateFrequency = object(forKey: "vitalsUpdateFrequency") as? NSString
|
|
19
23
|
let additionalConfig = object(forKey: "additionalConfig") as? NSDictionary
|
|
24
|
+
let configurationForTelemetry = object(forKey: "configurationForTelemetry") as? NSDictionary
|
|
20
25
|
return DdSdkConfiguration(
|
|
21
26
|
clientToken: (clientToken != nil) ? clientToken! : String(),
|
|
22
27
|
env: (env != nil) ? env! : String(),
|
|
23
28
|
applicationId: applicationId,
|
|
24
29
|
nativeCrashReportEnabled: nativeCrashReportEnabled,
|
|
30
|
+
nativeLongTaskThresholdMs: nativeLongTaskThresholdMs,
|
|
31
|
+
longTaskThresholdMs: (longTaskThresholdMs != nil) ? longTaskThresholdMs! : Double(),
|
|
25
32
|
sampleRate: sampleRate,
|
|
26
33
|
site: site,
|
|
27
34
|
trackingConsent: trackingConsent,
|
|
28
|
-
|
|
35
|
+
telemetrySampleRate: telemetrySampleRate,
|
|
36
|
+
vitalsUpdateFrequency: vitalsUpdateFrequency,
|
|
37
|
+
additionalConfig: additionalConfig,
|
|
38
|
+
configurationForTelemetry: configurationForTelemetry?.asConfigurationForTelemetry()
|
|
39
|
+
)
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
func asConfigurationForTelemetry() -> ConfigurationForTelemetry {
|
|
43
|
+
let initializationType = object(forKey: "initializationType") as? NSString
|
|
44
|
+
let trackErrors = object(forKey: "trackErrors") as? Bool
|
|
45
|
+
let trackInteractions = object(forKey: "trackInteractions") as? Bool
|
|
46
|
+
let trackNetworkRequests = object(forKey: "trackNetworkRequests") as? Bool
|
|
47
|
+
|
|
48
|
+
return ConfigurationForTelemetry(
|
|
49
|
+
initializationType: initializationType,
|
|
50
|
+
trackErrors: trackErrors,
|
|
51
|
+
trackInteractions: trackInteractions,
|
|
52
|
+
trackNetworkRequests: trackNetworkRequests
|
|
29
53
|
)
|
|
30
54
|
}
|
|
31
55
|
}
|
|
@@ -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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AACC,MAAP,CAAc,KAAKH,eAAnB,EAAoCI,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"]}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.bufferNativeCallWithId = exports.bufferNativeCallReturningId = exports.bufferVoidNativeCall = void 0;
|
|
7
|
+
|
|
8
|
+
var _BufferSingleton = require("./BufferSingleton");
|
|
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
|
+
const bufferVoidNativeCall = callback => {
|
|
16
|
+
return _BufferSingleton.BufferSingleton.getInstance().addCallback(callback);
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
exports.bufferVoidNativeCall = bufferVoidNativeCall;
|
|
20
|
+
|
|
21
|
+
const bufferNativeCallReturningId = callback => {
|
|
22
|
+
return _BufferSingleton.BufferSingleton.getInstance().addCallbackReturningId(callback);
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
exports.bufferNativeCallReturningId = bufferNativeCallReturningId;
|
|
26
|
+
|
|
27
|
+
const bufferNativeCallWithId = (callback, id) => {
|
|
28
|
+
return _BufferSingleton.BufferSingleton.getInstance().addCallbackWithId(callback, id);
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
exports.bufferNativeCallWithId = bufferNativeCallWithId;
|
|
32
|
+
//# sourceMappingURL=bufferNativeCall.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["bufferNativeCall.ts"],"names":["bufferVoidNativeCall","callback","BufferSingleton","getInstance","addCallback","bufferNativeCallReturningId","addCallbackReturningId","bufferNativeCallWithId","id","addCallbackWithId"],"mappings":";;;;;;;AAMA;;AANA;AACA;AACA;AACA;AACA;AAIO,MAAMA,oBAAoB,GAAIC,QAAD,IAAmC;AACnE,SAAOC,iCAAgBC,WAAhB,GAA8BC,WAA9B,CAA0CH,QAA1C,CAAP;AACH,CAFM;;;;AAIA,MAAMI,2BAA2B,GACpCJ,QADuC,IAEtC;AACD,SAAOC,iCAAgBC,WAAhB,GAA8BG,sBAA9B,CAAqDL,QAArD,CAAP;AACH,CAJM;;;;AAMA,MAAMM,sBAAsB,GAAG,CAClCN,QADkC,EAElCO,EAFkC,KAGjC;AACD,SAAON,iCAAgBC,WAAhB,GAA8BM,iBAA9B,CAAgDR,QAAhD,EAA0DO,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"]}
|