@datadog/mobile-react-native 1.0.0-rc5 → 1.0.0-rc8
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 +48 -17
- package/android/build.gradle +1 -1
- package/android/gradle.properties +4 -4
- package/ios/Sources/DdSdk.swift +6 -3
- package/lib/commonjs/DdSdkReactNative.js +35 -31
- package/lib/commonjs/DdSdkReactNative.js.map +1 -1
- package/lib/commonjs/DdSdkReactNativeConfiguration.js +20 -7
- package/lib/commonjs/DdSdkReactNativeConfiguration.js.map +1 -1
- package/lib/commonjs/InternalLog.js +10 -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 +27 -19
- package/lib/commonjs/index.js.map +1 -1
- 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 +118 -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/rum/instrumentation/URLHostParser.js +33 -0
- package/lib/commonjs/rum/instrumentation/URLHostParser.js.map +1 -0
- 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 +33 -29
- package/lib/module/DdSdkReactNative.js.map +1 -1
- package/lib/module/DdSdkReactNativeConfiguration.js +21 -8
- package/lib/module/DdSdkReactNativeConfiguration.js.map +1 -1
- package/lib/module/InternalLog.js +11 -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 +4 -3
- package/lib/module/index.js.map +1 -1
- 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 +113 -39
- 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/rum/instrumentation/URLHostParser.js +24 -0
- package/lib/module/rum/instrumentation/URLHostParser.js.map +1 -0
- 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 +15 -3
- package/lib/typescript/InternalLog.d.ts +5 -0
- package/lib/typescript/TimeProvider.d.ts +20 -0
- package/lib/typescript/Timer.d.ts +3 -2
- package/lib/typescript/index.d.ts +4 -3
- 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 +19 -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/rum/instrumentation/URLHostParser.d.ts +6 -0
- package/lib/typescript/version.d.ts +1 -1
- package/package.json +6 -3
- package/src/DdSdkReactNative.tsx +116 -70
- package/src/DdSdkReactNativeConfiguration.tsx +22 -13
- package/src/InternalLog.tsx +18 -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 +712 -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 +789 -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/URLHostParser.test.ts +40 -0
- package/src/__tests__/rum/instrumentation/__utils__/XMLHttpRequestMock.ts +97 -0
- package/src/foundation.tsx +13 -10
- package/src/index.tsx +15 -4
- package/src/rum/instrumentation/DdEventsInterceptor.tsx +51 -35
- package/src/rum/instrumentation/DdRumErrorTracking.tsx +49 -44
- package/src/rum/instrumentation/DdRumResourceTracking.tsx +369 -234
- 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/rum/instrumentation/URLHostParser.ts +23 -0
- package/src/types.tsx +199 -158
- package/src/version.ts +1 -1
|
@@ -4,24 +4,23 @@
|
|
|
4
4
|
* Copyright 2016-Present Datadog, Inc.
|
|
5
5
|
*/
|
|
6
6
|
|
|
7
|
-
import React from 'react'
|
|
8
|
-
import { DdEventsInterceptor } from './DdEventsInterceptor'
|
|
9
|
-
import NoOpEventsInterceptor from './NoOpEventsInterceptor'
|
|
10
|
-
import type EventsInterceptor from './EventsInterceptor'
|
|
11
|
-
import {InternalLog} from "../../InternalLog"
|
|
12
|
-
import {SdkVerbosity} from "../../SdkVerbosity"
|
|
7
|
+
import React from 'react';
|
|
13
8
|
|
|
9
|
+
import { InternalLog } from '../../InternalLog';
|
|
10
|
+
import { SdkVerbosity } from '../../SdkVerbosity';
|
|
14
11
|
|
|
15
|
-
|
|
12
|
+
import { DdEventsInterceptor } from './DdEventsInterceptor';
|
|
13
|
+
import type EventsInterceptor from './EventsInterceptor';
|
|
14
|
+
import NoOpEventsInterceptor from './NoOpEventsInterceptor';
|
|
15
|
+
import { areObjectShallowEqual } from './ShallowObjectEqualityChecker';
|
|
16
16
|
|
|
17
17
|
/**
|
|
18
|
-
* Provides RUM auto-instrumentation feature to track user interaction as RUM events.
|
|
19
|
-
* For now we are only covering the "onPress" events.
|
|
20
|
-
*/
|
|
18
|
+
* Provides RUM auto-instrumentation feature to track user interaction as RUM events.
|
|
19
|
+
* For now we are only covering the "onPress" events.
|
|
20
|
+
*/
|
|
21
21
|
export class DdRumUserInteractionTracking {
|
|
22
|
-
|
|
23
|
-
private static
|
|
24
|
-
private static eventsInterceptor: EventsInterceptor = new NoOpEventsInterceptor()
|
|
22
|
+
private static isTracking = false;
|
|
23
|
+
private static eventsInterceptor: EventsInterceptor = new NoOpEventsInterceptor();
|
|
25
24
|
|
|
26
25
|
/**
|
|
27
26
|
* Starts tracking user interactions and sends a RUM Action event every time a new interaction was detected.
|
|
@@ -31,25 +30,69 @@ export class DdRumUserInteractionTracking {
|
|
|
31
30
|
static startTracking(): void {
|
|
32
31
|
// extra safety to avoid wrapping more than 1 time this function
|
|
33
32
|
if (DdRumUserInteractionTracking.isTracking) {
|
|
34
|
-
InternalLog.log(
|
|
35
|
-
|
|
33
|
+
InternalLog.log(
|
|
34
|
+
'Datadog SDK is already tracking interactions',
|
|
35
|
+
SdkVerbosity.WARN
|
|
36
|
+
);
|
|
37
|
+
return;
|
|
36
38
|
}
|
|
37
|
-
DdRumUserInteractionTracking.eventsInterceptor = new DdEventsInterceptor()
|
|
38
|
-
const original = React.createElement
|
|
39
|
-
React.createElement = (
|
|
39
|
+
DdRumUserInteractionTracking.eventsInterceptor = new DdEventsInterceptor();
|
|
40
|
+
const original = React.createElement;
|
|
41
|
+
React.createElement = (
|
|
42
|
+
element: any,
|
|
43
|
+
props: any,
|
|
44
|
+
...children: any
|
|
45
|
+
): any => {
|
|
40
46
|
// check if we have an 'onPress' property and that this is really a function
|
|
41
|
-
if (props && typeof props.onPress ===
|
|
42
|
-
const originalOnPress = props.onPress
|
|
47
|
+
if (props && typeof props.onPress === 'function') {
|
|
48
|
+
const originalOnPress = props.onPress;
|
|
43
49
|
props.onPress = (...args: any[]) => {
|
|
44
|
-
DdRumUserInteractionTracking.eventsInterceptor.interceptOnPress(
|
|
45
|
-
|
|
46
|
-
|
|
50
|
+
DdRumUserInteractionTracking.eventsInterceptor.interceptOnPress(
|
|
51
|
+
...args
|
|
52
|
+
);
|
|
53
|
+
return originalOnPress(...args);
|
|
54
|
+
};
|
|
55
|
+
// we store the original onPress prop so we can keep memoization working
|
|
56
|
+
props.__DATADOG_INTERNAL_ORIGINAL_ON_PRESS__ = originalOnPress;
|
|
47
57
|
}
|
|
48
|
-
return original(element, props, ...children)
|
|
49
|
-
}
|
|
50
|
-
DdRumUserInteractionTracking.isTracking = true
|
|
51
|
-
InternalLog.log("Datadog SDK is tracking interactions", SdkVerbosity.INFO);
|
|
52
|
-
}
|
|
58
|
+
return original(element, props, ...children);
|
|
59
|
+
};
|
|
53
60
|
|
|
54
|
-
|
|
61
|
+
const originalMemo = React.memo;
|
|
62
|
+
React.memo = (
|
|
63
|
+
component: any,
|
|
64
|
+
propsAreEqual?: (prevProps: any, newProps: any) => boolean
|
|
65
|
+
) => {
|
|
66
|
+
return originalMemo(component, (prev, next) => {
|
|
67
|
+
if (!next.onPress || !prev.onPress) {
|
|
68
|
+
return propsAreEqual
|
|
69
|
+
? propsAreEqual(prev, next)
|
|
70
|
+
: areObjectShallowEqual(prev, next);
|
|
71
|
+
}
|
|
72
|
+
// we replace "our" onPress from the props by the original for comparison
|
|
73
|
+
const { onPress: _prevOnPress, ...partialPrevProps } = prev;
|
|
74
|
+
const prevProps = {
|
|
75
|
+
...partialPrevProps,
|
|
76
|
+
onPress: prev.__DATADOG_INTERNAL_ORIGINAL_ON_PRESS__
|
|
77
|
+
};
|
|
78
|
+
|
|
79
|
+
const { onPress: _nextOnPress, ...partialNextProps } = next;
|
|
80
|
+
const nextProps = {
|
|
81
|
+
...partialNextProps,
|
|
82
|
+
onPress: next.__DATADOG_INTERNAL_ORIGINAL_ON_PRESS__
|
|
83
|
+
};
|
|
84
|
+
|
|
85
|
+
// if no comparison function is provided we do shallow comparison
|
|
86
|
+
return propsAreEqual
|
|
87
|
+
? propsAreEqual(prevProps, nextProps)
|
|
88
|
+
: areObjectShallowEqual(nextProps, prevProps);
|
|
89
|
+
});
|
|
90
|
+
};
|
|
55
91
|
|
|
92
|
+
DdRumUserInteractionTracking.isTracking = true;
|
|
93
|
+
InternalLog.log(
|
|
94
|
+
'Datadog SDK is tracking interactions',
|
|
95
|
+
SdkVerbosity.INFO
|
|
96
|
+
);
|
|
97
|
+
}
|
|
98
|
+
}
|
|
@@ -4,20 +4,30 @@
|
|
|
4
4
|
* Copyright 2016-Present Datadog, Inc.
|
|
5
5
|
*/
|
|
6
6
|
|
|
7
|
-
import type Timer from
|
|
8
|
-
|
|
7
|
+
import type Timer from '../../Timer';
|
|
9
8
|
|
|
10
9
|
export interface DdRumXhr extends XMLHttpRequest {
|
|
11
|
-
|
|
12
|
-
_datadog_xhr: DdRumXhrContext
|
|
13
|
-
|
|
10
|
+
_datadog_xhr: DdRumXhrContext;
|
|
14
11
|
}
|
|
15
12
|
|
|
16
13
|
export interface DdRumXhrContext {
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
traceId: string
|
|
14
|
+
method: string;
|
|
15
|
+
url: string;
|
|
16
|
+
reported: boolean;
|
|
17
|
+
timer: Timer;
|
|
18
|
+
tracingAttributes: DdRumResourceTracingAttributes;
|
|
23
19
|
}
|
|
20
|
+
|
|
21
|
+
export type DdRumResourceTracingAttributes =
|
|
22
|
+
| {
|
|
23
|
+
tracingStrategy: 'KEEP';
|
|
24
|
+
traceId: string;
|
|
25
|
+
spanId: string;
|
|
26
|
+
samplingPriorityHeader: '1';
|
|
27
|
+
}
|
|
28
|
+
| {
|
|
29
|
+
tracingStrategy: 'DISCARD';
|
|
30
|
+
traceId?: void;
|
|
31
|
+
spanId?: void;
|
|
32
|
+
samplingPriorityHeader: '0';
|
|
33
|
+
};
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
* This product includes software developed at Datadog (https://www.datadoghq.com/).
|
|
4
4
|
* Copyright 2016-Present Datadog, Inc.
|
|
5
5
|
*/
|
|
6
|
-
|
|
6
|
+
|
|
7
7
|
export default interface EventsInterceptor {
|
|
8
|
-
interceptOnPress(...args: any[]): void
|
|
9
|
-
}
|
|
8
|
+
interceptOnPress(...args: any[]): void;
|
|
9
|
+
}
|
|
@@ -4,11 +4,11 @@
|
|
|
4
4
|
* Copyright 2016-Present Datadog, Inc.
|
|
5
5
|
*/
|
|
6
6
|
|
|
7
|
-
import type EventsInterceptor from './EventsInterceptor'
|
|
7
|
+
import type EventsInterceptor from './EventsInterceptor';
|
|
8
8
|
|
|
9
9
|
export default class NoOpEventsInterceptor implements EventsInterceptor {
|
|
10
10
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
11
11
|
interceptOnPress(..._args: any[]): void {
|
|
12
12
|
// NoOp
|
|
13
13
|
}
|
|
14
|
-
}
|
|
14
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
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
|
+
* Does a shallow comparison between 2 objects
|
|
9
|
+
*/
|
|
10
|
+
export const areObjectShallowEqual = (
|
|
11
|
+
objectA: Record<string, unknown>,
|
|
12
|
+
objectB: Record<string, unknown>
|
|
13
|
+
): boolean => {
|
|
14
|
+
const keys = Object.keys(objectA);
|
|
15
|
+
if (keys.length !== Object.keys(objectB).length) {
|
|
16
|
+
return false;
|
|
17
|
+
}
|
|
18
|
+
for (const key of keys) {
|
|
19
|
+
if (objectA[key] !== objectB[key]) {
|
|
20
|
+
return false;
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
return true;
|
|
24
|
+
};
|
|
@@ -9,26 +9,26 @@
|
|
|
9
9
|
*/
|
|
10
10
|
|
|
11
11
|
export function generateTraceId(): string {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
12
|
+
const radix = 10;
|
|
13
|
+
const MAX_32_BITS_NUMBER = 4294967295; // 2^32-1
|
|
14
|
+
let low: number = Math.floor(Math.random() * MAX_32_BITS_NUMBER);
|
|
15
|
+
let high: number = Math.floor(Math.random() * MAX_32_BITS_NUMBER);
|
|
16
|
+
let str = '';
|
|
17
17
|
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
18
|
+
while (high > 0 && low > 0) {
|
|
19
|
+
// Create an intermediate value with the same modulo as the combined high and low value
|
|
20
|
+
// but requiring 36 bits max (32 for the low value + 4 for the high part)
|
|
21
|
+
const modH = high % radix;
|
|
22
|
+
const temp = (modH << 32) + low;
|
|
23
|
+
const digit = temp % radix;
|
|
24
24
|
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
25
|
+
// update the high value
|
|
26
|
+
high = (high - modH) / radix; // we reuse the modH to avoid the need of a floor op
|
|
27
|
+
// the low value reuses the previous temp value to account for the "missing mod" in the high update
|
|
28
|
+
low = (temp - digit) / radix; // we reuse the digit to avoid the need of a floor op
|
|
29
29
|
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
30
|
+
// update the string from right to left
|
|
31
|
+
str = digit.toString() + str;
|
|
32
|
+
}
|
|
33
|
+
return str;
|
|
34
34
|
}
|
|
@@ -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
|
+
// matches what is between the first "://" and the next "/", ":" or whitespace
|
|
8
|
+
const hostRegex = '^.+://([^:/\\s]+)';
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Returns the host from an URL.
|
|
12
|
+
* @returns the host (without the port)
|
|
13
|
+
* @throws if URL is not well formatted
|
|
14
|
+
*/
|
|
15
|
+
export const URLHostParser = (url: string): string => {
|
|
16
|
+
const matchedHost = url.match(hostRegex);
|
|
17
|
+
if (matchedHost === null) {
|
|
18
|
+
throw new Error(`${url} is not a correctly formatted URL`);
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
// [0] is the input, [1] is the captured group
|
|
22
|
+
return matchedHost[1];
|
|
23
|
+
};
|