@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.
Files changed (123) hide show
  1. package/README.md +46 -17
  2. package/android/gradle.properties +4 -4
  3. package/lib/commonjs/DdSdkReactNative.js +31 -31
  4. package/lib/commonjs/DdSdkReactNative.js.map +1 -1
  5. package/lib/commonjs/DdSdkReactNativeConfiguration.js +18 -7
  6. package/lib/commonjs/DdSdkReactNativeConfiguration.js.map +1 -1
  7. package/lib/commonjs/InternalLog.js +5 -5
  8. package/lib/commonjs/InternalLog.js.map +1 -1
  9. package/lib/commonjs/ProxyConfiguration.js.map +1 -1
  10. package/lib/commonjs/SdkVerbosity.js.map +1 -1
  11. package/lib/commonjs/TimeProvider.js +72 -0
  12. package/lib/commonjs/TimeProvider.js.map +1 -0
  13. package/lib/commonjs/Timer.js +10 -23
  14. package/lib/commonjs/Timer.js.map +1 -1
  15. package/lib/commonjs/TrackingConsent.js.map +1 -1
  16. package/lib/commonjs/foundation.js +19 -54
  17. package/lib/commonjs/foundation.js.map +1 -1
  18. package/lib/commonjs/index.js +21 -21
  19. package/lib/commonjs/index.js.map +1 -1
  20. package/lib/commonjs/internal.js +14 -0
  21. package/lib/commonjs/internal.js.map +1 -0
  22. package/lib/commonjs/rum/instrumentation/DdEventsInterceptor.js +16 -11
  23. package/lib/commonjs/rum/instrumentation/DdEventsInterceptor.js.map +1 -1
  24. package/lib/commonjs/rum/instrumentation/DdRumErrorTracking.js +19 -23
  25. package/lib/commonjs/rum/instrumentation/DdRumErrorTracking.js.map +1 -1
  26. package/lib/commonjs/rum/instrumentation/DdRumResourceTracking.js +60 -42
  27. package/lib/commonjs/rum/instrumentation/DdRumResourceTracking.js.map +1 -1
  28. package/lib/commonjs/rum/instrumentation/DdRumUserInteractionTracking.js +46 -19
  29. package/lib/commonjs/rum/instrumentation/DdRumUserInteractionTracking.js.map +1 -1
  30. package/lib/commonjs/rum/instrumentation/DdRumXhr.js +0 -4
  31. package/lib/commonjs/rum/instrumentation/NoOpEventsInterceptor.js +1 -1
  32. package/lib/commonjs/rum/instrumentation/NoOpEventsInterceptor.js.map +1 -1
  33. package/lib/commonjs/rum/instrumentation/ShallowObjectEqualityChecker.js +34 -0
  34. package/lib/commonjs/rum/instrumentation/ShallowObjectEqualityChecker.js.map +1 -0
  35. package/lib/commonjs/rum/instrumentation/TraceIdentifier.js.map +1 -1
  36. package/lib/commonjs/types.js.map +1 -1
  37. package/lib/commonjs/version.js +1 -1
  38. package/lib/commonjs/version.js.map +1 -1
  39. package/lib/module/DdSdkReactNative.js +29 -29
  40. package/lib/module/DdSdkReactNative.js.map +1 -1
  41. package/lib/module/DdSdkReactNativeConfiguration.js +19 -8
  42. package/lib/module/DdSdkReactNativeConfiguration.js.map +1 -1
  43. package/lib/module/InternalLog.js +5 -5
  44. package/lib/module/InternalLog.js.map +1 -1
  45. package/lib/module/ProxyConfiguration.js.map +1 -1
  46. package/lib/module/SdkVerbosity.js.map +1 -1
  47. package/lib/module/TimeProvider.js +63 -0
  48. package/lib/module/TimeProvider.js.map +1 -0
  49. package/lib/module/Timer.js +14 -23
  50. package/lib/module/Timer.js.map +1 -1
  51. package/lib/module/TrackingConsent.js.map +1 -1
  52. package/lib/module/foundation.js +16 -39
  53. package/lib/module/foundation.js.map +1 -1
  54. package/lib/module/index.js +2 -2
  55. package/lib/module/index.js.map +1 -1
  56. package/lib/module/internal.js +2 -0
  57. package/lib/module/internal.js.map +1 -0
  58. package/lib/module/rum/instrumentation/DdEventsInterceptor.js +12 -10
  59. package/lib/module/rum/instrumentation/DdEventsInterceptor.js.map +1 -1
  60. package/lib/module/rum/instrumentation/DdRumErrorTracking.js +19 -23
  61. package/lib/module/rum/instrumentation/DdRumErrorTracking.js.map +1 -1
  62. package/lib/module/rum/instrumentation/DdRumResourceTracking.js +57 -38
  63. package/lib/module/rum/instrumentation/DdRumResourceTracking.js.map +1 -1
  64. package/lib/module/rum/instrumentation/DdRumUserInteractionTracking.js +44 -17
  65. package/lib/module/rum/instrumentation/DdRumUserInteractionTracking.js.map +1 -1
  66. package/lib/module/rum/instrumentation/DdRumXhr.js +1 -1
  67. package/lib/module/rum/instrumentation/NoOpEventsInterceptor.js +1 -1
  68. package/lib/module/rum/instrumentation/NoOpEventsInterceptor.js.map +1 -1
  69. package/lib/module/rum/instrumentation/ShallowObjectEqualityChecker.js +25 -0
  70. package/lib/module/rum/instrumentation/ShallowObjectEqualityChecker.js.map +1 -0
  71. package/lib/module/rum/instrumentation/TraceIdentifier.js.map +1 -1
  72. package/lib/module/types.js.map +1 -1
  73. package/lib/module/version.js +1 -1
  74. package/lib/module/version.js.map +1 -1
  75. package/lib/typescript/DdSdkReactNative.d.ts +6 -6
  76. package/lib/typescript/DdSdkReactNativeConfiguration.d.ts +14 -3
  77. package/lib/typescript/TimeProvider.d.ts +20 -0
  78. package/lib/typescript/Timer.d.ts +3 -2
  79. package/lib/typescript/index.d.ts +2 -2
  80. package/lib/typescript/internal.d.ts +1 -0
  81. package/lib/typescript/rum/instrumentation/DdEventsInterceptor.d.ts +1 -0
  82. package/lib/typescript/rum/instrumentation/DdRumErrorTracking.d.ts +2 -2
  83. package/lib/typescript/rum/instrumentation/DdRumResourceTracking.d.ts +10 -9
  84. package/lib/typescript/rum/instrumentation/DdRumUserInteractionTracking.d.ts +3 -3
  85. package/lib/typescript/rum/instrumentation/DdRumXhr.d.ts +13 -3
  86. package/lib/typescript/rum/instrumentation/ShallowObjectEqualityChecker.d.ts +4 -0
  87. package/lib/typescript/version.d.ts +1 -1
  88. package/package.json +6 -3
  89. package/src/DdSdkReactNative.tsx +112 -70
  90. package/src/DdSdkReactNativeConfiguration.tsx +21 -13
  91. package/src/InternalLog.tsx +13 -16
  92. package/src/ProxyConfiguration.tsx +5 -5
  93. package/src/SdkVerbosity.tsx +4 -4
  94. package/src/TimeProvider.tsx +64 -0
  95. package/src/Timer.ts +20 -35
  96. package/src/TrackingConsent.tsx +3 -3
  97. package/src/__mocks__/InternalLog.tsx +9 -0
  98. package/src/__tests__/DdRumWrapper.test.tsx +40 -33
  99. package/src/__tests__/DdSdkReactNative.test.tsx +697 -513
  100. package/src/__tests__/InternalLog.test.tsx +114 -117
  101. package/src/__tests__/TimeProvider.test.tsx +75 -0
  102. package/src/__tests__/Timer.test.ts +148 -57
  103. package/src/__tests__/rum/instrumentation/DdEventsInterceptor.test.tsx +151 -92
  104. package/src/__tests__/rum/instrumentation/DdRumErrorTracking.test.tsx +168 -116
  105. package/src/__tests__/rum/instrumentation/DdRumResourceTracking.test.tsx +714 -644
  106. package/src/__tests__/rum/instrumentation/DdRumUserInteractionTracking.test.tsx +239 -85
  107. package/src/__tests__/rum/instrumentation/ShallowObjectEqualityChecker.test.ts +31 -0
  108. package/src/__tests__/rum/instrumentation/TraceIdentifier.test.tsx +13 -15
  109. package/src/__tests__/rum/instrumentation/__utils__/XMLHttpRequestMock.ts +97 -0
  110. package/src/foundation.tsx +13 -10
  111. package/src/index.tsx +13 -4
  112. package/src/internal.tsx +1 -0
  113. package/src/rum/instrumentation/DdEventsInterceptor.tsx +51 -35
  114. package/src/rum/instrumentation/DdRumErrorTracking.tsx +49 -44
  115. package/src/rum/instrumentation/DdRumResourceTracking.tsx +308 -238
  116. package/src/rum/instrumentation/DdRumUserInteractionTracking.tsx +72 -29
  117. package/src/rum/instrumentation/DdRumXhr.tsx +21 -11
  118. package/src/rum/instrumentation/EventsInterceptor.tsx +3 -3
  119. package/src/rum/instrumentation/NoOpEventsInterceptor.tsx +2 -2
  120. package/src/rum/instrumentation/ShallowObjectEqualityChecker.ts +24 -0
  121. package/src/rum/instrumentation/TraceIdentifier.tsx +19 -19
  122. package/src/types.tsx +199 -158
  123. 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
