@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
|
@@ -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,7 +4,21 @@
|
|
|
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
|
+
} from './DdSdkReactNativeConfiguration';
|
|
8
22
|
import { InternalLog } from './InternalLog';
|
|
9
23
|
import { ProxyType } from './ProxyConfiguration';
|
|
10
24
|
import { SdkVerbosity } from './SdkVerbosity';
|
|
@@ -41,127 +55,133 @@ export class DdSdkReactNative {
|
|
|
41
55
|
private static readonly NATIVE_LONG_TASK_THRESHOLD_MS = 200;
|
|
42
56
|
|
|
43
57
|
private static wasInitialized = false;
|
|
58
|
+
private static wasAutoInstrumented = false;
|
|
59
|
+
private static configuration?: DdSdkReactNativeConfiguration;
|
|
60
|
+
private static features?: AutoInstrumentationConfiguration;
|
|
44
61
|
|
|
45
62
|
/**
|
|
46
63
|
* Initializes the Datadog SDK.
|
|
47
64
|
* @param configuration the configuration for the SDK library
|
|
48
65
|
* @returns a Promise.
|
|
49
66
|
*/
|
|
50
|
-
static initialize(
|
|
67
|
+
static async initialize(
|
|
51
68
|
configuration: DdSdkReactNativeConfiguration
|
|
52
69
|
): Promise<void> {
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
70
|
+
await DdSdkReactNative.initializeNativeSDK(configuration);
|
|
71
|
+
DdSdkReactNative.enableFeatures(configuration);
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
private static initializeNativeSDK = async (
|
|
75
|
+
configuration: DdSdkReactNativeConfiguration
|
|
76
|
+
): Promise<void> => {
|
|
77
|
+
if (DdSdkReactNative.wasInitialized) {
|
|
78
|
+
InternalLog.log(
|
|
79
|
+
"Can't initialize Datadog, SDK was already initialized",
|
|
80
|
+
SdkVerbosity.WARN
|
|
81
|
+
);
|
|
82
|
+
if (!__DEV__) {
|
|
83
|
+
DdSdk.telemetryDebug(
|
|
84
|
+
'RN SDK was already initialized in javascript'
|
|
58
85
|
);
|
|
59
|
-
resolve();
|
|
60
|
-
return;
|
|
61
86
|
}
|
|
87
|
+
return new Promise(resolve => resolve());
|
|
88
|
+
}
|
|
62
89
|
|
|
63
|
-
|
|
90
|
+
InternalLog.verbosity = configuration.verbosity;
|
|
64
91
|
|
|
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
|
-
}
|
|
92
|
+
DdSdkReactNative.buildConfiguration(configuration);
|
|
78
93
|
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
additionalConfig[
|
|
99
|
-
DdSdkReactNative.DD_PROXY_PASSWORD_KEY
|
|
100
|
-
] = proxyConfig.password;
|
|
101
|
-
}
|
|
102
|
-
}
|
|
103
|
-
}
|
|
94
|
+
await DdSdk.initialize(
|
|
95
|
+
new DdSdkConfiguration(
|
|
96
|
+
configuration.clientToken,
|
|
97
|
+
configuration.env,
|
|
98
|
+
configuration.applicationId,
|
|
99
|
+
configuration.nativeCrashReportEnabled,
|
|
100
|
+
configuration.sampleRate === undefined
|
|
101
|
+
? configuration.sessionSamplingRate
|
|
102
|
+
: configuration.sampleRate,
|
|
103
|
+
configuration.site,
|
|
104
|
+
configuration.trackingConsent,
|
|
105
|
+
configuration.additionalConfig,
|
|
106
|
+
configuration.telemetrySampleRate
|
|
107
|
+
)
|
|
108
|
+
);
|
|
109
|
+
InternalLog.log('Datadog SDK was initialized', SdkVerbosity.INFO);
|
|
110
|
+
DdSdkReactNative.wasInitialized = true;
|
|
111
|
+
BufferSingleton.onInitialization();
|
|
112
|
+
};
|
|
104
113
|
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
114
|
+
/**
|
|
115
|
+
* FOR INTERNAL USE ONLY.
|
|
116
|
+
*/
|
|
117
|
+
static async _initializeFromDatadogProvider(
|
|
118
|
+
configuration: DatadogProviderConfiguration
|
|
119
|
+
): Promise<void> {
|
|
120
|
+
DdSdkReactNative.enableFeatures(configuration);
|
|
121
|
+
DdSdkReactNative.configuration = configuration;
|
|
122
|
+
if (configuration.initializationMode === InitializationMode.SYNC) {
|
|
123
|
+
return DdSdkReactNative.initializeNativeSDK(configuration);
|
|
124
|
+
}
|
|
125
|
+
if (configuration.initializationMode === InitializationMode.ASYNC) {
|
|
126
|
+
return InteractionManager.runAfterInteractions(() => {
|
|
127
|
+
return DdSdkReactNative.initializeNativeSDK(configuration);
|
|
128
|
+
});
|
|
129
|
+
}
|
|
130
|
+
// TODO: Remove when DdSdkReactNativeConfiguration is deprecated
|
|
131
|
+
if (configuration instanceof DdSdkReactNativeConfiguration) {
|
|
132
|
+
return DdSdkReactNative.initializeNativeSDK(configuration);
|
|
133
|
+
}
|
|
134
|
+
}
|
|
110
135
|
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
136
|
+
/**
|
|
137
|
+
* FOR INTERNAL USE ONLY.
|
|
138
|
+
*/
|
|
139
|
+
static async _enableFeaturesFromDatadogProvider(
|
|
140
|
+
features: AutoInstrumentationConfiguration
|
|
141
|
+
): Promise<void> {
|
|
142
|
+
DdSdkReactNative.features = features;
|
|
143
|
+
DdSdkReactNative.enableFeatures(
|
|
144
|
+
addDefaultValuesToAutoInstrumentationConfiguration(features)
|
|
145
|
+
);
|
|
146
|
+
}
|
|
120
147
|
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
148
|
+
/**
|
|
149
|
+
* FOR INTERNAL USE ONLY.
|
|
150
|
+
*/
|
|
151
|
+
static _initializeFromDatadogProviderAsync = async (): Promise<void> => {
|
|
152
|
+
if (!DdSdkReactNative.configuration) {
|
|
153
|
+
InternalLog.log(
|
|
154
|
+
"Can't initialize Datadog, make sure the DatadogProvider component is mounted before calling this function",
|
|
155
|
+
SdkVerbosity.WARN
|
|
156
|
+
);
|
|
157
|
+
return new Promise(resolve => resolve());
|
|
158
|
+
}
|
|
159
|
+
return DdSdkReactNative.initializeNativeSDK(
|
|
160
|
+
DdSdkReactNative.configuration
|
|
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
|
+
);
|
|
184
|
+
};
|
|
165
185
|
|
|
166
186
|
/**
|
|
167
187
|
* Sets the global context (set of attributes) attached with all future Logs, Spans and RUM events.
|
|
@@ -201,9 +221,88 @@ export class DdSdkReactNative {
|
|
|
201
221
|
return DdSdk.setTrackingConsent(consent);
|
|
202
222
|
}
|
|
203
223
|
|
|
204
|
-
private static
|
|
224
|
+
private static buildConfiguration = (
|
|
205
225
|
configuration: DdSdkReactNativeConfiguration
|
|
226
|
+
) => {
|
|
227
|
+
configuration.additionalConfig[DdSdkReactNative.DD_SOURCE_KEY] =
|
|
228
|
+
'react-native';
|
|
229
|
+
configuration.additionalConfig[
|
|
230
|
+
DdSdkReactNative.DD_SDK_VERSION
|
|
231
|
+
] = sdkVersion;
|
|
232
|
+
configuration.additionalConfig[
|
|
233
|
+
DdSdkReactNative.DD_NATIVE_VIEW_TRACKING_KEY
|
|
234
|
+
] = configuration.nativeViewTracking;
|
|
235
|
+
if (configuration.verbosity) {
|
|
236
|
+
configuration.additionalConfig[
|
|
237
|
+
DdSdkReactNative.DD_SDK_VERBOSITY_KEY
|
|
238
|
+
] = configuration.verbosity;
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
if (configuration.proxyConfig) {
|
|
242
|
+
const additionalConfig = configuration.additionalConfig;
|
|
243
|
+
const proxyConfig = configuration.proxyConfig;
|
|
244
|
+
|
|
245
|
+
additionalConfig[DdSdkReactNative.DD_PROXY_TYPE_KEY] =
|
|
246
|
+
proxyConfig.type;
|
|
247
|
+
additionalConfig[DdSdkReactNative.DD_PROXY_ADDRESS_KEY] =
|
|
248
|
+
proxyConfig.address;
|
|
249
|
+
additionalConfig[DdSdkReactNative.DD_PROXY_PORT_KEY] =
|
|
250
|
+
proxyConfig.port;
|
|
251
|
+
if (proxyConfig.username && proxyConfig.password) {
|
|
252
|
+
if (proxyConfig.type === ProxyType.SOCKS) {
|
|
253
|
+
console.warn(
|
|
254
|
+
"SOCKS proxy configuration doesn't support Basic authentication."
|
|
255
|
+
);
|
|
256
|
+
} else {
|
|
257
|
+
additionalConfig[DdSdkReactNative.DD_PROXY_USERNAME_KEY] =
|
|
258
|
+
proxyConfig.username;
|
|
259
|
+
additionalConfig[DdSdkReactNative.DD_PROXY_PASSWORD_KEY] =
|
|
260
|
+
proxyConfig.password;
|
|
261
|
+
}
|
|
262
|
+
}
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
if (configuration.serviceName) {
|
|
266
|
+
configuration.additionalConfig[DdSdkReactNative.DD_SERVICE_NAME] =
|
|
267
|
+
configuration.serviceName;
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
if (configuration.version) {
|
|
271
|
+
configuration.additionalConfig[DdSdkReactNative.DD_VERSION] = `${
|
|
272
|
+
configuration.version
|
|
273
|
+
}${
|
|
274
|
+
configuration.versionSuffix
|
|
275
|
+
? `-${configuration.versionSuffix}`
|
|
276
|
+
: ''
|
|
277
|
+
}`;
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
// If both version and version suffix are provided, we merge them into the version field.
|
|
281
|
+
// To avoid adding it in again the native part, we only set it if the version isn't set.
|
|
282
|
+
if (configuration.versionSuffix && !configuration.version) {
|
|
283
|
+
configuration.additionalConfig[
|
|
284
|
+
DdSdkReactNative.DD_VERSION_SUFFIX
|
|
285
|
+
] = `-${configuration.versionSuffix}`;
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
configuration.additionalConfig[
|
|
289
|
+
DdSdkReactNative.DD_NATIVE_LONG_TASK_THRESHOLD_KEY
|
|
290
|
+
] = DdSdkReactNative.NATIVE_LONG_TASK_THRESHOLD_MS;
|
|
291
|
+
|
|
292
|
+
configuration.additionalConfig['_dd.first_party_hosts'] =
|
|
293
|
+
configuration.firstPartyHosts;
|
|
294
|
+
};
|
|
295
|
+
|
|
296
|
+
private static enableFeatures(
|
|
297
|
+
configuration: AutoInstrumentationParameters
|
|
206
298
|
) {
|
|
299
|
+
if (DdSdkReactNative.wasAutoInstrumented) {
|
|
300
|
+
InternalLog.log(
|
|
301
|
+
"Can't auto instrument Datadog, SDK was already instrumented",
|
|
302
|
+
SdkVerbosity.WARN
|
|
303
|
+
);
|
|
304
|
+
return;
|
|
305
|
+
}
|
|
207
306
|
if (configuration.trackInteractions) {
|
|
208
307
|
DdRumUserInteractionTracking.startTracking();
|
|
209
308
|
}
|
|
@@ -218,5 +317,6 @@ export class DdSdkReactNative {
|
|
|
218
317
|
if (configuration.trackErrors) {
|
|
219
318
|
DdRumErrorTracking.startTracking();
|
|
220
319
|
}
|
|
320
|
+
DdSdkReactNative.wasAutoInstrumented = true;
|
|
221
321
|
}
|
|
222
322
|
}
|