@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.
Files changed (128) hide show
  1. package/DatadogSDKReactNative.podspec +1 -1
  2. package/README.md +48 -17
  3. package/android/build.gradle +1 -1
  4. package/android/gradle.properties +4 -4
  5. package/ios/Sources/DdSdk.swift +6 -3
  6. package/lib/commonjs/DdSdkReactNative.js +35 -31
  7. package/lib/commonjs/DdSdkReactNative.js.map +1 -1
  8. package/lib/commonjs/DdSdkReactNativeConfiguration.js +20 -7
  9. package/lib/commonjs/DdSdkReactNativeConfiguration.js.map +1 -1
  10. package/lib/commonjs/InternalLog.js +10 -5
  11. package/lib/commonjs/InternalLog.js.map +1 -1
  12. package/lib/commonjs/ProxyConfiguration.js.map +1 -1
  13. package/lib/commonjs/SdkVerbosity.js.map +1 -1
  14. package/lib/commonjs/TimeProvider.js +72 -0
  15. package/lib/commonjs/TimeProvider.js.map +1 -0
  16. package/lib/commonjs/Timer.js +10 -23
  17. package/lib/commonjs/Timer.js.map +1 -1
  18. package/lib/commonjs/TrackingConsent.js.map +1 -1
  19. package/lib/commonjs/foundation.js +19 -54
  20. package/lib/commonjs/foundation.js.map +1 -1
  21. package/lib/commonjs/index.js +27 -19
  22. package/lib/commonjs/index.js.map +1 -1
  23. package/lib/commonjs/rum/instrumentation/DdEventsInterceptor.js +16 -11
  24. package/lib/commonjs/rum/instrumentation/DdEventsInterceptor.js.map +1 -1
  25. package/lib/commonjs/rum/instrumentation/DdRumErrorTracking.js +19 -23
  26. package/lib/commonjs/rum/instrumentation/DdRumErrorTracking.js.map +1 -1
  27. package/lib/commonjs/rum/instrumentation/DdRumResourceTracking.js +118 -42
  28. package/lib/commonjs/rum/instrumentation/DdRumResourceTracking.js.map +1 -1
  29. package/lib/commonjs/rum/instrumentation/DdRumUserInteractionTracking.js +46 -19
  30. package/lib/commonjs/rum/instrumentation/DdRumUserInteractionTracking.js.map +1 -1
  31. package/lib/commonjs/rum/instrumentation/DdRumXhr.js +0 -4
  32. package/lib/commonjs/rum/instrumentation/NoOpEventsInterceptor.js +1 -1
  33. package/lib/commonjs/rum/instrumentation/NoOpEventsInterceptor.js.map +1 -1
  34. package/lib/commonjs/rum/instrumentation/ShallowObjectEqualityChecker.js +34 -0
  35. package/lib/commonjs/rum/instrumentation/ShallowObjectEqualityChecker.js.map +1 -0
  36. package/lib/commonjs/rum/instrumentation/TraceIdentifier.js.map +1 -1
  37. package/lib/commonjs/rum/instrumentation/URLHostParser.js +33 -0
  38. package/lib/commonjs/rum/instrumentation/URLHostParser.js.map +1 -0
  39. package/lib/commonjs/types.js.map +1 -1
  40. package/lib/commonjs/version.js +1 -1
  41. package/lib/commonjs/version.js.map +1 -1
  42. package/lib/module/DdSdkReactNative.js +33 -29
  43. package/lib/module/DdSdkReactNative.js.map +1 -1
  44. package/lib/module/DdSdkReactNativeConfiguration.js +21 -8
  45. package/lib/module/DdSdkReactNativeConfiguration.js.map +1 -1
  46. package/lib/module/InternalLog.js +11 -5
  47. package/lib/module/InternalLog.js.map +1 -1
  48. package/lib/module/ProxyConfiguration.js.map +1 -1
  49. package/lib/module/SdkVerbosity.js.map +1 -1
  50. package/lib/module/TimeProvider.js +63 -0
  51. package/lib/module/TimeProvider.js.map +1 -0
  52. package/lib/module/Timer.js +14 -23
  53. package/lib/module/Timer.js.map +1 -1
  54. package/lib/module/TrackingConsent.js.map +1 -1
  55. package/lib/module/foundation.js +16 -39
  56. package/lib/module/foundation.js.map +1 -1
  57. package/lib/module/index.js +4 -3
  58. package/lib/module/index.js.map +1 -1
  59. package/lib/module/rum/instrumentation/DdEventsInterceptor.js +12 -10
  60. package/lib/module/rum/instrumentation/DdEventsInterceptor.js.map +1 -1
  61. package/lib/module/rum/instrumentation/DdRumErrorTracking.js +19 -23
  62. package/lib/module/rum/instrumentation/DdRumErrorTracking.js.map +1 -1
  63. package/lib/module/rum/instrumentation/DdRumResourceTracking.js +113 -39
  64. package/lib/module/rum/instrumentation/DdRumResourceTracking.js.map +1 -1
  65. package/lib/module/rum/instrumentation/DdRumUserInteractionTracking.js +44 -17
  66. package/lib/module/rum/instrumentation/DdRumUserInteractionTracking.js.map +1 -1
  67. package/lib/module/rum/instrumentation/DdRumXhr.js +1 -1
  68. package/lib/module/rum/instrumentation/NoOpEventsInterceptor.js +1 -1
  69. package/lib/module/rum/instrumentation/NoOpEventsInterceptor.js.map +1 -1
  70. package/lib/module/rum/instrumentation/ShallowObjectEqualityChecker.js +25 -0
  71. package/lib/module/rum/instrumentation/ShallowObjectEqualityChecker.js.map +1 -0
  72. package/lib/module/rum/instrumentation/TraceIdentifier.js.map +1 -1
  73. package/lib/module/rum/instrumentation/URLHostParser.js +24 -0
  74. package/lib/module/rum/instrumentation/URLHostParser.js.map +1 -0
  75. package/lib/module/types.js.map +1 -1
  76. package/lib/module/version.js +1 -1
  77. package/lib/module/version.js.map +1 -1
  78. package/lib/typescript/DdSdkReactNative.d.ts +6 -6
  79. package/lib/typescript/DdSdkReactNativeConfiguration.d.ts +15 -3
  80. package/lib/typescript/InternalLog.d.ts +5 -0
  81. package/lib/typescript/TimeProvider.d.ts +20 -0
  82. package/lib/typescript/Timer.d.ts +3 -2
  83. package/lib/typescript/index.d.ts +4 -3
  84. package/lib/typescript/rum/instrumentation/DdEventsInterceptor.d.ts +1 -0
  85. package/lib/typescript/rum/instrumentation/DdRumErrorTracking.d.ts +2 -2
  86. package/lib/typescript/rum/instrumentation/DdRumResourceTracking.d.ts +19 -9
  87. package/lib/typescript/rum/instrumentation/DdRumUserInteractionTracking.d.ts +3 -3
  88. package/lib/typescript/rum/instrumentation/DdRumXhr.d.ts +13 -3
  89. package/lib/typescript/rum/instrumentation/ShallowObjectEqualityChecker.d.ts +4 -0
  90. package/lib/typescript/rum/instrumentation/URLHostParser.d.ts +6 -0
  91. package/lib/typescript/version.d.ts +1 -1
  92. package/package.json +6 -3
  93. package/src/DdSdkReactNative.tsx +116 -70
  94. package/src/DdSdkReactNativeConfiguration.tsx +22 -13
  95. package/src/InternalLog.tsx +18 -16
  96. package/src/ProxyConfiguration.tsx +5 -5
  97. package/src/SdkVerbosity.tsx +4 -4
  98. package/src/TimeProvider.tsx +64 -0
  99. package/src/Timer.ts +20 -35
  100. package/src/TrackingConsent.tsx +3 -3
  101. package/src/__mocks__/InternalLog.tsx +9 -0
  102. package/src/__tests__/DdRumWrapper.test.tsx +40 -33
  103. package/src/__tests__/DdSdkReactNative.test.tsx +712 -513
  104. package/src/__tests__/InternalLog.test.tsx +114 -117
  105. package/src/__tests__/TimeProvider.test.tsx +75 -0
  106. package/src/__tests__/Timer.test.ts +148 -57
  107. package/src/__tests__/rum/instrumentation/DdEventsInterceptor.test.tsx +151 -92
  108. package/src/__tests__/rum/instrumentation/DdRumErrorTracking.test.tsx +168 -116
  109. package/src/__tests__/rum/instrumentation/DdRumResourceTracking.test.tsx +789 -644
  110. package/src/__tests__/rum/instrumentation/DdRumUserInteractionTracking.test.tsx +239 -85
  111. package/src/__tests__/rum/instrumentation/ShallowObjectEqualityChecker.test.ts +31 -0
  112. package/src/__tests__/rum/instrumentation/TraceIdentifier.test.tsx +13 -15
  113. package/src/__tests__/rum/instrumentation/URLHostParser.test.ts +40 -0
  114. package/src/__tests__/rum/instrumentation/__utils__/XMLHttpRequestMock.ts +97 -0
  115. package/src/foundation.tsx +13 -10
  116. package/src/index.tsx +15 -4
  117. package/src/rum/instrumentation/DdEventsInterceptor.tsx +51 -35
  118. package/src/rum/instrumentation/DdRumErrorTracking.tsx +49 -44
  119. package/src/rum/instrumentation/DdRumResourceTracking.tsx +369 -234
  120. package/src/rum/instrumentation/DdRumUserInteractionTracking.tsx +72 -29
  121. package/src/rum/instrumentation/DdRumXhr.tsx +21 -11
  122. package/src/rum/instrumentation/EventsInterceptor.tsx +3 -3
  123. package/src/rum/instrumentation/NoOpEventsInterceptor.tsx +2 -2
  124. package/src/rum/instrumentation/ShallowObjectEqualityChecker.ts +24 -0
  125. package/src/rum/instrumentation/TraceIdentifier.tsx +19 -19
  126. package/src/rum/instrumentation/URLHostParser.ts +23 -0
  127. package/src/types.tsx +199 -158
  128. 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
- const PROPERTY_FUNCTION_TYPE = "function"
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 isTracking = false
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("Datadog SDK is already tracking interactions", SdkVerbosity.WARN);
35
- return
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 = (element: any, props: any, ...children: any): any => {
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 === PROPERTY_FUNCTION_TYPE) {
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(...args)
45
- return originalOnPress(...args)
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 "../../Timer";
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
- method: string,
18
- url: string,
19
- reported: boolean,
20
- timer: Timer,
21
- spanId: string,
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
- 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 = ''
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
- 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
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
- // 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
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
- // update the string from right to left
31
- str = digit.toString() + str
32
- }
33
- return str
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
+ };