- * Starts tracking resources and sends a RUM Resource event every time a network request is detected.
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
- * Starts tracking resources and sends a RUM Resource event every time a fetch or XHR call is detected.
22
- */
23
- static startTrackingInternal(xhrType: any): void;
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 "../../Timer";
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
- spanId: string;
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
+ };
@@ -0,0 +1,4 @@
1
+ /**
2
+ * Does a shallow comparison between 2 objects
3
+ */
4
+ export declare const areObjectShallowEqual: (objectA: Record<string, unknown>, objectB: Record<string, unknown>) => boolean;
@@ -1 +1 @@
1
- export declare const version = "1.0.0-rc5";
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-rc5",
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/index",
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": "6be800b36e37b072e43a36a32fd058a1ba6fd889"
74
+ "gitHead": "db2b48ab61c67e64567b91fc5d858473bf64d448"
72
75
  }
@@ -4,87 +4,111 @@
4
4
  * Copyright 2016-Present Datadog, Inc.
5
5
  */
6
6
 
7
- import type {DdSdkReactNativeConfiguration} from "./DdSdkReactNativeConfiguration"
8
- import {DdSdkConfiguration} from "./types"
9
- import {DdSdk} from "./foundation"
10
- import {DdRumUserInteractionTracking} from './rum/instrumentation/DdRumUserInteractionTracking'
11
- import {DdRumErrorTracking} from './rum/instrumentation/DdRumErrorTracking'
12
- import {DdRumResourceTracking} from './rum/instrumentation/DdRumResourceTracking'
13
- import type {TrackingConsent} from "./TrackingConsent"
14
- import {ProxyType} from "./ProxyConfiguration"
15
- import {version as sdkVersion} from './version';
16
- import {InternalLog} from "./InternalLog"
17
- import {SdkVerbosity} from "./SdkVerbosity";
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 DD_SOURCE_KEY = "_dd.source";
25
- private static readonly DD_SDK_VERSION = "_dd.sdk_version";
26
- private static readonly DD_SERVICE_NAME = "_dd.service_name";
27
- private static readonly DD_SDK_VERBOSITY_KEY = "_dd.sdk_verbosity";
28
- private static readonly DD_NATIVE_VIEW_TRACKING_KEY = "_dd.native_view_tracking";
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 = "_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";
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
- * Initializes the Datadog SDK.
45
- * @param configuration the configuration for the SDK library
46
- * @returns a Promise.
47
- */
48
- static initialize(configuration: DdSdkReactNativeConfiguration): Promise<void> {
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("Can't initialize Datadog, SDK was already initialized", SdkVerbosity.WARN);
52
- resolve()
53
- return
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] = 'react-native';
59
- configuration.additionalConfig[DdSdkReactNative.DD_SDK_VERSION] = sdkVersion;
60
- configuration.additionalConfig[DdSdkReactNative.DD_NATIVE_VIEW_TRACKING_KEY] = configuration.nativeViewTracking;
61
- if (configuration.verbosity != undefined) {
62
- configuration.additionalConfig[DdSdkReactNative.DD_SDK_VERBOSITY_KEY] = configuration.verbosity;
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] = proxyConfig.type;
70
- additionalConfig[DdSdkReactNative.DD_PROXY_ADDRESS_KEY] = proxyConfig.address;
71
- additionalConfig[DdSdkReactNative.DD_PROXY_PORT_KEY] = proxyConfig.port;
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 == ProxyType.SOCKS) {
74
- console.warn("SOCKS proxy configuration doesn't support Basic authentication.")
88
+ if (proxyConfig.type === ProxyType.SOCKS) {
89
+ console.warn(
90
+ "SOCKS proxy configuration doesn't support Basic authentication."
91
+ );
75
92
  } else {
76
- additionalConfig[DdSdkReactNative.DD_PROXY_USERNAME_KEY] = proxyConfig.username;
77
- additionalConfig[DdSdkReactNative.DD_PROXY_PASSWORD_KEY] = proxyConfig.password;
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[DdSdkReactNative.DD_SERVICE_NAME] = configuration.serviceName;
104
+ configuration.additionalConfig[
105
+ DdSdkReactNative.DD_SERVICE_NAME
106
+ ] = configuration.serviceName;
84
107
  }
85
108
 
86
- configuration.additionalConfig[DdSdkReactNative.DD_NATIVE_LONG_TASK_THRESHOLD_KEY]
87
- = DdSdkReactNative.NATIVE_LONG_TASK_THRESHOLD_MS
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
- InternalLog.log("Datadog SDK was initialized", SdkVerbosity.INFO);
102
- DdSdkReactNative.enableFeatures(configuration)
103
- DdSdkReactNative.wasInitialized = true
104
- resolve()
105
- }, (rejection) => {
106
- reject(rejection)
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("Setting attributes " + JSON.stringify(attributes), SdkVerbosity.DEBUG);
119
- return DdSdk.setAttributes(attributes)
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("Setting user " + JSON.stringify(user), SdkVerbosity.DEBUG);
130
- return DdSdk.setUser(user)
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("Setting consent " + consent, SdkVerbosity.DEBUG);
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(configuration: DdSdkReactNativeConfiguration) {
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
- public sampleRate: number = 100.0;
19
- public site: string = "US"
20
- public verbosity: SdkVerbosity|undefined = undefined
21
- public nativeViewTracking: boolean = false
22
- public proxyConfig?: ProxyConfiguration = undefined
23
- public serviceName?: string = undefined
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
  }
@@ -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 (message: string, verbosity: SdkVerbosity): void {
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 = "DATADOG: " + message
30
- if (verbosity == SdkVerbosity.ERROR && (requiredLevel >= allowedLevel)) {
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 == SdkVerbosity.WARN && (requiredLevel >= allowedLevel)) {
35
- console.warn(prefixedMessage)
33
+ if (verbosity === SdkVerbosity.WARN && requiredLevel >= allowedLevel) {
34
+ console.warn(prefixedMessage);
36
35
  }
37
36
 
38
- if (verbosity == SdkVerbosity.INFO && (requiredLevel >= allowedLevel)) {
39
- console.info(prefixedMessage)
37
+ if (verbosity === SdkVerbosity.INFO && requiredLevel >= allowedLevel) {
38
+ console.info(prefixedMessage);
40
39
  }
41
40
 
42
- if (verbosity == SdkVerbosity.DEBUG && (requiredLevel >= allowedLevel)) {
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 = "http",
33
- HTTPS = "https",
34
- SOCKS = "socks"
32
+ HTTP = 'http',
33
+ HTTPS = 'https',
34
+ SOCKS = 'socks'
35
35
  }
36
36
 
37
- export { ProxyConfiguration, ProxyType }
37
+ export { ProxyConfiguration, ProxyType };
@@ -8,8 +8,8 @@
8
8
  * Enum specifying possible log levels for DD SDK.
9
9
  */
10
10
  export enum SdkVerbosity {
11
- DEBUG = "debug",
12
- INFO = "info",
13
- WARN = "warn",
14
- ERROR = "error"
11
+ DEBUG = 'debug',
12
+ INFO = 'info',
13
+ WARN = 'warn',
14
+ ERROR = 'error'
15
15
  }
@@ -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
+ }