@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
|
@@ -0,0 +1,174 @@
|
|
|
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 { fireEvent } from '@testing-library/react-native';
|
|
8
|
+
import { NativeModules } from 'react-native';
|
|
9
|
+
|
|
10
|
+
import { InitializationMode } from '../../DdSdkReactNativeConfiguration';
|
|
11
|
+
import { DdSdkReactNative } from '../../DdSdkReactNative';
|
|
12
|
+
import { TimeProvider } from '../../TimeProvider';
|
|
13
|
+
import { DdRumUserInteractionTracking } from '../../rum/instrumentation/DdRumUserInteractionTracking';
|
|
14
|
+
import { BufferSingleton } from '../Buffer/BufferSingleton';
|
|
15
|
+
import {
|
|
16
|
+
DatadogProvider,
|
|
17
|
+
__internalResetIsInitializedForTesting
|
|
18
|
+
} from '../DatadogProvider';
|
|
19
|
+
|
|
20
|
+
import {
|
|
21
|
+
getDefaultConfiguration,
|
|
22
|
+
mockAnimation,
|
|
23
|
+
renderWithProvider,
|
|
24
|
+
renderWithProviderAndAnimation
|
|
25
|
+
} from './__utils__/renderWithProvider';
|
|
26
|
+
|
|
27
|
+
jest.mock('../../TimeProvider', () => {
|
|
28
|
+
const now = jest.fn();
|
|
29
|
+
return {
|
|
30
|
+
TimeProvider: jest.fn().mockImplementation(() => {
|
|
31
|
+
return { now };
|
|
32
|
+
})
|
|
33
|
+
};
|
|
34
|
+
});
|
|
35
|
+
const nowMock = new TimeProvider().now;
|
|
36
|
+
|
|
37
|
+
const flushPromises = () => new Promise<void>(setImmediate);
|
|
38
|
+
|
|
39
|
+
describe('DatadogProvider', () => {
|
|
40
|
+
beforeEach(() => {
|
|
41
|
+
jest.clearAllMocks();
|
|
42
|
+
DdSdkReactNative['wasInitialized'] = false;
|
|
43
|
+
DdSdkReactNative['wasAutoInstrumented'] = false;
|
|
44
|
+
__internalResetIsInitializedForTesting();
|
|
45
|
+
BufferSingleton.reset();
|
|
46
|
+
DdRumUserInteractionTracking.stopTracking();
|
|
47
|
+
(nowMock as any).mockReturnValue('timestamp_not_specified');
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
describe('initializationMode SYNC', () => {
|
|
51
|
+
it('starts auto-instrumentation', async () => {
|
|
52
|
+
const { getByText } = renderWithProvider();
|
|
53
|
+
await flushPromises();
|
|
54
|
+
|
|
55
|
+
expect(NativeModules.DdSdk.initialize).toHaveBeenCalledTimes(1);
|
|
56
|
+
|
|
57
|
+
const button = getByText('test button');
|
|
58
|
+
fireEvent(button, 'press', {
|
|
59
|
+
_targetInst: {
|
|
60
|
+
props: {
|
|
61
|
+
'dd-action-name': 'press button'
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
expect(NativeModules.DdRum.addAction).toHaveBeenCalledTimes(1);
|
|
67
|
+
});
|
|
68
|
+
it('initializes the SDK before animations are done', async () => {
|
|
69
|
+
const { finishAnimation } = mockAnimation();
|
|
70
|
+
renderWithProvider();
|
|
71
|
+
|
|
72
|
+
await flushPromises();
|
|
73
|
+
expect(NativeModules.DdSdk.initialize).toHaveBeenCalledTimes(1);
|
|
74
|
+
finishAnimation();
|
|
75
|
+
});
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
describe('initializationMode ASYNC', () => {
|
|
79
|
+
beforeEach(() => {
|
|
80
|
+
jest.useFakeTimers();
|
|
81
|
+
});
|
|
82
|
+
afterEach(() => {
|
|
83
|
+
jest.useRealTimers();
|
|
84
|
+
});
|
|
85
|
+
it('starts auto-instrumentation after animations are done (with real Animation)', async () => {
|
|
86
|
+
const configuration = getDefaultConfiguration();
|
|
87
|
+
configuration.initializationMode = InitializationMode.ASYNC;
|
|
88
|
+
|
|
89
|
+
const { getByText } = renderWithProviderAndAnimation({
|
|
90
|
+
configuration
|
|
91
|
+
});
|
|
92
|
+
await flushPromises();
|
|
93
|
+
expect(NativeModules.DdSdk.initialize).toHaveBeenCalledTimes(0);
|
|
94
|
+
jest.advanceTimersByTime(700);
|
|
95
|
+
await flushPromises();
|
|
96
|
+
expect(NativeModules.DdSdk.initialize).toHaveBeenCalledTimes(1);
|
|
97
|
+
const button = getByText('test button');
|
|
98
|
+
fireEvent(button, 'press', {
|
|
99
|
+
_targetInst: {
|
|
100
|
+
props: {
|
|
101
|
+
'dd-action-name': 'press button'
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
});
|
|
105
|
+
expect(NativeModules.DdRum.addAction).toHaveBeenCalledTimes(1);
|
|
106
|
+
});
|
|
107
|
+
|
|
108
|
+
it('starts auto-instrumentation after animations are done (with InteractionManager)', async () => {
|
|
109
|
+
const configuration = getDefaultConfiguration();
|
|
110
|
+
configuration.initializationMode = InitializationMode.ASYNC;
|
|
111
|
+
|
|
112
|
+
const { finishAnimation } = mockAnimation();
|
|
113
|
+
const { getByText } = renderWithProvider({ configuration });
|
|
114
|
+
|
|
115
|
+
await flushPromises();
|
|
116
|
+
expect(NativeModules.DdSdk.initialize).toHaveBeenCalledTimes(0);
|
|
117
|
+
|
|
118
|
+
finishAnimation();
|
|
119
|
+
await flushPromises();
|
|
120
|
+
|
|
121
|
+
expect(NativeModules.DdSdk.initialize).toHaveBeenCalledTimes(1);
|
|
122
|
+
const button = getByText('test button');
|
|
123
|
+
fireEvent(button, 'press', {
|
|
124
|
+
_targetInst: {
|
|
125
|
+
props: {
|
|
126
|
+
'dd-action-name': 'press button'
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
});
|
|
130
|
+
expect(NativeModules.DdRum.addAction).toHaveBeenCalledTimes(1);
|
|
131
|
+
});
|
|
132
|
+
});
|
|
133
|
+
|
|
134
|
+
describe('partial initialization', () => {
|
|
135
|
+
it('does not start reporting auto-instrumentation', async () => {
|
|
136
|
+
const { getByText } = renderWithProvider({
|
|
137
|
+
configuration: {
|
|
138
|
+
trackErrors: true,
|
|
139
|
+
trackResources: true,
|
|
140
|
+
trackInteractions: true,
|
|
141
|
+
firstPartyHosts: ['api.com'],
|
|
142
|
+
resourceTracingSamplingRate: 100
|
|
143
|
+
}
|
|
144
|
+
});
|
|
145
|
+
await flushPromises();
|
|
146
|
+
|
|
147
|
+
const button = getByText('test button');
|
|
148
|
+
fireEvent(button, 'press', {
|
|
149
|
+
_targetInst: {
|
|
150
|
+
props: {
|
|
151
|
+
'dd-action-name': 'press button'
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
});
|
|
155
|
+
|
|
156
|
+
expect(NativeModules.DdSdk.initialize).not.toHaveBeenCalled();
|
|
157
|
+
expect(NativeModules.DdRum.addAction).not.toHaveBeenCalled();
|
|
158
|
+
|
|
159
|
+
await DatadogProvider.initialize({
|
|
160
|
+
applicationId: 'fake-application-id',
|
|
161
|
+
clientToken: 'fake-client-token',
|
|
162
|
+
env: 'fake-env'
|
|
163
|
+
});
|
|
164
|
+
await flushPromises();
|
|
165
|
+
|
|
166
|
+
expect(NativeModules.DdSdk.initialize).toHaveBeenCalledTimes(1);
|
|
167
|
+
expect(
|
|
168
|
+
NativeModules.DdSdk.initialize.mock.calls[0][0]
|
|
169
|
+
.additionalConfig['_dd.first_party_hosts']
|
|
170
|
+
).toEqual(['api.com']);
|
|
171
|
+
expect(NativeModules.DdRum.addAction).toHaveBeenCalledTimes(1);
|
|
172
|
+
});
|
|
173
|
+
});
|
|
174
|
+
});
|
package/src/DdSdkReactNative.tsx
CHANGED
|
@@ -4,12 +4,28 @@
|
|
|
4
4
|
* Copyright 2016-Present Datadog, Inc.
|
|
5
5
|
*/
|
|
6
6
|
|
|
7
|
-
import
|
|
7
|
+
import { InteractionManager } from 'react-native';
|
|
8
|
+
|
|
9
|
+
import { BufferSingleton } from './DatadogProvider/Buffer/BufferSingleton';
|
|
10
|
+
import {
|
|
11
|
+
DdSdkReactNativeConfiguration,
|
|
12
|
+
buildConfigurationFromPartialConfiguration,
|
|
13
|
+
addDefaultValuesToAutoInstrumentationConfiguration,
|
|
14
|
+
InitializationMode
|
|
15
|
+
} from './DdSdkReactNativeConfiguration';
|
|
16
|
+
import type {
|
|
17
|
+
AutoInstrumentationParameters,
|
|
18
|
+
DatadogProviderConfiguration,
|
|
19
|
+
PartialInitializationConfiguration,
|
|
20
|
+
AutoInstrumentationConfiguration,
|
|
21
|
+
InitializationModeForTelemetry
|
|
22
|
+
} from './DdSdkReactNativeConfiguration';
|
|
8
23
|
import { InternalLog } from './InternalLog';
|
|
9
24
|
import { ProxyType } from './ProxyConfiguration';
|
|
10
25
|
import { SdkVerbosity } from './SdkVerbosity';
|
|
11
26
|
import type { TrackingConsent } from './TrackingConsent';
|
|
12
27
|
import { DdSdk } from './foundation';
|
|
28
|
+
import { adaptLongTaskThreshold } from './longTasksUtils';
|
|
13
29
|
import { DdRumErrorTracking } from './rum/instrumentation/DdRumErrorTracking';
|
|
14
30
|
import { DdRumUserInteractionTracking } from './rum/instrumentation/DdRumUserInteractionTracking';
|
|
15
31
|
import { DdRumResourceTracking } from './rum/instrumentation/resourceTracking/DdRumResourceTracking';
|
|
@@ -36,132 +52,137 @@ export class DdSdkReactNative {
|
|
|
36
52
|
private static readonly DD_PROXY_USERNAME_KEY = '_dd.proxy.username';
|
|
37
53
|
private static readonly DD_PROXY_PASSWORD_KEY = '_dd.proxy.password';
|
|
38
54
|
|
|
39
|
-
private static readonly DD_NATIVE_LONG_TASK_THRESHOLD_KEY =
|
|
40
|
-
'_dd.long_task.threshold';
|
|
41
|
-
private static readonly NATIVE_LONG_TASK_THRESHOLD_MS = 200;
|
|
42
|
-
|
|
43
55
|
private static wasInitialized = false;
|
|
56
|
+
private static wasAutoInstrumented = false;
|
|
57
|
+
private static features?: AutoInstrumentationConfiguration;
|
|
44
58
|
|
|
45
59
|
/**
|
|
46
60
|
* Initializes the Datadog SDK.
|
|
47
61
|
* @param configuration the configuration for the SDK library
|
|
48
62
|
* @returns a Promise.
|
|
49
63
|
*/
|
|
50
|
-
static initialize(
|
|
64
|
+
static async initialize(
|
|
51
65
|
configuration: DdSdkReactNativeConfiguration
|
|
52
66
|
): Promise<void> {
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
67
|
+
await DdSdkReactNative.initializeNativeSDK(configuration, {
|
|
68
|
+
initializationModeForTelemetry: 'LEGACY'
|
|
69
|
+
});
|
|
70
|
+
DdSdkReactNative.enableFeatures(configuration);
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
private static initializeNativeSDK = async (
|
|
74
|
+
configuration: DdSdkReactNativeConfiguration,
|
|
75
|
+
params: {
|
|
76
|
+
initializationModeForTelemetry: InitializationModeForTelemetry;
|
|
77
|
+
}
|
|
78
|
+
): Promise<void> => {
|
|
79
|
+
if (DdSdkReactNative.wasInitialized) {
|
|
80
|
+
InternalLog.log(
|
|
81
|
+
"Can't initialize Datadog, SDK was already initialized",
|
|
82
|
+
SdkVerbosity.WARN
|
|
83
|
+
);
|
|
84
|
+
if (!__DEV__) {
|
|
85
|
+
DdSdk.telemetryDebug(
|
|
86
|
+
'RN SDK was already initialized in javascript'
|
|
58
87
|
);
|
|
59
|
-
resolve();
|
|
60
|
-
return;
|
|
61
88
|
}
|
|
89
|
+
return new Promise(resolve => resolve());
|
|
90
|
+
}
|
|
62
91
|
|
|
63
|
-
|
|
92
|
+
InternalLog.verbosity = configuration.verbosity;
|
|
64
93
|
|
|
65
|
-
|
|
66
|
-
'react-native';
|
|
67
|
-
configuration.additionalConfig[
|
|
68
|
-
DdSdkReactNative.DD_SDK_VERSION
|
|
69
|
-
] = sdkVersion;
|
|
70
|
-
configuration.additionalConfig[
|
|
71
|
-
DdSdkReactNative.DD_NATIVE_VIEW_TRACKING_KEY
|
|
72
|
-
] = configuration.nativeViewTracking;
|
|
73
|
-
if (configuration.verbosity) {
|
|
74
|
-
configuration.additionalConfig[
|
|
75
|
-
DdSdkReactNative.DD_SDK_VERBOSITY_KEY
|
|
76
|
-
] = configuration.verbosity;
|
|
77
|
-
}
|
|
94
|
+
DdSdkReactNative.buildConfiguration(configuration);
|
|
78
95
|
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
] = proxyConfig.password;
|
|
101
|
-
}
|
|
96
|
+
await DdSdk.initialize(
|
|
97
|
+
new DdSdkConfiguration(
|
|
98
|
+
configuration.clientToken,
|
|
99
|
+
configuration.env,
|
|
100
|
+
configuration.applicationId,
|
|
101
|
+
configuration.nativeCrashReportEnabled,
|
|
102
|
+
adaptLongTaskThreshold(configuration.nativeLongTaskThresholdMs),
|
|
103
|
+
adaptLongTaskThreshold(configuration.longTaskThresholdMs),
|
|
104
|
+
configuration.sampleRate === undefined
|
|
105
|
+
? configuration.sessionSamplingRate
|
|
106
|
+
: configuration.sampleRate,
|
|
107
|
+
configuration.site,
|
|
108
|
+
configuration.trackingConsent,
|
|
109
|
+
configuration.additionalConfig,
|
|
110
|
+
configuration.telemetrySampleRate,
|
|
111
|
+
configuration.vitalsUpdateFrequency,
|
|
112
|
+
{
|
|
113
|
+
initializationType: params.initializationModeForTelemetry,
|
|
114
|
+
trackErrors: configuration.trackErrors,
|
|
115
|
+
trackInteractions: configuration.trackInteractions,
|
|
116
|
+
trackNetworkRequests: configuration.trackResources
|
|
102
117
|
}
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
}
|
|
118
|
+
)
|
|
119
|
+
);
|
|
120
|
+
InternalLog.log('Datadog SDK was initialized', SdkVerbosity.INFO);
|
|
121
|
+
DdSdkReactNative.wasInitialized = true;
|
|
122
|
+
BufferSingleton.onInitialization();
|
|
123
|
+
};
|
|
110
124
|
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
125
|
+
/**
|
|
126
|
+
* FOR INTERNAL USE ONLY.
|
|
127
|
+
*/
|
|
128
|
+
static async _initializeFromDatadogProvider(
|
|
129
|
+
configuration: DatadogProviderConfiguration
|
|
130
|
+
): Promise<void> {
|
|
131
|
+
DdSdkReactNative.enableFeatures(configuration);
|
|
132
|
+
if (configuration.initializationMode === InitializationMode.SYNC) {
|
|
133
|
+
return DdSdkReactNative.initializeNativeSDK(configuration, {
|
|
134
|
+
initializationModeForTelemetry: 'SYNC'
|
|
135
|
+
});
|
|
136
|
+
}
|
|
137
|
+
if (configuration.initializationMode === InitializationMode.ASYNC) {
|
|
138
|
+
return InteractionManager.runAfterInteractions(() => {
|
|
139
|
+
return DdSdkReactNative.initializeNativeSDK(configuration, {
|
|
140
|
+
initializationModeForTelemetry: 'ASYNC'
|
|
141
|
+
});
|
|
142
|
+
});
|
|
143
|
+
}
|
|
144
|
+
// TODO: Remove when DdSdkReactNativeConfiguration is deprecated
|
|
145
|
+
if (configuration instanceof DdSdkReactNativeConfiguration) {
|
|
146
|
+
return DdSdkReactNative.initializeNativeSDK(configuration, {
|
|
147
|
+
initializationModeForTelemetry: 'SYNC'
|
|
148
|
+
});
|
|
149
|
+
}
|
|
150
|
+
}
|
|
120
151
|
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
152
|
+
/**
|
|
153
|
+
* FOR INTERNAL USE ONLY.
|
|
154
|
+
*/
|
|
155
|
+
static async _enableFeaturesFromDatadogProvider(
|
|
156
|
+
features: AutoInstrumentationConfiguration
|
|
157
|
+
): Promise<void> {
|
|
158
|
+
DdSdkReactNative.features = features;
|
|
159
|
+
DdSdkReactNative.enableFeatures(
|
|
160
|
+
addDefaultValuesToAutoInstrumentationConfiguration(features)
|
|
161
|
+
);
|
|
162
|
+
}
|
|
128
163
|
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
configuration.env,
|
|
140
|
-
configuration.applicationId,
|
|
141
|
-
configuration.nativeCrashReportEnabled,
|
|
142
|
-
configuration.sampleRate === undefined
|
|
143
|
-
? configuration.sessionSamplingRate
|
|
144
|
-
: configuration.sampleRate,
|
|
145
|
-
configuration.site,
|
|
146
|
-
configuration.trackingConsent,
|
|
147
|
-
configuration.additionalConfig
|
|
148
|
-
)
|
|
149
|
-
).then(
|
|
150
|
-
() => {
|
|
151
|
-
InternalLog.log(
|
|
152
|
-
'Datadog SDK was initialized',
|
|
153
|
-
SdkVerbosity.INFO
|
|
154
|
-
);
|
|
155
|
-
DdSdkReactNative.enableFeatures(configuration);
|
|
156
|
-
DdSdkReactNative.wasInitialized = true;
|
|
157
|
-
resolve();
|
|
158
|
-
},
|
|
159
|
-
rejection => {
|
|
160
|
-
reject(rejection);
|
|
161
|
-
}
|
|
164
|
+
/**
|
|
165
|
+
* FOR INTERNAL USE ONLY.
|
|
166
|
+
*/
|
|
167
|
+
static _initializeFromDatadogProviderWithConfigurationAsync = async (
|
|
168
|
+
configuration: PartialInitializationConfiguration
|
|
169
|
+
): Promise<void> => {
|
|
170
|
+
if (!DdSdkReactNative.features) {
|
|
171
|
+
InternalLog.log(
|
|
172
|
+
"Can't initialize Datadog, make sure the DatadogProvider component is mounted before calling this function",
|
|
173
|
+
SdkVerbosity.WARN
|
|
162
174
|
);
|
|
163
|
-
|
|
164
|
-
|
|
175
|
+
return new Promise(resolve => resolve());
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
return DdSdkReactNative.initializeNativeSDK(
|
|
179
|
+
buildConfigurationFromPartialConfiguration(
|
|
180
|
+
DdSdkReactNative.features,
|
|
181
|
+
configuration
|
|
182
|
+
),
|
|
183
|
+
{ initializationModeForTelemetry: 'PARTIAL' }
|
|
184
|
+
);
|
|
185
|
+
};
|
|
165
186
|
|
|
166
187
|
/**
|
|
167
188
|
* Sets the global context (set of attributes) attached with all future Logs, Spans and RUM events.
|
|
@@ -201,9 +222,84 @@ export class DdSdkReactNative {
|
|
|
201
222
|
return DdSdk.setTrackingConsent(consent);
|
|
202
223
|
}
|
|
203
224
|
|
|
204
|
-
private static
|
|
225
|
+
private static buildConfiguration = (
|
|
205
226
|
configuration: DdSdkReactNativeConfiguration
|
|
227
|
+
) => {
|
|
228
|
+
configuration.additionalConfig[DdSdkReactNative.DD_SOURCE_KEY] =
|
|
229
|
+
'react-native';
|
|
230
|
+
configuration.additionalConfig[
|
|
231
|
+
DdSdkReactNative.DD_SDK_VERSION
|
|
232
|
+
] = sdkVersion;
|
|
233
|
+
configuration.additionalConfig[
|
|
234
|
+
DdSdkReactNative.DD_NATIVE_VIEW_TRACKING_KEY
|
|
235
|
+
] = configuration.nativeViewTracking;
|
|
236
|
+
if (configuration.verbosity) {
|
|
237
|
+
configuration.additionalConfig[
|
|
238
|
+
DdSdkReactNative.DD_SDK_VERBOSITY_KEY
|
|
239
|
+
] = configuration.verbosity;
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
if (configuration.proxyConfig) {
|
|
243
|
+
const additionalConfig = configuration.additionalConfig;
|
|
244
|
+
const proxyConfig = configuration.proxyConfig;
|
|
245
|
+
|
|
246
|
+
additionalConfig[DdSdkReactNative.DD_PROXY_TYPE_KEY] =
|
|
247
|
+
proxyConfig.type;
|
|
248
|
+
additionalConfig[DdSdkReactNative.DD_PROXY_ADDRESS_KEY] =
|
|
249
|
+
proxyConfig.address;
|
|
250
|
+
additionalConfig[DdSdkReactNative.DD_PROXY_PORT_KEY] =
|
|
251
|
+
proxyConfig.port;
|
|
252
|
+
if (proxyConfig.username && proxyConfig.password) {
|
|
253
|
+
if (proxyConfig.type === ProxyType.SOCKS) {
|
|
254
|
+
console.warn(
|
|
255
|
+
"SOCKS proxy configuration doesn't support Basic authentication."
|
|
256
|
+
);
|
|
257
|
+
} else {
|
|
258
|
+
additionalConfig[DdSdkReactNative.DD_PROXY_USERNAME_KEY] =
|
|
259
|
+
proxyConfig.username;
|
|
260
|
+
additionalConfig[DdSdkReactNative.DD_PROXY_PASSWORD_KEY] =
|
|
261
|
+
proxyConfig.password;
|
|
262
|
+
}
|
|
263
|
+
}
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
if (configuration.serviceName) {
|
|
267
|
+
configuration.additionalConfig[DdSdkReactNative.DD_SERVICE_NAME] =
|
|
268
|
+
configuration.serviceName;
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
if (configuration.version) {
|
|
272
|
+
configuration.additionalConfig[DdSdkReactNative.DD_VERSION] = `${
|
|
273
|
+
configuration.version
|
|
274
|
+
}${
|
|
275
|
+
configuration.versionSuffix
|
|
276
|
+
? `-${configuration.versionSuffix}`
|
|
277
|
+
: ''
|
|
278
|
+
}`;
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
// If both version and version suffix are provided, we merge them into the version field.
|
|
282
|
+
// To avoid adding it in again the native part, we only set it if the version isn't set.
|
|
283
|
+
if (configuration.versionSuffix && !configuration.version) {
|
|
284
|
+
configuration.additionalConfig[
|
|
285
|
+
DdSdkReactNative.DD_VERSION_SUFFIX
|
|
286
|
+
] = `-${configuration.versionSuffix}`;
|
|
287
|
+
}
|
|
288
|
+
|
|
289
|
+
configuration.additionalConfig['_dd.first_party_hosts'] =
|
|
290
|
+
configuration.firstPartyHosts;
|
|
291
|
+
};
|
|
292
|
+
|
|
293
|
+
private static enableFeatures(
|
|
294
|
+
configuration: AutoInstrumentationParameters
|
|
206
295
|
) {
|
|
296
|
+
if (DdSdkReactNative.wasAutoInstrumented) {
|
|
297
|
+
InternalLog.log(
|
|
298
|
+
"Can't auto instrument Datadog, SDK was already instrumented",
|
|
299
|
+
SdkVerbosity.WARN
|
|
300
|
+
);
|
|
301
|
+
return;
|
|
302
|
+
}
|
|
207
303
|
if (configuration.trackInteractions) {
|
|
208
304
|
DdRumUserInteractionTracking.startTracking();
|
|
209
305
|
}
|
|
@@ -218,5 +314,6 @@ export class DdSdkReactNative {
|
|
|
218
314
|
if (configuration.trackErrors) {
|
|
219
315
|
DdRumErrorTracking.startTracking();
|
|
220
316
|
}
|
|
317
|
+
DdSdkReactNative.wasAutoInstrumented = true;
|
|
221
318
|
}
|
|
222
319
|
}
|