@datadog/mobile-react-native 1.1.5 → 1.2.0-beta2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/DatadogSDKReactNative.podspec +2 -2
- package/README.md +18 -14
- package/android/build.gradle +28 -3
- package/android/detekt.yml +572 -0
- package/android/src/main/kotlin/com/datadog/reactnative/DatadogSDKWrapper.kt +12 -0
- package/android/src/main/kotlin/com/datadog/reactnative/DatadogWrapper.kt +15 -0
- package/android/src/main/kotlin/com/datadog/reactnative/DdSdk.kt +143 -8
- package/android/src/main/kotlin/com/datadog/reactnative/DdSdkConfiguration.kt +25 -1
- package/android/src/main/kotlin/com/datadog/reactnative/DdSdkConfigurationExt.kt +31 -1
- package/android/src/main/kotlin/com/datadog/reactnative/VitalFrameCallback.kt +41 -0
- package/android/src/test/kotlin/com/datadog/reactnative/DdRumTest.kt +7 -2
- package/android/src/test/kotlin/com/datadog/reactnative/DdSdkTest.kt +429 -27
- package/android/src/test/kotlin/com/datadog/reactnative/DdTraceTest.kt +5 -1
- package/android/src/test/kotlin/com/datadog/tools/unit/DdSdkConfigurationExt.kt +40 -1
- package/android/src/test/kotlin/com/datadog/tools/unit/GenericAssert.kt +21 -1
- package/android/src/test/kotlin/com/datadog/tools/unit/MapExt.kt +1 -1
- package/android/src/test/kotlin/com/datadog/tools/unit/forge/BaseConfigurator.kt +1 -0
- package/android/src/test/kotlin/com/datadog/tools/unit/forge/DdSdkConfigurationForgeryFactory.kt +22 -2
- package/android/src/test/kotlin/com/datadog/tools/unit/forge/PackageInfoForgeryFactory.kt +2 -3
- package/android/src/test/kotlin/com/datadog/tools/unit/forge/TelemetryConfigurationEventForgeryFactory.kt +94 -0
- package/datadog-sourcemaps.gradle +85 -28
- package/ios/Sources/Attributes.swift +0 -4
- package/ios/Sources/DdSdk.m +10 -0
- package/ios/Sources/DdSdk.swift +113 -10
- package/ios/Sources/DdSdkConfiguration.swift +38 -1
- package/ios/Sources/JSRefreshRateListener.swift +86 -0
- package/ios/Sources/QueueHolder.swift +7 -0
- package/ios/Sources/RNDdSdkConfiguration.swift +25 -1
- package/lib/commonjs/DatadogProvider/Buffer/BoundedBuffer.js +173 -0
- package/lib/commonjs/DatadogProvider/Buffer/BoundedBuffer.js.map +1 -0
- package/lib/commonjs/DatadogProvider/Buffer/BufferSingleton.js +32 -0
- package/lib/commonjs/DatadogProvider/Buffer/BufferSingleton.js.map +1 -0
- package/lib/commonjs/DatadogProvider/Buffer/DatadogBuffer.js +29 -0
- package/lib/commonjs/DatadogProvider/Buffer/DatadogBuffer.js.map +1 -0
- package/lib/commonjs/DatadogProvider/Buffer/PassThroughBuffer.js +28 -0
- package/lib/commonjs/DatadogProvider/Buffer/PassThroughBuffer.js.map +1 -0
- package/lib/commonjs/DatadogProvider/Buffer/bufferNativeCall.js +32 -0
- package/lib/commonjs/DatadogProvider/Buffer/bufferNativeCall.js.map +1 -0
- package/lib/commonjs/DatadogProvider/DatadogProvider.js +101 -0
- package/lib/commonjs/DatadogProvider/DatadogProvider.js.map +1 -0
- package/lib/commonjs/DdSdkReactNative.js +140 -59
- package/lib/commonjs/DdSdkReactNative.js.map +1 -1
- package/lib/commonjs/DdSdkReactNativeConfiguration.js +166 -9
- package/lib/commonjs/DdSdkReactNativeConfiguration.js.map +1 -1
- package/lib/commonjs/errorUtils.js +69 -0
- package/lib/commonjs/errorUtils.js.map +1 -0
- package/lib/commonjs/foundation.js +19 -12
- package/lib/commonjs/foundation.js.map +1 -1
- package/lib/commonjs/index.js +20 -0
- package/lib/commonjs/index.js.map +1 -1
- package/lib/commonjs/longTasksUtils.js +40 -0
- package/lib/commonjs/longTasksUtils.js.map +1 -0
- package/lib/commonjs/nativeModulesTypes.js.map +1 -1
- package/lib/commonjs/rum/instrumentation/DdRumErrorTracking.js +8 -45
- package/lib/commonjs/rum/instrumentation/DdRumErrorTracking.js.map +1 -1
- package/lib/commonjs/rum/instrumentation/DdRumUserInteractionTracking.js +16 -1
- package/lib/commonjs/rum/instrumentation/DdRumUserInteractionTracking.js.map +1 -1
- package/lib/commonjs/rum/instrumentation/getJsxRuntime.js +1 -1
- package/lib/commonjs/rum/instrumentation/getJsxRuntime.js.map +1 -1
- package/lib/commonjs/rum/instrumentation/resourceTracking/domain/distributedTracing.js +2 -1
- package/lib/commonjs/rum/instrumentation/resourceTracking/domain/distributedTracing.js.map +1 -1
- package/lib/commonjs/rum/instrumentation/resourceTracking/implementation/DatadogRumResource/ResourceReporter.js +2 -1
- package/lib/commonjs/rum/instrumentation/resourceTracking/implementation/DatadogRumResource/ResourceReporter.js.map +1 -1
- package/lib/commonjs/types.js +6 -1
- package/lib/commonjs/types.js.map +1 -1
- package/lib/commonjs/version.js +1 -1
- package/lib/commonjs/version.js.map +1 -1
- package/lib/module/DatadogProvider/Buffer/BoundedBuffer.js +163 -0
- package/lib/module/DatadogProvider/Buffer/BoundedBuffer.js.map +1 -0
- package/lib/module/DatadogProvider/Buffer/BufferSingleton.js +26 -0
- package/lib/module/DatadogProvider/Buffer/BufferSingleton.js.map +1 -0
- package/lib/module/DatadogProvider/Buffer/DatadogBuffer.js +20 -0
- package/lib/module/DatadogProvider/Buffer/DatadogBuffer.js.map +1 -0
- package/lib/module/DatadogProvider/Buffer/PassThroughBuffer.js +23 -0
- package/lib/module/DatadogProvider/Buffer/PassThroughBuffer.js.map +1 -0
- package/lib/module/DatadogProvider/Buffer/bufferNativeCall.js +16 -0
- package/lib/module/DatadogProvider/Buffer/bufferNativeCall.js.map +1 -0
- package/lib/module/DatadogProvider/DatadogProvider.js +82 -0
- package/lib/module/DatadogProvider/DatadogProvider.js.map +1 -0
- package/lib/module/DdSdkReactNative.js +132 -57
- package/lib/module/DdSdkReactNative.js.map +1 -1
- package/lib/module/DdSdkReactNativeConfiguration.js +154 -8
- package/lib/module/DdSdkReactNativeConfiguration.js.map +1 -1
- package/lib/module/errorUtils.js +54 -0
- package/lib/module/errorUtils.js.map +1 -0
- package/lib/module/foundation.js +18 -12
- package/lib/module/foundation.js.map +1 -1
- package/lib/module/index.js +3 -2
- package/lib/module/index.js.map +1 -1
- package/lib/module/longTasksUtils.js +31 -0
- package/lib/module/longTasksUtils.js.map +1 -0
- package/lib/module/nativeModulesTypes.js.map +1 -1
- package/lib/module/rum/instrumentation/DdRumErrorTracking.js +5 -42
- package/lib/module/rum/instrumentation/DdRumErrorTracking.js.map +1 -1
- package/lib/module/rum/instrumentation/DdRumUserInteractionTracking.js +14 -1
- package/lib/module/rum/instrumentation/DdRumUserInteractionTracking.js.map +1 -1
- package/lib/module/rum/instrumentation/getJsxRuntime.js +1 -1
- package/lib/module/rum/instrumentation/getJsxRuntime.js.map +1 -1
- package/lib/module/rum/instrumentation/resourceTracking/domain/distributedTracing.js +2 -1
- package/lib/module/rum/instrumentation/resourceTracking/domain/distributedTracing.js.map +1 -1
- package/lib/module/rum/instrumentation/resourceTracking/implementation/DatadogRumResource/ResourceReporter.js +2 -1
- package/lib/module/rum/instrumentation/resourceTracking/implementation/DatadogRumResource/ResourceReporter.js.map +1 -1
- package/lib/module/types.js +6 -1
- package/lib/module/types.js.map +1 -1
- package/lib/module/version.js +1 -1
- package/lib/module/version.js.map +1 -1
- package/lib/typescript/DatadogProvider/Buffer/BoundedBuffer.d.ts +15 -0
- package/lib/typescript/DatadogProvider/Buffer/BufferSingleton.d.ts +7 -0
- package/lib/typescript/DatadogProvider/Buffer/DatadogBuffer.d.ts +20 -0
- package/lib/typescript/DatadogProvider/Buffer/PassThroughBuffer.d.ts +7 -0
- package/lib/typescript/DatadogProvider/Buffer/bufferNativeCall.d.ts +3 -0
- package/lib/typescript/DatadogProvider/DatadogProvider.d.ts +26 -0
- package/lib/typescript/DdSdkReactNative.d.ts +18 -3
- package/lib/typescript/DdSdkReactNativeConfiguration.d.ts +114 -0
- package/lib/typescript/errorUtils.d.ts +12 -0
- package/lib/typescript/index.d.ts +3 -2
- package/lib/typescript/longTasksUtils.d.ts +6 -0
- package/lib/typescript/nativeModulesTypes.d.ts +12 -0
- package/lib/typescript/rum/instrumentation/DdRumErrorTracking.d.ts +0 -2
- package/lib/typescript/rum/instrumentation/DdRumUserInteractionTracking.d.ts +3 -0
- package/lib/typescript/rum/instrumentation/resourceTracking/domain/distributedTracing.d.ts +1 -0
- package/lib/typescript/rum/instrumentation/resourceTracking/domain/interfaces/RumResource.d.ts +1 -1
- package/lib/typescript/types.d.ts +16 -1
- package/lib/typescript/version.d.ts +1 -1
- package/package.json +3 -2
- package/src/DatadogProvider/Buffer/BoundedBuffer.ts +209 -0
- package/src/DatadogProvider/Buffer/BufferSingleton.ts +26 -0
- package/src/DatadogProvider/Buffer/DatadogBuffer.ts +34 -0
- package/src/DatadogProvider/Buffer/PassThroughBuffer.ts +16 -0
- package/src/DatadogProvider/Buffer/__tests__/BoundedBuffer.test.ts +202 -0
- package/src/DatadogProvider/Buffer/__tests__/BufferSingleton.test.ts +50 -0
- package/src/DatadogProvider/Buffer/bufferNativeCall.ts +24 -0
- package/src/DatadogProvider/DatadogProvider.tsx +122 -0
- package/src/DatadogProvider/__tests__/__utils__/renderWithProvider.tsx +111 -0
- package/src/DatadogProvider/__tests__/initialization.test.tsx +182 -0
- package/src/DatadogProvider/__tests__/initializationModes.test.tsx +174 -0
- package/src/DdSdkReactNative.tsx +206 -109
- package/src/DdSdkReactNativeConfiguration.tsx +225 -8
- package/src/__tests__/DdRumWrapper.test.tsx +3 -27
- package/src/__tests__/DdSdkReactNative.test.tsx +57 -13
- package/src/__tests__/DdSdkReactNativeConfiguration.test.ts +181 -0
- package/src/__tests__/foundation.test.ts +11 -2
- package/src/__tests__/longTasksUtils.ts +23 -0
- package/src/__tests__/rum/instrumentation/DdRumUserInteractionTracking.test.tsx +18 -4
- package/src/errorUtils.ts +58 -0
- package/src/foundation.tsx +15 -12
- package/src/index.tsx +9 -1
- package/src/longTasksUtils.ts +30 -0
- package/src/nativeModulesTypes.ts +14 -0
- package/src/rum/instrumentation/DdRumErrorTracking.tsx +9 -46
- package/src/rum/instrumentation/DdRumUserInteractionTracking.tsx +11 -1
- package/src/rum/instrumentation/getJsxRuntime.ts +1 -1
- package/src/rum/instrumentation/resourceTracking/__tests__/DdRumResourceTracking.test.ts +2 -0
- package/src/rum/instrumentation/resourceTracking/domain/distributedTracing.tsx +3 -1
- package/src/rum/instrumentation/resourceTracking/domain/interfaces/RumResource.ts +1 -1
- package/src/rum/instrumentation/resourceTracking/implementation/DatadogRumResource/ResourceReporter.ts +2 -1
- package/src/rum/instrumentation/resourceTracking/implementation/DatadogRumResource/__tests__/ResourceReporter.test.ts +2 -0
- package/src/rum/instrumentation/resourceTracking/implementation/__tests__/XHRProxy.test.ts +12 -47
- package/src/types.tsx +11 -1
- package/src/version.ts +1 -1
|
@@ -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 () => {
|
|
@@ -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
|
+
});
|
|
@@ -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,58 @@
|
|
|
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
|
+
/**
|
|
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
|
+
*/
|
|
31
|
+
export const getErrorStackTrace = (error: any | undefined): string => {
|
|
32
|
+
let stack = EMPTY_STACK_TRACE;
|
|
33
|
+
|
|
34
|
+
try {
|
|
35
|
+
if (error === undefined || error === null) {
|
|
36
|
+
stack = EMPTY_STACK_TRACE;
|
|
37
|
+
} else if (typeof error === 'string') {
|
|
38
|
+
stack = EMPTY_STACK_TRACE;
|
|
39
|
+
} else if (typeof error === 'object') {
|
|
40
|
+
if ('stacktrace' in error) {
|
|
41
|
+
stack = String(error.stacktrace);
|
|
42
|
+
} else if ('stack' in error) {
|
|
43
|
+
stack = String(error.stack);
|
|
44
|
+
} else if ('componentStack' in error) {
|
|
45
|
+
stack = String(error.componentStack);
|
|
46
|
+
} else if (
|
|
47
|
+
'sourceURL' in error &&
|
|
48
|
+
'line' in error &&
|
|
49
|
+
'column' in error
|
|
50
|
+
) {
|
|
51
|
+
stack = `at ${error.sourceURL}:${error.line}:${error.column}`;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
} catch (e) {
|
|
55
|
+
// Do nothing
|
|
56
|
+
}
|
|
57
|
+
return stack;
|
|
58
|
+
};
|
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
|
|
package/src/index.tsx
CHANGED
|
@@ -4,7 +4,12 @@
|
|
|
4
4
|
* Copyright 2016-Present Datadog, Inc.
|
|
5
5
|
*/
|
|
6
6
|
|
|
7
|
-
import {
|
|
7
|
+
import { DatadogProvider } from './DatadogProvider/DatadogProvider';
|
|
8
|
+
import {
|
|
9
|
+
DatadogProviderConfiguration,
|
|
10
|
+
DdSdkReactNativeConfiguration,
|
|
11
|
+
InitializationMode
|
|
12
|
+
} from './DdSdkReactNativeConfiguration';
|
|
8
13
|
import { DdSdkReactNative } from './DdSdkReactNative';
|
|
9
14
|
import { InternalLog } from './InternalLog';
|
|
10
15
|
import { ProxyConfiguration, ProxyType } from './ProxyConfiguration';
|
|
@@ -14,6 +19,9 @@ import { DdLogs, DdTrace, DdRum } from './foundation';
|
|
|
14
19
|
import { RumActionType, ErrorSource } from './types';
|
|
15
20
|
|
|
16
21
|
export {
|
|
22
|
+
DatadogProvider,
|
|
23
|
+
DatadogProviderConfiguration,
|
|
24
|
+
InitializationMode,
|
|
17
25
|
DdLogs,
|
|
18
26
|
DdTrace,
|
|
19
27
|
DdRum,
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 100ms is the lower bound for a noticeable long task event.
|
|
3
|
+
*/
|
|
4
|
+
const MIN_LONG_TASK_THRESHOLD_MS = 100;
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* 5000ms is considered an Application Not Responding (ANR) event.
|
|
8
|
+
*/
|
|
9
|
+
const MAX_LONG_TASK_THRESHOLD_MS = 5000;
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Makes sure the long task threshold value is above 100 and below 5000.
|
|
13
|
+
* Also makes sure it is a number, passing `0` if it is `false`, as the React Native
|
|
14
|
+
* bridge cannot handle values with dual types.
|
|
15
|
+
*/
|
|
16
|
+
export const adaptLongTaskThreshold = (
|
|
17
|
+
longTaskThreshold: number | false
|
|
18
|
+
): number => {
|
|
19
|
+
if (!longTaskThreshold) {
|
|
20
|
+
return 0;
|
|
21
|
+
}
|
|
22
|
+
if (longTaskThreshold < MIN_LONG_TASK_THRESHOLD_MS) {
|
|
23
|
+
return MIN_LONG_TASK_THRESHOLD_MS;
|
|
24
|
+
}
|
|
25
|
+
if (longTaskThreshold > MAX_LONG_TASK_THRESHOLD_MS) {
|
|
26
|
+
return MAX_LONG_TASK_THRESHOLD_MS;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
return longTaskThreshold;
|
|
30
|
+
};
|
|
@@ -47,6 +47,20 @@ export type DdNativeSdkType = {
|
|
|
47
47
|
* @param trackingConsent: Consent, which can take one of the following values: 'pending', 'granted', 'not_granted'.
|
|
48
48
|
*/
|
|
49
49
|
setTrackingConsent(trackingConsent: string): Promise<void>;
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* Sends internal telemetry debug message
|
|
53
|
+
* @param message debug message
|
|
54
|
+
*/
|
|
55
|
+
telemetryDebug(message: string): Promise<void>;
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* Sends internal telemetry error
|
|
59
|
+
* @param message error message
|
|
60
|
+
* @param stack error stack
|
|
61
|
+
* @param kind error kind
|
|
62
|
+
*/
|
|
63
|
+
telemetryError(message: string, stack: string, kind: string): Promise<void>;
|
|
50
64
|
};
|
|
51
65
|
|
|
52
66
|
/**
|
|
@@ -8,12 +8,14 @@ import type { ErrorHandlerCallback } from 'react-native';
|
|
|
8
8
|
|
|
9
9
|
import { InternalLog } from '../../InternalLog';
|
|
10
10
|
import { SdkVerbosity } from '../../SdkVerbosity';
|
|
11
|
+
import {
|
|
12
|
+
getErrorMessage,
|
|
13
|
+
getErrorStackTrace,
|
|
14
|
+
EMPTY_STACK_TRACE
|
|
15
|
+
} from '../../errorUtils';
|
|
11
16
|
import { DdRum } from '../../foundation';
|
|
12
17
|
import { ErrorSource } from '../../types';
|
|
13
18
|
|
|
14
|
-
const EMPTY_MESSAGE = 'Unknown Error';
|
|
15
|
-
const EMPTY_STACK_TRACE = '';
|
|
16
|
-
|
|
17
19
|
/**
|
|
18
20
|
* Provides RUM auto-instrumentation feature to track errors as RUM events.
|
|
19
21
|
*/
|
|
@@ -63,8 +65,8 @@ export class DdRumErrorTracking {
|
|
|
63
65
|
|
|
64
66
|
// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
|
|
65
67
|
static onGlobalError(error: any, isFatal?: boolean): void {
|
|
66
|
-
const message =
|
|
67
|
-
const stacktrace =
|
|
68
|
+
const message = getErrorMessage(error);
|
|
69
|
+
const stacktrace = getErrorStackTrace(error);
|
|
68
70
|
DdRum.addError(message, ErrorSource.SOURCE, stacktrace, {
|
|
69
71
|
'_dd.error.is_crash': isFatal,
|
|
70
72
|
'_dd.error.raw': error
|
|
@@ -86,7 +88,7 @@ export class DdRumErrorTracking {
|
|
|
86
88
|
let stack: string = EMPTY_STACK_TRACE;
|
|
87
89
|
for (let i = 0; i < params.length; i += 1) {
|
|
88
90
|
const param = params[i];
|
|
89
|
-
const paramStack =
|
|
91
|
+
const paramStack = getErrorStackTrace(param);
|
|
90
92
|
if (paramStack !== EMPTY_STACK_TRACE) {
|
|
91
93
|
stack = paramStack;
|
|
92
94
|
break;
|
|
@@ -98,7 +100,7 @@ export class DdRumErrorTracking {
|
|
|
98
100
|
if (typeof param === 'string') {
|
|
99
101
|
return param;
|
|
100
102
|
} else {
|
|
101
|
-
return
|
|
103
|
+
return getErrorMessage(param);
|
|
102
104
|
}
|
|
103
105
|
})
|
|
104
106
|
.join(' ');
|
|
@@ -107,43 +109,4 @@ export class DdRumErrorTracking {
|
|
|
107
109
|
DdRumErrorTracking.defaultConsoleError.apply(console, params);
|
|
108
110
|
});
|
|
109
111
|
}
|
|
110
|
-
|
|
111
|
-
private static getErrorMessage(error: any | undefined): string {
|
|
112
|
-
let message = EMPTY_MESSAGE;
|
|
113
|
-
if (error === undefined || error === null) {
|
|
114
|
-
message = EMPTY_MESSAGE;
|
|
115
|
-
} else if (typeof error === 'object' && 'message' in error) {
|
|
116
|
-
message = String(error.message);
|
|
117
|
-
} else {
|
|
118
|
-
message = String(error);
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
return message;
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
private static getErrorStackTrace(error: any | undefined): string {
|
|
125
|
-
let stack = EMPTY_STACK_TRACE;
|
|
126
|
-
|
|
127
|
-
if (error === undefined || error === null) {
|
|
128
|
-
stack = EMPTY_STACK_TRACE;
|
|
129
|
-
} else if (typeof error === 'string') {
|
|
130
|
-
stack = EMPTY_STACK_TRACE;
|
|
131
|
-
} else if (typeof error === 'object') {
|
|
132
|
-
if ('componentStack' in error) {
|
|
133
|
-
stack = String(error.componentStack);
|
|
134
|
-
} else if ('stacktrace' in error) {
|
|
135
|
-
stack = String(error.stacktrace);
|
|
136
|
-
} else if ('stack' in error) {
|
|
137
|
-
stack = String(error.stack);
|
|
138
|
-
} else if (
|
|
139
|
-
'sourceURL' in error &&
|
|
140
|
-
'line' in error &&
|
|
141
|
-
'column' in error
|
|
142
|
-
) {
|
|
143
|
-
stack = `at ${error.sourceURL}:${error.line}:${error.column}`;
|
|
144
|
-
}
|
|
145
|
-
}
|
|
146
|
-
|
|
147
|
-
return stack;
|
|
148
|
-
}
|
|
149
112
|
}
|
|
@@ -8,6 +8,8 @@ import React from 'react';
|
|
|
8
8
|
|
|
9
9
|
import { InternalLog } from '../../InternalLog';
|
|
10
10
|
import { SdkVerbosity } from '../../SdkVerbosity';
|
|
11
|
+
import { getErrorMessage } from '../../errorUtils';
|
|
12
|
+
import { DdSdk } from '../../foundation';
|
|
11
13
|
|
|
12
14
|
import { DdEventsInterceptor } from './DdEventsInterceptor';
|
|
13
15
|
import type EventsInterceptor from './EventsInterceptor';
|
|
@@ -22,6 +24,8 @@ import { getJsxRuntime } from './getJsxRuntime';
|
|
|
22
24
|
export class DdRumUserInteractionTracking {
|
|
23
25
|
private static isTracking = false;
|
|
24
26
|
private static eventsInterceptor: EventsInterceptor = new NoOpEventsInterceptor();
|
|
27
|
+
private static originalCreateElement = React.createElement;
|
|
28
|
+
private static originalMemo = React.memo;
|
|
25
29
|
|
|
26
30
|
private static patchCreateElementFunction = (
|
|
27
31
|
originalFunction: typeof React.createElement,
|
|
@@ -80,7 +84,7 @@ export class DdRumUserInteractionTracking {
|
|
|
80
84
|
return this.patchCreateElementFunction(originaljsx, args);
|
|
81
85
|
};
|
|
82
86
|
} catch (e) {
|
|
83
|
-
|
|
87
|
+
DdSdk.telemetryDebug(getErrorMessage(e));
|
|
84
88
|
}
|
|
85
89
|
|
|
86
90
|
const originalMemo = React.memo;
|
|
@@ -120,4 +124,10 @@ export class DdRumUserInteractionTracking {
|
|
|
120
124
|
SdkVerbosity.INFO
|
|
121
125
|
);
|
|
122
126
|
}
|
|
127
|
+
|
|
128
|
+
static stopTracking() {
|
|
129
|
+
React.createElement = this.originalCreateElement;
|
|
130
|
+
React.memo = this.originalMemo;
|
|
131
|
+
DdRumUserInteractionTracking.isTracking = false;
|
|
132
|
+
}
|
|
123
133
|
}
|
|
@@ -24,7 +24,7 @@ export const getJsxRuntime = () => {
|
|
|
24
24
|
// eslint-disable-next-line global-require, @typescript-eslint/no-var-requires
|
|
25
25
|
const jsxRuntime = require('react/jsx-runtime');
|
|
26
26
|
if (!jsxRuntime.jsx) {
|
|
27
|
-
throw new Error('React
|
|
27
|
+
throw new Error('React jsx runtime does not export new jsx transform');
|
|
28
28
|
}
|
|
29
29
|
return jsxRuntime;
|
|
30
30
|
};
|
|
@@ -6,6 +6,7 @@
|
|
|
6
6
|
|
|
7
7
|
import { NativeModules } from 'react-native';
|
|
8
8
|
|
|
9
|
+
import { BufferSingleton } from '../../../../DatadogProvider/Buffer/BufferSingleton';
|
|
9
10
|
import { DdRumResourceTracking } from '../DdRumResourceTracking';
|
|
10
11
|
|
|
11
12
|
import { XMLHttpRequestMock } from './__utils__/XMLHttpRequestMock';
|
|
@@ -17,6 +18,7 @@ const flushPromises = () => new Promise(setImmediate);
|
|
|
17
18
|
beforeEach(() => {
|
|
18
19
|
DdRum.startResource.mockClear();
|
|
19
20
|
DdRum.stopResource.mockClear();
|
|
21
|
+
BufferSingleton.onInitialization();
|
|
20
22
|
global.XMLHttpRequest = XMLHttpRequestMock;
|
|
21
23
|
});
|
|
22
24
|
|
|
@@ -13,6 +13,7 @@ export type DdRumResourceTracingAttributes =
|
|
|
13
13
|
traceId: string;
|
|
14
14
|
spanId: string;
|
|
15
15
|
samplingPriorityHeader: '1';
|
|
16
|
+
rulePsr: number;
|
|
16
17
|
}
|
|
17
18
|
| {
|
|
18
19
|
tracingStrategy: 'DISCARD';
|
|
@@ -52,7 +53,8 @@ const generateTracingAttributesWithSampling = (
|
|
|
52
53
|
traceId: generateTraceId(),
|
|
53
54
|
spanId: generateTraceId(),
|
|
54
55
|
samplingPriorityHeader: '1',
|
|
55
|
-
tracingStrategy: 'KEEP'
|
|
56
|
+
tracingStrategy: 'KEEP',
|
|
57
|
+
rulePsr: tracingSamplingRate / 100
|
|
56
58
|
};
|
|
57
59
|
}
|
|
58
60
|
return DISCARDED_TRACE_ATTRIBUTES;
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
* Copyright 2016-Present Datadog, Inc.
|
|
5
5
|
*/
|
|
6
6
|
|
|
7
|
-
import type { ResourceKind } from '
|
|
7
|
+
import type { ResourceKind } from '../../../../../../src/types';
|
|
8
8
|
import type { DdRumResourceTracingAttributes } from '../distributedTracing';
|
|
9
9
|
|
|
10
10
|
export interface RUMResource {
|
|
@@ -6,6 +6,7 @@
|
|
|
6
6
|
|
|
7
7
|
import { NativeModules } from 'react-native';
|
|
8
8
|
|
|
9
|
+
import { BufferSingleton } from '../../../../../../DatadogProvider/Buffer/BufferSingleton';
|
|
9
10
|
import type { RUMResource } from '../../../domain/interfaces/RumResource';
|
|
10
11
|
import { ResourceReporter } from '../ResourceReporter';
|
|
11
12
|
|
|
@@ -18,6 +19,7 @@ const flushPromises = () => new Promise(setImmediate);
|
|
|
18
19
|
beforeEach(() => {
|
|
19
20
|
DdRum.startResource.mockClear();
|
|
20
21
|
DdRum.stopResource.mockClear();
|
|
22
|
+
BufferSingleton.onInitialization();
|
|
21
23
|
});
|
|
22
24
|
|
|
23
25
|
describe('Resource reporter', () => {
|