@datadog/mobile-react-native 1.1.4 → 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 +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/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 +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/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/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 +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/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
|
@@ -8,12 +8,25 @@ import type { ProxyConfiguration } from './ProxyConfiguration';
|
|
|
8
8
|
import type { SdkVerbosity } from './SdkVerbosity';
|
|
9
9
|
import { TrackingConsent } from './TrackingConsent';
|
|
10
10
|
|
|
11
|
+
const DEFAULTS = {
|
|
12
|
+
nativeCrashReportEnabled: false,
|
|
13
|
+
sessionSamplingRate: 100.0,
|
|
14
|
+
resourceTracingSamplingRate: 20.0,
|
|
15
|
+
site: 'US1',
|
|
16
|
+
nativeViewTracking: false,
|
|
17
|
+
getFirstPartyHosts: () => [],
|
|
18
|
+
getAdditionalConfig: () => ({}),
|
|
19
|
+
trackingConsent: TrackingConsent.GRANTED,
|
|
20
|
+
telemetrySampleRate: 20.0
|
|
21
|
+
};
|
|
22
|
+
|
|
11
23
|
/**
|
|
12
24
|
* The SDK configuration class.
|
|
13
25
|
* It will be used to configure the SDK functionality at initialization.
|
|
14
26
|
*/
|
|
15
27
|
export class DdSdkReactNativeConfiguration {
|
|
16
|
-
public nativeCrashReportEnabled: boolean =
|
|
28
|
+
public nativeCrashReportEnabled: boolean =
|
|
29
|
+
DEFAULTS.nativeCrashReportEnabled;
|
|
17
30
|
/**
|
|
18
31
|
* @deprecated `sampleRate` has been replaced by `sessionSamplingRate` to avoid confusion with `resourceTracingSamplingRate` and will be removed in a future release.
|
|
19
32
|
*/
|
|
@@ -21,17 +34,18 @@ export class DdSdkReactNativeConfiguration {
|
|
|
21
34
|
/**
|
|
22
35
|
* Percentage of sampled RUM sessions. Range `0`-`100`.
|
|
23
36
|
*/
|
|
24
|
-
public sessionSamplingRate: number =
|
|
37
|
+
public sessionSamplingRate: number = DEFAULTS.sessionSamplingRate;
|
|
25
38
|
/**
|
|
26
39
|
* Percentage of tracing integrations for network calls between your app and your backend. Range `0`-`100`.
|
|
27
40
|
*/
|
|
28
|
-
public resourceTracingSamplingRate: number =
|
|
29
|
-
|
|
41
|
+
public resourceTracingSamplingRate: number =
|
|
42
|
+
DEFAULTS.resourceTracingSamplingRate;
|
|
43
|
+
public site: string = DEFAULTS.site;
|
|
30
44
|
public verbosity: SdkVerbosity | undefined = undefined;
|
|
31
|
-
public nativeViewTracking: boolean =
|
|
45
|
+
public nativeViewTracking: boolean = DEFAULTS.nativeViewTracking;
|
|
32
46
|
public proxyConfig?: ProxyConfiguration = undefined;
|
|
33
47
|
public serviceName?: string = undefined;
|
|
34
|
-
public firstPartyHosts: string[] =
|
|
48
|
+
public firstPartyHosts: string[] = DEFAULTS.getFirstPartyHosts();
|
|
35
49
|
/**
|
|
36
50
|
* Overrides the reported version of the app.
|
|
37
51
|
* Accepted characters are alphanumerics and `_`, `-`, `:`, `.`, `/`.
|
|
@@ -53,7 +67,20 @@ export class DdSdkReactNativeConfiguration {
|
|
|
53
67
|
*/
|
|
54
68
|
public versionSuffix?: string;
|
|
55
69
|
|
|
56
|
-
|
|
70
|
+
/**
|
|
71
|
+
* The sampling rate for Internal Telemetry (info related to the work of the
|
|
72
|
+
* SDK internals).
|
|
73
|
+
*
|
|
74
|
+
* The sampling rate must be a value between 0 and 100. A value of 0 means no
|
|
75
|
+
* telemetry will be sent, 100 means all telemetry will be sent. When
|
|
76
|
+
* `telemetrySampleRate` is not set, the default value from the iOS and
|
|
77
|
+
* Android SDK is used, which is 20.
|
|
78
|
+
*/
|
|
79
|
+
public telemetrySampleRate: number = DEFAULTS.telemetrySampleRate;
|
|
80
|
+
|
|
81
|
+
public additionalConfig: {
|
|
82
|
+
[k: string]: any;
|
|
83
|
+
} = DEFAULTS.getAdditionalConfig();
|
|
57
84
|
|
|
58
85
|
constructor(
|
|
59
86
|
readonly clientToken: string,
|
|
@@ -62,6 +89,131 @@ export class DdSdkReactNativeConfiguration {
|
|
|
62
89
|
readonly trackInteractions: boolean = false,
|
|
63
90
|
readonly trackResources: boolean = false,
|
|
64
91
|
readonly trackErrors: boolean = false,
|
|
65
|
-
readonly trackingConsent: TrackingConsent =
|
|
92
|
+
readonly trackingConsent: TrackingConsent = DEFAULTS.trackingConsent
|
|
66
93
|
) {}
|
|
67
94
|
}
|
|
95
|
+
|
|
96
|
+
/**
|
|
97
|
+
* Auto Instrumentation configuration passed to DatadogProvider.
|
|
98
|
+
* Does not include default values.
|
|
99
|
+
*/
|
|
100
|
+
export type AutoInstrumentationConfiguration = {
|
|
101
|
+
readonly trackInteractions: boolean;
|
|
102
|
+
readonly trackResources: boolean;
|
|
103
|
+
readonly firstPartyHosts?: string[];
|
|
104
|
+
readonly resourceTracingSamplingRate?: number;
|
|
105
|
+
readonly trackErrors: boolean;
|
|
106
|
+
};
|
|
107
|
+
|
|
108
|
+
/**
|
|
109
|
+
* Parameters needed to start auto instrumentation. Includes default values.
|
|
110
|
+
*/
|
|
111
|
+
export type AutoInstrumentationParameters = {
|
|
112
|
+
readonly trackInteractions: boolean;
|
|
113
|
+
readonly trackResources: boolean;
|
|
114
|
+
readonly firstPartyHosts: string[];
|
|
115
|
+
readonly resourceTracingSamplingRate: number;
|
|
116
|
+
readonly trackErrors: boolean;
|
|
117
|
+
};
|
|
118
|
+
|
|
119
|
+
/**
|
|
120
|
+
* We could use `Proxy` instead of this function, but `Proxy` is not available on
|
|
121
|
+
* the older android jsc that can still be used.
|
|
122
|
+
*/
|
|
123
|
+
export const addDefaultValuesToAutoInstrumentationConfiguration = (
|
|
124
|
+
features: AutoInstrumentationConfiguration
|
|
125
|
+
): AutoInstrumentationParameters => {
|
|
126
|
+
return {
|
|
127
|
+
...features,
|
|
128
|
+
firstPartyHosts:
|
|
129
|
+
features.firstPartyHosts || DEFAULTS.getFirstPartyHosts(),
|
|
130
|
+
resourceTracingSamplingRate:
|
|
131
|
+
features.resourceTracingSamplingRate ||
|
|
132
|
+
DEFAULTS.resourceTracingSamplingRate
|
|
133
|
+
};
|
|
134
|
+
};
|
|
135
|
+
|
|
136
|
+
export type PartialInitializationConfiguration = {
|
|
137
|
+
readonly clientToken: string;
|
|
138
|
+
readonly env: string;
|
|
139
|
+
readonly applicationId: string;
|
|
140
|
+
readonly sessionSamplingRate?: number;
|
|
141
|
+
readonly site?: string;
|
|
142
|
+
readonly verbosity?: SdkVerbosity | undefined;
|
|
143
|
+
readonly nativeViewTracking?: boolean;
|
|
144
|
+
readonly proxyConfig?: ProxyConfiguration;
|
|
145
|
+
readonly serviceName?: string;
|
|
146
|
+
readonly version?: string;
|
|
147
|
+
versionSuffix?: string;
|
|
148
|
+
readonly additionalConfig?: { [k: string]: any };
|
|
149
|
+
readonly trackingConsent?: TrackingConsent;
|
|
150
|
+
readonly nativeCrashReportEnabled?: boolean;
|
|
151
|
+
readonly telemetrySampleRate?: number;
|
|
152
|
+
};
|
|
153
|
+
|
|
154
|
+
const setConfigurationAttribute = <
|
|
155
|
+
AttributeName extends keyof DdSdkReactNativeConfiguration
|
|
156
|
+
>(
|
|
157
|
+
attribute: {
|
|
158
|
+
value?: DdSdkReactNativeConfiguration[AttributeName];
|
|
159
|
+
name: AttributeName;
|
|
160
|
+
},
|
|
161
|
+
configuration: DdSdkReactNativeConfiguration
|
|
162
|
+
) => {
|
|
163
|
+
if (attribute.value !== undefined) {
|
|
164
|
+
configuration[attribute.name] = attribute.value;
|
|
165
|
+
}
|
|
166
|
+
};
|
|
167
|
+
|
|
168
|
+
export const buildConfigurationFromPartialConfiguration = (
|
|
169
|
+
features: AutoInstrumentationConfiguration,
|
|
170
|
+
configuration: PartialInitializationConfiguration
|
|
171
|
+
): DdSdkReactNativeConfiguration => {
|
|
172
|
+
const {
|
|
173
|
+
clientToken,
|
|
174
|
+
env,
|
|
175
|
+
applicationId,
|
|
176
|
+
...remainingConfiguration
|
|
177
|
+
} = configuration;
|
|
178
|
+
const SdkConfiguration = new DdSdkReactNativeConfiguration(
|
|
179
|
+
clientToken,
|
|
180
|
+
env,
|
|
181
|
+
applicationId,
|
|
182
|
+
features.trackInteractions,
|
|
183
|
+
features.trackResources,
|
|
184
|
+
features.trackErrors,
|
|
185
|
+
configuration.trackingConsent
|
|
186
|
+
);
|
|
187
|
+
|
|
188
|
+
(Object.keys(
|
|
189
|
+
remainingConfiguration
|
|
190
|
+
) as (keyof typeof remainingConfiguration)[]).forEach(name => {
|
|
191
|
+
setConfigurationAttribute(
|
|
192
|
+
{ value: remainingConfiguration[name], name },
|
|
193
|
+
SdkConfiguration
|
|
194
|
+
);
|
|
195
|
+
});
|
|
196
|
+
|
|
197
|
+
setConfigurationAttribute(
|
|
198
|
+
{
|
|
199
|
+
name: 'resourceTracingSamplingRate',
|
|
200
|
+
value: features.resourceTracingSamplingRate
|
|
201
|
+
},
|
|
202
|
+
SdkConfiguration
|
|
203
|
+
);
|
|
204
|
+
setConfigurationAttribute(
|
|
205
|
+
{ name: 'firstPartyHosts', value: features.firstPartyHosts },
|
|
206
|
+
SdkConfiguration
|
|
207
|
+
);
|
|
208
|
+
|
|
209
|
+
return SdkConfiguration;
|
|
210
|
+
};
|
|
211
|
+
|
|
212
|
+
export class DatadogProviderConfiguration extends DdSdkReactNativeConfiguration {
|
|
213
|
+
public initializationMode: InitializationMode = InitializationMode.SYNC;
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
export enum InitializationMode {
|
|
217
|
+
SYNC = 'SYNC',
|
|
218
|
+
ASYNC = 'ASYNC'
|
|
219
|
+
}
|
|
@@ -6,36 +6,12 @@
|
|
|
6
6
|
|
|
7
7
|
import { NativeModules } from 'react-native';
|
|
8
8
|
|
|
9
|
+
import { BufferSingleton } from '../DatadogProvider/Buffer/BufferSingleton';
|
|
9
10
|
import { DdRum } from '../foundation';
|
|
10
11
|
|
|
11
|
-
jest.mock('react-native', () => {
|
|
12
|
-
return {
|
|
13
|
-
NativeModules: {
|
|
14
|
-
DdRum: {
|
|
15
|
-
startView: jest.fn().mockImplementation(() => {}),
|
|
16
|
-
stopView: jest.fn().mockImplementation(() => {}),
|
|
17
|
-
startAction: jest.fn().mockImplementation(() => {}),
|
|
18
|
-
stopAction: jest.fn().mockImplementation(() => {}),
|
|
19
|
-
addAction: jest.fn().mockImplementation(() => {}),
|
|
20
|
-
startResource: jest.fn().mockImplementation(() => {}),
|
|
21
|
-
stopResource: jest.fn().mockImplementation(() => {}),
|
|
22
|
-
addError: jest.fn().mockImplementation(() => {}),
|
|
23
|
-
addTiming: jest.fn().mockImplementation(() => {})
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
};
|
|
27
|
-
});
|
|
28
|
-
|
|
29
12
|
beforeEach(async () => {
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
NativeModules.DdRum.startAction.mockClear();
|
|
33
|
-
NativeModules.DdRum.stopAction.mockClear();
|
|
34
|
-
NativeModules.DdRum.addAction.mockClear();
|
|
35
|
-
NativeModules.DdRum.startResource.mockClear();
|
|
36
|
-
NativeModules.DdRum.stopResource.mockClear();
|
|
37
|
-
NativeModules.DdRum.addError.mockClear();
|
|
38
|
-
NativeModules.DdRum.addTiming.mockClear();
|
|
13
|
+
jest.clearAllMocks();
|
|
14
|
+
BufferSingleton.onInitialization();
|
|
39
15
|
});
|
|
40
16
|
|
|
41
17
|
it('M add error source type W addError()', async () => {
|
|
@@ -49,6 +49,7 @@ jest.mock('../rum/instrumentation/DdRumErrorTracking', () => {
|
|
|
49
49
|
|
|
50
50
|
beforeEach(async () => {
|
|
51
51
|
DdSdkReactNative['wasInitialized'] = false;
|
|
52
|
+
DdSdkReactNative['wasAutoInstrumented'] = false;
|
|
52
53
|
NativeModules.DdSdk.initialize.mockClear();
|
|
53
54
|
NativeModules.DdSdk.setAttributes.mockClear();
|
|
54
55
|
NativeModules.DdSdk.setUser.mockClear();
|
|
@@ -0,0 +1,168 @@
|
|
|
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 { buildConfigurationFromPartialConfiguration } from '../DdSdkReactNativeConfiguration';
|
|
8
|
+
import { ProxyConfiguration, ProxyType } from '../ProxyConfiguration';
|
|
9
|
+
import { SdkVerbosity } from '../SdkVerbosity';
|
|
10
|
+
import { TrackingConsent } from '../TrackingConsent';
|
|
11
|
+
|
|
12
|
+
describe('DdSdkReactNativeConfiguration', () => {
|
|
13
|
+
describe('buildConfigurationFromPartialConfiguration', () => {
|
|
14
|
+
it('builds the SDK configuration when minimal configuration is passed', () => {
|
|
15
|
+
expect(
|
|
16
|
+
buildConfigurationFromPartialConfiguration(
|
|
17
|
+
{
|
|
18
|
+
trackErrors: false,
|
|
19
|
+
trackInteractions: false,
|
|
20
|
+
trackResources: false
|
|
21
|
+
},
|
|
22
|
+
{
|
|
23
|
+
applicationId: 'fake-app-id',
|
|
24
|
+
clientToken: 'fake-client-token',
|
|
25
|
+
env: 'fake-env'
|
|
26
|
+
}
|
|
27
|
+
)
|
|
28
|
+
).toMatchInlineSnapshot(`
|
|
29
|
+
DdSdkReactNativeConfiguration {
|
|
30
|
+
"additionalConfig": Object {},
|
|
31
|
+
"applicationId": "fake-app-id",
|
|
32
|
+
"clientToken": "fake-client-token",
|
|
33
|
+
"env": "fake-env",
|
|
34
|
+
"firstPartyHosts": Array [],
|
|
35
|
+
"nativeCrashReportEnabled": false,
|
|
36
|
+
"nativeViewTracking": false,
|
|
37
|
+
"proxyConfig": undefined,
|
|
38
|
+
"resourceTracingSamplingRate": 20,
|
|
39
|
+
"serviceName": undefined,
|
|
40
|
+
"sessionSamplingRate": 100,
|
|
41
|
+
"site": "US1",
|
|
42
|
+
"telemetrySampleRate": 20,
|
|
43
|
+
"trackErrors": false,
|
|
44
|
+
"trackInteractions": false,
|
|
45
|
+
"trackResources": false,
|
|
46
|
+
"trackingConsent": "granted",
|
|
47
|
+
"verbosity": undefined,
|
|
48
|
+
}
|
|
49
|
+
`);
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
it('builds the SDK configuration when every configuration attibute is set', () => {
|
|
53
|
+
expect(
|
|
54
|
+
buildConfigurationFromPartialConfiguration(
|
|
55
|
+
{
|
|
56
|
+
trackErrors: true,
|
|
57
|
+
trackInteractions: true,
|
|
58
|
+
trackResources: true,
|
|
59
|
+
firstPartyHosts: ['api.com'],
|
|
60
|
+
resourceTracingSamplingRate: 100
|
|
61
|
+
},
|
|
62
|
+
{
|
|
63
|
+
applicationId: 'fake-app-id',
|
|
64
|
+
clientToken: 'fake-client-token',
|
|
65
|
+
env: 'fake-env',
|
|
66
|
+
sessionSamplingRate: 80,
|
|
67
|
+
site: 'EU',
|
|
68
|
+
verbosity: SdkVerbosity.DEBUG,
|
|
69
|
+
nativeViewTracking: true,
|
|
70
|
+
proxyConfig: new ProxyConfiguration(
|
|
71
|
+
ProxyType.HTTPS,
|
|
72
|
+
'api.com',
|
|
73
|
+
443
|
|
74
|
+
),
|
|
75
|
+
serviceName: 'com.test.app',
|
|
76
|
+
version: '1.4.5',
|
|
77
|
+
versionSuffix: 'codepush-3',
|
|
78
|
+
additionalConfig: { additionalField: 'fake-value' },
|
|
79
|
+
trackingConsent: TrackingConsent.PENDING,
|
|
80
|
+
nativeCrashReportEnabled: true
|
|
81
|
+
}
|
|
82
|
+
)
|
|
83
|
+
).toMatchInlineSnapshot(`
|
|
84
|
+
DdSdkReactNativeConfiguration {
|
|
85
|
+
"additionalConfig": Object {
|
|
86
|
+
"additionalField": "fake-value",
|
|
87
|
+
},
|
|
88
|
+
"applicationId": "fake-app-id",
|
|
89
|
+
"clientToken": "fake-client-token",
|
|
90
|
+
"env": "fake-env",
|
|
91
|
+
"firstPartyHosts": Array [
|
|
92
|
+
"api.com",
|
|
93
|
+
],
|
|
94
|
+
"nativeCrashReportEnabled": true,
|
|
95
|
+
"nativeViewTracking": true,
|
|
96
|
+
"proxyConfig": ProxyConfiguration {
|
|
97
|
+
"address": "api.com",
|
|
98
|
+
"password": undefined,
|
|
99
|
+
"port": 443,
|
|
100
|
+
"type": "https",
|
|
101
|
+
"username": undefined,
|
|
102
|
+
},
|
|
103
|
+
"resourceTracingSamplingRate": 100,
|
|
104
|
+
"serviceName": "com.test.app",
|
|
105
|
+
"sessionSamplingRate": 80,
|
|
106
|
+
"site": "EU",
|
|
107
|
+
"telemetrySampleRate": 20,
|
|
108
|
+
"trackErrors": true,
|
|
109
|
+
"trackInteractions": true,
|
|
110
|
+
"trackResources": true,
|
|
111
|
+
"trackingConsent": "pending",
|
|
112
|
+
"verbosity": "debug",
|
|
113
|
+
"version": "1.4.5",
|
|
114
|
+
"versionSuffix": "codepush-3",
|
|
115
|
+
}
|
|
116
|
+
`);
|
|
117
|
+
});
|
|
118
|
+
|
|
119
|
+
it('builds the SDK configuration when falsy values are passed', () => {
|
|
120
|
+
expect(
|
|
121
|
+
buildConfigurationFromPartialConfiguration(
|
|
122
|
+
{
|
|
123
|
+
trackErrors: false,
|
|
124
|
+
trackInteractions: false,
|
|
125
|
+
trackResources: false,
|
|
126
|
+
resourceTracingSamplingRate: 0
|
|
127
|
+
},
|
|
128
|
+
{
|
|
129
|
+
applicationId: '',
|
|
130
|
+
clientToken: '',
|
|
131
|
+
env: '',
|
|
132
|
+
sessionSamplingRate: 0,
|
|
133
|
+
site: '',
|
|
134
|
+
nativeViewTracking: false,
|
|
135
|
+
serviceName: '',
|
|
136
|
+
version: '',
|
|
137
|
+
versionSuffix: '',
|
|
138
|
+
additionalConfig: {},
|
|
139
|
+
nativeCrashReportEnabled: false
|
|
140
|
+
}
|
|
141
|
+
)
|
|
142
|
+
).toMatchInlineSnapshot(`
|
|
143
|
+
DdSdkReactNativeConfiguration {
|
|
144
|
+
"additionalConfig": Object {},
|
|
145
|
+
"applicationId": "",
|
|
146
|
+
"clientToken": "",
|
|
147
|
+
"env": "",
|
|
148
|
+
"firstPartyHosts": Array [],
|
|
149
|
+
"nativeCrashReportEnabled": false,
|
|
150
|
+
"nativeViewTracking": false,
|
|
151
|
+
"proxyConfig": undefined,
|
|
152
|
+
"resourceTracingSamplingRate": 0,
|
|
153
|
+
"serviceName": "",
|
|
154
|
+
"sessionSamplingRate": 0,
|
|
155
|
+
"site": "",
|
|
156
|
+
"telemetrySampleRate": 20,
|
|
157
|
+
"trackErrors": false,
|
|
158
|
+
"trackInteractions": false,
|
|
159
|
+
"trackResources": false,
|
|
160
|
+
"trackingConsent": "granted",
|
|
161
|
+
"verbosity": undefined,
|
|
162
|
+
"version": "",
|
|
163
|
+
"versionSuffix": "",
|
|
164
|
+
}
|
|
165
|
+
`);
|
|
166
|
+
});
|
|
167
|
+
});
|
|
168
|
+
});
|
|
@@ -6,7 +6,8 @@
|
|
|
6
6
|
|
|
7
7
|
import { NativeModules } from 'react-native';
|
|
8
8
|
|
|
9
|
-
import {
|
|
9
|
+
import { BufferSingleton } from '../DatadogProvider/Buffer/BufferSingleton';
|
|
10
|
+
import { DdRum, DdSdk } from '../foundation';
|
|
10
11
|
|
|
11
12
|
jest.mock('../TimeProvider', () => {
|
|
12
13
|
return {
|
|
@@ -20,6 +21,7 @@ describe('foundation', () => {
|
|
|
20
21
|
describe('DdRum.stopAction', () => {
|
|
21
22
|
beforeEach(() => {
|
|
22
23
|
jest.clearAllMocks();
|
|
24
|
+
BufferSingleton.onInitialization();
|
|
23
25
|
});
|
|
24
26
|
|
|
25
27
|
test('calls the native SDK when called with new API', async () => {
|
|
@@ -42,9 +44,10 @@ describe('foundation', () => {
|
|
|
42
44
|
);
|
|
43
45
|
});
|
|
44
46
|
|
|
45
|
-
test('does not call the native SDK when
|
|
47
|
+
test('does not call the native SDK when startAction has not been called before and using old API', async () => {
|
|
46
48
|
await DdRum.stopAction({ user: 'me' }, 789);
|
|
47
49
|
expect(NativeModules.DdRum.stopAction).not.toHaveBeenCalled();
|
|
50
|
+
expect(DdSdk.telemetryDebug).not.toHaveBeenCalled();
|
|
48
51
|
});
|
|
49
52
|
|
|
50
53
|
test('calls the native SDK when called with old API', async () => {
|
|
@@ -56,6 +59,9 @@ describe('foundation', () => {
|
|
|
56
59
|
{ user: 'me' },
|
|
57
60
|
789
|
|
58
61
|
);
|
|
62
|
+
expect(DdSdk.telemetryDebug).toHaveBeenCalledWith(
|
|
63
|
+
'DDdRum.stopAction called with the old signature'
|
|
64
|
+
);
|
|
59
65
|
});
|
|
60
66
|
|
|
61
67
|
test('calls the native SDK when called with old API with default values', async () => {
|
|
@@ -67,6 +73,9 @@ describe('foundation', () => {
|
|
|
67
73
|
{},
|
|
68
74
|
456
|
|
69
75
|
);
|
|
76
|
+
expect(DdSdk.telemetryDebug).toHaveBeenCalledWith(
|
|
77
|
+
'DDdRum.stopAction called with the old signature'
|
|
78
|
+
);
|
|
70
79
|
});
|
|
71
80
|
|
|
72
81
|
test('cleans the action data when stopAction is called', async () => {
|
|
@@ -17,6 +17,7 @@ import {
|
|
|
17
17
|
} from 'react-native';
|
|
18
18
|
import React from 'react';
|
|
19
19
|
|
|
20
|
+
import { DdSdk } from '../../../foundation';
|
|
20
21
|
import { DdEventsInterceptor } from '../../../rum/instrumentation/DdEventsInterceptor';
|
|
21
22
|
import { DdRumUserInteractionTracking } from '../../../rum/instrumentation/DdRumUserInteractionTracking';
|
|
22
23
|
|
|
@@ -39,6 +40,7 @@ let originalMethod: typeof React.createElement;
|
|
|
39
40
|
beforeEach(() => {
|
|
40
41
|
originalMethod = React.createElement;
|
|
41
42
|
jest.setTimeout(20000);
|
|
43
|
+
jest.clearAllMocks();
|
|
42
44
|
});
|
|
43
45
|
|
|
44
46
|
afterEach(() => {
|
|
@@ -342,16 +344,28 @@ it('M keep memoization working for elements W an onPress prop is passed and cust
|
|
|
342
344
|
});
|
|
343
345
|
|
|
344
346
|
describe('startTracking', () => {
|
|
345
|
-
|
|
347
|
+
/**
|
|
348
|
+
* WARNING: Because of caching in the require, the following 2 tests need
|
|
349
|
+
* to be run in this order
|
|
350
|
+
*/
|
|
351
|
+
it('does not crash if jsx-runtime does not contain jsx', () => {
|
|
346
352
|
expect(DdRumUserInteractionTracking['isTracking']).toBe(false);
|
|
347
|
-
jest.setMock('react/jsx-runtime',
|
|
353
|
+
jest.setMock('react/jsx-runtime', {});
|
|
354
|
+
|
|
348
355
|
DdRumUserInteractionTracking.startTracking();
|
|
349
356
|
expect(DdRumUserInteractionTracking['isTracking']).toBe(true);
|
|
357
|
+
expect(DdSdk.telemetryDebug).toBeCalledWith(
|
|
358
|
+
'React jsx runtime does not export new jsx transform'
|
|
359
|
+
);
|
|
350
360
|
});
|
|
351
|
-
it('does not crash if jsx-runtime
|
|
361
|
+
it('does not crash if jsx-runtime is not exported from react', () => {
|
|
352
362
|
expect(DdRumUserInteractionTracking['isTracking']).toBe(false);
|
|
353
|
-
jest.setMock('react/
|
|
363
|
+
jest.setMock('react/package.json', { version: '16.13.0' });
|
|
364
|
+
|
|
354
365
|
DdRumUserInteractionTracking.startTracking();
|
|
355
366
|
expect(DdRumUserInteractionTracking['isTracking']).toBe(true);
|
|
367
|
+
expect(DdSdk.telemetryDebug).toBeCalledWith(
|
|
368
|
+
'React version does not support new jsx transform'
|
|
369
|
+
);
|
|
356
370
|
});
|
|
357
371
|
});
|
|
@@ -0,0 +1,50 @@
|
|
|
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
|
+
export const EMPTY_MESSAGE = 'Unknown Error';
|
|
8
|
+
export const EMPTY_STACK_TRACE = '';
|
|
9
|
+
|
|
10
|
+
export const getErrorMessage = (error: any | undefined): string => {
|
|
11
|
+
let message = EMPTY_MESSAGE;
|
|
12
|
+
if (error === undefined || error === null) {
|
|
13
|
+
message = EMPTY_MESSAGE;
|
|
14
|
+
} else if (typeof error === 'object' && 'message' in error) {
|
|
15
|
+
message = String(error.message);
|
|
16
|
+
} else {
|
|
17
|
+
message = String(error);
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
return message;
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
export const getErrorStackTrace = (error: any | undefined): string => {
|
|
24
|
+
let stack = EMPTY_STACK_TRACE;
|
|
25
|
+
|
|
26
|
+
try {
|
|
27
|
+
if (error === undefined || error === null) {
|
|
28
|
+
stack = EMPTY_STACK_TRACE;
|
|
29
|
+
} else if (typeof error === 'string') {
|
|
30
|
+
stack = EMPTY_STACK_TRACE;
|
|
31
|
+
} else if (typeof error === 'object') {
|
|
32
|
+
if ('componentStack' in error) {
|
|
33
|
+
stack = String(error.componentStack);
|
|
34
|
+
} else if ('stacktrace' in error) {
|
|
35
|
+
stack = String(error.stacktrace);
|
|
36
|
+
} else if ('stack' in error) {
|
|
37
|
+
stack = String(error.stack);
|
|
38
|
+
} else if (
|
|
39
|
+
'sourceURL' in error &&
|
|
40
|
+
'line' in error &&
|
|
41
|
+
'column' in error
|
|
42
|
+
) {
|
|
43
|
+
stack = `at ${error.sourceURL}:${error.line}:${error.column}`;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
} catch (e) {
|
|
47
|
+
// Do nothing
|
|
48
|
+
}
|
|
49
|
+
return stack;
|
|
50
|
+
};
|
package/src/foundation.tsx
CHANGED
|
@@ -10,6 +10,7 @@ import {InternalLog} from "./InternalLog"
|
|
|
10
10
|
import {SdkVerbosity} from "./SdkVerbosity";
|
|
11
11
|
import {TimeProvider} from "./TimeProvider";
|
|
12
12
|
import type { DdNativeLogsType, DdNativeRumType, DdNativeSdkType, DdNativeTraceType } from './nativeModulesTypes';
|
|
13
|
+
import { bufferNativeCallReturningId, bufferNativeCallWithId, bufferVoidNativeCall } from './DatadogProvider/Buffer/bufferNativeCall';
|
|
13
14
|
|
|
14
15
|
const timeProvider = new TimeProvider();
|
|
15
16
|
|
|
@@ -44,14 +45,14 @@ class DdTraceWrapper implements DdTraceType {
|
|
|
44
45
|
private nativeTrace: DdNativeTraceType = NativeModules.DdTrace;
|
|
45
46
|
|
|
46
47
|
startSpan(operation: string, context: object = {}, timestampMs: number = timeProvider.now()): Promise<string> {
|
|
47
|
-
let spanId = this.nativeTrace.startSpan(operation, context, timestampMs);
|
|
48
|
+
let spanId = bufferNativeCallReturningId(() =>this.nativeTrace.startSpan(operation, context, timestampMs));
|
|
48
49
|
InternalLog.log("Starting span “" + operation + "” #" + spanId, SdkVerbosity.DEBUG);
|
|
49
50
|
return spanId
|
|
50
51
|
}
|
|
51
52
|
|
|
52
53
|
finishSpan(spanId: string, context: object = {}, timestampMs: number = timeProvider.now()): Promise<void> {
|
|
53
54
|
InternalLog.log("Finishing span #" + spanId, SdkVerbosity.DEBUG);
|
|
54
|
-
return this.nativeTrace.finishSpan(
|
|
55
|
+
return bufferNativeCallWithId((id) => this.nativeTrace.finishSpan(id, context, timestampMs), spanId);
|
|
55
56
|
}
|
|
56
57
|
}
|
|
57
58
|
|
|
@@ -70,18 +71,18 @@ class DdRumWrapper implements DdRumType {
|
|
|
70
71
|
|
|
71
72
|
startView(key: string, name: string, context: object = {}, timestampMs: number = timeProvider.now()): Promise<void> {
|
|
72
73
|
InternalLog.log("Starting RUM View “" + name + "” #" + key, SdkVerbosity.DEBUG);
|
|
73
|
-
return this.nativeRum.startView(key, name, context, timestampMs);
|
|
74
|
+
return bufferVoidNativeCall(() => this.nativeRum.startView(key, name, context, timestampMs));
|
|
74
75
|
}
|
|
75
76
|
|
|
76
77
|
stopView(key: string, context: object = {}, timestampMs: number = timeProvider.now()): Promise<void> {
|
|
77
78
|
InternalLog.log("Stopping RUM View #" + key, SdkVerbosity.DEBUG);
|
|
78
|
-
return this.nativeRum.stopView(key, context, timestampMs);
|
|
79
|
+
return bufferVoidNativeCall(() => this.nativeRum.stopView(key, context, timestampMs));
|
|
79
80
|
}
|
|
80
81
|
|
|
81
82
|
startAction(type: RumActionType, name: string, context: object = {}, timestampMs: number = timeProvider.now()): Promise<void> {
|
|
82
83
|
InternalLog.log("Starting RUM Action “" + name + "” (" + type + ")", SdkVerbosity.DEBUG);
|
|
83
84
|
this.lastActionData={type, name}
|
|
84
|
-
return this.nativeRum.startAction(type, name, context, timestampMs);
|
|
85
|
+
return bufferVoidNativeCall(() => this.nativeRum.startAction(type, name, context, timestampMs));
|
|
85
86
|
}
|
|
86
87
|
|
|
87
88
|
stopAction(...args: [type: RumActionType, name: string, context?: object, timestampMs?: number] | [context?: object, timestampMs?: number]): Promise<void> {
|
|
@@ -93,11 +94,13 @@ class DdRumWrapper implements DdRumType {
|
|
|
93
94
|
|
|
94
95
|
private getStopActionNativeCall = (args: [type: RumActionType, name: string, context?: object, timestampMs?: number] | [context?: object, timestampMs?: number]): Promise<void> => {
|
|
95
96
|
if (isNewStopActionAPI(args)) {
|
|
96
|
-
return this.nativeRum.stopAction(args[0], args[1], args[2] || {}, args[3] || timeProvider.now())
|
|
97
|
+
return bufferVoidNativeCall(() => this.nativeRum.stopAction(args[0], args[1], args[2] || {}, args[3] || timeProvider.now()))
|
|
97
98
|
}
|
|
98
99
|
if (isOldStopActionAPI(args)) {
|
|
99
100
|
if (this.lastActionData) {
|
|
100
|
-
|
|
101
|
+
DdSdk.telemetryDebug('DDdRum.stopAction called with the old signature')
|
|
102
|
+
const {type, name} = this.lastActionData;
|
|
103
|
+
return bufferVoidNativeCall(() => this.nativeRum.stopAction(type, name, args[0] || {}, args[1] || timeProvider.now()));
|
|
101
104
|
}
|
|
102
105
|
InternalLog.log("DdRum.startAction needs to be called before DdRum.stopAction", SdkVerbosity.WARN);
|
|
103
106
|
} else {
|
|
@@ -109,29 +112,29 @@ class DdRumWrapper implements DdRumType {
|
|
|
109
112
|
|
|
110
113
|
addAction(type: RumActionType, name: string, context: object = {}, timestampMs: number = timeProvider.now()): Promise<void> {
|
|
111
114
|
InternalLog.log("Adding RUM Action “" + name + "” (" + type + ")", SdkVerbosity.DEBUG);
|
|
112
|
-
return this.nativeRum.addAction(type, name, context, timestampMs);
|
|
115
|
+
return bufferVoidNativeCall(() => this.nativeRum.addAction(type, name, context, timestampMs));
|
|
113
116
|
}
|
|
114
117
|
|
|
115
118
|
startResource(key: string, method: string, url: string, context: object = {}, timestampMs: number = timeProvider.now()): Promise<void> {
|
|
116
119
|
InternalLog.log("Starting RUM Resource #" + key + " " + method + ": " + url, SdkVerbosity.DEBUG);
|
|
117
|
-
return this.nativeRum.startResource(key, method, url, context, timestampMs);
|
|
120
|
+
return bufferVoidNativeCall(() => this.nativeRum.startResource(key, method, url, context, timestampMs));
|
|
118
121
|
}
|
|
119
122
|
|
|
120
123
|
stopResource(key: string, statusCode: number, kind: ResourceKind, size: number = -1, context: object = {}, timestampMs: number = timeProvider.now()): Promise<void> {
|
|
121
124
|
InternalLog.log("Stopping RUM Resource #" + key + " status:" + statusCode, SdkVerbosity.DEBUG);
|
|
122
|
-
return this.nativeRum.stopResource(key, statusCode, kind, size, context, timestampMs);
|
|
125
|
+
return bufferVoidNativeCall(() => this.nativeRum.stopResource(key, statusCode, kind, size, context, timestampMs));
|
|
123
126
|
}
|
|
124
127
|
|
|
125
128
|
addError(message: string, source: ErrorSource, stacktrace: string, context: object = {}, timestampMs: number = timeProvider.now()): Promise<void> {
|
|
126
129
|
InternalLog.log("Adding RUM Error “" + message + "”", SdkVerbosity.DEBUG);
|
|
127
130
|
let updatedContext: any = context;
|
|
128
131
|
updatedContext["_dd.error.source_type"] = "react-native";
|
|
129
|
-
return this.nativeRum.addError(message, source, stacktrace, updatedContext, timestampMs);
|
|
132
|
+
return bufferVoidNativeCall(() => this.nativeRum.addError(message, source, stacktrace, updatedContext, timestampMs));
|
|
130
133
|
}
|
|
131
134
|
|
|
132
135
|
addTiming(name: string): Promise<void> {
|
|
133
136
|
InternalLog.log("Adding timing “" + name + "” to RUM View", SdkVerbosity.DEBUG);
|
|
134
|
-
return this.nativeRum.addTiming(name);
|
|
137
|
+
return bufferVoidNativeCall(() => this.nativeRum.addTiming(name));
|
|
135
138
|
}
|
|
136
139
|
}
|
|
137
140
|
|