@datadog/mobile-react-native 1.2.0-beta1 → 1.2.0
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/android/build.gradle +28 -3
- package/android/detekt.yml +572 -0
- package/android/src/main/kotlin/com/datadog/reactnative/DatadogSDKWrapper.kt +4 -0
- package/android/src/main/kotlin/com/datadog/reactnative/DatadogWrapper.kt +7 -2
- package/android/src/main/kotlin/com/datadog/reactnative/DdSdk.kt +118 -8
- package/android/src/main/kotlin/com/datadog/reactnative/DdSdkConfiguration.kt +23 -1
- package/android/src/main/kotlin/com/datadog/reactnative/DdSdkConfigurationExt.kt +29 -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 +377 -27
- package/android/src/test/kotlin/com/datadog/reactnative/DdTraceTest.kt +5 -1
- package/android/src/test/kotlin/com/datadog/tools/unit/DdSdkConfigurationExt.kt +33 -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 +21 -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.swift +99 -13
- package/ios/Sources/DdSdkConfiguration.swift +34 -1
- package/ios/Sources/JSRefreshRateListener.swift +86 -0
- package/ios/Sources/QueueHolder.swift +7 -0
- package/ios/Sources/RNDdSdkConfiguration.swift +23 -1
- package/lib/commonjs/DdSdkReactNative.js +24 -25
- package/lib/commonjs/DdSdkReactNative.js.map +1 -1
- package/lib/commonjs/DdSdkReactNativeConfiguration.js +66 -2
- package/lib/commonjs/DdSdkReactNativeConfiguration.js.map +1 -1
- package/lib/commonjs/errorUtils.js +12 -3
- package/lib/commonjs/errorUtils.js.map +1 -1
- package/lib/commonjs/longTasksUtils.js +40 -0
- package/lib/commonjs/longTasksUtils.js.map +1 -0
- package/lib/commonjs/rum/instrumentation/getJsxRuntime.js +11 -8
- 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 +5 -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/DdSdkReactNative.js +23 -24
- package/lib/module/DdSdkReactNative.js.map +1 -1
- package/lib/module/DdSdkReactNativeConfiguration.js +64 -1
- package/lib/module/DdSdkReactNativeConfiguration.js.map +1 -1
- package/lib/module/errorUtils.js +12 -3
- package/lib/module/errorUtils.js.map +1 -1
- package/lib/module/longTasksUtils.js +31 -0
- package/lib/module/longTasksUtils.js.map +1 -0
- package/lib/module/rum/instrumentation/getJsxRuntime.js +11 -8
- 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 +5 -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/DdSdkReactNative.d.ts +0 -7
- package/lib/typescript/DdSdkReactNativeConfiguration.d.ts +51 -0
- package/lib/typescript/errorUtils.d.ts +8 -0
- package/lib/typescript/longTasksUtils.d.ts +6 -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 +15 -1
- package/lib/typescript/version.d.ts +1 -1
- package/package.json +6 -3
- package/scripts/replace-react-require.js +78 -0
- package/src/DatadogProvider/__tests__/initialization.test.tsx +9 -1
- package/src/DdSdkReactNative.tsx +31 -34
- package/src/DdSdkReactNativeConfiguration.tsx +66 -1
- package/src/__tests__/DdSdkReactNative.test.tsx +56 -13
- package/src/__tests__/DdSdkReactNativeConfiguration.test.ts +15 -2
- package/src/__tests__/longTasksUtils.ts +23 -0
- package/src/errorUtils.ts +11 -3
- package/src/longTasksUtils.ts +30 -0
- package/src/rum/instrumentation/getJsxRuntime.ts +11 -11
- 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/__tests__/XHRProxy.test.ts +9 -47
- package/src/types.tsx +10 -1
- package/src/version.ts +1 -1
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
/*
|
|
4
|
+
* Unless explicitly stated otherwise all files in this repository are licensed under the Apache License Version 2.0.
|
|
5
|
+
* This product includes software developed at Datadog (https://www.datadoghq.com/).
|
|
6
|
+
* Copyright 2016-Present Datadog, Inc.
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* This script replaces the inline require of 'react' in src/rum/instrumentation/getJsxRuntime.ts
|
|
11
|
+
* to 'react/jsx-runtime'.
|
|
12
|
+
*
|
|
13
|
+
* Context:
|
|
14
|
+
* From its version 16.14, React adds the `jsx` function as a new way to create components. This replaces
|
|
15
|
+
* the createElement function (which is still used in current versions in some cases).
|
|
16
|
+
* From React 18, this seems to become the default. This is also used by default in Expo since Expo 45 at least.
|
|
17
|
+
* On React versions below 16.14, trying to import 'react/jsx-runtime' would fail (see https://github.com/facebook/metro/issues/836)
|
|
18
|
+
* and this failure then disables all imports (see first fix: https://github.com/DataDog/dd-sdk-reactnative/pull/310).
|
|
19
|
+
* However, metro does not support inline requires (see https://github.com/DataDog/dd-sdk-reactnative/issues/353), so
|
|
20
|
+
* we replace the import in this postinstall script.
|
|
21
|
+
*
|
|
22
|
+
* We choose to have 'react/jsx-runtime' as default in the code, that way we don't have to deal with this change in the source when we work on it.
|
|
23
|
+
*/
|
|
24
|
+
|
|
25
|
+
// We can only use requires in node
|
|
26
|
+
// eslint-disable-next-line global-require, @typescript-eslint/no-var-requires
|
|
27
|
+
const { readFileSync, writeFileSync } = require('fs');
|
|
28
|
+
|
|
29
|
+
process.stdout.write('[datadog] postinstall replace-react-require starts\n');
|
|
30
|
+
|
|
31
|
+
const GET_JSX_RUNTIME_RELATIVE_PATH = 'rum/instrumentation/getJsxRuntime';
|
|
32
|
+
|
|
33
|
+
const isJsxExportedInReactVersion = (major, minor) => {
|
|
34
|
+
if (Number(major) > 16) {
|
|
35
|
+
return true;
|
|
36
|
+
}
|
|
37
|
+
if (Number(major) === 16 && Number(minor) > 13) {
|
|
38
|
+
return true;
|
|
39
|
+
}
|
|
40
|
+
return false;
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
const replaceReactJsxRequire = () => {
|
|
44
|
+
process.stdout.write('[datadog] replacing react/jsx-runtime by react\n');
|
|
45
|
+
const datadogPath = `${__dirname}/..`;
|
|
46
|
+
const locations = [
|
|
47
|
+
{ directory: `${datadogPath}/src`, extension: 'ts' },
|
|
48
|
+
{ directory: `${datadogPath}/lib/commonjs`, extension: 'js' },
|
|
49
|
+
{ directory: `${datadogPath}/lib/commonjs`, extension: 'js.map' },
|
|
50
|
+
{ directory: `${datadogPath}/lib/module`, extension: 'js' },
|
|
51
|
+
{ directory: `${datadogPath}/lib/module`, extension: 'js.map' }
|
|
52
|
+
];
|
|
53
|
+
|
|
54
|
+
locations.forEach(location => {
|
|
55
|
+
const fileLocation = `${location.directory}/${GET_JSX_RUNTIME_RELATIVE_PATH}.${location.extension}`;
|
|
56
|
+
const file = readFileSync(fileLocation).toString();
|
|
57
|
+
writeFileSync(
|
|
58
|
+
fileLocation,
|
|
59
|
+
file.replace("require('react/jsx-runtime')", "require('react')")
|
|
60
|
+
);
|
|
61
|
+
});
|
|
62
|
+
};
|
|
63
|
+
|
|
64
|
+
try {
|
|
65
|
+
// Get React version
|
|
66
|
+
// eslint-disable-next-line global-require, @typescript-eslint/no-var-requires
|
|
67
|
+
const [major, minor] = require('react/package.json').version.split('.');
|
|
68
|
+
process.stdout.write(`[datadog] found react version ${major}${minor}\n`);
|
|
69
|
+
|
|
70
|
+
if (!isJsxExportedInReactVersion(major, minor)) {
|
|
71
|
+
replaceReactJsxRequire();
|
|
72
|
+
}
|
|
73
|
+
process.stdout.write('[datadog] postinstall replace-react-require end\n');
|
|
74
|
+
} catch (error) {
|
|
75
|
+
process.stderr.write(
|
|
76
|
+
`[datadog] Error running replace-react-require: ${error}\n`
|
|
77
|
+
);
|
|
78
|
+
}
|
|
@@ -60,18 +60,26 @@ describe('DatadogProvider', () => {
|
|
|
60
60
|
DdSdkConfiguration {
|
|
61
61
|
"additionalConfig": Object {
|
|
62
62
|
"_dd.first_party_hosts": Array [],
|
|
63
|
-
"_dd.long_task.threshold": 200,
|
|
64
63
|
"_dd.native_view_tracking": false,
|
|
65
64
|
"_dd.source": "react-native",
|
|
66
65
|
},
|
|
67
66
|
"applicationId": "fakeApplicationId",
|
|
68
67
|
"clientToken": "fakeToken",
|
|
68
|
+
"configurationForTelemetry": Object {
|
|
69
|
+
"initializationType": "SYNC",
|
|
70
|
+
"trackErrors": true,
|
|
71
|
+
"trackInteractions": true,
|
|
72
|
+
"trackNetworkRequests": false,
|
|
73
|
+
},
|
|
69
74
|
"env": "fakeEnv",
|
|
75
|
+
"longTaskThresholdMs": 0,
|
|
70
76
|
"nativeCrashReportEnabled": false,
|
|
77
|
+
"nativeLongTaskThresholdMs": 200,
|
|
71
78
|
"sampleRate": 100,
|
|
72
79
|
"site": "US1",
|
|
73
80
|
"telemetrySampleRate": 20,
|
|
74
81
|
"trackingConsent": "granted",
|
|
82
|
+
"vitalsUpdateFrequency": "AVERAGE",
|
|
75
83
|
}
|
|
76
84
|
`);
|
|
77
85
|
|
package/src/DdSdkReactNative.tsx
CHANGED
|
@@ -17,13 +17,15 @@ import type {
|
|
|
17
17
|
AutoInstrumentationParameters,
|
|
18
18
|
DatadogProviderConfiguration,
|
|
19
19
|
PartialInitializationConfiguration,
|
|
20
|
-
AutoInstrumentationConfiguration
|
|
20
|
+
AutoInstrumentationConfiguration,
|
|
21
|
+
InitializationModeForTelemetry
|
|
21
22
|
} from './DdSdkReactNativeConfiguration';
|
|
22
23
|
import { InternalLog } from './InternalLog';
|
|
23
24
|
import { ProxyType } from './ProxyConfiguration';
|
|
24
25
|
import { SdkVerbosity } from './SdkVerbosity';
|
|
25
26
|
import type { TrackingConsent } from './TrackingConsent';
|
|
26
27
|
import { DdSdk } from './foundation';
|
|
28
|
+
import { adaptLongTaskThreshold } from './longTasksUtils';
|
|
27
29
|
import { DdRumErrorTracking } from './rum/instrumentation/DdRumErrorTracking';
|
|
28
30
|
import { DdRumUserInteractionTracking } from './rum/instrumentation/DdRumUserInteractionTracking';
|
|
29
31
|
import { DdRumResourceTracking } from './rum/instrumentation/resourceTracking/DdRumResourceTracking';
|
|
@@ -50,13 +52,8 @@ export class DdSdkReactNative {
|
|
|
50
52
|
private static readonly DD_PROXY_USERNAME_KEY = '_dd.proxy.username';
|
|
51
53
|
private static readonly DD_PROXY_PASSWORD_KEY = '_dd.proxy.password';
|
|
52
54
|
|
|
53
|
-
private static readonly DD_NATIVE_LONG_TASK_THRESHOLD_KEY =
|
|
54
|
-
'_dd.long_task.threshold';
|
|
55
|
-
private static readonly NATIVE_LONG_TASK_THRESHOLD_MS = 200;
|
|
56
|
-
|
|
57
55
|
private static wasInitialized = false;
|
|
58
56
|
private static wasAutoInstrumented = false;
|
|
59
|
-
private static configuration?: DdSdkReactNativeConfiguration;
|
|
60
57
|
private static features?: AutoInstrumentationConfiguration;
|
|
61
58
|
|
|
62
59
|
/**
|
|
@@ -67,12 +64,17 @@ export class DdSdkReactNative {
|
|
|
67
64
|
static async initialize(
|
|
68
65
|
configuration: DdSdkReactNativeConfiguration
|
|
69
66
|
): Promise<void> {
|
|
70
|
-
await DdSdkReactNative.initializeNativeSDK(configuration
|
|
67
|
+
await DdSdkReactNative.initializeNativeSDK(configuration, {
|
|
68
|
+
initializationModeForTelemetry: 'LEGACY'
|
|
69
|
+
});
|
|
71
70
|
DdSdkReactNative.enableFeatures(configuration);
|
|
72
71
|
}
|
|
73
72
|
|
|
74
73
|
private static initializeNativeSDK = async (
|
|
75
|
-
configuration: DdSdkReactNativeConfiguration
|
|
74
|
+
configuration: DdSdkReactNativeConfiguration,
|
|
75
|
+
params: {
|
|
76
|
+
initializationModeForTelemetry: InitializationModeForTelemetry;
|
|
77
|
+
}
|
|
76
78
|
): Promise<void> => {
|
|
77
79
|
if (DdSdkReactNative.wasInitialized) {
|
|
78
80
|
InternalLog.log(
|
|
@@ -97,13 +99,22 @@ export class DdSdkReactNative {
|
|
|
97
99
|
configuration.env,
|
|
98
100
|
configuration.applicationId,
|
|
99
101
|
configuration.nativeCrashReportEnabled,
|
|
102
|
+
adaptLongTaskThreshold(configuration.nativeLongTaskThresholdMs),
|
|
103
|
+
adaptLongTaskThreshold(configuration.longTaskThresholdMs),
|
|
100
104
|
configuration.sampleRate === undefined
|
|
101
105
|
? configuration.sessionSamplingRate
|
|
102
106
|
: configuration.sampleRate,
|
|
103
107
|
configuration.site,
|
|
104
108
|
configuration.trackingConsent,
|
|
105
109
|
configuration.additionalConfig,
|
|
106
|
-
configuration.telemetrySampleRate
|
|
110
|
+
configuration.telemetrySampleRate,
|
|
111
|
+
configuration.vitalsUpdateFrequency,
|
|
112
|
+
{
|
|
113
|
+
initializationType: params.initializationModeForTelemetry,
|
|
114
|
+
trackErrors: configuration.trackErrors,
|
|
115
|
+
trackInteractions: configuration.trackInteractions,
|
|
116
|
+
trackNetworkRequests: configuration.trackResources
|
|
117
|
+
}
|
|
107
118
|
)
|
|
108
119
|
);
|
|
109
120
|
InternalLog.log('Datadog SDK was initialized', SdkVerbosity.INFO);
|
|
@@ -118,18 +129,23 @@ export class DdSdkReactNative {
|
|
|
118
129
|
configuration: DatadogProviderConfiguration
|
|
119
130
|
): Promise<void> {
|
|
120
131
|
DdSdkReactNative.enableFeatures(configuration);
|
|
121
|
-
DdSdkReactNative.configuration = configuration;
|
|
122
132
|
if (configuration.initializationMode === InitializationMode.SYNC) {
|
|
123
|
-
return DdSdkReactNative.initializeNativeSDK(configuration
|
|
133
|
+
return DdSdkReactNative.initializeNativeSDK(configuration, {
|
|
134
|
+
initializationModeForTelemetry: 'SYNC'
|
|
135
|
+
});
|
|
124
136
|
}
|
|
125
137
|
if (configuration.initializationMode === InitializationMode.ASYNC) {
|
|
126
138
|
return InteractionManager.runAfterInteractions(() => {
|
|
127
|
-
return DdSdkReactNative.initializeNativeSDK(configuration
|
|
139
|
+
return DdSdkReactNative.initializeNativeSDK(configuration, {
|
|
140
|
+
initializationModeForTelemetry: 'ASYNC'
|
|
141
|
+
});
|
|
128
142
|
});
|
|
129
143
|
}
|
|
130
144
|
// TODO: Remove when DdSdkReactNativeConfiguration is deprecated
|
|
131
145
|
if (configuration instanceof DdSdkReactNativeConfiguration) {
|
|
132
|
-
return DdSdkReactNative.initializeNativeSDK(configuration
|
|
146
|
+
return DdSdkReactNative.initializeNativeSDK(configuration, {
|
|
147
|
+
initializationModeForTelemetry: 'SYNC'
|
|
148
|
+
});
|
|
133
149
|
}
|
|
134
150
|
}
|
|
135
151
|
|
|
@@ -145,22 +161,6 @@ export class DdSdkReactNative {
|
|
|
145
161
|
);
|
|
146
162
|
}
|
|
147
163
|
|
|
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
|
-
};
|
|
163
|
-
|
|
164
164
|
/**
|
|
165
165
|
* FOR INTERNAL USE ONLY.
|
|
166
166
|
*/
|
|
@@ -179,7 +179,8 @@ export class DdSdkReactNative {
|
|
|
179
179
|
buildConfigurationFromPartialConfiguration(
|
|
180
180
|
DdSdkReactNative.features,
|
|
181
181
|
configuration
|
|
182
|
-
)
|
|
182
|
+
),
|
|
183
|
+
{ initializationModeForTelemetry: 'PARTIAL' }
|
|
183
184
|
);
|
|
184
185
|
};
|
|
185
186
|
|
|
@@ -285,10 +286,6 @@ export class DdSdkReactNative {
|
|
|
285
286
|
] = `-${configuration.versionSuffix}`;
|
|
286
287
|
}
|
|
287
288
|
|
|
288
|
-
configuration.additionalConfig[
|
|
289
|
-
DdSdkReactNative.DD_NATIVE_LONG_TASK_THRESHOLD_KEY
|
|
290
|
-
] = DdSdkReactNative.NATIVE_LONG_TASK_THRESHOLD_MS;
|
|
291
|
-
|
|
292
289
|
configuration.additionalConfig['_dd.first_party_hosts'] =
|
|
293
290
|
configuration.firstPartyHosts;
|
|
294
291
|
};
|
|
@@ -8,16 +8,26 @@ import type { ProxyConfiguration } from './ProxyConfiguration';
|
|
|
8
8
|
import type { SdkVerbosity } from './SdkVerbosity';
|
|
9
9
|
import { TrackingConsent } from './TrackingConsent';
|
|
10
10
|
|
|
11
|
+
export enum VitalsUpdateFrequency {
|
|
12
|
+
FREQUENT = 'FREQUENT',
|
|
13
|
+
AVERAGE = 'AVERAGE',
|
|
14
|
+
RARE = 'RARE',
|
|
15
|
+
NEVER = 'NEVER'
|
|
16
|
+
}
|
|
17
|
+
|
|
11
18
|
const DEFAULTS = {
|
|
12
19
|
nativeCrashReportEnabled: false,
|
|
13
20
|
sessionSamplingRate: 100.0,
|
|
14
21
|
resourceTracingSamplingRate: 20.0,
|
|
15
22
|
site: 'US1',
|
|
23
|
+
longTaskThresholdMs: 0,
|
|
24
|
+
nativeLongTaskThresholdMs: 200,
|
|
16
25
|
nativeViewTracking: false,
|
|
17
26
|
getFirstPartyHosts: () => [],
|
|
18
27
|
getAdditionalConfig: () => ({}),
|
|
19
28
|
trackingConsent: TrackingConsent.GRANTED,
|
|
20
|
-
telemetrySampleRate: 20.0
|
|
29
|
+
telemetrySampleRate: 20.0,
|
|
30
|
+
vitalsUpdateFrequency: VitalsUpdateFrequency.AVERAGE
|
|
21
31
|
};
|
|
22
32
|
|
|
23
33
|
/**
|
|
@@ -25,6 +35,9 @@ const DEFAULTS = {
|
|
|
25
35
|
* It will be used to configure the SDK functionality at initialization.
|
|
26
36
|
*/
|
|
27
37
|
export class DdSdkReactNativeConfiguration {
|
|
38
|
+
/**
|
|
39
|
+
* Enables crash reporting for native plaforms (iOS, Android). Default `false`.
|
|
40
|
+
*/
|
|
28
41
|
public nativeCrashReportEnabled: boolean =
|
|
29
42
|
DEFAULTS.nativeCrashReportEnabled;
|
|
30
43
|
/**
|
|
@@ -41,10 +54,24 @@ export class DdSdkReactNativeConfiguration {
|
|
|
41
54
|
public resourceTracingSamplingRate: number =
|
|
42
55
|
DEFAULTS.resourceTracingSamplingRate;
|
|
43
56
|
public site: string = DEFAULTS.site;
|
|
57
|
+
/**
|
|
58
|
+
* Verbosity for internal SDK logging.
|
|
59
|
+
* Set to `SdkVerbosity.DEBUG` to debug your SDK implementation.
|
|
60
|
+
*/
|
|
44
61
|
public verbosity: SdkVerbosity | undefined = undefined;
|
|
62
|
+
/**
|
|
63
|
+
* Enables native views tracking.
|
|
64
|
+
* Set to `true` if you use a custom navigation system relying on native views.
|
|
65
|
+
*/
|
|
45
66
|
public nativeViewTracking: boolean = DEFAULTS.nativeViewTracking;
|
|
46
67
|
public proxyConfig?: ProxyConfiguration = undefined;
|
|
47
68
|
public serviceName?: string = undefined;
|
|
69
|
+
/**
|
|
70
|
+
* List of your backends hosts to enable tracing with.
|
|
71
|
+
* Regular expressions are NOT supported.
|
|
72
|
+
*
|
|
73
|
+
* Matches domains and subdomains, e.g. `['example.com']` matches `example.com` and `api.example.com`.
|
|
74
|
+
*/
|
|
48
75
|
public firstPartyHosts: string[] = DEFAULTS.getFirstPartyHosts();
|
|
49
76
|
/**
|
|
50
77
|
* Overrides the reported version of the app.
|
|
@@ -78,6 +105,35 @@ export class DdSdkReactNativeConfiguration {
|
|
|
78
105
|
*/
|
|
79
106
|
public telemetrySampleRate: number = DEFAULTS.telemetrySampleRate;
|
|
80
107
|
|
|
108
|
+
/**
|
|
109
|
+
* The threshold for native long tasks reporting in milliseconds.
|
|
110
|
+
*
|
|
111
|
+
* - Setting it to `0` or `false` disables native long task reporting.
|
|
112
|
+
* - Values below `100` will be raised to `100`.
|
|
113
|
+
* - Values above `5000` will be lowered to `5000`.
|
|
114
|
+
*
|
|
115
|
+
* Default value is `200`.
|
|
116
|
+
*/
|
|
117
|
+
public nativeLongTaskThresholdMs: number | false =
|
|
118
|
+
DEFAULTS.nativeLongTaskThresholdMs;
|
|
119
|
+
|
|
120
|
+
/**
|
|
121
|
+
* The threshold for javascript long tasks reporting in milliseconds.
|
|
122
|
+
*
|
|
123
|
+
* - Setting it to `0` or `false` disables javascript long task reporting.
|
|
124
|
+
* - Values below `100` will be raised to `100`.
|
|
125
|
+
* - Values above `5000` will be lowered to `5000`.
|
|
126
|
+
*
|
|
127
|
+
* Default value is `0`
|
|
128
|
+
*/
|
|
129
|
+
public longTaskThresholdMs: number | false = DEFAULTS.longTaskThresholdMs;
|
|
130
|
+
|
|
131
|
+
/**
|
|
132
|
+
* Sets the preferred frequency for collecting mobile vitals.
|
|
133
|
+
*/
|
|
134
|
+
public vitalsUpdateFrequency: VitalsUpdateFrequency =
|
|
135
|
+
DEFAULTS.vitalsUpdateFrequency;
|
|
136
|
+
|
|
81
137
|
public additionalConfig: {
|
|
82
138
|
[k: string]: any;
|
|
83
139
|
} = DEFAULTS.getAdditionalConfig();
|
|
@@ -147,8 +203,11 @@ export type PartialInitializationConfiguration = {
|
|
|
147
203
|
versionSuffix?: string;
|
|
148
204
|
readonly additionalConfig?: { [k: string]: any };
|
|
149
205
|
readonly trackingConsent?: TrackingConsent;
|
|
206
|
+
readonly longTaskThresholdMs?: number | false;
|
|
207
|
+
readonly nativeLongTaskThresholdMs?: number | false;
|
|
150
208
|
readonly nativeCrashReportEnabled?: boolean;
|
|
151
209
|
readonly telemetrySampleRate?: number;
|
|
210
|
+
readonly vitalsUpdateFrequency?: VitalsUpdateFrequency;
|
|
152
211
|
};
|
|
153
212
|
|
|
154
213
|
const setConfigurationAttribute = <
|
|
@@ -217,3 +276,9 @@ export enum InitializationMode {
|
|
|
217
276
|
SYNC = 'SYNC',
|
|
218
277
|
ASYNC = 'ASYNC'
|
|
219
278
|
}
|
|
279
|
+
|
|
280
|
+
export type InitializationModeForTelemetry =
|
|
281
|
+
| 'LEGACY'
|
|
282
|
+
| 'SYNC'
|
|
283
|
+
| 'ASYNC'
|
|
284
|
+
| 'PARTIAL';
|
|
@@ -98,7 +98,6 @@ describe('DdSdkReactNative', () => {
|
|
|
98
98
|
'_dd.source': 'react-native',
|
|
99
99
|
'_dd.sdk_version': sdkVersion,
|
|
100
100
|
'_dd.native_view_tracking': false,
|
|
101
|
-
'_dd.long_task.threshold': 200,
|
|
102
101
|
'_dd.first_party_hosts': []
|
|
103
102
|
});
|
|
104
103
|
});
|
|
@@ -135,7 +134,6 @@ describe('DdSdkReactNative', () => {
|
|
|
135
134
|
'_dd.source': 'react-native',
|
|
136
135
|
'_dd.sdk_version': sdkVersion,
|
|
137
136
|
'_dd.native_view_tracking': false,
|
|
138
|
-
'_dd.long_task.threshold': 200,
|
|
139
137
|
'_dd.first_party_hosts': []
|
|
140
138
|
});
|
|
141
139
|
|
|
@@ -180,7 +178,6 @@ describe('DdSdkReactNative', () => {
|
|
|
180
178
|
'_dd.source': 'react-native',
|
|
181
179
|
'_dd.sdk_version': sdkVersion,
|
|
182
180
|
'_dd.native_view_tracking': false,
|
|
183
|
-
'_dd.long_task.threshold': 200,
|
|
184
181
|
'_dd.first_party_hosts': []
|
|
185
182
|
});
|
|
186
183
|
});
|
|
@@ -215,7 +212,6 @@ describe('DdSdkReactNative', () => {
|
|
|
215
212
|
'_dd.source': 'react-native',
|
|
216
213
|
'_dd.sdk_version': sdkVersion,
|
|
217
214
|
'_dd.native_view_tracking': false,
|
|
218
|
-
'_dd.long_task.threshold': 200,
|
|
219
215
|
'_dd.first_party_hosts': []
|
|
220
216
|
});
|
|
221
217
|
});
|
|
@@ -272,7 +268,6 @@ describe('DdSdkReactNative', () => {
|
|
|
272
268
|
'_dd.proxy.type': proxyType,
|
|
273
269
|
'_dd.proxy.address': proxyAddress,
|
|
274
270
|
'_dd.proxy.port': proxyPort,
|
|
275
|
-
'_dd.long_task.threshold': 200,
|
|
276
271
|
'_dd.first_party_hosts': []
|
|
277
272
|
});
|
|
278
273
|
expect(spyConsoleWarn).toHaveBeenCalledTimes(1);
|
|
@@ -455,7 +450,6 @@ describe('DdSdkReactNative', () => {
|
|
|
455
450
|
'_dd.source': 'react-native',
|
|
456
451
|
'_dd.sdk_version': sdkVersion,
|
|
457
452
|
'_dd.native_view_tracking': false,
|
|
458
|
-
'_dd.long_task.threshold': 200,
|
|
459
453
|
'_dd.first_party_hosts': []
|
|
460
454
|
});
|
|
461
455
|
expect(
|
|
@@ -494,7 +488,6 @@ describe('DdSdkReactNative', () => {
|
|
|
494
488
|
'_dd.source': 'react-native',
|
|
495
489
|
'_dd.sdk_version': sdkVersion,
|
|
496
490
|
'_dd.native_view_tracking': false,
|
|
497
|
-
'_dd.long_task.threshold': 200,
|
|
498
491
|
'_dd.first_party_hosts': ['api.example.com']
|
|
499
492
|
});
|
|
500
493
|
expect(DdRumResourceTracking.startTracking).toHaveBeenCalledTimes(
|
|
@@ -537,7 +530,6 @@ describe('DdSdkReactNative', () => {
|
|
|
537
530
|
'_dd.source': 'react-native',
|
|
538
531
|
'_dd.sdk_version': sdkVersion,
|
|
539
532
|
'_dd.native_view_tracking': false,
|
|
540
|
-
'_dd.long_task.threshold': 200,
|
|
541
533
|
'_dd.first_party_hosts': []
|
|
542
534
|
});
|
|
543
535
|
expect(DdRumErrorTracking.startTracking).toHaveBeenCalledTimes(1);
|
|
@@ -576,7 +568,6 @@ describe('DdSdkReactNative', () => {
|
|
|
576
568
|
'_dd.sdk_version': sdkVersion,
|
|
577
569
|
'_dd.service_name': fakeServiceName,
|
|
578
570
|
'_dd.native_view_tracking': false,
|
|
579
|
-
'_dd.long_task.threshold': 200,
|
|
580
571
|
'_dd.first_party_hosts': []
|
|
581
572
|
});
|
|
582
573
|
expect(DdRumErrorTracking.startTracking).toHaveBeenCalledTimes(1);
|
|
@@ -614,7 +605,6 @@ describe('DdSdkReactNative', () => {
|
|
|
614
605
|
'_dd.sdk_version': sdkVersion,
|
|
615
606
|
'_dd.sdk_verbosity': SdkVerbosity.DEBUG,
|
|
616
607
|
'_dd.native_view_tracking': false,
|
|
617
|
-
'_dd.long_task.threshold': 200,
|
|
618
608
|
'_dd.first_party_hosts': []
|
|
619
609
|
});
|
|
620
610
|
expect(DdRumErrorTracking.startTracking).toHaveBeenCalledTimes(1);
|
|
@@ -651,11 +641,66 @@ describe('DdSdkReactNative', () => {
|
|
|
651
641
|
'_dd.source': 'react-native',
|
|
652
642
|
'_dd.sdk_version': sdkVersion,
|
|
653
643
|
'_dd.native_view_tracking': true,
|
|
654
|
-
'_dd.long_task.threshold': 200,
|
|
655
644
|
'_dd.first_party_hosts': []
|
|
656
645
|
});
|
|
657
646
|
expect(DdRumErrorTracking.startTracking).toHaveBeenCalledTimes(1);
|
|
658
647
|
});
|
|
648
|
+
|
|
649
|
+
it('enables long task tracking when initialize { native and javascript long task custom threshold }', async () => {
|
|
650
|
+
// GIVEN
|
|
651
|
+
const fakeAppId = '1';
|
|
652
|
+
const fakeClientToken = '2';
|
|
653
|
+
const fakeEnvName = 'env';
|
|
654
|
+
const configuration = new DdSdkReactNativeConfiguration(
|
|
655
|
+
fakeClientToken,
|
|
656
|
+
fakeEnvName,
|
|
657
|
+
fakeAppId,
|
|
658
|
+
false,
|
|
659
|
+
false,
|
|
660
|
+
true
|
|
661
|
+
);
|
|
662
|
+
configuration.nativeLongTaskThresholdMs = 234;
|
|
663
|
+
configuration.longTaskThresholdMs = 456;
|
|
664
|
+
|
|
665
|
+
NativeModules.DdSdk.initialize.mockResolvedValue(null);
|
|
666
|
+
|
|
667
|
+
// WHEN
|
|
668
|
+
await DdSdkReactNative.initialize(configuration);
|
|
669
|
+
|
|
670
|
+
// THEN
|
|
671
|
+
const ddSdkConfiguration = NativeModules.DdSdk.initialize.mock
|
|
672
|
+
.calls[0][0] as DdSdkConfiguration;
|
|
673
|
+
expect(ddSdkConfiguration.nativeLongTaskThresholdMs).toBe(234);
|
|
674
|
+
expect(ddSdkConfiguration.longTaskThresholdMs).toBe(456);
|
|
675
|
+
});
|
|
676
|
+
|
|
677
|
+
it('enables long task tracking when initialize { native and javascript long task false threshold }', async () => {
|
|
678
|
+
// GIVEN
|
|
679
|
+
const fakeAppId = '1';
|
|
680
|
+
const fakeClientToken = '2';
|
|
681
|
+
const fakeEnvName = 'env';
|
|
682
|
+
const configuration = new DdSdkReactNativeConfiguration(
|
|
683
|
+
fakeClientToken,
|
|
684
|
+
fakeEnvName,
|
|
685
|
+
fakeAppId,
|
|
686
|
+
false,
|
|
687
|
+
false,
|
|
688
|
+
true
|
|
689
|
+
);
|
|
690
|
+
configuration.nativeLongTaskThresholdMs = false;
|
|
691
|
+
configuration.longTaskThresholdMs = false;
|
|
692
|
+
|
|
693
|
+
NativeModules.DdSdk.initialize.mockResolvedValue(null);
|
|
694
|
+
|
|
695
|
+
// WHEN
|
|
696
|
+
await DdSdkReactNative.initialize(configuration);
|
|
697
|
+
|
|
698
|
+
// THEN
|
|
699
|
+
const ddSdkConfiguration = NativeModules.DdSdk.initialize.mock
|
|
700
|
+
.calls[0][0] as DdSdkConfiguration;
|
|
701
|
+
expect(ddSdkConfiguration.nativeLongTaskThresholdMs).toBe(0);
|
|
702
|
+
expect(ddSdkConfiguration.longTaskThresholdMs).toBe(0);
|
|
703
|
+
});
|
|
659
704
|
});
|
|
660
705
|
|
|
661
706
|
describe('setAttributes', () => {
|
|
@@ -750,7 +795,6 @@ describe('DdSdkReactNative', () => {
|
|
|
750
795
|
'_dd.proxy.type': proxyType,
|
|
751
796
|
'_dd.proxy.address': proxyAddress,
|
|
752
797
|
'_dd.proxy.port': proxyPort,
|
|
753
|
-
'_dd.long_task.threshold': 200,
|
|
754
798
|
'_dd.first_party_hosts': []
|
|
755
799
|
});
|
|
756
800
|
});
|
|
@@ -811,7 +855,6 @@ describe('DdSdkReactNative', () => {
|
|
|
811
855
|
'_dd.proxy.port': proxyPort,
|
|
812
856
|
'_dd.proxy.username': proxyUsername,
|
|
813
857
|
'_dd.proxy.password': proxyPassword,
|
|
814
|
-
'_dd.long_task.threshold': 200,
|
|
815
858
|
'_dd.first_party_hosts': []
|
|
816
859
|
});
|
|
817
860
|
});
|
|
@@ -32,7 +32,9 @@ describe('DdSdkReactNativeConfiguration', () => {
|
|
|
32
32
|
"clientToken": "fake-client-token",
|
|
33
33
|
"env": "fake-env",
|
|
34
34
|
"firstPartyHosts": Array [],
|
|
35
|
+
"longTaskThresholdMs": 0,
|
|
35
36
|
"nativeCrashReportEnabled": false,
|
|
37
|
+
"nativeLongTaskThresholdMs": 200,
|
|
36
38
|
"nativeViewTracking": false,
|
|
37
39
|
"proxyConfig": undefined,
|
|
38
40
|
"resourceTracingSamplingRate": 20,
|
|
@@ -45,6 +47,7 @@ describe('DdSdkReactNativeConfiguration', () => {
|
|
|
45
47
|
"trackResources": false,
|
|
46
48
|
"trackingConsent": "granted",
|
|
47
49
|
"verbosity": undefined,
|
|
50
|
+
"vitalsUpdateFrequency": "AVERAGE",
|
|
48
51
|
}
|
|
49
52
|
`);
|
|
50
53
|
});
|
|
@@ -77,7 +80,9 @@ describe('DdSdkReactNativeConfiguration', () => {
|
|
|
77
80
|
versionSuffix: 'codepush-3',
|
|
78
81
|
additionalConfig: { additionalField: 'fake-value' },
|
|
79
82
|
trackingConsent: TrackingConsent.PENDING,
|
|
80
|
-
nativeCrashReportEnabled: true
|
|
83
|
+
nativeCrashReportEnabled: true,
|
|
84
|
+
nativeLongTaskThresholdMs: 345,
|
|
85
|
+
longTaskThresholdMs: 567
|
|
81
86
|
}
|
|
82
87
|
)
|
|
83
88
|
).toMatchInlineSnapshot(`
|
|
@@ -91,7 +96,9 @@ describe('DdSdkReactNativeConfiguration', () => {
|
|
|
91
96
|
"firstPartyHosts": Array [
|
|
92
97
|
"api.com",
|
|
93
98
|
],
|
|
99
|
+
"longTaskThresholdMs": 567,
|
|
94
100
|
"nativeCrashReportEnabled": true,
|
|
101
|
+
"nativeLongTaskThresholdMs": 345,
|
|
95
102
|
"nativeViewTracking": true,
|
|
96
103
|
"proxyConfig": ProxyConfiguration {
|
|
97
104
|
"address": "api.com",
|
|
@@ -112,6 +119,7 @@ describe('DdSdkReactNativeConfiguration', () => {
|
|
|
112
119
|
"verbosity": "debug",
|
|
113
120
|
"version": "1.4.5",
|
|
114
121
|
"versionSuffix": "codepush-3",
|
|
122
|
+
"vitalsUpdateFrequency": "AVERAGE",
|
|
115
123
|
}
|
|
116
124
|
`);
|
|
117
125
|
});
|
|
@@ -136,7 +144,9 @@ describe('DdSdkReactNativeConfiguration', () => {
|
|
|
136
144
|
version: '',
|
|
137
145
|
versionSuffix: '',
|
|
138
146
|
additionalConfig: {},
|
|
139
|
-
nativeCrashReportEnabled: false
|
|
147
|
+
nativeCrashReportEnabled: false,
|
|
148
|
+
nativeLongTaskThresholdMs: false,
|
|
149
|
+
longTaskThresholdMs: false
|
|
140
150
|
}
|
|
141
151
|
)
|
|
142
152
|
).toMatchInlineSnapshot(`
|
|
@@ -146,7 +156,9 @@ describe('DdSdkReactNativeConfiguration', () => {
|
|
|
146
156
|
"clientToken": "",
|
|
147
157
|
"env": "",
|
|
148
158
|
"firstPartyHosts": Array [],
|
|
159
|
+
"longTaskThresholdMs": false,
|
|
149
160
|
"nativeCrashReportEnabled": false,
|
|
161
|
+
"nativeLongTaskThresholdMs": false,
|
|
150
162
|
"nativeViewTracking": false,
|
|
151
163
|
"proxyConfig": undefined,
|
|
152
164
|
"resourceTracingSamplingRate": 0,
|
|
@@ -161,6 +173,7 @@ describe('DdSdkReactNativeConfiguration', () => {
|
|
|
161
173
|
"verbosity": undefined,
|
|
162
174
|
"version": "",
|
|
163
175
|
"versionSuffix": "",
|
|
176
|
+
"vitalsUpdateFrequency": "AVERAGE",
|
|
164
177
|
}
|
|
165
178
|
`);
|
|
166
179
|
});
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { adaptLongTaskThreshold } from '../longTasksUtils';
|
|
2
|
+
|
|
3
|
+
describe('adaptLongTaskThreshold', () => {
|
|
4
|
+
it('returns 0 if false is given', () => {
|
|
5
|
+
expect(adaptLongTaskThreshold(false)).toBe(0);
|
|
6
|
+
});
|
|
7
|
+
it('returns 0 if 0 is given', () => {
|
|
8
|
+
expect(adaptLongTaskThreshold(0)).toBe(0);
|
|
9
|
+
});
|
|
10
|
+
it('returns 100 if positive below 100 is given', () => {
|
|
11
|
+
expect(adaptLongTaskThreshold(42)).toBe(100);
|
|
12
|
+
});
|
|
13
|
+
it('returns 100 if negative is given', () => {
|
|
14
|
+
expect(adaptLongTaskThreshold(-1)).toBe(100);
|
|
15
|
+
});
|
|
16
|
+
it('returns the value if an acceptable value is given', () => {
|
|
17
|
+
expect(adaptLongTaskThreshold(700)).toBe(700);
|
|
18
|
+
expect(adaptLongTaskThreshold(2000)).toBe(2000);
|
|
19
|
+
});
|
|
20
|
+
it('returns 5000 if a value too high is given', () => {
|
|
21
|
+
expect(adaptLongTaskThreshold(7000)).toBe(5000);
|
|
22
|
+
});
|
|
23
|
+
});
|
package/src/errorUtils.ts
CHANGED
|
@@ -20,6 +20,14 @@ export const getErrorMessage = (error: any | undefined): string => {
|
|
|
20
20
|
return message;
|
|
21
21
|
};
|
|
22
22
|
|
|
23
|
+
/**
|
|
24
|
+
* Will extract the stack from the error, taking the first key found among:
|
|
25
|
+
* `stacktrace`, `stack`, `componentStack` (component tree for component errors,
|
|
26
|
+
* which contains only native components names in production).
|
|
27
|
+
*
|
|
28
|
+
* In last resort and if `sourceURL`, `line` and `column` are present, it will
|
|
29
|
+
* generate a stack from this information.
|
|
30
|
+
*/
|
|
23
31
|
export const getErrorStackTrace = (error: any | undefined): string => {
|
|
24
32
|
let stack = EMPTY_STACK_TRACE;
|
|
25
33
|
|
|
@@ -29,12 +37,12 @@ export const getErrorStackTrace = (error: any | undefined): string => {
|
|
|
29
37
|
} else if (typeof error === 'string') {
|
|
30
38
|
stack = EMPTY_STACK_TRACE;
|
|
31
39
|
} else if (typeof error === 'object') {
|
|
32
|
-
if ('
|
|
33
|
-
stack = String(error.componentStack);
|
|
34
|
-
} else if ('stacktrace' in error) {
|
|
40
|
+
if ('stacktrace' in error) {
|
|
35
41
|
stack = String(error.stacktrace);
|
|
36
42
|
} else if ('stack' in error) {
|
|
37
43
|
stack = String(error.stack);
|
|
44
|
+
} else if ('componentStack' in error) {
|
|
45
|
+
stack = String(error.componentStack);
|
|
38
46
|
} else if (
|
|
39
47
|
'sourceURL' in error &&
|
|
40
48
|
'line' in error &&
|