@datadog/mobile-react-native 1.0.0-rc5 → 1.0.0-rc6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +46 -17
- package/android/gradle.properties +4 -4
- package/lib/commonjs/DdSdkReactNative.js +31 -31
- package/lib/commonjs/DdSdkReactNative.js.map +1 -1
- package/lib/commonjs/DdSdkReactNativeConfiguration.js +18 -7
- package/lib/commonjs/DdSdkReactNativeConfiguration.js.map +1 -1
- package/lib/commonjs/InternalLog.js +5 -5
- package/lib/commonjs/InternalLog.js.map +1 -1
- package/lib/commonjs/ProxyConfiguration.js.map +1 -1
- package/lib/commonjs/SdkVerbosity.js.map +1 -1
- package/lib/commonjs/TimeProvider.js +72 -0
- package/lib/commonjs/TimeProvider.js.map +1 -0
- package/lib/commonjs/Timer.js +10 -23
- package/lib/commonjs/Timer.js.map +1 -1
- package/lib/commonjs/TrackingConsent.js.map +1 -1
- package/lib/commonjs/foundation.js +19 -54
- package/lib/commonjs/foundation.js.map +1 -1
- package/lib/commonjs/index.js +21 -21
- package/lib/commonjs/index.js.map +1 -1
- package/lib/commonjs/internal.js +14 -0
- package/lib/commonjs/internal.js.map +1 -0
- package/lib/commonjs/rum/instrumentation/DdEventsInterceptor.js +16 -11
- package/lib/commonjs/rum/instrumentation/DdEventsInterceptor.js.map +1 -1
- package/lib/commonjs/rum/instrumentation/DdRumErrorTracking.js +19 -23
- package/lib/commonjs/rum/instrumentation/DdRumErrorTracking.js.map +1 -1
- package/lib/commonjs/rum/instrumentation/DdRumResourceTracking.js +60 -42
- package/lib/commonjs/rum/instrumentation/DdRumResourceTracking.js.map +1 -1
- package/lib/commonjs/rum/instrumentation/DdRumUserInteractionTracking.js +46 -19
- package/lib/commonjs/rum/instrumentation/DdRumUserInteractionTracking.js.map +1 -1
- package/lib/commonjs/rum/instrumentation/DdRumXhr.js +0 -4
- package/lib/commonjs/rum/instrumentation/NoOpEventsInterceptor.js +1 -1
- package/lib/commonjs/rum/instrumentation/NoOpEventsInterceptor.js.map +1 -1
- package/lib/commonjs/rum/instrumentation/ShallowObjectEqualityChecker.js +34 -0
- package/lib/commonjs/rum/instrumentation/ShallowObjectEqualityChecker.js.map +1 -0
- package/lib/commonjs/rum/instrumentation/TraceIdentifier.js.map +1 -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 +29 -29
- package/lib/module/DdSdkReactNative.js.map +1 -1
- package/lib/module/DdSdkReactNativeConfiguration.js +19 -8
- package/lib/module/DdSdkReactNativeConfiguration.js.map +1 -1
- package/lib/module/InternalLog.js +5 -5
- package/lib/module/InternalLog.js.map +1 -1
- package/lib/module/ProxyConfiguration.js.map +1 -1
- package/lib/module/SdkVerbosity.js.map +1 -1
- package/lib/module/TimeProvider.js +63 -0
- package/lib/module/TimeProvider.js.map +1 -0
- package/lib/module/Timer.js +14 -23
- package/lib/module/Timer.js.map +1 -1
- package/lib/module/TrackingConsent.js.map +1 -1
- package/lib/module/foundation.js +16 -39
- package/lib/module/foundation.js.map +1 -1
- package/lib/module/index.js +2 -2
- package/lib/module/index.js.map +1 -1
- package/lib/module/internal.js +2 -0
- package/lib/module/internal.js.map +1 -0
- package/lib/module/rum/instrumentation/DdEventsInterceptor.js +12 -10
- package/lib/module/rum/instrumentation/DdEventsInterceptor.js.map +1 -1
- package/lib/module/rum/instrumentation/DdRumErrorTracking.js +19 -23
- package/lib/module/rum/instrumentation/DdRumErrorTracking.js.map +1 -1
- package/lib/module/rum/instrumentation/DdRumResourceTracking.js +57 -38
- package/lib/module/rum/instrumentation/DdRumResourceTracking.js.map +1 -1
- package/lib/module/rum/instrumentation/DdRumUserInteractionTracking.js +44 -17
- package/lib/module/rum/instrumentation/DdRumUserInteractionTracking.js.map +1 -1
- package/lib/module/rum/instrumentation/DdRumXhr.js +1 -1
- package/lib/module/rum/instrumentation/NoOpEventsInterceptor.js +1 -1
- package/lib/module/rum/instrumentation/NoOpEventsInterceptor.js.map +1 -1
- package/lib/module/rum/instrumentation/ShallowObjectEqualityChecker.js +25 -0
- package/lib/module/rum/instrumentation/ShallowObjectEqualityChecker.js.map +1 -0
- package/lib/module/rum/instrumentation/TraceIdentifier.js.map +1 -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 +6 -6
- package/lib/typescript/DdSdkReactNativeConfiguration.d.ts +14 -3
- package/lib/typescript/TimeProvider.d.ts +20 -0
- package/lib/typescript/Timer.d.ts +3 -2
- package/lib/typescript/index.d.ts +2 -2
- package/lib/typescript/internal.d.ts +1 -0
- package/lib/typescript/rum/instrumentation/DdEventsInterceptor.d.ts +1 -0
- package/lib/typescript/rum/instrumentation/DdRumErrorTracking.d.ts +2 -2
- package/lib/typescript/rum/instrumentation/DdRumResourceTracking.d.ts +10 -9
- package/lib/typescript/rum/instrumentation/DdRumUserInteractionTracking.d.ts +3 -3
- package/lib/typescript/rum/instrumentation/DdRumXhr.d.ts +13 -3
- package/lib/typescript/rum/instrumentation/ShallowObjectEqualityChecker.d.ts +4 -0
- package/lib/typescript/version.d.ts +1 -1
- package/package.json +6 -3
- package/src/DdSdkReactNative.tsx +112 -70
- package/src/DdSdkReactNativeConfiguration.tsx +21 -13
- package/src/InternalLog.tsx +13 -16
- package/src/ProxyConfiguration.tsx +5 -5
- package/src/SdkVerbosity.tsx +4 -4
- package/src/TimeProvider.tsx +64 -0
- package/src/Timer.ts +20 -35
- package/src/TrackingConsent.tsx +3 -3
- package/src/__mocks__/InternalLog.tsx +9 -0
- package/src/__tests__/DdRumWrapper.test.tsx +40 -33
- package/src/__tests__/DdSdkReactNative.test.tsx +697 -513
- package/src/__tests__/InternalLog.test.tsx +114 -117
- package/src/__tests__/TimeProvider.test.tsx +75 -0
- package/src/__tests__/Timer.test.ts +148 -57
- package/src/__tests__/rum/instrumentation/DdEventsInterceptor.test.tsx +151 -92
- package/src/__tests__/rum/instrumentation/DdRumErrorTracking.test.tsx +168 -116
- package/src/__tests__/rum/instrumentation/DdRumResourceTracking.test.tsx +714 -644
- package/src/__tests__/rum/instrumentation/DdRumUserInteractionTracking.test.tsx +239 -85
- package/src/__tests__/rum/instrumentation/ShallowObjectEqualityChecker.test.ts +31 -0
- package/src/__tests__/rum/instrumentation/TraceIdentifier.test.tsx +13 -15
- package/src/__tests__/rum/instrumentation/__utils__/XMLHttpRequestMock.ts +97 -0
- package/src/foundation.tsx +13 -10
- package/src/index.tsx +13 -4
- package/src/internal.tsx +1 -0
- package/src/rum/instrumentation/DdEventsInterceptor.tsx +51 -35
- package/src/rum/instrumentation/DdRumErrorTracking.tsx +49 -44
- package/src/rum/instrumentation/DdRumResourceTracking.tsx +308 -238
- package/src/rum/instrumentation/DdRumUserInteractionTracking.tsx +72 -29
- package/src/rum/instrumentation/DdRumXhr.tsx +21 -11
- package/src/rum/instrumentation/EventsInterceptor.tsx +3 -3
- package/src/rum/instrumentation/NoOpEventsInterceptor.tsx +2 -2
- package/src/rum/instrumentation/ShallowObjectEqualityChecker.ts +24 -0
- package/src/rum/instrumentation/TraceIdentifier.tsx +19 -19
- package/src/types.tsx +199 -158
- package/src/version.ts +1 -1
|
@@ -1,9 +1,12 @@
|
|
|
1
|
+
import { TimeProvider } from './TimeProvider';
|
|
1
2
|
/**
|
|
2
3
|
* Simple timer which records time ticks. Shouldn't be re-used once stopped.
|
|
3
4
|
* All timestamps/durations returned are in milliseconds.
|
|
4
5
|
*/
|
|
5
6
|
export default class Timer {
|
|
7
|
+
private timeProvider;
|
|
6
8
|
private times;
|
|
9
|
+
constructor(timeProvider?: TimeProvider);
|
|
7
10
|
get startTime(): number;
|
|
8
11
|
get stopTime(): number;
|
|
9
12
|
start(): void;
|
|
@@ -14,7 +17,5 @@ export default class Timer {
|
|
|
14
17
|
timeAt(label: string): number;
|
|
15
18
|
reset(): void;
|
|
16
19
|
private durationBetweenTicks;
|
|
17
|
-
private performanceNow;
|
|
18
|
-
private canUsePerformanceNow;
|
|
19
20
|
private checkLabelExists;
|
|
20
21
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { DdLogs, DdTrace, DdRum } from './foundation';
|
|
2
1
|
import { DdSdkReactNativeConfiguration } from './DdSdkReactNativeConfiguration';
|
|
3
2
|
import { DdSdkReactNative } from './DdSdkReactNative';
|
|
4
3
|
import { ProxyConfiguration, ProxyType } from './ProxyConfiguration';
|
|
5
|
-
import { TrackingConsent } from './TrackingConsent';
|
|
6
4
|
import { SdkVerbosity } from './SdkVerbosity';
|
|
5
|
+
import { TrackingConsent } from './TrackingConsent';
|
|
6
|
+
import { DdLogs, DdTrace, DdRum } from './foundation';
|
|
7
7
|
export { DdLogs, DdTrace, DdRum, DdSdkReactNativeConfiguration, DdSdkReactNative, ProxyConfiguration, ProxyType, TrackingConsent, SdkVerbosity };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { InternalLog } from './InternalLog';
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type EventsInterceptor from './EventsInterceptor';
|
|
2
2
|
export declare const UNKNOWN_TARGET_NAME = "unknown_target";
|
|
3
3
|
export declare class DdEventsInterceptor implements EventsInterceptor {
|
|
4
|
+
static ACTION_EVENT_DROPPED_WARN_MESSAGE: string;
|
|
4
5
|
private debouncingStartedTimestamp;
|
|
5
6
|
interceptOnPress(...args: any[]): void;
|
|
6
7
|
private handleTargetEvent;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Provides RUM auto-instrumentation feature to track errors as RUM events.
|
|
3
|
-
*/
|
|
2
|
+
* Provides RUM auto-instrumentation feature to track errors as RUM events.
|
|
3
|
+
*/
|
|
4
4
|
export declare class DdRumErrorTracking {
|
|
5
5
|
private static isTracking;
|
|
6
6
|
private static isInDefaultErrorHandler;
|
|
@@ -3,24 +3,25 @@ export declare const TRACE_ID_HEADER_KEY = "x-datadog-trace-id";
|
|
|
3
3
|
export declare const PARENT_ID_HEADER_KEY = "x-datadog-parent-id";
|
|
4
4
|
export declare const ORIGIN_HEADER_KEY = "x-datadog-origin";
|
|
5
5
|
export declare const SAMPLING_PRIORITY_HEADER_KEY = "x-datadog-sampling-priority";
|
|
6
|
-
export declare const SAMPLED_HEADER_KEY = "x-datadog-sampled";
|
|
7
6
|
export declare const ORIGIN_RUM = "rum";
|
|
7
|
+
export declare const RESOURCE_SIZE_ERROR_MESSAGE = "Couldn't get resource size, because an error occured: ";
|
|
8
8
|
export declare function calculateResponseSize(xhr: XMLHttpRequest): number;
|
|
9
9
|
/**
|
|
10
|
-
* Provides RUM auto-instrumentation feature to track resources (fetch, XHR, axios) as RUM events.
|
|
11
|
-
*/
|
|
10
|
+
* Provides RUM auto-instrumentation feature to track resources (fetch, XHR, axios) as RUM events.
|
|
11
|
+
*/
|
|
12
12
|
export declare class DdRumResourceTracking {
|
|
13
13
|
private static isTracking;
|
|
14
|
+
private static tracingSamplingRate;
|
|
14
15
|
private static originalXhrOpen;
|
|
15
16
|
private static originalXhrSend;
|
|
16
17
|
/**
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
static startTracking(): void;
|
|
18
|
+
* Starts tracking resources and sends a RUM Resource event every time a network request is detected.
|
|
19
|
+
*/
|
|
20
|
+
static startTracking(tracingSamplingRate: number): void;
|
|
20
21
|
/**
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
static startTrackingInternal(xhrType:
|
|
22
|
+
* Starts tracking resources and sends a RUM Resource event every time a fetch or XHR call is detected.
|
|
23
|
+
*/
|
|
24
|
+
static startTrackingInternal(xhrType: typeof XMLHttpRequest, tracingSamplingRate: number): void;
|
|
24
25
|
static stopTracking(): void;
|
|
25
26
|
static proxyXhr(xhrType: any): void;
|
|
26
27
|
private static proxyOpen;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Provides RUM auto-instrumentation feature to track user interaction as RUM events.
|
|
3
|
-
* For now we are only covering the "onPress" events.
|
|
4
|
-
*/
|
|
2
|
+
* Provides RUM auto-instrumentation feature to track user interaction as RUM events.
|
|
3
|
+
* For now we are only covering the "onPress" events.
|
|
4
|
+
*/
|
|
5
5
|
export declare class DdRumUserInteractionTracking {
|
|
6
6
|
private static isTracking;
|
|
7
7
|
private static eventsInterceptor;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/// <reference types="react-native" />
|
|
2
|
-
import type Timer from
|
|
2
|
+
import type Timer from '../../Timer';
|
|
3
3
|
export interface DdRumXhr extends XMLHttpRequest {
|
|
4
4
|
_datadog_xhr: DdRumXhrContext;
|
|
5
5
|
}
|
|
@@ -8,6 +8,16 @@ export interface DdRumXhrContext {
|
|
|
8
8
|
url: string;
|
|
9
9
|
reported: boolean;
|
|
10
10
|
timer: Timer;
|
|
11
|
-
|
|
12
|
-
traceId: string;
|
|
11
|
+
tracingAttributes: DdRumResourceTracingAttributes;
|
|
13
12
|
}
|
|
13
|
+
export declare type DdRumResourceTracingAttributes = {
|
|
14
|
+
tracingStrategy: 'KEEP';
|
|
15
|
+
traceId: string;
|
|
16
|
+
spanId: string;
|
|
17
|
+
samplingPriorityHeader: '1';
|
|
18
|
+
} | {
|
|
19
|
+
tracingStrategy: 'DISCARD';
|
|
20
|
+
traceId?: void;
|
|
21
|
+
spanId?: void;
|
|
22
|
+
samplingPriorityHeader: '0';
|
|
23
|
+
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const version = "1.0.0-
|
|
1
|
+
export declare const version = "1.0.0-rc6";
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@datadog/mobile-react-native",
|
|
3
|
-
"version": "1.0.0-
|
|
3
|
+
"version": "1.0.0-rc6",
|
|
4
4
|
"description": "A client-side React Native module to interact with Datadog",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"datadog",
|
|
@@ -30,7 +30,7 @@
|
|
|
30
30
|
],
|
|
31
31
|
"types": "lib/typescript/index.d.ts",
|
|
32
32
|
"react-native": "src/index",
|
|
33
|
-
"source": "src
|
|
33
|
+
"source": "src",
|
|
34
34
|
"module": "lib/module/index",
|
|
35
35
|
"publishConfig": {
|
|
36
36
|
"access": "public"
|
|
@@ -44,6 +44,9 @@
|
|
|
44
44
|
"react": ">=16.13.1",
|
|
45
45
|
"react-native": ">=0.63.4 <1.0"
|
|
46
46
|
},
|
|
47
|
+
"devDependencies": {
|
|
48
|
+
"@testing-library/react-native": "7.0.2"
|
|
49
|
+
},
|
|
47
50
|
"jest": {
|
|
48
51
|
"preset": "react-native",
|
|
49
52
|
"modulePathIgnorePatterns": [
|
|
@@ -68,5 +71,5 @@
|
|
|
68
71
|
]
|
|
69
72
|
]
|
|
70
73
|
},
|
|
71
|
-
"gitHead": "
|
|
74
|
+
"gitHead": "db2b48ab61c67e64567b91fc5d858473bf64d448"
|
|
72
75
|
}
|
package/src/DdSdkReactNative.tsx
CHANGED
|
@@ -4,87 +4,111 @@
|
|
|
4
4
|
* Copyright 2016-Present Datadog, Inc.
|
|
5
5
|
*/
|
|
6
6
|
|
|
7
|
-
import type {DdSdkReactNativeConfiguration} from
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
10
|
-
import {
|
|
11
|
-
import {
|
|
12
|
-
import {
|
|
13
|
-
import
|
|
14
|
-
import {
|
|
15
|
-
import {
|
|
16
|
-
import {
|
|
17
|
-
import {
|
|
7
|
+
import type { DdSdkReactNativeConfiguration } from './DdSdkReactNativeConfiguration';
|
|
8
|
+
import { InternalLog } from './InternalLog';
|
|
9
|
+
import { ProxyType } from './ProxyConfiguration';
|
|
10
|
+
import { SdkVerbosity } from './SdkVerbosity';
|
|
11
|
+
import type { TrackingConsent } from './TrackingConsent';
|
|
12
|
+
import { DdSdk } from './foundation';
|
|
13
|
+
import { DdRumErrorTracking } from './rum/instrumentation/DdRumErrorTracking';
|
|
14
|
+
import { DdRumResourceTracking } from './rum/instrumentation/DdRumResourceTracking';
|
|
15
|
+
import { DdRumUserInteractionTracking } from './rum/instrumentation/DdRumUserInteractionTracking';
|
|
16
|
+
import { DdSdkConfiguration } from './types';
|
|
17
|
+
import { version as sdkVersion } from './version';
|
|
18
18
|
|
|
19
19
|
/**
|
|
20
20
|
* This class initializes the Datadog SDK, and sets up communication with the server.
|
|
21
21
|
*/
|
|
22
22
|
export class DdSdkReactNative {
|
|
23
|
-
|
|
24
|
-
private static readonly
|
|
25
|
-
private static readonly
|
|
26
|
-
private static readonly
|
|
27
|
-
private static readonly
|
|
28
|
-
|
|
23
|
+
private static readonly DD_SOURCE_KEY = '_dd.source';
|
|
24
|
+
private static readonly DD_SDK_VERSION = '_dd.sdk_version';
|
|
25
|
+
private static readonly DD_SERVICE_NAME = '_dd.service_name';
|
|
26
|
+
private static readonly DD_SDK_VERBOSITY_KEY = '_dd.sdk_verbosity';
|
|
27
|
+
private static readonly DD_NATIVE_VIEW_TRACKING_KEY =
|
|
28
|
+
'_dd.native_view_tracking';
|
|
29
29
|
|
|
30
30
|
// Proxy
|
|
31
|
-
private static readonly DD_PROXY_TYPE_KEY =
|
|
32
|
-
private static readonly DD_PROXY_ADDRESS_KEY =
|
|
33
|
-
private static readonly DD_PROXY_PORT_KEY =
|
|
34
|
-
private static readonly DD_PROXY_USERNAME_KEY =
|
|
35
|
-
private static readonly DD_PROXY_PASSWORD_KEY =
|
|
36
|
-
|
|
37
|
-
private static readonly DD_NATIVE_LONG_TASK_THRESHOLD_KEY = "_dd.long_task.threshold"
|
|
38
|
-
private static readonly NATIVE_LONG_TASK_THRESHOLD_MS = 200
|
|
31
|
+
private static readonly DD_PROXY_TYPE_KEY = '_dd.proxy.type';
|
|
32
|
+
private static readonly DD_PROXY_ADDRESS_KEY = '_dd.proxy.address';
|
|
33
|
+
private static readonly DD_PROXY_PORT_KEY = '_dd.proxy.port';
|
|
34
|
+
private static readonly DD_PROXY_USERNAME_KEY = '_dd.proxy.username';
|
|
35
|
+
private static readonly DD_PROXY_PASSWORD_KEY = '_dd.proxy.password';
|
|
39
36
|
|
|
37
|
+
private static readonly DD_NATIVE_LONG_TASK_THRESHOLD_KEY =
|
|
38
|
+
'_dd.long_task.threshold';
|
|
39
|
+
private static readonly NATIVE_LONG_TASK_THRESHOLD_MS = 200;
|
|
40
40
|
|
|
41
|
-
private static wasInitialized = false
|
|
41
|
+
private static wasInitialized = false;
|
|
42
42
|
|
|
43
43
|
/**
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
static initialize(
|
|
44
|
+
* Initializes the Datadog SDK.
|
|
45
|
+
* @param configuration the configuration for the SDK library
|
|
46
|
+
* @returns a Promise.
|
|
47
|
+
*/
|
|
48
|
+
static initialize(
|
|
49
|
+
configuration: DdSdkReactNativeConfiguration
|
|
50
|
+
): Promise<void> {
|
|
49
51
|
return new Promise<void>((resolve, reject) => {
|
|
50
52
|
if (DdSdkReactNative.wasInitialized) {
|
|
51
|
-
InternalLog.log(
|
|
52
|
-
|
|
53
|
-
|
|
53
|
+
InternalLog.log(
|
|
54
|
+
"Can't initialize Datadog, SDK was already initialized",
|
|
55
|
+
SdkVerbosity.WARN
|
|
56
|
+
);
|
|
57
|
+
resolve();
|
|
58
|
+
return;
|
|
54
59
|
}
|
|
55
60
|
|
|
56
|
-
InternalLog.verbosity = configuration.verbosity
|
|
57
|
-
|
|
58
|
-
configuration.additionalConfig[DdSdkReactNative.DD_SOURCE_KEY] =
|
|
59
|
-
|
|
60
|
-
configuration.additionalConfig[
|
|
61
|
-
|
|
62
|
-
|
|
61
|
+
InternalLog.verbosity = configuration.verbosity;
|
|
62
|
+
|
|
63
|
+
configuration.additionalConfig[DdSdkReactNative.DD_SOURCE_KEY] =
|
|
64
|
+
'react-native';
|
|
65
|
+
configuration.additionalConfig[
|
|
66
|
+
DdSdkReactNative.DD_SDK_VERSION
|
|
67
|
+
] = sdkVersion;
|
|
68
|
+
configuration.additionalConfig[
|
|
69
|
+
DdSdkReactNative.DD_NATIVE_VIEW_TRACKING_KEY
|
|
70
|
+
] = configuration.nativeViewTracking;
|
|
71
|
+
if (configuration.verbosity) {
|
|
72
|
+
configuration.additionalConfig[
|
|
73
|
+
DdSdkReactNative.DD_SDK_VERBOSITY_KEY
|
|
74
|
+
] = configuration.verbosity;
|
|
63
75
|
}
|
|
64
76
|
|
|
65
77
|
if (configuration.proxyConfig) {
|
|
66
78
|
const additionalConfig = configuration.additionalConfig;
|
|
67
79
|
const proxyConfig = configuration.proxyConfig;
|
|
68
80
|
|
|
69
|
-
additionalConfig[DdSdkReactNative.DD_PROXY_TYPE_KEY] =
|
|
70
|
-
|
|
71
|
-
additionalConfig[DdSdkReactNative.
|
|
81
|
+
additionalConfig[DdSdkReactNative.DD_PROXY_TYPE_KEY] =
|
|
82
|
+
proxyConfig.type;
|
|
83
|
+
additionalConfig[DdSdkReactNative.DD_PROXY_ADDRESS_KEY] =
|
|
84
|
+
proxyConfig.address;
|
|
85
|
+
additionalConfig[DdSdkReactNative.DD_PROXY_PORT_KEY] =
|
|
86
|
+
proxyConfig.port;
|
|
72
87
|
if (proxyConfig.username && proxyConfig.password) {
|
|
73
|
-
if (proxyConfig.type
|
|
74
|
-
console.warn(
|
|
88
|
+
if (proxyConfig.type === ProxyType.SOCKS) {
|
|
89
|
+
console.warn(
|
|
90
|
+
"SOCKS proxy configuration doesn't support Basic authentication."
|
|
91
|
+
);
|
|
75
92
|
} else {
|
|
76
|
-
additionalConfig[
|
|
77
|
-
|
|
93
|
+
additionalConfig[
|
|
94
|
+
DdSdkReactNative.DD_PROXY_USERNAME_KEY
|
|
95
|
+
] = proxyConfig.username;
|
|
96
|
+
additionalConfig[
|
|
97
|
+
DdSdkReactNative.DD_PROXY_PASSWORD_KEY
|
|
98
|
+
] = proxyConfig.password;
|
|
78
99
|
}
|
|
79
100
|
}
|
|
80
101
|
}
|
|
81
102
|
|
|
82
103
|
if (configuration.serviceName) {
|
|
83
|
-
configuration.additionalConfig[
|
|
104
|
+
configuration.additionalConfig[
|
|
105
|
+
DdSdkReactNative.DD_SERVICE_NAME
|
|
106
|
+
] = configuration.serviceName;
|
|
84
107
|
}
|
|
85
108
|
|
|
86
|
-
configuration.additionalConfig[
|
|
87
|
-
|
|
109
|
+
configuration.additionalConfig[
|
|
110
|
+
DdSdkReactNative.DD_NATIVE_LONG_TASK_THRESHOLD_KEY
|
|
111
|
+
] = DdSdkReactNative.NATIVE_LONG_TASK_THRESHOLD_MS;
|
|
88
112
|
|
|
89
113
|
DdSdk.initialize(
|
|
90
114
|
new DdSdkConfiguration(
|
|
@@ -92,20 +116,28 @@ export class DdSdkReactNative {
|
|
|
92
116
|
configuration.env,
|
|
93
117
|
configuration.applicationId,
|
|
94
118
|
configuration.nativeCrashReportEnabled,
|
|
95
|
-
configuration.sampleRate
|
|
119
|
+
configuration.sampleRate === undefined
|
|
120
|
+
? configuration.sessionSamplingRate
|
|
121
|
+
: configuration.sampleRate,
|
|
96
122
|
configuration.site,
|
|
97
123
|
configuration.trackingConsent,
|
|
98
124
|
configuration.additionalConfig
|
|
99
125
|
)
|
|
100
|
-
).then(
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
126
|
+
).then(
|
|
127
|
+
() => {
|
|
128
|
+
InternalLog.log(
|
|
129
|
+
'Datadog SDK was initialized',
|
|
130
|
+
SdkVerbosity.INFO
|
|
131
|
+
);
|
|
132
|
+
DdSdkReactNative.enableFeatures(configuration);
|
|
133
|
+
DdSdkReactNative.wasInitialized = true;
|
|
134
|
+
resolve();
|
|
135
|
+
},
|
|
136
|
+
rejection => {
|
|
137
|
+
reject(rejection);
|
|
138
|
+
}
|
|
139
|
+
);
|
|
140
|
+
});
|
|
109
141
|
}
|
|
110
142
|
|
|
111
143
|
/**
|
|
@@ -115,8 +147,11 @@ export class DdSdkReactNative {
|
|
|
115
147
|
*/
|
|
116
148
|
// eslint-disable-next-line @typescript-eslint/ban-types
|
|
117
149
|
static setAttributes(attributes: object): Promise<void> {
|
|
118
|
-
InternalLog.log(
|
|
119
|
-
|
|
150
|
+
InternalLog.log(
|
|
151
|
+
`Setting attributes ${JSON.stringify(attributes)}`,
|
|
152
|
+
SdkVerbosity.DEBUG
|
|
153
|
+
);
|
|
154
|
+
return DdSdk.setAttributes(attributes);
|
|
120
155
|
}
|
|
121
156
|
|
|
122
157
|
/**
|
|
@@ -126,8 +161,11 @@ export class DdSdkReactNative {
|
|
|
126
161
|
*/
|
|
127
162
|
// eslint-disable-next-line @typescript-eslint/ban-types
|
|
128
163
|
static setUser(user: object): Promise<void> {
|
|
129
|
-
InternalLog.log(
|
|
130
|
-
|
|
164
|
+
InternalLog.log(
|
|
165
|
+
`Setting user ${JSON.stringify(user)}`,
|
|
166
|
+
SdkVerbosity.DEBUG
|
|
167
|
+
);
|
|
168
|
+
return DdSdk.setUser(user);
|
|
131
169
|
}
|
|
132
170
|
|
|
133
171
|
/**
|
|
@@ -136,21 +174,25 @@ export class DdSdkReactNative {
|
|
|
136
174
|
* @returns a Promise.
|
|
137
175
|
*/
|
|
138
176
|
static setTrackingConsent(consent: TrackingConsent): Promise<void> {
|
|
139
|
-
InternalLog.log(
|
|
140
|
-
return DdSdk.setTrackingConsent(consent)
|
|
177
|
+
InternalLog.log(`Setting consent ${consent}`, SdkVerbosity.DEBUG);
|
|
178
|
+
return DdSdk.setTrackingConsent(consent);
|
|
141
179
|
}
|
|
142
180
|
|
|
143
|
-
private static enableFeatures(
|
|
181
|
+
private static enableFeatures(
|
|
182
|
+
configuration: DdSdkReactNativeConfiguration
|
|
183
|
+
) {
|
|
144
184
|
if (configuration.trackInteractions) {
|
|
145
185
|
DdRumUserInteractionTracking.startTracking();
|
|
146
186
|
}
|
|
147
187
|
|
|
148
188
|
if (configuration.trackResources) {
|
|
149
|
-
DdRumResourceTracking.startTracking(
|
|
189
|
+
DdRumResourceTracking.startTracking(
|
|
190
|
+
configuration.resourceTracingSamplingRate
|
|
191
|
+
);
|
|
150
192
|
}
|
|
151
193
|
|
|
152
194
|
if (configuration.trackErrors) {
|
|
153
195
|
DdRumErrorTracking.startTracking();
|
|
154
196
|
}
|
|
155
197
|
}
|
|
156
|
-
}
|
|
198
|
+
}
|
|
@@ -4,25 +4,35 @@
|
|
|
4
4
|
* Copyright 2016-Present Datadog, Inc.
|
|
5
5
|
*/
|
|
6
6
|
|
|
7
|
-
import { TrackingConsent } from './TrackingConsent'
|
|
8
|
-
import type { SdkVerbosity } from './SdkVerbosity'
|
|
9
7
|
import type { ProxyConfiguration } from './ProxyConfiguration';
|
|
8
|
+
import type { SdkVerbosity } from './SdkVerbosity';
|
|
9
|
+
import { TrackingConsent } from './TrackingConsent';
|
|
10
10
|
|
|
11
11
|
/**
|
|
12
12
|
* The SDK configuration class.
|
|
13
13
|
* It will be used to configure the SDK functionality at initialization.
|
|
14
14
|
*/
|
|
15
15
|
export class DdSdkReactNativeConfiguration {
|
|
16
|
-
|
|
17
16
|
public nativeCrashReportEnabled: boolean = false;
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
public
|
|
22
|
-
|
|
23
|
-
|
|
17
|
+
/**
|
|
18
|
+
* @deprecated `sampleRate` has been replaced by `sessionSamplingRate` to avoid confusion with `resourceTracingSamplingRate` and will be removed in a future release.
|
|
19
|
+
*/
|
|
20
|
+
public sampleRate?: number;
|
|
21
|
+
/**
|
|
22
|
+
* Percentage of sampled RUM sessions. Range `0`-`100`.
|
|
23
|
+
*/
|
|
24
|
+
public sessionSamplingRate: number = 100.0;
|
|
25
|
+
/**
|
|
26
|
+
* Percentage of tracing integrations for network calls between your app and your backend. Range `0`-`100`.
|
|
27
|
+
*/
|
|
28
|
+
public resourceTracingSamplingRate: number = 20.0;
|
|
29
|
+
public site: string = 'US';
|
|
30
|
+
public verbosity: SdkVerbosity | undefined = undefined;
|
|
31
|
+
public nativeViewTracking: boolean = false;
|
|
32
|
+
public proxyConfig?: ProxyConfiguration = undefined;
|
|
33
|
+
public serviceName?: string = undefined;
|
|
24
34
|
|
|
25
|
-
public additionalConfig: {[k: string]: any} = {};
|
|
35
|
+
public additionalConfig: { [k: string]: any } = {};
|
|
26
36
|
|
|
27
37
|
constructor(
|
|
28
38
|
readonly clientToken: string,
|
|
@@ -32,7 +42,5 @@ export class DdSdkReactNativeConfiguration {
|
|
|
32
42
|
readonly trackResources: boolean = false,
|
|
33
43
|
readonly trackErrors: boolean = false,
|
|
34
44
|
readonly trackingConsent: TrackingConsent = TrackingConsent.GRANTED
|
|
35
|
-
) {
|
|
36
|
-
|
|
37
|
-
}
|
|
45
|
+
) {}
|
|
38
46
|
}
|
package/src/InternalLog.tsx
CHANGED
|
@@ -4,10 +4,9 @@
|
|
|
4
4
|
* Copyright 2016-Present Datadog, Inc.
|
|
5
5
|
*/
|
|
6
6
|
|
|
7
|
-
import {SdkVerbosity} from './SdkVerbosity'
|
|
7
|
+
import { SdkVerbosity } from './SdkVerbosity';
|
|
8
8
|
|
|
9
9
|
export class InternalLog {
|
|
10
|
-
|
|
11
10
|
private static levelMap = new Map<SdkVerbosity, number>([
|
|
12
11
|
[SdkVerbosity.DEBUG, 1],
|
|
13
12
|
[SdkVerbosity.INFO, 2],
|
|
@@ -15,9 +14,9 @@ export class InternalLog {
|
|
|
15
14
|
[SdkVerbosity.ERROR, 4]
|
|
16
15
|
]);
|
|
17
16
|
|
|
18
|
-
public static verbosity: SdkVerbosity|undefined = undefined
|
|
17
|
+
public static verbosity: SdkVerbosity | undefined = undefined;
|
|
19
18
|
|
|
20
|
-
public static log
|
|
19
|
+
public static log(message: string, verbosity: SdkVerbosity): void {
|
|
21
20
|
if (InternalLog.verbosity === undefined) {
|
|
22
21
|
return;
|
|
23
22
|
}
|
|
@@ -26,23 +25,21 @@ export class InternalLog {
|
|
|
26
25
|
if (allowedLevel === undefined || requiredLevel === undefined) {
|
|
27
26
|
return;
|
|
28
27
|
}
|
|
29
|
-
const prefixedMessage =
|
|
30
|
-
if (verbosity
|
|
31
|
-
console.error(prefixedMessage)
|
|
28
|
+
const prefixedMessage = `DATADOG: ${message}`;
|
|
29
|
+
if (verbosity === SdkVerbosity.ERROR && requiredLevel >= allowedLevel) {
|
|
30
|
+
console.error(prefixedMessage);
|
|
32
31
|
}
|
|
33
32
|
|
|
34
|
-
if (verbosity
|
|
35
|
-
console.warn(prefixedMessage)
|
|
33
|
+
if (verbosity === SdkVerbosity.WARN && requiredLevel >= allowedLevel) {
|
|
34
|
+
console.warn(prefixedMessage);
|
|
36
35
|
}
|
|
37
36
|
|
|
38
|
-
if (verbosity
|
|
39
|
-
console.info(prefixedMessage)
|
|
37
|
+
if (verbosity === SdkVerbosity.INFO && requiredLevel >= allowedLevel) {
|
|
38
|
+
console.info(prefixedMessage);
|
|
40
39
|
}
|
|
41
40
|
|
|
42
|
-
if (verbosity
|
|
43
|
-
console.debug(prefixedMessage)
|
|
41
|
+
if (verbosity === SdkVerbosity.DEBUG && requiredLevel >= allowedLevel) {
|
|
42
|
+
console.debug(prefixedMessage);
|
|
44
43
|
}
|
|
45
44
|
}
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
}
|
|
45
|
+
}
|
|
@@ -25,13 +25,13 @@ class ProxyConfiguration {
|
|
|
25
25
|
* Password for Basic authentication scheme.
|
|
26
26
|
*/
|
|
27
27
|
readonly password?: string
|
|
28
|
-
) {
|
|
28
|
+
) {}
|
|
29
29
|
}
|
|
30
30
|
|
|
31
31
|
enum ProxyType {
|
|
32
|
-
HTTP =
|
|
33
|
-
HTTPS =
|
|
34
|
-
SOCKS =
|
|
32
|
+
HTTP = 'http',
|
|
33
|
+
HTTPS = 'https',
|
|
34
|
+
SOCKS = 'socks'
|
|
35
35
|
}
|
|
36
36
|
|
|
37
|
-
export { ProxyConfiguration, ProxyType }
|
|
37
|
+
export { ProxyConfiguration, ProxyType };
|
package/src/SdkVerbosity.tsx
CHANGED
|
@@ -0,0 +1,64 @@
|
|
|
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
|
+
/**
|
|
8
|
+
* A Timestamp structure holding the
|
|
9
|
+
*/
|
|
10
|
+
export type Timestamp = {
|
|
11
|
+
// Result of Date API. Unix timestamp in ms.
|
|
12
|
+
unix: number;
|
|
13
|
+
// Result of performance.now API. Timestamp in ms (with microsecond precision)
|
|
14
|
+
// since JS context start.
|
|
15
|
+
react_native: number | null;
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Simple class providing timestamps in milliseconds.
|
|
20
|
+
* If available, it will use the `performance.now()` method, and will fallback on `Date.now()` otherwise.
|
|
21
|
+
*/
|
|
22
|
+
export class TimeProvider {
|
|
23
|
+
private canUsePerformanceNow =
|
|
24
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
25
|
+
// @ts-ignore
|
|
26
|
+
global.performance && typeof performance.now === 'function';
|
|
27
|
+
|
|
28
|
+
/** Keeps an average offset between the unix time and the provided timestamp. */
|
|
29
|
+
private baseOffset: number;
|
|
30
|
+
|
|
31
|
+
constructor() {
|
|
32
|
+
const timestamp = this.getTimestamp();
|
|
33
|
+
if (timestamp.react_native == null) {
|
|
34
|
+
this.baseOffset = 0;
|
|
35
|
+
} else {
|
|
36
|
+
this.baseOffset = timestamp.unix - timestamp.react_native;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
getTimestamp(): Timestamp {
|
|
41
|
+
return {
|
|
42
|
+
unix: Date.now(),
|
|
43
|
+
react_native: this.performanceNow()
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
now(): number {
|
|
48
|
+
const timestamp = this.getTimestamp();
|
|
49
|
+
if (timestamp.react_native == null) {
|
|
50
|
+
return timestamp.unix;
|
|
51
|
+
} else {
|
|
52
|
+
return this.baseOffset + timestamp.react_native;
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
private performanceNow(): number | null {
|
|
57
|
+
if (this.canUsePerformanceNow) {
|
|
58
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
59
|
+
// @ts-ignore
|
|
60
|
+
return performance.now();
|
|
61
|
+
}
|
|
62
|
+
return null;
|
|
63
|
+
}
|
|
64
|
+
}
|