@datadog/mobile-react-native 2.3.2 → 2.3.4
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 +1 -0
- package/android/build.gradle +2 -0
- package/android/src/main/kotlin/com/datadog/reactnative/DdRumImplementation.kt +9 -0
- package/android/src/main/kotlin/com/datadog/reactnative/DdSdkBridgeExt.kt +13 -2
- package/android/src/main/kotlin/com/datadog/reactnative/SdkVersion.kt +1 -1
- package/android/src/newarch/kotlin/com/datadog/reactnative/DdLogs.kt +3 -2
- package/android/src/newarch/kotlin/com/datadog/reactnative/DdRum.kt +36 -13
- package/android/src/newarch/kotlin/com/datadog/reactnative/DdSdk.kt +3 -2
- package/android/src/newarch/kotlin/com/datadog/reactnative/DdTrace.kt +4 -2
- package/android/src/oldarch/kotlin/com/datadog/reactnative/DdLogs.kt +1 -1
- package/android/src/oldarch/kotlin/com/datadog/reactnative/DdRum.kt +11 -2
- package/android/src/oldarch/kotlin/com/datadog/reactnative/DdTrace.kt +4 -2
- package/datadog-sourcemaps.gradle +13 -2
- package/ios/Sources/DdRum.mm +11 -0
- package/ios/Sources/DdRumImplementation.swift +7 -0
- package/ios/Sources/SdkVersion.swift +1 -1
- package/jest/mock.js +9 -1
- package/lib/commonjs/DdSdkReactNative.js +11 -4
- package/lib/commonjs/DdSdkReactNative.js.map +1 -1
- package/lib/commonjs/index.js +16 -0
- package/lib/commonjs/index.js.map +1 -1
- package/lib/commonjs/rum/DdRum.js +26 -12
- package/lib/commonjs/rum/DdRum.js.map +1 -1
- package/lib/commonjs/rum/types.js.map +1 -1
- package/lib/commonjs/sdk/DatadogProvider/Buffer/BoundedBuffer.js +14 -6
- package/lib/commonjs/sdk/DatadogProvider/Buffer/BoundedBuffer.js.map +1 -1
- package/lib/commonjs/specs/NativeDdRum.js.map +1 -1
- package/lib/commonjs/trace/DdTrace.js +2 -2
- package/lib/commonjs/trace/DdTrace.js.map +1 -1
- package/lib/commonjs/utils/Timer.js +4 -4
- package/lib/commonjs/utils/Timer.js.map +1 -1
- package/lib/commonjs/utils/time-provider/DefaultTimeProvider.js +41 -0
- package/lib/commonjs/utils/time-provider/DefaultTimeProvider.js.map +1 -0
- package/lib/commonjs/utils/{TimeProvider.js → time-provider/TimeProvider.js} +4 -25
- package/lib/commonjs/utils/time-provider/TimeProvider.js.map +1 -0
- package/lib/commonjs/version.js +1 -1
- package/lib/commonjs/version.js.map +1 -1
- package/lib/module/DdSdkReactNative.js +11 -4
- package/lib/module/DdSdkReactNative.js.map +1 -1
- package/lib/module/index.js +3 -1
- package/lib/module/index.js.map +1 -1
- package/lib/module/rum/DdRum.js +25 -11
- package/lib/module/rum/DdRum.js.map +1 -1
- package/lib/module/rum/types.js.map +1 -1
- package/lib/module/sdk/DatadogProvider/Buffer/BoundedBuffer.js +14 -6
- package/lib/module/sdk/DatadogProvider/Buffer/BoundedBuffer.js.map +1 -1
- package/lib/module/specs/NativeDdRum.js.map +1 -1
- package/lib/module/trace/DdTrace.js +2 -2
- package/lib/module/trace/DdTrace.js.map +1 -1
- package/lib/module/utils/Timer.js +4 -4
- package/lib/module/utils/Timer.js.map +1 -1
- package/lib/module/utils/time-provider/DefaultTimeProvider.js +36 -0
- package/lib/module/utils/time-provider/DefaultTimeProvider.js.map +1 -0
- package/lib/module/utils/{TimeProvider.js → time-provider/TimeProvider.js} +4 -25
- package/lib/module/utils/time-provider/TimeProvider.js.map +1 -0
- package/lib/module/version.js +1 -1
- package/lib/module/version.js.map +1 -1
- package/lib/typescript/DdSdkReactNative.d.ts +5 -1
- package/lib/typescript/DdSdkReactNativeConfiguration.d.ts +7 -7
- package/lib/typescript/index.d.ts +5 -1
- package/lib/typescript/logs/types.d.ts +10 -10
- package/lib/typescript/nativeModulesTypes.d.ts +5 -5
- package/lib/typescript/rum/DdRum.d.ts +4 -0
- package/lib/typescript/rum/eventMappers/actionEventMapper.d.ts +4 -4
- package/lib/typescript/rum/eventMappers/errorEventMapper.d.ts +4 -4
- package/lib/typescript/rum/eventMappers/resourceEventMapper.d.ts +4 -4
- package/lib/typescript/rum/instrumentation/resourceTracking/distributedTracing/distributedTracing.d.ts +3 -3
- package/lib/typescript/rum/instrumentation/resourceTracking/distributedTracing/firstPartyHosts.d.ts +1 -1
- package/lib/typescript/rum/instrumentation/resourceTracking/requestProxy/XHRProxy/DatadogRumResource/ResourceReporter.d.ts +1 -1
- package/lib/typescript/rum/instrumentation/resourceTracking/requestProxy/interfaces/RequestProxy.d.ts +1 -1
- package/lib/typescript/rum/instrumentation/resourceTracking/requestProxy/interfaces/RumResource.d.ts +1 -1
- package/lib/typescript/rum/types.d.ts +7 -3
- package/lib/typescript/sdk/AttributesSingleton/types.d.ts +1 -1
- package/lib/typescript/sdk/DatadogProvider/Buffer/BoundedBuffer.d.ts +2 -0
- package/lib/typescript/sdk/DatadogProvider/DatadogProvider.d.ts +2 -2
- package/lib/typescript/sdk/EventMappers/EventMapper.d.ts +1 -1
- package/lib/typescript/sdk/UserInfoSingleton/types.d.ts +1 -1
- package/lib/typescript/specs/NativeDdRum.d.ts +4 -0
- package/lib/typescript/types.d.ts +2 -2
- package/lib/typescript/utils/Timer.d.ts +1 -1
- package/lib/typescript/utils/time-provider/DefaultTimeProvider.d.ts +7 -0
- package/lib/typescript/utils/{TimeProvider.d.ts → time-provider/TimeProvider.d.ts} +5 -7
- package/lib/typescript/version.d.ts +1 -1
- package/package.json +2 -2
- package/src/DdSdkReactNative.tsx +10 -4
- package/src/__tests__/DdSdkReactNative.test.tsx +2 -2
- package/src/__tests__/mock.test.ts +1 -1
- package/src/index.tsx +7 -0
- package/src/rum/DdRum.ts +24 -12
- package/src/rum/__mocks__/MockTimeProvider.ts +26 -0
- package/src/rum/__tests__/DdRum.test.ts +39 -13
- package/src/rum/__tests__/DdRumTimeProvider.test.ts +23 -0
- package/src/rum/types.ts +5 -0
- package/src/sdk/DatadogProvider/Buffer/BoundedBuffer.ts +22 -14
- package/src/sdk/DatadogProvider/__tests__/initialization.test.tsx +7 -6
- package/src/sdk/DatadogProvider/__tests__/initializationModes.test.tsx +5 -5
- package/src/specs/NativeDdRum.ts +5 -0
- package/src/trace/DdTrace.ts +2 -2
- package/src/utils/Timer.ts +5 -5
- package/src/utils/__tests__/TimeProvider.test.tsx +24 -7
- package/src/utils/__tests__/Timer.test.ts +38 -22
- package/src/utils/time-provider/DefaultTimeProvider.tsx +31 -0
- package/src/utils/{TimeProvider.tsx → time-provider/TimeProvider.tsx} +8 -27
- package/src/version.ts +1 -1
- package/lib/commonjs/utils/TimeProvider.js.map +0 -1
- package/lib/module/utils/TimeProvider.js.map +0 -1
|
@@ -3,7 +3,7 @@ import type { PropsWithChildren } from 'react';
|
|
|
3
3
|
import { DatadogProviderConfiguration } from '../../DdSdkReactNativeConfiguration';
|
|
4
4
|
import type { PartialInitializationConfiguration, AutoInstrumentationConfiguration } from '../../DdSdkReactNativeConfiguration';
|
|
5
5
|
import type { FileBasedConfiguration } from '../FileBasedConfiguration/FileBasedConfiguration';
|
|
6
|
-
|
|
6
|
+
type Props = PropsWithChildren<{
|
|
7
7
|
/**
|
|
8
8
|
* If a `DatadogProviderConfiguration` instance is passed, the SDK will start tracking errors, resources and actions and sending events.
|
|
9
9
|
*
|
|
@@ -15,7 +15,7 @@ declare type Props = PropsWithChildren<{
|
|
|
15
15
|
*/
|
|
16
16
|
onInitialization?: () => void;
|
|
17
17
|
}>;
|
|
18
|
-
|
|
18
|
+
type StaticProperties = {
|
|
19
19
|
initialize: (configuration: PartialInitializationConfiguration) => Promise<void>;
|
|
20
20
|
onInitialization?: () => void;
|
|
21
21
|
};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { Attributes } from '../AttributesSingleton/types';
|
|
2
2
|
import type { UserInfo } from '../UserInfoSingleton/types';
|
|
3
|
-
export
|
|
3
|
+
export type AdditionalEventDataForMapper = {
|
|
4
4
|
userInfo: UserInfo;
|
|
5
5
|
attributes: Attributes;
|
|
6
6
|
};
|
|
@@ -87,6 +87,10 @@ export interface Spec extends TurboModule {
|
|
|
87
87
|
* @param value: The value of the feature flag, encapsulated in an Object to accept all types
|
|
88
88
|
*/
|
|
89
89
|
addFeatureFlagEvaluation(name: string, value: Object): Promise<void>;
|
|
90
|
+
/**
|
|
91
|
+
* Get current Session ID, or `undefined` if not available.
|
|
92
|
+
*/
|
|
93
|
+
getCurrentSessionId(): Promise<string | undefined>;
|
|
90
94
|
}
|
|
91
95
|
declare const _default: Spec | null;
|
|
92
96
|
export default _default;
|
|
@@ -73,7 +73,7 @@ export declare class DdSdkConfiguration {
|
|
|
73
73
|
/**
|
|
74
74
|
* The entry point to initialize Datadog's features.
|
|
75
75
|
*/
|
|
76
|
-
export
|
|
76
|
+
export type DdSdkType = {
|
|
77
77
|
/**
|
|
78
78
|
* Initializes Datadog's features.
|
|
79
79
|
* @param configuration: The configuration to use.
|
|
@@ -98,7 +98,7 @@ export declare type DdSdkType = {
|
|
|
98
98
|
/**
|
|
99
99
|
* The entry point to use Datadog's Trace feature.
|
|
100
100
|
*/
|
|
101
|
-
export
|
|
101
|
+
export type DdTraceType = {
|
|
102
102
|
/**
|
|
103
103
|
* Start a span, and returns a unique identifier for the span.
|
|
104
104
|
* @param operation: The operation name of the span.
|
|
@@ -1,20 +1,18 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* A Timestamp structure holding the
|
|
3
3
|
*/
|
|
4
|
-
export
|
|
4
|
+
export type Timestamp = {
|
|
5
5
|
unix: number;
|
|
6
|
-
|
|
6
|
+
reactNative: number | null;
|
|
7
7
|
};
|
|
8
8
|
/**
|
|
9
9
|
* Simple class providing timestamps in milliseconds.
|
|
10
10
|
* If available, it will use the `performance.now()` method, and will fallback on `Date.now()` otherwise.
|
|
11
11
|
*/
|
|
12
|
-
export declare class TimeProvider {
|
|
13
|
-
private canUsePerformanceNow;
|
|
12
|
+
export declare abstract class TimeProvider {
|
|
14
13
|
/** Keeps an average offset between the unix time and the provided timestamp. */
|
|
15
|
-
|
|
14
|
+
protected baseOffset: number;
|
|
16
15
|
constructor();
|
|
17
|
-
getTimestamp(): Timestamp;
|
|
16
|
+
abstract getTimestamp(): Timestamp;
|
|
18
17
|
now(): number;
|
|
19
|
-
private performanceNow;
|
|
20
18
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const version = "2.3.
|
|
1
|
+
export declare const version = "2.3.4";
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@datadog/mobile-react-native",
|
|
3
|
-
"version": "2.3.
|
|
3
|
+
"version": "2.3.4",
|
|
4
4
|
"description": "A client-side React Native module to interact with Datadog",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"datadog",
|
|
@@ -97,5 +97,5 @@
|
|
|
97
97
|
"javaPackageName": "com.datadog.reactnative"
|
|
98
98
|
}
|
|
99
99
|
},
|
|
100
|
-
"gitHead": "
|
|
100
|
+
"gitHead": "7293c15981edb7c5c523c7062866ef1bc2a7f339"
|
|
101
101
|
}
|
package/src/DdSdkReactNative.tsx
CHANGED
|
@@ -47,10 +47,9 @@ export class DdSdkReactNative {
|
|
|
47
47
|
private static readonly DD_SDK_VERSION = '_dd.sdk_version';
|
|
48
48
|
private static readonly DD_VERSION = '_dd.version';
|
|
49
49
|
private static readonly DD_VERSION_SUFFIX = '_dd.version_suffix';
|
|
50
|
-
|
|
51
|
-
private static wasInitialized = false;
|
|
52
50
|
private static wasAutoInstrumented = false;
|
|
53
51
|
private static features?: AutoInstrumentationConfiguration;
|
|
52
|
+
private static _isInitialized = false;
|
|
54
53
|
|
|
55
54
|
/**
|
|
56
55
|
* Initializes the Datadog SDK.
|
|
@@ -72,7 +71,7 @@ export class DdSdkReactNative {
|
|
|
72
71
|
initializationModeForTelemetry: InitializationModeForTelemetry;
|
|
73
72
|
}
|
|
74
73
|
): Promise<void> => {
|
|
75
|
-
if (DdSdkReactNative.
|
|
74
|
+
if (DdSdkReactNative._isInitialized) {
|
|
76
75
|
InternalLog.log(
|
|
77
76
|
"Can't initialize Datadog, SDK was already initialized",
|
|
78
77
|
SdkVerbosity.WARN
|
|
@@ -91,7 +90,7 @@ export class DdSdkReactNative {
|
|
|
91
90
|
DdSdkReactNative.buildConfiguration(configuration, params)
|
|
92
91
|
);
|
|
93
92
|
InternalLog.log('Datadog SDK was initialized', SdkVerbosity.INFO);
|
|
94
|
-
DdSdkReactNative.
|
|
93
|
+
DdSdkReactNative._isInitialized = true;
|
|
95
94
|
BufferSingleton.onInitialization();
|
|
96
95
|
};
|
|
97
96
|
|
|
@@ -212,6 +211,13 @@ export class DdSdkReactNative {
|
|
|
212
211
|
return DdSdk.clearAllData();
|
|
213
212
|
};
|
|
214
213
|
|
|
214
|
+
/**
|
|
215
|
+
* Returns `true` if the SDK was initialized, `false` otherwise.
|
|
216
|
+
*/
|
|
217
|
+
public static isInitialized() {
|
|
218
|
+
return DdSdkReactNative._isInitialized;
|
|
219
|
+
}
|
|
220
|
+
|
|
215
221
|
private static buildConfiguration = (
|
|
216
222
|
configuration: DdSdkReactNativeConfiguration,
|
|
217
223
|
params: {
|
|
@@ -56,7 +56,7 @@ jest.mock('../rum/instrumentation/DdRumErrorTracking', () => {
|
|
|
56
56
|
});
|
|
57
57
|
|
|
58
58
|
beforeEach(async () => {
|
|
59
|
-
DdSdkReactNative['
|
|
59
|
+
DdSdkReactNative['_isInitialized'] = false;
|
|
60
60
|
DdSdkReactNative['wasAutoInstrumented'] = false;
|
|
61
61
|
NativeModules.DdSdk.initialize.mockClear();
|
|
62
62
|
NativeModules.DdSdk.setAttributes.mockClear();
|
|
@@ -151,7 +151,7 @@ describe('DdSdkReactNative', () => {
|
|
|
151
151
|
'_dd.sdk_version': sdkVersion
|
|
152
152
|
});
|
|
153
153
|
|
|
154
|
-
expect(DdSdkReactNative['
|
|
154
|
+
expect(DdSdkReactNative['_isInitialized']).toBe(false);
|
|
155
155
|
expect(DdRumUserInteractionTracking.startTracking).toBeCalledTimes(
|
|
156
156
|
0
|
|
157
157
|
);
|
package/src/index.tsx
CHANGED
|
@@ -28,6 +28,9 @@ import { RumActionType, ErrorSource, PropagatorType } from './rum/types';
|
|
|
28
28
|
import { DatadogProvider } from './sdk/DatadogProvider/DatadogProvider';
|
|
29
29
|
import { FileBasedConfiguration } from './sdk/FileBasedConfiguration/FileBasedConfiguration';
|
|
30
30
|
import { DdTrace } from './trace/DdTrace';
|
|
31
|
+
import { DefaultTimeProvider } from './utils/time-provider/DefaultTimeProvider';
|
|
32
|
+
import { TimeProvider } from './utils/time-provider/TimeProvider';
|
|
33
|
+
import type { Timestamp } from './utils/time-provider/TimeProvider';
|
|
31
34
|
|
|
32
35
|
export {
|
|
33
36
|
DatadogProvider,
|
|
@@ -50,7 +53,11 @@ export {
|
|
|
50
53
|
PropagatorType,
|
|
51
54
|
UploadFrequency,
|
|
52
55
|
BatchSize,
|
|
56
|
+
TimeProvider,
|
|
57
|
+
DefaultTimeProvider,
|
|
53
58
|
DATADOG_GRAPH_QL_OPERATION_TYPE_HEADER,
|
|
54
59
|
DATADOG_GRAPH_QL_OPERATION_NAME_HEADER,
|
|
55
60
|
DATADOG_GRAPH_QL_VARIABLES_HEADER
|
|
56
61
|
};
|
|
62
|
+
|
|
63
|
+
export type { Timestamp };
|
package/src/rum/DdRum.ts
CHANGED
|
@@ -6,12 +6,14 @@
|
|
|
6
6
|
|
|
7
7
|
import type { GestureResponderEvent } from 'react-native';
|
|
8
8
|
|
|
9
|
+
import { DdSdkReactNative } from '../DdSdkReactNative';
|
|
9
10
|
import { InternalLog } from '../InternalLog';
|
|
10
11
|
import { SdkVerbosity } from '../SdkVerbosity';
|
|
11
12
|
import type { DdNativeRumType } from '../nativeModulesTypes';
|
|
12
13
|
import { bufferVoidNativeCall } from '../sdk/DatadogProvider/Buffer/bufferNativeCall';
|
|
13
14
|
import { DdSdk } from '../sdk/DdSdk';
|
|
14
|
-
import {
|
|
15
|
+
import { DefaultTimeProvider } from '../utils/time-provider/DefaultTimeProvider';
|
|
16
|
+
import type { TimeProvider } from '../utils/time-provider/TimeProvider';
|
|
15
17
|
|
|
16
18
|
import type { ActionEventMapper } from './eventMappers/actionEventMapper';
|
|
17
19
|
import { generateActionEventMapper } from './eventMappers/actionEventMapper';
|
|
@@ -26,8 +28,6 @@ import type {
|
|
|
26
28
|
ErrorSource
|
|
27
29
|
} from './types';
|
|
28
30
|
|
|
29
|
-
const timeProvider = new TimeProvider();
|
|
30
|
-
|
|
31
31
|
const generateEmptyPromise = () => new Promise<void>(resolve => resolve());
|
|
32
32
|
|
|
33
33
|
class DdRumWrapper implements DdRumType {
|
|
@@ -38,12 +38,13 @@ class DdRumWrapper implements DdRumType {
|
|
|
38
38
|
private errorEventMapper = generateErrorEventMapper(undefined);
|
|
39
39
|
private resourceEventMapper = generateResourceEventMapper(undefined);
|
|
40
40
|
private actionEventMapper = generateActionEventMapper(undefined);
|
|
41
|
+
private timeProvider: TimeProvider = new DefaultTimeProvider();
|
|
41
42
|
|
|
42
43
|
startView = (
|
|
43
44
|
key: string,
|
|
44
45
|
name: string,
|
|
45
46
|
context: object = {},
|
|
46
|
-
timestampMs: number = timeProvider.now()
|
|
47
|
+
timestampMs: number = this.timeProvider.now()
|
|
47
48
|
): Promise<void> => {
|
|
48
49
|
InternalLog.log(
|
|
49
50
|
`Starting RUM View “${name}” #${key}`,
|
|
@@ -57,7 +58,7 @@ class DdRumWrapper implements DdRumType {
|
|
|
57
58
|
stopView = (
|
|
58
59
|
key: string,
|
|
59
60
|
context: object = {},
|
|
60
|
-
timestampMs: number = timeProvider.now()
|
|
61
|
+
timestampMs: number = this.timeProvider.now()
|
|
61
62
|
): Promise<void> => {
|
|
62
63
|
InternalLog.log(`Stopping RUM View #${key}`, SdkVerbosity.DEBUG);
|
|
63
64
|
return bufferVoidNativeCall(() =>
|
|
@@ -69,7 +70,7 @@ class DdRumWrapper implements DdRumType {
|
|
|
69
70
|
type: RumActionType,
|
|
70
71
|
name: string,
|
|
71
72
|
context: object = {},
|
|
72
|
-
timestampMs: number = timeProvider.now()
|
|
73
|
+
timestampMs: number = this.timeProvider.now()
|
|
73
74
|
): Promise<void> => {
|
|
74
75
|
InternalLog.log(
|
|
75
76
|
`Starting RUM Action “${name}” (${type})`,
|
|
@@ -100,6 +101,10 @@ class DdRumWrapper implements DdRumType {
|
|
|
100
101
|
return this.callNativeStopAction(...nativeCallArgs);
|
|
101
102
|
};
|
|
102
103
|
|
|
104
|
+
setTimeProvider = (timeProvider: TimeProvider): void => {
|
|
105
|
+
this.timeProvider = timeProvider;
|
|
106
|
+
};
|
|
107
|
+
|
|
103
108
|
private callNativeStopAction = (
|
|
104
109
|
type: RumActionType,
|
|
105
110
|
name: string,
|
|
@@ -157,7 +162,7 @@ class DdRumWrapper implements DdRumType {
|
|
|
157
162
|
args[0],
|
|
158
163
|
args[1],
|
|
159
164
|
args[2] || {},
|
|
160
|
-
args[3] || timeProvider.now()
|
|
165
|
+
args[3] || this.timeProvider.now()
|
|
161
166
|
];
|
|
162
167
|
}
|
|
163
168
|
if (isOldStopActionAPI(args)) {
|
|
@@ -170,7 +175,7 @@ class DdRumWrapper implements DdRumType {
|
|
|
170
175
|
type,
|
|
171
176
|
name,
|
|
172
177
|
args[0] || {},
|
|
173
|
-
args[1] || timeProvider.now()
|
|
178
|
+
args[1] || this.timeProvider.now()
|
|
174
179
|
];
|
|
175
180
|
}
|
|
176
181
|
InternalLog.log(
|
|
@@ -191,7 +196,7 @@ class DdRumWrapper implements DdRumType {
|
|
|
191
196
|
type: RumActionType,
|
|
192
197
|
name: string,
|
|
193
198
|
context: object = {},
|
|
194
|
-
timestampMs: number = timeProvider.now(),
|
|
199
|
+
timestampMs: number = this.timeProvider.now(),
|
|
195
200
|
actionContext?: GestureResponderEvent
|
|
196
201
|
): Promise<void> => {
|
|
197
202
|
const mappedEvent = this.actionEventMapper.applyEventMapper({
|
|
@@ -223,7 +228,7 @@ class DdRumWrapper implements DdRumType {
|
|
|
223
228
|
method: string,
|
|
224
229
|
url: string,
|
|
225
230
|
context: object = {},
|
|
226
|
-
timestampMs: number = timeProvider.now()
|
|
231
|
+
timestampMs: number = this.timeProvider.now()
|
|
227
232
|
): Promise<void> => {
|
|
228
233
|
InternalLog.log(
|
|
229
234
|
`Starting RUM Resource #${key} ${method}: ${url}`,
|
|
@@ -240,7 +245,7 @@ class DdRumWrapper implements DdRumType {
|
|
|
240
245
|
kind: ResourceKind,
|
|
241
246
|
size: number = -1,
|
|
242
247
|
context: object = {},
|
|
243
|
-
timestampMs: number = timeProvider.now(),
|
|
248
|
+
timestampMs: number = this.timeProvider.now(),
|
|
244
249
|
resourceContext?: XMLHttpRequest
|
|
245
250
|
): Promise<void> => {
|
|
246
251
|
const mappedEvent = this.resourceEventMapper.applyEventMapper({
|
|
@@ -293,7 +298,7 @@ class DdRumWrapper implements DdRumType {
|
|
|
293
298
|
source: ErrorSource,
|
|
294
299
|
stacktrace: string,
|
|
295
300
|
context: object = {},
|
|
296
|
-
timestampMs: number = timeProvider.now()
|
|
301
|
+
timestampMs: number = this.timeProvider.now()
|
|
297
302
|
): Promise<void> => {
|
|
298
303
|
const mappedEvent = this.errorEventMapper.applyEventMapper({
|
|
299
304
|
message,
|
|
@@ -347,6 +352,13 @@ class DdRumWrapper implements DdRumType {
|
|
|
347
352
|
);
|
|
348
353
|
};
|
|
349
354
|
|
|
355
|
+
async getCurrentSessionId(): Promise<string | undefined> {
|
|
356
|
+
if (!DdSdkReactNative.isInitialized()) {
|
|
357
|
+
return undefined;
|
|
358
|
+
}
|
|
359
|
+
return this.nativeRum.getCurrentSessionId();
|
|
360
|
+
}
|
|
361
|
+
|
|
350
362
|
registerErrorEventMapper(errorEventMapper: ErrorEventMapper) {
|
|
351
363
|
this.errorEventMapper = generateErrorEventMapper(errorEventMapper);
|
|
352
364
|
}
|
|
@@ -0,0 +1,26 @@
|
|
|
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 type { Timestamp } from '../../utils/time-provider/TimeProvider';
|
|
8
|
+
import { TimeProvider } from '../../utils/time-provider/TimeProvider';
|
|
9
|
+
|
|
10
|
+
export default class MockTimeProvider extends TimeProvider {
|
|
11
|
+
unixMockedTime: number;
|
|
12
|
+
reactNativeMockedTime: number | null;
|
|
13
|
+
|
|
14
|
+
constructor(unixMockedTime: number, reactNativeMockedTime: number | null) {
|
|
15
|
+
super();
|
|
16
|
+
this.unixMockedTime = unixMockedTime;
|
|
17
|
+
this.reactNativeMockedTime = reactNativeMockedTime;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
getTimestamp(): Timestamp {
|
|
21
|
+
return {
|
|
22
|
+
unix: this.unixMockedTime,
|
|
23
|
+
reactNative: this.reactNativeMockedTime
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
}
|
|
@@ -7,6 +7,7 @@
|
|
|
7
7
|
|
|
8
8
|
import { NativeModules } from 'react-native';
|
|
9
9
|
|
|
10
|
+
import { DdSdkReactNative } from '../../DdSdkReactNative';
|
|
10
11
|
import { BufferSingleton } from '../../sdk/DatadogProvider/Buffer/BufferSingleton';
|
|
11
12
|
import { DdSdk } from '../../sdk/DdSdk';
|
|
12
13
|
import { DdRum } from '../DdRum';
|
|
@@ -15,9 +16,9 @@ import type { ErrorEventMapper } from '../eventMappers/errorEventMapper';
|
|
|
15
16
|
import type { ResourceEventMapper } from '../eventMappers/resourceEventMapper';
|
|
16
17
|
import { ErrorSource, PropagatorType, RumActionType } from '../types';
|
|
17
18
|
|
|
18
|
-
jest.mock('../../utils/
|
|
19
|
+
jest.mock('../../utils/time-provider/DefaultTimeProvider', () => {
|
|
19
20
|
return {
|
|
20
|
-
|
|
21
|
+
DefaultTimeProvider: jest.fn().mockImplementation(() => {
|
|
21
22
|
return { now: jest.fn().mockReturnValue(456) };
|
|
22
23
|
})
|
|
23
24
|
};
|
|
@@ -31,9 +32,14 @@ describe('DdRum', () => {
|
|
|
31
32
|
|
|
32
33
|
describe('DdRum.stopAction', () => {
|
|
33
34
|
test('calls the native SDK when called with new API', async () => {
|
|
34
|
-
await DdRum.stopAction(
|
|
35
|
+
await DdRum.stopAction(
|
|
36
|
+
RumActionType.SCROLL,
|
|
37
|
+
'page',
|
|
38
|
+
{ user: 'me' },
|
|
39
|
+
123
|
|
40
|
+
);
|
|
35
41
|
expect(NativeModules.DdRum.stopAction).toHaveBeenCalledWith(
|
|
36
|
-
|
|
42
|
+
RumActionType.SCROLL,
|
|
37
43
|
'page',
|
|
38
44
|
{ user: 'me' },
|
|
39
45
|
123
|
|
@@ -41,9 +47,9 @@ describe('DdRum', () => {
|
|
|
41
47
|
});
|
|
42
48
|
|
|
43
49
|
test('calls the native SDK when called with new API with default values', async () => {
|
|
44
|
-
await DdRum.stopAction(
|
|
50
|
+
await DdRum.stopAction(RumActionType.SCROLL, 'page');
|
|
45
51
|
expect(NativeModules.DdRum.stopAction).toHaveBeenCalledWith(
|
|
46
|
-
|
|
52
|
+
RumActionType.SCROLL,
|
|
47
53
|
'page',
|
|
48
54
|
{},
|
|
49
55
|
456
|
|
@@ -57,10 +63,10 @@ describe('DdRum', () => {
|
|
|
57
63
|
});
|
|
58
64
|
|
|
59
65
|
test('calls the native SDK when called with old API', async () => {
|
|
60
|
-
await DdRum.startAction(
|
|
66
|
+
await DdRum.startAction(RumActionType.SCROLL, 'page_old_api');
|
|
61
67
|
await DdRum.stopAction({ user: 'me' }, 789);
|
|
62
68
|
expect(NativeModules.DdRum.stopAction).toHaveBeenCalledWith(
|
|
63
|
-
|
|
69
|
+
RumActionType.SCROLL,
|
|
64
70
|
'page_old_api',
|
|
65
71
|
{ user: 'me' },
|
|
66
72
|
789
|
|
@@ -71,10 +77,10 @@ describe('DdRum', () => {
|
|
|
71
77
|
});
|
|
72
78
|
|
|
73
79
|
test('calls the native SDK when called with old API with default values', async () => {
|
|
74
|
-
await DdRum.startAction(
|
|
80
|
+
await DdRum.startAction(RumActionType.SCROLL, 'page_old_api');
|
|
75
81
|
await DdRum.stopAction();
|
|
76
82
|
expect(NativeModules.DdRum.stopAction).toHaveBeenCalledWith(
|
|
77
|
-
|
|
83
|
+
RumActionType.SCROLL,
|
|
78
84
|
'page_old_api',
|
|
79
85
|
{},
|
|
80
86
|
456
|
|
@@ -85,7 +91,7 @@ describe('DdRum', () => {
|
|
|
85
91
|
});
|
|
86
92
|
|
|
87
93
|
test('cleans the action data when stopAction is called', async () => {
|
|
88
|
-
await DdRum.startAction(
|
|
94
|
+
await DdRum.startAction(RumActionType.SCROLL, 'page_old_api');
|
|
89
95
|
await DdRum.stopAction();
|
|
90
96
|
await DdRum.stopAction();
|
|
91
97
|
expect(NativeModules.DdRum.stopAction).toHaveBeenCalledTimes(1);
|
|
@@ -101,7 +107,7 @@ describe('DdRum', () => {
|
|
|
101
107
|
it('M add error source type W addError()', async () => {
|
|
102
108
|
// Given
|
|
103
109
|
const message = 'Oops I did it again!';
|
|
104
|
-
const source =
|
|
110
|
+
const source = ErrorSource.SOURCE;
|
|
105
111
|
const stacktrace = 'doSomething() at ./path/to/file.js:67:3';
|
|
106
112
|
|
|
107
113
|
// When
|
|
@@ -123,7 +129,7 @@ describe('DdRum', () => {
|
|
|
123
129
|
it('M add error source type W addError() {with custom attributes}', async () => {
|
|
124
130
|
// Given
|
|
125
131
|
const message = 'Oops I did it again!';
|
|
126
|
-
const source =
|
|
132
|
+
const source = ErrorSource.SOURCE;
|
|
127
133
|
const stacktrace = 'doSomething() at ./path/to/file.js:67:3';
|
|
128
134
|
const random = Math.random();
|
|
129
135
|
const attributes = {
|
|
@@ -369,6 +375,26 @@ describe('DdRum', () => {
|
|
|
369
375
|
});
|
|
370
376
|
});
|
|
371
377
|
|
|
378
|
+
describe('DdRum.getCurrentSessionId', () => {
|
|
379
|
+
it('calls the native API if SDK is initialized', async () => {
|
|
380
|
+
DdSdkReactNative['_isInitialized'] = true;
|
|
381
|
+
const sessionId = await DdRum.getCurrentSessionId();
|
|
382
|
+
expect(NativeModules.DdRum.getCurrentSessionId).toHaveBeenCalled();
|
|
383
|
+
expect(sessionId).toBe('test-session-id');
|
|
384
|
+
});
|
|
385
|
+
});
|
|
386
|
+
|
|
387
|
+
describe('DdRum.getCurrentSessionId', () => {
|
|
388
|
+
it('returns undefined if SDK is not initialized', async () => {
|
|
389
|
+
DdSdkReactNative['_isInitialized'] = false;
|
|
390
|
+
const sessionId = await DdRum.getCurrentSessionId();
|
|
391
|
+
expect(
|
|
392
|
+
NativeModules.DdRum.getCurrentSessionId
|
|
393
|
+
).toHaveBeenCalledTimes(0);
|
|
394
|
+
expect(sessionId).toBe(undefined);
|
|
395
|
+
});
|
|
396
|
+
});
|
|
397
|
+
|
|
372
398
|
describe('PropagatorTypes', () => {
|
|
373
399
|
it('matches with the native name of propagators', () => {
|
|
374
400
|
/**
|
|
@@ -0,0 +1,23 @@
|
|
|
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 { DdRum } from '../DdRum';
|
|
8
|
+
import MockTimeProvider from '../__mocks__/MockTimeProvider';
|
|
9
|
+
|
|
10
|
+
jest.unmock('../../utils/time-provider/TimeProvider');
|
|
11
|
+
|
|
12
|
+
describe('DdRum', () => {
|
|
13
|
+
describe('setTimeProvider', () => {
|
|
14
|
+
it('overrides default time provider', async () => {
|
|
15
|
+
const mockTimeProvider = new MockTimeProvider(1000, 2000);
|
|
16
|
+
DdRum.setTimeProvider(mockTimeProvider);
|
|
17
|
+
|
|
18
|
+
const timestamp = DdRum['timeProvider'].getTimestamp();
|
|
19
|
+
expect(timestamp.unix).toBe(1000);
|
|
20
|
+
expect(timestamp.reactNative).toBe(2000);
|
|
21
|
+
});
|
|
22
|
+
});
|
|
23
|
+
});
|
package/src/rum/types.ts
CHANGED
|
@@ -147,6 +147,11 @@ export type DdRumType = {
|
|
|
147
147
|
* Stops the current RUM Session.
|
|
148
148
|
*/
|
|
149
149
|
stopSession(): Promise<void>;
|
|
150
|
+
|
|
151
|
+
/**
|
|
152
|
+
* Returns current session ID, or undefined if unavailable.
|
|
153
|
+
*/
|
|
154
|
+
getCurrentSessionId(): Promise<string | undefined>;
|
|
150
155
|
};
|
|
151
156
|
|
|
152
157
|
/**
|
|
@@ -54,7 +54,7 @@ export class BoundedBuffer extends DatadogBuffer {
|
|
|
54
54
|
if (this.buffer.length < this.bufferSize) {
|
|
55
55
|
this.buffer.push({ callback, _type: 'VOID' });
|
|
56
56
|
} else {
|
|
57
|
-
this.
|
|
57
|
+
this.logBufferOverflow();
|
|
58
58
|
}
|
|
59
59
|
|
|
60
60
|
return new Promise<void>(resolve => resolve(undefined));
|
|
@@ -71,21 +71,12 @@ export class BoundedBuffer extends DatadogBuffer {
|
|
|
71
71
|
});
|
|
72
72
|
this.idTable[bufferId] = null;
|
|
73
73
|
} else {
|
|
74
|
-
this.
|
|
74
|
+
this.logBufferOverflow();
|
|
75
75
|
}
|
|
76
76
|
|
|
77
77
|
return new Promise<string>(resolve => resolve(bufferId));
|
|
78
|
-
} catch (error) {
|
|
79
|
-
this.
|
|
80
|
-
'Could not generate enough random numbers',
|
|
81
|
-
getErrorStackTrace(error),
|
|
82
|
-
'RandomIdGenerationError'
|
|
83
|
-
);
|
|
84
|
-
// Not using InternalLog here as it is not yet instantiated
|
|
85
|
-
console.warn(
|
|
86
|
-
`[Datadog] Could not generate enough random numbers for RUM buffer. Please check that Math.random is not overwritten. Math.random returns: ${Math.random()}`
|
|
87
|
-
);
|
|
88
|
-
|
|
78
|
+
} catch (error: any) {
|
|
79
|
+
this.logRandomIdGenerationError(error);
|
|
89
80
|
return new Promise<string>(resolve => resolve(''));
|
|
90
81
|
}
|
|
91
82
|
};
|
|
@@ -101,7 +92,7 @@ export class BoundedBuffer extends DatadogBuffer {
|
|
|
101
92
|
_type: 'WITH_ID'
|
|
102
93
|
});
|
|
103
94
|
} else {
|
|
104
|
-
this.
|
|
95
|
+
this.logBufferOverflow();
|
|
105
96
|
}
|
|
106
97
|
|
|
107
98
|
return new Promise<void>(resolve => resolve(undefined));
|
|
@@ -164,6 +155,23 @@ export class BoundedBuffer extends DatadogBuffer {
|
|
|
164
155
|
this.drainTelemetry();
|
|
165
156
|
};
|
|
166
157
|
|
|
158
|
+
private logBufferOverflow() {
|
|
159
|
+
this.addTelemetryEvent('Buffer overflow', '', 'BufferOverflow');
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
private logRandomIdGenerationError = (error: any): void => {
|
|
163
|
+
this.addTelemetryEvent(
|
|
164
|
+
'Could not generate enough random numbers',
|
|
165
|
+
getErrorStackTrace(error),
|
|
166
|
+
'RandomIdGenerationError'
|
|
167
|
+
);
|
|
168
|
+
|
|
169
|
+
// Not using InternalLog here as it is not yet instantiated
|
|
170
|
+
console.warn(
|
|
171
|
+
`[Datadog] Could not generate enough random numbers for RUM buffer. Please check that Math.random is not overwritten. Math.random returns: ${Math.random()}`
|
|
172
|
+
);
|
|
173
|
+
};
|
|
174
|
+
|
|
167
175
|
private generateRandomBufferId = (): string => {
|
|
168
176
|
let tries = 0;
|
|
169
177
|
while (tries < 20) {
|
|
@@ -11,7 +11,7 @@ import { DdSdkReactNative } from '../../../DdSdkReactNative';
|
|
|
11
11
|
import { DdRum } from '../../../rum/DdRum';
|
|
12
12
|
import { RumActionType } from '../../../rum/types';
|
|
13
13
|
import { DdTrace } from '../../../trace/DdTrace';
|
|
14
|
-
import {
|
|
14
|
+
import { DefaultTimeProvider } from '../../../utils/time-provider/DefaultTimeProvider';
|
|
15
15
|
import { BufferSingleton } from '../Buffer/BufferSingleton';
|
|
16
16
|
import {
|
|
17
17
|
DatadogProvider,
|
|
@@ -24,15 +24,16 @@ import {
|
|
|
24
24
|
renderWithProvider
|
|
25
25
|
} from './__utils__/renderWithProvider';
|
|
26
26
|
|
|
27
|
-
jest.mock('../../../utils/
|
|
27
|
+
jest.mock('../../../utils/time-provider/DefaultTimeProvider', () => {
|
|
28
28
|
const now = jest.fn();
|
|
29
29
|
return {
|
|
30
|
-
|
|
30
|
+
DefaultTimeProvider: jest.fn().mockImplementation(() => {
|
|
31
31
|
return { now };
|
|
32
32
|
})
|
|
33
33
|
};
|
|
34
34
|
});
|
|
35
|
-
|
|
35
|
+
|
|
36
|
+
const nowMock = new DefaultTimeProvider().now;
|
|
36
37
|
|
|
37
38
|
const flushPromises = () =>
|
|
38
39
|
new Promise<void>(jest.requireActual('timers').setImmediate);
|
|
@@ -40,7 +41,7 @@ const flushPromises = () =>
|
|
|
40
41
|
describe('DatadogProvider', () => {
|
|
41
42
|
afterEach(() => {
|
|
42
43
|
jest.clearAllMocks();
|
|
43
|
-
DdSdkReactNative['
|
|
44
|
+
DdSdkReactNative['_isInitialized'] = false;
|
|
44
45
|
__internalResetIsInitializedForTesting();
|
|
45
46
|
BufferSingleton.reset();
|
|
46
47
|
(nowMock as any).mockReturnValue('timestamp_not_specified');
|
|
@@ -72,7 +73,7 @@ describe('DatadogProvider', () => {
|
|
|
72
73
|
"clientToken": "fakeToken",
|
|
73
74
|
"configurationForTelemetry": {
|
|
74
75
|
"initializationType": "SYNC",
|
|
75
|
-
"reactNativeVersion": "0.
|
|
76
|
+
"reactNativeVersion": "0.73.6",
|
|
76
77
|
"reactVersion": "18.2.0",
|
|
77
78
|
"trackErrors": true,
|
|
78
79
|
"trackInteractions": true,
|