@datadog/mobile-react-native 1.0.0-rc3 → 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/DatadogSDKReactNative.podspec +1 -1
- package/README.md +47 -16
- package/android/build.gradle +2 -3
- package/android/gradle.properties +4 -4
- package/android/src/main/java/com/datadog/reactnative/DdRum.kt +25 -24
- package/android/src/main/java/com/datadog/reactnative/DdTrace.kt +6 -6
- package/ios/Sources/DdRum.m +10 -9
- package/ios/Sources/DdRum.swift +24 -24
- package/ios/Sources/DdTrace.m +2 -2
- package/ios/Sources/DdTrace.swift +6 -6
- package/lib/commonjs/DdSdkReactNative.js +42 -22
- package/lib/commonjs/DdSdkReactNative.js.map +1 -1
- package/lib/commonjs/DdSdkReactNativeConfiguration.js +17 -2
- package/lib/commonjs/DdSdkReactNativeConfiguration.js.map +1 -1
- package/lib/commonjs/InternalLog.js +51 -0
- package/lib/commonjs/InternalLog.js.map +1 -0
- package/lib/commonjs/ProxyConfiguration.js.map +1 -1
- package/lib/commonjs/SdkVerbosity.js +26 -0
- package/lib/commonjs/SdkVerbosity.js.map +1 -0
- 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 +62 -40
- package/lib/commonjs/foundation.js.map +1 -1
- package/lib/commonjs/index.js +26 -18
- 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 +14 -5
- package/lib/commonjs/rum/instrumentation/DdEventsInterceptor.js.map +1 -1
- package/lib/commonjs/rum/instrumentation/DdRumErrorTracking.js +51 -20
- package/lib/commonjs/rum/instrumentation/DdRumErrorTracking.js.map +1 -1
- package/lib/commonjs/rum/instrumentation/DdRumResourceTracking.js +141 -30
- package/lib/commonjs/rum/instrumentation/DdRumResourceTracking.js.map +1 -1
- package/lib/commonjs/rum/instrumentation/DdRumUserInteractionTracking.js +46 -7
- package/lib/commonjs/rum/instrumentation/DdRumUserInteractionTracking.js.map +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 +10 -0
- package/lib/commonjs/version.js.map +1 -0
- package/lib/module/DdSdkReactNative.js +34 -22
- package/lib/module/DdSdkReactNative.js.map +1 -1
- package/lib/module/DdSdkReactNativeConfiguration.js +18 -3
- package/lib/module/DdSdkReactNativeConfiguration.js.map +1 -1
- package/lib/module/InternalLog.js +46 -0
- package/lib/module/InternalLog.js.map +1 -0
- package/lib/module/ProxyConfiguration.js.map +1 -1
- package/lib/module/SdkVerbosity.js +18 -0
- package/lib/module/SdkVerbosity.js.map +1 -0
- 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 +42 -40
- 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/internal.js +2 -0
- package/lib/module/internal.js.map +1 -0
- package/lib/module/rum/instrumentation/DdEventsInterceptor.js +11 -5
- package/lib/module/rum/instrumentation/DdEventsInterceptor.js.map +1 -1
- package/lib/module/rum/instrumentation/DdRumErrorTracking.js +46 -20
- package/lib/module/rum/instrumentation/DdRumErrorTracking.js.map +1 -1
- package/lib/module/rum/instrumentation/DdRumResourceTracking.js +133 -29
- package/lib/module/rum/instrumentation/DdRumResourceTracking.js.map +1 -1
- package/lib/module/rum/instrumentation/DdRumUserInteractionTracking.js +41 -6
- package/lib/module/rum/instrumentation/DdRumUserInteractionTracking.js.map +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 +3 -0
- package/lib/module/version.js.map +1 -0
- package/lib/typescript/DdSdkReactNative.d.ts +7 -6
- package/lib/typescript/DdSdkReactNativeConfiguration.d.ts +15 -4
- package/lib/typescript/InternalLog.d.ts +6 -0
- package/lib/typescript/SdkVerbosity.d.ts +9 -0
- package/lib/typescript/TimeProvider.d.ts +20 -0
- package/lib/typescript/Timer.d.ts +3 -2
- package/lib/typescript/index.d.ts +3 -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 +3 -2
- package/lib/typescript/rum/instrumentation/DdRumResourceTracking.d.ts +13 -8
- 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/types.d.ts +12 -11
- package/lib/typescript/version.d.ts +1 -0
- package/package.json +7 -4
- package/src/DdSdkReactNative.tsx +112 -58
- package/src/DdSdkReactNativeConfiguration.tsx +22 -14
- package/src/InternalLog.tsx +45 -0
- package/src/ProxyConfiguration.tsx +5 -5
- package/src/{NativeSdkVerbosity.tsx → SdkVerbosity.tsx} +6 -6
- 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 +98 -0
- package/src/__tests__/DdSdkReactNative.test.tsx +699 -500
- package/src/__tests__/InternalLog.test.tsx +379 -0
- 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 +243 -76
- package/src/__tests__/rum/instrumentation/DdRumResourceTracking.test.tsx +723 -403
- 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 +55 -42
- package/src/index.tsx +13 -3
- package/src/internal.tsx +1 -0
- package/src/rum/instrumentation/DdEventsInterceptor.tsx +51 -35
- package/src/rum/instrumentation/DdRumErrorTracking.tsx +75 -42
- package/src/rum/instrumentation/DdRumResourceTracking.tsx +312 -166
- package/src/rum/instrumentation/DdRumUserInteractionTracking.tsx +72 -25
- 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 -157
- package/src/version.ts +2 -0
- package/lib/commonjs/NativeSdkVerbosity.js +0 -26
- package/lib/commonjs/NativeSdkVerbosity.js.map +0 -1
- package/lib/module/NativeSdkVerbosity.js +0 -18
- package/lib/module/NativeSdkVerbosity.js.map +0 -1
- package/lib/typescript/NativeSdkVerbosity.d.ts +0 -9
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A Timestamp structure holding the
|
|
3
|
+
*/
|
|
4
|
+
export declare type Timestamp = {
|
|
5
|
+
unix: number;
|
|
6
|
+
react_native: number | null;
|
|
7
|
+
};
|
|
8
|
+
/**
|
|
9
|
+
* Simple class providing timestamps in milliseconds.
|
|
10
|
+
* If available, it will use the `performance.now()` method, and will fallback on `Date.now()` otherwise.
|
|
11
|
+
*/
|
|
12
|
+
export declare class TimeProvider {
|
|
13
|
+
private canUsePerformanceNow;
|
|
14
|
+
/** Keeps an average offset between the unix time and the provided timestamp. */
|
|
15
|
+
private baseOffset;
|
|
16
|
+
constructor();
|
|
17
|
+
getTimestamp(): Timestamp;
|
|
18
|
+
now(): number;
|
|
19
|
+
private performanceNow;
|
|
20
|
+
}
|
|
@@ -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,6 +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';
|
|
4
|
+
import { SdkVerbosity } from './SdkVerbosity';
|
|
5
5
|
import { TrackingConsent } from './TrackingConsent';
|
|
6
|
-
|
|
6
|
+
import { DdLogs, DdTrace, DdRum } from './foundation';
|
|
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;
|
|
@@ -12,5 +12,6 @@ export declare class DdRumErrorTracking {
|
|
|
12
12
|
static startTracking(): void;
|
|
13
13
|
static onGlobalError(error: any, isFatal?: boolean): void;
|
|
14
14
|
static onConsoleError(...params: unknown[]): void;
|
|
15
|
+
private static getErrorMessage;
|
|
15
16
|
private static getErrorStackTrace;
|
|
16
17
|
}
|
|
@@ -1,22 +1,27 @@
|
|
|
1
|
+
/// <reference types="react-native" />
|
|
1
2
|
export declare const TRACE_ID_HEADER_KEY = "x-datadog-trace-id";
|
|
2
3
|
export declare const PARENT_ID_HEADER_KEY = "x-datadog-parent-id";
|
|
3
4
|
export declare const ORIGIN_HEADER_KEY = "x-datadog-origin";
|
|
5
|
+
export declare const SAMPLING_PRIORITY_HEADER_KEY = "x-datadog-sampling-priority";
|
|
4
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
|
+
export declare function calculateResponseSize(xhr: XMLHttpRequest): number;
|
|
5
9
|
/**
|
|
6
|
-
* Provides RUM auto-instrumentation feature to track resources (fetch, XHR, axios) as RUM events.
|
|
7
|
-
*/
|
|
10
|
+
* Provides RUM auto-instrumentation feature to track resources (fetch, XHR, axios) as RUM events.
|
|
11
|
+
*/
|
|
8
12
|
export declare class DdRumResourceTracking {
|
|
9
13
|
private static isTracking;
|
|
14
|
+
private static tracingSamplingRate;
|
|
10
15
|
private static originalXhrOpen;
|
|
11
16
|
private static originalXhrSend;
|
|
12
17
|
/**
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
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;
|
|
16
21
|
/**
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
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;
|
|
20
25
|
static stopTracking(): void;
|
|
21
26
|
static proxyXhr(xhrType: any): void;
|
|
22
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
|
+
};
|
|
@@ -74,14 +74,14 @@ export declare type DdTraceType = {
|
|
|
74
74
|
* Start a span, and returns a unique identifier for the span.
|
|
75
75
|
* @param operation: The operation name of the span.
|
|
76
76
|
* @param context: The additional context to send.
|
|
77
|
-
* @param timestampMs: The timestamp when the operation started (in milliseconds).
|
|
77
|
+
* @param timestampMs: The timestamp when the operation started (in milliseconds). If not provided, current timestamp will be used.
|
|
78
78
|
*/
|
|
79
79
|
startSpan(operation: string, context?: object, timestampMs?: number): Promise<string>;
|
|
80
80
|
/**
|
|
81
81
|
* Finish a started span.
|
|
82
82
|
* @param spanId: The unique identifier of the span.
|
|
83
83
|
* @param context: The additional context to send.
|
|
84
|
-
* @param timestampMs: The timestamp when the operation stopped (in milliseconds).
|
|
84
|
+
* @param timestampMs: The timestamp when the operation stopped (in milliseconds). If not provided, current timestamp will be used.
|
|
85
85
|
*/
|
|
86
86
|
finishSpan(spanId: string, context?: object, timestampMs?: number): Promise<void>;
|
|
87
87
|
};
|
|
@@ -94,14 +94,14 @@ export declare type DdRumType = {
|
|
|
94
94
|
* @param key: The view unique key identifier.
|
|
95
95
|
* @param name: The view name.
|
|
96
96
|
* @param context: The additional context to send.
|
|
97
|
-
* @param timestampMs: The timestamp when the view started (in milliseconds).
|
|
97
|
+
* @param timestampMs: The timestamp when the view started (in milliseconds). If not provided, current timestamp will be used.
|
|
98
98
|
*/
|
|
99
99
|
startView(key: string, name: string, context?: object, timestampMs?: number): Promise<void>;
|
|
100
100
|
/**
|
|
101
101
|
* Stop tracking a RUM View.
|
|
102
102
|
* @param key: The view unique key identifier.
|
|
103
103
|
* @param context: The additional context to send.
|
|
104
|
-
* @param timestampMs: The timestamp when the view stopped (in milliseconds).
|
|
104
|
+
* @param timestampMs: The timestamp when the view stopped (in milliseconds). If not provided, current timestamp will be used.
|
|
105
105
|
*/
|
|
106
106
|
stopView(key: string, context?: object, timestampMs?: number): Promise<void>;
|
|
107
107
|
/**
|
|
@@ -109,13 +109,13 @@ export declare type DdRumType = {
|
|
|
109
109
|
* @param type: The action type (tap, scroll, swipe, click, custom).
|
|
110
110
|
* @param name: The action name.
|
|
111
111
|
* @param context: The additional context to send.
|
|
112
|
-
* @param timestampMs: The timestamp when the action started (in milliseconds).
|
|
112
|
+
* @param timestampMs: The timestamp when the action started (in milliseconds). If not provided, current timestamp will be used.
|
|
113
113
|
*/
|
|
114
114
|
startAction(type: string, name: string, context?: object, timestampMs?: number): Promise<void>;
|
|
115
115
|
/**
|
|
116
116
|
* Stop tracking the ongoing RUM Action.
|
|
117
117
|
* @param context: The additional context to send.
|
|
118
|
-
* @param timestampMs: The timestamp when the action stopped (in milliseconds).
|
|
118
|
+
* @param timestampMs: The timestamp when the action stopped (in milliseconds). If not provided, current timestamp will be used.
|
|
119
119
|
*/
|
|
120
120
|
stopAction(context?: object, timestampMs?: number): Promise<void>;
|
|
121
121
|
/**
|
|
@@ -123,7 +123,7 @@ export declare type DdRumType = {
|
|
|
123
123
|
* @param type: The action type (tap, scroll, swipe, click, custom).
|
|
124
124
|
* @param name: The action name.
|
|
125
125
|
* @param context: The additional context to send.
|
|
126
|
-
* @param timestampMs: The timestamp when the action occurred (in milliseconds).
|
|
126
|
+
* @param timestampMs: The timestamp when the action occurred (in milliseconds). If not provided, current timestamp will be used.
|
|
127
127
|
*/
|
|
128
128
|
addAction(type: string, name: string, context?: object, timestampMs?: number): Promise<void>;
|
|
129
129
|
/**
|
|
@@ -132,7 +132,7 @@ export declare type DdRumType = {
|
|
|
132
132
|
* @param method: The resource method (GET, POST, …).
|
|
133
133
|
* @param url: The resource url.
|
|
134
134
|
* @param context: The additional context to send.
|
|
135
|
-
* @param timestampMs: The timestamp when the resource started (in milliseconds).
|
|
135
|
+
* @param timestampMs: The timestamp when the resource started (in milliseconds). If not provided, current timestamp will be used.
|
|
136
136
|
*/
|
|
137
137
|
startResource(key: string, method: string, url: string, context?: object, timestampMs?: number): Promise<void>;
|
|
138
138
|
/**
|
|
@@ -140,17 +140,18 @@ export declare type DdRumType = {
|
|
|
140
140
|
* @param key: The resource unique key identifier.
|
|
141
141
|
* @param statusCode: The resource status code.
|
|
142
142
|
* @param kind: The resource's kind (xhr, document, image, css, font, …).
|
|
143
|
+
* @param size: The resource size in bytes. If size is unknown, use -1.
|
|
143
144
|
* @param context: The additional context to send.
|
|
144
|
-
* @param timestampMs: The timestamp when the resource stopped (in milliseconds).
|
|
145
|
+
* @param timestampMs: The timestamp when the resource stopped (in milliseconds). If not provided, current timestamp will be used.
|
|
145
146
|
*/
|
|
146
|
-
stopResource(key: string, statusCode: number, kind: string, context?: object, timestampMs?: number): Promise<void>;
|
|
147
|
+
stopResource(key: string, statusCode: number, kind: string, size?: number, context?: object, timestampMs?: number): Promise<void>;
|
|
147
148
|
/**
|
|
148
149
|
* Add a RUM Error.
|
|
149
150
|
* @param message: The error message.
|
|
150
151
|
* @param source: The error source (network, source, console, logger, …).
|
|
151
152
|
* @param stacktrace: The error stacktrace.
|
|
152
153
|
* @param context: The additional context to send.
|
|
153
|
-
* @param timestampMs: The timestamp when the error occurred (in milliseconds).
|
|
154
|
+
* @param timestampMs: The timestamp when the error occurred (in milliseconds). If not provided, current timestamp will be used.
|
|
154
155
|
*/
|
|
155
156
|
addError(message: string, source: string, stacktrace: string, context?: object, timestampMs?: number): Promise<void>;
|
|
156
157
|
/**
|
|
@@ -0,0 +1 @@
|
|
|
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"
|
|
@@ -42,7 +42,10 @@
|
|
|
42
42
|
},
|
|
43
43
|
"peerDependencies": {
|
|
44
44
|
"react": ">=16.13.1",
|
|
45
|
-
"react-native": "
|
|
45
|
+
"react-native": ">=0.63.4 <1.0"
|
|
46
|
+
},
|
|
47
|
+
"devDependencies": {
|
|
48
|
+
"@testing-library/react-native": "7.0.2"
|
|
46
49
|
},
|
|
47
50
|
"jest": {
|
|
48
51
|
"preset": "react-native",
|
|
@@ -68,5 +71,5 @@
|
|
|
68
71
|
]
|
|
69
72
|
]
|
|
70
73
|
},
|
|
71
|
-
"gitHead": "
|
|
74
|
+
"gitHead": "db2b48ab61c67e64567b91fc5d858473bf64d448"
|
|
72
75
|
}
|
package/src/DdSdkReactNative.tsx
CHANGED
|
@@ -4,79 +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 {
|
|
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';
|
|
15
18
|
|
|
16
19
|
/**
|
|
17
20
|
* This class initializes the Datadog SDK, and sets up communication with the server.
|
|
18
21
|
*/
|
|
19
22
|
export class DdSdkReactNative {
|
|
20
|
-
|
|
21
|
-
private static readonly
|
|
22
|
-
private static readonly DD_SERVICE_NAME =
|
|
23
|
-
private static readonly DD_SDK_VERBOSITY_KEY =
|
|
24
|
-
private static readonly DD_NATIVE_VIEW_TRACKING_KEY =
|
|
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';
|
|
25
29
|
|
|
26
30
|
// Proxy
|
|
27
|
-
private static readonly DD_PROXY_TYPE_KEY =
|
|
28
|
-
private static readonly DD_PROXY_ADDRESS_KEY =
|
|
29
|
-
private static readonly DD_PROXY_PORT_KEY =
|
|
30
|
-
private static readonly DD_PROXY_USERNAME_KEY =
|
|
31
|
-
private static readonly DD_PROXY_PASSWORD_KEY =
|
|
32
|
-
|
|
33
|
-
private static readonly DD_NATIVE_LONG_TASK_THRESHOLD_KEY = "_dd.long_task.threshold"
|
|
34
|
-
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';
|
|
35
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;
|
|
36
40
|
|
|
37
|
-
private static wasInitialized = false
|
|
41
|
+
private static wasInitialized = false;
|
|
38
42
|
|
|
39
43
|
/**
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
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> {
|
|
45
51
|
return new Promise<void>((resolve, reject) => {
|
|
46
52
|
if (DdSdkReactNative.wasInitialized) {
|
|
47
|
-
|
|
48
|
-
|
|
53
|
+
InternalLog.log(
|
|
54
|
+
"Can't initialize Datadog, SDK was already initialized",
|
|
55
|
+
SdkVerbosity.WARN
|
|
56
|
+
);
|
|
57
|
+
resolve();
|
|
58
|
+
return;
|
|
49
59
|
}
|
|
50
60
|
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
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;
|
|
55
75
|
}
|
|
56
76
|
|
|
57
77
|
if (configuration.proxyConfig) {
|
|
58
78
|
const additionalConfig = configuration.additionalConfig;
|
|
59
79
|
const proxyConfig = configuration.proxyConfig;
|
|
60
80
|
|
|
61
|
-
additionalConfig[DdSdkReactNative.DD_PROXY_TYPE_KEY] =
|
|
62
|
-
|
|
63
|
-
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;
|
|
64
87
|
if (proxyConfig.username && proxyConfig.password) {
|
|
65
|
-
if (proxyConfig.type
|
|
66
|
-
console.warn(
|
|
88
|
+
if (proxyConfig.type === ProxyType.SOCKS) {
|
|
89
|
+
console.warn(
|
|
90
|
+
"SOCKS proxy configuration doesn't support Basic authentication."
|
|
91
|
+
);
|
|
67
92
|
} else {
|
|
68
|
-
additionalConfig[
|
|
69
|
-
|
|
93
|
+
additionalConfig[
|
|
94
|
+
DdSdkReactNative.DD_PROXY_USERNAME_KEY
|
|
95
|
+
] = proxyConfig.username;
|
|
96
|
+
additionalConfig[
|
|
97
|
+
DdSdkReactNative.DD_PROXY_PASSWORD_KEY
|
|
98
|
+
] = proxyConfig.password;
|
|
70
99
|
}
|
|
71
100
|
}
|
|
72
101
|
}
|
|
73
102
|
|
|
74
103
|
if (configuration.serviceName) {
|
|
75
|
-
configuration.additionalConfig[
|
|
104
|
+
configuration.additionalConfig[
|
|
105
|
+
DdSdkReactNative.DD_SERVICE_NAME
|
|
106
|
+
] = configuration.serviceName;
|
|
76
107
|
}
|
|
77
108
|
|
|
78
|
-
configuration.additionalConfig[
|
|
79
|
-
|
|
109
|
+
configuration.additionalConfig[
|
|
110
|
+
DdSdkReactNative.DD_NATIVE_LONG_TASK_THRESHOLD_KEY
|
|
111
|
+
] = DdSdkReactNative.NATIVE_LONG_TASK_THRESHOLD_MS;
|
|
80
112
|
|
|
81
113
|
DdSdk.initialize(
|
|
82
114
|
new DdSdkConfiguration(
|
|
@@ -84,19 +116,28 @@ export class DdSdkReactNative {
|
|
|
84
116
|
configuration.env,
|
|
85
117
|
configuration.applicationId,
|
|
86
118
|
configuration.nativeCrashReportEnabled,
|
|
87
|
-
configuration.sampleRate
|
|
119
|
+
configuration.sampleRate === undefined
|
|
120
|
+
? configuration.sessionSamplingRate
|
|
121
|
+
: configuration.sampleRate,
|
|
88
122
|
configuration.site,
|
|
89
123
|
configuration.trackingConsent,
|
|
90
124
|
configuration.additionalConfig
|
|
91
125
|
)
|
|
92
|
-
).then(
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
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
|
+
});
|
|
100
141
|
}
|
|
101
142
|
|
|
102
143
|
/**
|
|
@@ -106,7 +147,11 @@ export class DdSdkReactNative {
|
|
|
106
147
|
*/
|
|
107
148
|
// eslint-disable-next-line @typescript-eslint/ban-types
|
|
108
149
|
static setAttributes(attributes: object): Promise<void> {
|
|
109
|
-
|
|
150
|
+
InternalLog.log(
|
|
151
|
+
`Setting attributes ${JSON.stringify(attributes)}`,
|
|
152
|
+
SdkVerbosity.DEBUG
|
|
153
|
+
);
|
|
154
|
+
return DdSdk.setAttributes(attributes);
|
|
110
155
|
}
|
|
111
156
|
|
|
112
157
|
/**
|
|
@@ -116,7 +161,11 @@ export class DdSdkReactNative {
|
|
|
116
161
|
*/
|
|
117
162
|
// eslint-disable-next-line @typescript-eslint/ban-types
|
|
118
163
|
static setUser(user: object): Promise<void> {
|
|
119
|
-
|
|
164
|
+
InternalLog.log(
|
|
165
|
+
`Setting user ${JSON.stringify(user)}`,
|
|
166
|
+
SdkVerbosity.DEBUG
|
|
167
|
+
);
|
|
168
|
+
return DdSdk.setUser(user);
|
|
120
169
|
}
|
|
121
170
|
|
|
122
171
|
/**
|
|
@@ -125,20 +174,25 @@ export class DdSdkReactNative {
|
|
|
125
174
|
* @returns a Promise.
|
|
126
175
|
*/
|
|
127
176
|
static setTrackingConsent(consent: TrackingConsent): Promise<void> {
|
|
128
|
-
|
|
177
|
+
InternalLog.log(`Setting consent ${consent}`, SdkVerbosity.DEBUG);
|
|
178
|
+
return DdSdk.setTrackingConsent(consent);
|
|
129
179
|
}
|
|
130
180
|
|
|
131
|
-
private static enableFeatures(
|
|
181
|
+
private static enableFeatures(
|
|
182
|
+
configuration: DdSdkReactNativeConfiguration
|
|
183
|
+
) {
|
|
132
184
|
if (configuration.trackInteractions) {
|
|
133
185
|
DdRumUserInteractionTracking.startTracking();
|
|
134
186
|
}
|
|
135
187
|
|
|
136
188
|
if (configuration.trackResources) {
|
|
137
|
-
DdRumResourceTracking.startTracking(
|
|
189
|
+
DdRumResourceTracking.startTracking(
|
|
190
|
+
configuration.resourceTracingSamplingRate
|
|
191
|
+
);
|
|
138
192
|
}
|
|
139
193
|
|
|
140
194
|
if (configuration.trackErrors) {
|
|
141
195
|
DdRumErrorTracking.startTracking();
|
|
142
196
|
}
|
|
143
197
|
}
|
|
144
|
-
}
|
|
198
|
+
}
|
|
@@ -4,25 +4,35 @@
|
|
|
4
4
|
* Copyright 2016-Present Datadog, Inc.
|
|
5
5
|
*/
|
|
6
6
|
|
|
7
|
-
import { TrackingConsent } from './TrackingConsent'
|
|
8
|
-
import type { NativeSdkVerbosity } from './NativeSdkVerbosity'
|
|
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
|
-
|
|
24
|
-
|
|
25
|
-
public
|
|
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;
|
|
34
|
+
|
|
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
|
}
|
|
@@ -0,0 +1,45 @@
|
|
|
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 { SdkVerbosity } from './SdkVerbosity';
|
|
8
|
+
|
|
9
|
+
export class InternalLog {
|
|
10
|
+
private static levelMap = new Map<SdkVerbosity, number>([
|
|
11
|
+
[SdkVerbosity.DEBUG, 1],
|
|
12
|
+
[SdkVerbosity.INFO, 2],
|
|
13
|
+
[SdkVerbosity.WARN, 3],
|
|
14
|
+
[SdkVerbosity.ERROR, 4]
|
|
15
|
+
]);
|
|
16
|
+
|
|
17
|
+
public static verbosity: SdkVerbosity | undefined = undefined;
|
|
18
|
+
|
|
19
|
+
public static log(message: string, verbosity: SdkVerbosity): void {
|
|
20
|
+
if (InternalLog.verbosity === undefined) {
|
|
21
|
+
return;
|
|
22
|
+
}
|
|
23
|
+
const requiredLevel = InternalLog.levelMap.get(verbosity);
|
|
24
|
+
const allowedLevel = InternalLog.levelMap.get(InternalLog.verbosity);
|
|
25
|
+
if (allowedLevel === undefined || requiredLevel === undefined) {
|
|
26
|
+
return;
|
|
27
|
+
}
|
|
28
|
+
const prefixedMessage = `DATADOG: ${message}`;
|
|
29
|
+
if (verbosity === SdkVerbosity.ERROR && requiredLevel >= allowedLevel) {
|
|
30
|
+
console.error(prefixedMessage);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
if (verbosity === SdkVerbosity.WARN && requiredLevel >= allowedLevel) {
|
|
34
|
+
console.warn(prefixedMessage);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
if (verbosity === SdkVerbosity.INFO && requiredLevel >= allowedLevel) {
|
|
38
|
+
console.info(prefixedMessage);
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
if (verbosity === SdkVerbosity.DEBUG && requiredLevel >= allowedLevel) {
|
|
42
|
+
console.debug(prefixedMessage);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
}
|