@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
package/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # React-Native Monitoring
2
2
 
3
- Datadog *Real User Monitoring (RUM)* enables you to visualize and analyze the real-time performance and user journeys of your application’s individual users.
3
+ Datadog Real User Monitoring (RUM) enables you to visualize and analyze the real-time performance and user journeys of your application’s individual users.
4
4
 
5
5
  ## Setup
6
6
 
@@ -18,6 +18,8 @@ yarn add @datadog/mobile-react-native
18
18
 
19
19
  **Minimum React Native version**: SDK supports React Native version 0.63.4 or higher. Compatibility with older versions is not guaranteed out of the box.
20
20
 
21
+ Versions `1.0.0-rc5` and higher require you to have `compileSdkVersion = 31` in the Android application setup, which implies that you should use Build Tools version 31, Android Gradle Plugin version 7, and Gradle version 7 or higher. To modify the versions, change the values in the `buildscript.ext` block of your application's top-level `build.gradle` file. Datadog recommends using React Native version 0.67 or higher.
22
+
21
23
  ### Specify application details in UI
22
24
 
23
25
  1. In the [Datadog app][1], select **UX Monitoring > RUM Applications > New Application**.
@@ -31,29 +33,33 @@ To ensure the safety of your data, you must use a client token. You cannot use o
31
33
  ### Initialize the library with application context
32
34
 
33
35
  ```js
34
- import { DdSdkReactNative, DdSdkReactNativeConfiguration } from '@datadog/mobile-react-native';
35
-
36
+ import {
37
+ DdSdkReactNative,
38
+ DdSdkReactNativeConfiguration
39
+ } from '@datadog/mobile-react-native';
36
40
 
37
41
  const config = new DdSdkReactNativeConfiguration(
38
- "<CLIENT_TOKEN>",
39
- "<ENVIRONMENT_NAME>",
40
- "<RUM_APPLICATION_ID>",
42
+ '<CLIENT_TOKEN>',
43
+ '<ENVIRONMENT_NAME>',
44
+ '<RUM_APPLICATION_ID>',
41
45
  true, // track User interactions (e.g.: Tap on buttons. You can use 'accessibilityLabel' element property to give tap action the name, otherwise element type will be reported)
42
46
  true, // track XHR Resources
43
47
  true // track Errors
44
- )
48
+ );
45
49
  // Optional: Select your Datadog website (one of "US1", "US3", "US5", EU1", or "US1_FED"). Default is "US1".
46
- config.site = "US1"
50
+ config.site = 'US1';
47
51
  // Optional: enable or disable native crash reports
48
- config.nativeCrashReportEnabled = true
52
+ config.nativeCrashReportEnabled = true;
49
53
  // Optional: sample RUM sessions (here, 80% of session will be sent to Datadog. Default = 100%)
50
- config.sampleRate = 80
54
+ config.sessionSamplingRate = 80;
55
+ // Optional: sample tracing integrations for network calls between your app and your backend (here, 80% of calls to your instrumented backend will be linked from the RUM view to the APM view. Default = 20%)
56
+ config.resourceTracingSamplingRate = 80;
51
57
  // Optional: set the reported service name (by default, it'll use the package name / bundleIdentifier of your Android / iOS app respectively)
52
- config.serviceName = "com.example.reactnative"
58
+ config.serviceName = 'com.example.reactnative';
53
59
  // Optional: let the SDK print internal logs (above or equal to the provided level. Default = undefined (meaning no logs))
54
- config.verbosity = SdkVerbosity.WARN
60
+ config.verbosity = SdkVerbosity.WARN;
55
61
 
56
- await DdSdkReactNative.initialize(config)
62
+ await DdSdkReactNative.initialize(config);
57
63
 
58
64
  // Once SDK is initialized you need to setup view tracking to be able to see data in the RUM Dashboard.
59
65
  ```
@@ -62,14 +68,37 @@ await DdSdkReactNative.initialize(config)
62
68
 
63
69
  Because React Native offers a wide range of libraries to create screen navigation, by default only manual View tracking is supported. You can manually start and stop a View using the following `startView()` and `stopView` methods.
64
70
 
65
-
66
71
  ```js
67
- import { DdSdkReactNative, DdSdkReactNativeConfiguration, DdLogs, DdRum } from '@datadog/mobile-react-native';
68
-
72
+ import {
73
+ DdSdkReactNative,
74
+ DdSdkReactNativeConfiguration,
75
+ DdLogs,
76
+ DdRum
77
+ } from '@datadog/mobile-react-native';
69
78
 
70
79
  // Start a view with a unique view identifier, a custom view url, and an object to attach additional attributes to the view
71
- DdRum.startView('<view-key>', '/view/url', Date.now(), { 'custom.foo': "something" });
80
+ DdRum.startView('<view-key>', '/view/url', Date.now(), {
81
+ 'custom.foo': 'something'
82
+ });
72
83
  // Stops a previously started view with the same unique view identifier, and an object to attach additional attributes to the view
73
84
  DdRum.stopView('<view-key>', Date.now(), { 'custom.bar': 42 });
74
85
  ```
75
86
 
87
+ ## Data Storage
88
+
89
+ ### Android
90
+
91
+ Before data is uploaded to Datadog, it is stored in cleartext in your application's cache directory.
92
+ This cache folder is protected by [Android's Application Sandbox][3], meaning that on most devices
93
+ this data can't be read by other applications. However, if the mobile device is rooted, or someone
94
+ tempers with the linux kernel, the stored data might become readable.
95
+
96
+ ### iOS
97
+
98
+ Before data is uploaded to Datadog, it is stored in cleartext in the cache directory (`Library/Caches`)
99
+ of your [application sandbox](4), which can't be read by any other app installed on the device.
100
+
101
+ [1]: https://app.datadoghq.com/rum/application/create
102
+ [2]: https://raw.githubusercontent.com/DataDog/dd-sdk-reactnative/main/docs/image_reactnative.png
103
+ [3]: https://source.android.com/security/app-sandbox
104
+ [4]: https://support.apple.com/guide/security/security-of-runtime-process-sec15bfe098e/web
@@ -1,4 +1,4 @@
1
- DdSdkReactNative_kotlinVersion=1.3.50
2
- DdSdkReactNative_compileSdkVersion=28
3
- DdSdkReactNative_buildToolsVersion=28.0.3
4
- DdSdkReactNative_targetSdkVersion=28
1
+ DdSdkReactNative_kotlinVersion=1.5.31
2
+ DdSdkReactNative_compileSdkVersion=31
3
+ DdSdkReactNative_buildToolsVersion=31.0.0
4
+ DdSdkReactNative_targetSdkVersion=31
@@ -5,23 +5,23 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  exports.DdSdkReactNative = void 0;
7
7
 
8
- var _types = require("./types");
8
+ var _InternalLog = require("./InternalLog");
9
9
 
10
- var _foundation = require("./foundation");
10
+ var _ProxyConfiguration = require("./ProxyConfiguration");
11
11
 
12
- var _DdRumUserInteractionTracking = require("./rum/instrumentation/DdRumUserInteractionTracking");
12
+ var _SdkVerbosity = require("./SdkVerbosity");
13
+
14
+ var _foundation = require("./foundation");
13
15
 
14
16
  var _DdRumErrorTracking = require("./rum/instrumentation/DdRumErrorTracking");
15
17
 
16
18
  var _DdRumResourceTracking = require("./rum/instrumentation/DdRumResourceTracking");
17
19
 
18
- var _ProxyConfiguration = require("./ProxyConfiguration");
19
-
20
- var _version = require("./version");
20
+ var _DdRumUserInteractionTracking = require("./rum/instrumentation/DdRumUserInteractionTracking");
21
21
 
22
- var _InternalLog = require("./InternalLog");
22
+ var _types = require("./types");
23
23
 
24
- var _SdkVerbosity = require("./SdkVerbosity");
24
+ var _version = require("./version");
25
25
 
26
26
  function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
27
27
 
@@ -32,10 +32,10 @@ class DdSdkReactNative {
32
32
  // Proxy
33
33
 
34
34
  /**
35
- * Initializes the Datadog SDK.
36
- * @param configuration the configuration for the SDK library
37
- * @returns a Promise.
38
- */
35
+ * Initializes the Datadog SDK.
36
+ * @param configuration the configuration for the SDK library
37
+ * @returns a Promise.
38
+ */
39
39
  static initialize(configuration) {
40
40
  return new Promise((resolve, reject) => {
41
41
  if (DdSdkReactNative.wasInitialized) {
@@ -50,7 +50,7 @@ class DdSdkReactNative {
50
50
  configuration.additionalConfig[DdSdkReactNative.DD_SDK_VERSION] = _version.version;
51
51
  configuration.additionalConfig[DdSdkReactNative.DD_NATIVE_VIEW_TRACKING_KEY] = configuration.nativeViewTracking;
52
52
 
53
- if (configuration.verbosity != undefined) {
53
+ if (configuration.verbosity) {
54
54
  configuration.additionalConfig[DdSdkReactNative.DD_SDK_VERBOSITY_KEY] = configuration.verbosity;
55
55
  }
56
56
 
@@ -62,7 +62,7 @@ class DdSdkReactNative {
62
62
  additionalConfig[DdSdkReactNative.DD_PROXY_PORT_KEY] = proxyConfig.port;
63
63
 
64
64
  if (proxyConfig.username && proxyConfig.password) {
65
- if (proxyConfig.type == _ProxyConfiguration.ProxyType.SOCKS) {
65
+ if (proxyConfig.type === _ProxyConfiguration.ProxyType.SOCKS) {
66
66
  console.warn("SOCKS proxy configuration doesn't support Basic authentication.");
67
67
  } else {
68
68
  additionalConfig[DdSdkReactNative.DD_PROXY_USERNAME_KEY] = proxyConfig.username;
@@ -77,8 +77,8 @@ class DdSdkReactNative {
77
77
 
78
78
  configuration.additionalConfig[DdSdkReactNative.DD_NATIVE_LONG_TASK_THRESHOLD_KEY] = DdSdkReactNative.NATIVE_LONG_TASK_THRESHOLD_MS;
79
79
 
80
- _foundation.DdSdk.initialize(new _types.DdSdkConfiguration(configuration.clientToken, configuration.env, configuration.applicationId, configuration.nativeCrashReportEnabled, configuration.sampleRate, configuration.site, configuration.trackingConsent, configuration.additionalConfig)).then(() => {
81
- _InternalLog.InternalLog.log("Datadog SDK was initialized", _SdkVerbosity.SdkVerbosity.INFO);
80
+ _foundation.DdSdk.initialize(new _types.DdSdkConfiguration(configuration.clientToken, configuration.env, configuration.applicationId, configuration.nativeCrashReportEnabled, configuration.sampleRate === undefined ? configuration.sessionSamplingRate : configuration.sampleRate, configuration.site, configuration.trackingConsent, configuration.additionalConfig)).then(() => {
81
+ _InternalLog.InternalLog.log('Datadog SDK was initialized', _SdkVerbosity.SdkVerbosity.INFO);
82
82
 
83
83
  DdSdkReactNative.enableFeatures(configuration);
84
84
  DdSdkReactNative.wasInitialized = true;
@@ -97,7 +97,7 @@ class DdSdkReactNative {
97
97
 
98
98
 
99
99
  static setAttributes(attributes) {
100
- _InternalLog.InternalLog.log("Setting attributes " + JSON.stringify(attributes), _SdkVerbosity.SdkVerbosity.DEBUG);
100
+ _InternalLog.InternalLog.log(`Setting attributes ${JSON.stringify(attributes)}`, _SdkVerbosity.SdkVerbosity.DEBUG);
101
101
 
102
102
  return _foundation.DdSdk.setAttributes(attributes);
103
103
  }
@@ -110,7 +110,7 @@ class DdSdkReactNative {
110
110
 
111
111
 
112
112
  static setUser(user) {
113
- _InternalLog.InternalLog.log("Setting user " + JSON.stringify(user), _SdkVerbosity.SdkVerbosity.DEBUG);
113
+ _InternalLog.InternalLog.log(`Setting user ${JSON.stringify(user)}`, _SdkVerbosity.SdkVerbosity.DEBUG);
114
114
 
115
115
  return _foundation.DdSdk.setUser(user);
116
116
  }
@@ -122,7 +122,7 @@ class DdSdkReactNative {
122
122
 
123
123
 
124
124
  static setTrackingConsent(consent) {
125
- _InternalLog.InternalLog.log("Setting consent " + consent, _SdkVerbosity.SdkVerbosity.DEBUG);
125
+ _InternalLog.InternalLog.log(`Setting consent ${consent}`, _SdkVerbosity.SdkVerbosity.DEBUG);
126
126
 
127
127
  return _foundation.DdSdk.setTrackingConsent(consent);
128
128
  }
@@ -133,7 +133,7 @@ class DdSdkReactNative {
133
133
  }
134
134
 
135
135
  if (configuration.trackResources) {
136
- _DdRumResourceTracking.DdRumResourceTracking.startTracking();
136
+ _DdRumResourceTracking.DdRumResourceTracking.startTracking(configuration.resourceTracingSamplingRate);
137
137
  }
138
138
 
139
139
  if (configuration.trackErrors) {
@@ -145,27 +145,27 @@ class DdSdkReactNative {
145
145
 
146
146
  exports.DdSdkReactNative = DdSdkReactNative;
147
147
 
148
- _defineProperty(DdSdkReactNative, "DD_SOURCE_KEY", "_dd.source");
148
+ _defineProperty(DdSdkReactNative, "DD_SOURCE_KEY", '_dd.source');
149
149
 
150
- _defineProperty(DdSdkReactNative, "DD_SDK_VERSION", "_dd.sdk_version");
150
+ _defineProperty(DdSdkReactNative, "DD_SDK_VERSION", '_dd.sdk_version');
151
151
 
152
- _defineProperty(DdSdkReactNative, "DD_SERVICE_NAME", "_dd.service_name");
152
+ _defineProperty(DdSdkReactNative, "DD_SERVICE_NAME", '_dd.service_name');
153
153
 
154
- _defineProperty(DdSdkReactNative, "DD_SDK_VERBOSITY_KEY", "_dd.sdk_verbosity");
154
+ _defineProperty(DdSdkReactNative, "DD_SDK_VERBOSITY_KEY", '_dd.sdk_verbosity');
155
155
 
156
- _defineProperty(DdSdkReactNative, "DD_NATIVE_VIEW_TRACKING_KEY", "_dd.native_view_tracking");
156
+ _defineProperty(DdSdkReactNative, "DD_NATIVE_VIEW_TRACKING_KEY", '_dd.native_view_tracking');
157
157
 
158
- _defineProperty(DdSdkReactNative, "DD_PROXY_TYPE_KEY", "_dd.proxy.type");
158
+ _defineProperty(DdSdkReactNative, "DD_PROXY_TYPE_KEY", '_dd.proxy.type');
159
159
 
160
- _defineProperty(DdSdkReactNative, "DD_PROXY_ADDRESS_KEY", "_dd.proxy.address");
160
+ _defineProperty(DdSdkReactNative, "DD_PROXY_ADDRESS_KEY", '_dd.proxy.address');
161
161
 
162
- _defineProperty(DdSdkReactNative, "DD_PROXY_PORT_KEY", "_dd.proxy.port");
162
+ _defineProperty(DdSdkReactNative, "DD_PROXY_PORT_KEY", '_dd.proxy.port');
163
163
 
164
- _defineProperty(DdSdkReactNative, "DD_PROXY_USERNAME_KEY", "_dd.proxy.username");
164
+ _defineProperty(DdSdkReactNative, "DD_PROXY_USERNAME_KEY", '_dd.proxy.username');
165
165
 
166
- _defineProperty(DdSdkReactNative, "DD_PROXY_PASSWORD_KEY", "_dd.proxy.password");
166
+ _defineProperty(DdSdkReactNative, "DD_PROXY_PASSWORD_KEY", '_dd.proxy.password');
167
167
 
168
- _defineProperty(DdSdkReactNative, "DD_NATIVE_LONG_TASK_THRESHOLD_KEY", "_dd.long_task.threshold");
168
+ _defineProperty(DdSdkReactNative, "DD_NATIVE_LONG_TASK_THRESHOLD_KEY", '_dd.long_task.threshold');
169
169
 
170
170
  _defineProperty(DdSdkReactNative, "NATIVE_LONG_TASK_THRESHOLD_MS", 200);
171
171
 
@@ -1 +1 @@
1
- {"version":3,"sources":["DdSdkReactNative.tsx"],"names":["DdSdkReactNative","initialize","configuration","Promise","resolve","reject","wasInitialized","InternalLog","log","SdkVerbosity","WARN","verbosity","additionalConfig","DD_SOURCE_KEY","DD_SDK_VERSION","sdkVersion","DD_NATIVE_VIEW_TRACKING_KEY","nativeViewTracking","undefined","DD_SDK_VERBOSITY_KEY","proxyConfig","DD_PROXY_TYPE_KEY","type","DD_PROXY_ADDRESS_KEY","address","DD_PROXY_PORT_KEY","port","username","password","ProxyType","SOCKS","console","warn","DD_PROXY_USERNAME_KEY","DD_PROXY_PASSWORD_KEY","serviceName","DD_SERVICE_NAME","DD_NATIVE_LONG_TASK_THRESHOLD_KEY","NATIVE_LONG_TASK_THRESHOLD_MS","DdSdk","DdSdkConfiguration","clientToken","env","applicationId","nativeCrashReportEnabled","sampleRate","site","trackingConsent","then","INFO","enableFeatures","rejection","setAttributes","attributes","JSON","stringify","DEBUG","setUser","user","setTrackingConsent","consent","trackInteractions","DdRumUserInteractionTracking","startTracking","trackResources","DdRumResourceTracking","trackErrors","DdRumErrorTracking"],"mappings":";;;;;;;AAOA;;AACA;;AACA;;AACA;;AACA;;AAEA;;AACA;;AACA;;AACA;;;;AAEA;AACA;AACA;AACO,MAAMA,gBAAN,CAAuB;AAQ1B;;AAaA;AACJ;AACA;AACA;AACA;AACqB,SAAVC,UAAU,CAACC,aAAD,EAA8D;AAC3E,WAAO,IAAIC,OAAJ,CAAkB,CAACC,OAAD,EAAUC,MAAV,KAAqB;AAC1C,UAAIL,gBAAgB,CAACM,cAArB,EAAqC;AACjCC,iCAAYC,GAAZ,CAAgB,uDAAhB,EAAyEC,2BAAaC,IAAtF;;AACAN,QAAAA,OAAO;AACP;AACH;;AAEDG,+BAAYI,SAAZ,GAAwBT,aAAa,CAACS,SAAtC;AAEAT,MAAAA,aAAa,CAACU,gBAAd,CAA+BZ,gBAAgB,CAACa,aAAhD,IAAiE,cAAjE;AACAX,MAAAA,aAAa,CAACU,gBAAd,CAA+BZ,gBAAgB,CAACc,cAAhD,IAAkEC,gBAAlE;AACAb,MAAAA,aAAa,CAACU,gBAAd,CAA+BZ,gBAAgB,CAACgB,2BAAhD,IAA+Ed,aAAa,CAACe,kBAA7F;;AACA,UAAIf,aAAa,CAACS,SAAd,IAA2BO,SAA/B,EAA0C;AACtChB,QAAAA,aAAa,CAACU,gBAAd,CAA+BZ,gBAAgB,CAACmB,oBAAhD,IAAwEjB,aAAa,CAACS,SAAtF;AACH;;AAED,UAAIT,aAAa,CAACkB,WAAlB,EAA+B;AAC3B,cAAMR,gBAAgB,GAAGV,aAAa,CAACU,gBAAvC;AACA,cAAMQ,WAAW,GAAGlB,aAAa,CAACkB,WAAlC;AAEAR,QAAAA,gBAAgB,CAACZ,gBAAgB,CAACqB,iBAAlB,CAAhB,GAAuDD,WAAW,CAACE,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gB,0BAKsC,mB;;gBALtCA,gB,iCAM6C,0B;;gBAN7CA,gB,uBASmC,gB;;gBATnCA,gB,0BAUsC,mB;;gBAVtCA,gB,uBAWmC,gB;;gBAXnCA,gB,2BAYuC,oB;;gBAZvCA,gB,2BAauC,oB;;gBAbvCA,gB,uCAemD,yB;;gBAfnDA,gB,mCAgB+C,G;;gBAhB/CA,gB,oBAmBuB,K","sourcesContent":["/*\n * Unless explicitly stated otherwise all files in this repository are licensed under the Apache License Version 2.0.\n * This product includes software developed at Datadog (https://www.datadoghq.com/).\n * Copyright 2016-Present Datadog, Inc.\n */\n\nimport type {DdSdkReactNativeConfiguration} from \"./DdSdkReactNativeConfiguration\"\nimport {DdSdkConfiguration} from \"./types\"\nimport {DdSdk} from \"./foundation\"\nimport {DdRumUserInteractionTracking} from './rum/instrumentation/DdRumUserInteractionTracking'\nimport {DdRumErrorTracking} from './rum/instrumentation/DdRumErrorTracking'\nimport {DdRumResourceTracking} from './rum/instrumentation/DdRumResourceTracking'\nimport type {TrackingConsent} from \"./TrackingConsent\"\nimport {ProxyType} from \"./ProxyConfiguration\"\nimport {version as sdkVersion} from './version';\nimport {InternalLog} from \"./InternalLog\"\nimport {SdkVerbosity} from \"./SdkVerbosity\";\n\n/**\n * This class initializes the Datadog SDK, and sets up communication with the server.\n */\nexport class DdSdkReactNative {\n\n private static readonly DD_SOURCE_KEY = \"_dd.source\";\n private static readonly DD_SDK_VERSION = \"_dd.sdk_version\";\n private static readonly DD_SERVICE_NAME = \"_dd.service_name\";\n private static readonly DD_SDK_VERBOSITY_KEY = \"_dd.sdk_verbosity\";\n private static readonly DD_NATIVE_VIEW_TRACKING_KEY = \"_dd.native_view_tracking\";\n\n // Proxy\n private static readonly DD_PROXY_TYPE_KEY = \"_dd.proxy.type\";\n private static readonly DD_PROXY_ADDRESS_KEY = \"_dd.proxy.address\";\n private static readonly DD_PROXY_PORT_KEY = \"_dd.proxy.port\";\n private static readonly DD_PROXY_USERNAME_KEY = \"_dd.proxy.username\";\n private static readonly DD_PROXY_PASSWORD_KEY = \"_dd.proxy.password\";\n\n private static readonly DD_NATIVE_LONG_TASK_THRESHOLD_KEY = \"_dd.long_task.threshold\"\n private static readonly NATIVE_LONG_TASK_THRESHOLD_MS = 200\n\n\n private static wasInitialized = false\n\n /**\n * Initializes the Datadog SDK.\n * @param configuration the configuration for the SDK library\n * @returns a Promise.\n */\n static initialize(configuration: DdSdkReactNativeConfiguration): Promise<void> {\n return new Promise<void>((resolve, reject) => {\n if (DdSdkReactNative.wasInitialized) {\n InternalLog.log(\"Can't initialize Datadog, SDK was already initialized\", SdkVerbosity.WARN);\n resolve()\n return\n }\n\n InternalLog.verbosity = configuration.verbosity\n\n configuration.additionalConfig[DdSdkReactNative.DD_SOURCE_KEY] = 'react-native';\n configuration.additionalConfig[DdSdkReactNative.DD_SDK_VERSION] = sdkVersion;\n configuration.additionalConfig[DdSdkReactNative.DD_NATIVE_VIEW_TRACKING_KEY] = configuration.nativeViewTracking;\n if (configuration.verbosity != undefined) {\n configuration.additionalConfig[DdSdkReactNative.DD_SDK_VERBOSITY_KEY] = configuration.verbosity;\n }\n\n if (configuration.proxyConfig) {\n const additionalConfig = configuration.additionalConfig;\n const proxyConfig = configuration.proxyConfig;\n\n additionalConfig[DdSdkReactNative.DD_PROXY_TYPE_KEY] = proxyConfig.type;\n additionalConfig[DdSdkReactNative.DD_PROXY_ADDRESS_KEY] = proxyConfig.address;\n additionalConfig[DdSdkReactNative.DD_PROXY_PORT_KEY] = proxyConfig.port;\n if (proxyConfig.username && proxyConfig.password) {\n if (proxyConfig.type == ProxyType.SOCKS) {\n console.warn(\"SOCKS proxy configuration doesn't support Basic authentication.\")\n } else {\n additionalConfig[DdSdkReactNative.DD_PROXY_USERNAME_KEY] = proxyConfig.username;\n additionalConfig[DdSdkReactNative.DD_PROXY_PASSWORD_KEY] = proxyConfig.password;\n }\n }\n }\n\n if (configuration.serviceName) {\n configuration.additionalConfig[DdSdkReactNative.DD_SERVICE_NAME] = configuration.serviceName;\n }\n\n configuration.additionalConfig[DdSdkReactNative.DD_NATIVE_LONG_TASK_THRESHOLD_KEY]\n = DdSdkReactNative.NATIVE_LONG_TASK_THRESHOLD_MS\n\n DdSdk.initialize(\n new DdSdkConfiguration(\n configuration.clientToken,\n configuration.env,\n configuration.applicationId,\n configuration.nativeCrashReportEnabled,\n configuration.sampleRate,\n configuration.site,\n configuration.trackingConsent,\n configuration.additionalConfig\n )\n ).then(() => {\n InternalLog.log(\"Datadog SDK was initialized\", SdkVerbosity.INFO);\n DdSdkReactNative.enableFeatures(configuration)\n DdSdkReactNative.wasInitialized = true\n resolve()\n }, (rejection) => {\n reject(rejection)\n })\n })\n }\n\n /**\n * Sets the global context (set of attributes) attached with all future Logs, Spans and RUM events.\n * @param attributes: The global context attributes.\n * @returns a Promise.\n */\n // eslint-disable-next-line @typescript-eslint/ban-types\n static setAttributes(attributes: object): Promise<void> {\n InternalLog.log(\"Setting attributes \" + JSON.stringify(attributes), SdkVerbosity.DEBUG);\n return DdSdk.setAttributes(attributes)\n }\n\n /**\n * Set the user information.\n * @param user: The user object (use builtin attributes: 'id', 'email', 'name', and/or any custom attribute).\n * @returns a Promise.\n */\n // eslint-disable-next-line @typescript-eslint/ban-types\n static setUser(user: object): Promise<void> {\n InternalLog.log(\"Setting user \" + JSON.stringify(user), SdkVerbosity.DEBUG);\n return DdSdk.setUser(user)\n }\n\n /**\n * Set the tracking consent regarding the data collection.\n * @param trackingConsent: One of TrackingConsent values.\n * @returns a Promise.\n */\n static setTrackingConsent(consent: TrackingConsent): Promise<void> {\n InternalLog.log(\"Setting consent \" + consent, SdkVerbosity.DEBUG);\n return DdSdk.setTrackingConsent(consent)\n }\n\n private static enableFeatures(configuration: DdSdkReactNativeConfiguration) {\n if (configuration.trackInteractions) {\n DdRumUserInteractionTracking.startTracking();\n }\n\n if (configuration.trackResources) {\n DdRumResourceTracking.startTracking();\n }\n\n if (configuration.trackErrors) {\n DdRumErrorTracking.startTracking();\n }\n }\n}"]}
1
+ {"version":3,"sources":["DdSdkReactNative.tsx"],"names":["DdSdkReactNative","initialize","configuration","Promise","resolve","reject","wasInitialized","InternalLog","log","SdkVerbosity","WARN","verbosity","additionalConfig","DD_SOURCE_KEY","DD_SDK_VERSION","sdkVersion","DD_NATIVE_VIEW_TRACKING_KEY","nativeViewTracking","DD_SDK_VERBOSITY_KEY","proxyConfig","DD_PROXY_TYPE_KEY","type","DD_PROXY_ADDRESS_KEY","address","DD_PROXY_PORT_KEY","port","username","password","ProxyType","SOCKS","console","warn","DD_PROXY_USERNAME_KEY","DD_PROXY_PASSWORD_KEY","serviceName","DD_SERVICE_NAME","DD_NATIVE_LONG_TASK_THRESHOLD_KEY","NATIVE_LONG_TASK_THRESHOLD_MS","DdSdk","DdSdkConfiguration","clientToken","env","applicationId","nativeCrashReportEnabled","sampleRate","undefined","sessionSamplingRate","site","trackingConsent","then","INFO","enableFeatures","rejection","setAttributes","attributes","JSON","stringify","DEBUG","setUser","user","setTrackingConsent","consent","trackInteractions","DdRumUserInteractionTracking","startTracking","trackResources","DdRumResourceTracking","resourceTracingSamplingRate","trackErrors","DdRumErrorTracking"],"mappings":";;;;;;;AAOA;;AACA;;AACA;;AAEA;;AACA;;AACA;;AACA;;AACA;;AACA;;;;AAEA;AACA;AACA;AACO,MAAMA,gBAAN,CAAuB;AAQ1B;;AAaA;AACJ;AACA;AACA;AACA;AACqB,SAAVC,UAAU,CACbC,aADa,EAEA;AACb,WAAO,IAAIC,OAAJ,CAAkB,CAACC,OAAD,EAAUC,MAAV,KAAqB;AAC1C,UAAIL,gBAAgB,CAACM,cAArB,EAAqC;AACjCC,iCAAYC,GAAZ,CACI,uDADJ,EAEIC,2BAAaC,IAFjB;;AAIAN,QAAAA,OAAO;AACP;AACH;;AAEDG,+BAAYI,SAAZ,GAAwBT,aAAa,CAACS,SAAtC;AAEAT,MAAAA,aAAa,CAACU,gBAAd,CAA+BZ,gBAAgB,CAACa,aAAhD,IACI,cADJ;AAEA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;AAED;AACJ;AACA;AACA;AACA;;;AAC6B,SAAlBC,kBAAkB,CAACC,OAAD,EAA0C;AAC/DtD,6BAAYC,GAAZ,CAAiB,mBAAkBqD,OAAQ,EAA3C,EAA8CpD,2BAAagD,KAA3D;;AACA,WAAOnB,kBAAMsB,kBAAN,CAAyBC,OAAzB,CAAP;AACH;;AAE4B,SAAdV,cAAc,CACzBjD,aADyB,EAE3B;AACE,QAAIA,aAAa,CAAC4D,iBAAlB,EAAqC;AACjCC,iEAA6BC,aAA7B;AACH;;AAED,QAAI9D,aAAa,CAAC+D,cAAlB,EAAkC;AAC9BC,mDAAsBF,aAAtB,CACI9D,aAAa,CAACiE,2BADlB;AAGH;;AAED,QAAIjE,aAAa,CAACkE,WAAlB,EAA+B;AAC3BC,6CAAmBL,aAAnB;AACH;AACJ;;AA/KyB;;;;gBAAjBhE,gB,mBAC+B,Y;;gBAD/BA,gB,oBAEgC,iB;;gBAFhCA,gB,qBAGiC,kB;;gBAHjCA,gB,0BAIsC,mB;;gBAJtCA,gB,iCAML,0B;;gBANKA,gB,uBASmC,gB;;gBATnCA,gB,0BAUsC,mB;;gBAVtCA,gB,uBAWmC,gB;;gBAXnCA,gB,2BAYuC,oB;;gBAZvCA,gB,2BAauC,oB;;gBAbvCA,gB,uCAgBL,yB;;gBAhBKA,gB,mCAiB+C,G;;gBAjB/CA,gB,oBAmBuB,K","sourcesContent":["/*\n * Unless explicitly stated otherwise all files in this repository are licensed under the Apache License Version 2.0.\n * This product includes software developed at Datadog (https://www.datadoghq.com/).\n * Copyright 2016-Present Datadog, Inc.\n */\n\nimport type { DdSdkReactNativeConfiguration } from './DdSdkReactNativeConfiguration';\nimport { InternalLog } from './InternalLog';\nimport { ProxyType } from './ProxyConfiguration';\nimport { SdkVerbosity } from './SdkVerbosity';\nimport type { TrackingConsent } from './TrackingConsent';\nimport { DdSdk } from './foundation';\nimport { DdRumErrorTracking } from './rum/instrumentation/DdRumErrorTracking';\nimport { DdRumResourceTracking } from './rum/instrumentation/DdRumResourceTracking';\nimport { DdRumUserInteractionTracking } from './rum/instrumentation/DdRumUserInteractionTracking';\nimport { DdSdkConfiguration } from './types';\nimport { version as sdkVersion } from './version';\n\n/**\n * This class initializes the Datadog SDK, and sets up communication with the server.\n */\nexport class DdSdkReactNative {\n private static readonly DD_SOURCE_KEY = '_dd.source';\n private static readonly DD_SDK_VERSION = '_dd.sdk_version';\n private static readonly DD_SERVICE_NAME = '_dd.service_name';\n private static readonly DD_SDK_VERBOSITY_KEY = '_dd.sdk_verbosity';\n private static readonly DD_NATIVE_VIEW_TRACKING_KEY =\n '_dd.native_view_tracking';\n\n // Proxy\n private static readonly DD_PROXY_TYPE_KEY = '_dd.proxy.type';\n private static readonly DD_PROXY_ADDRESS_KEY = '_dd.proxy.address';\n private static readonly DD_PROXY_PORT_KEY = '_dd.proxy.port';\n private static readonly DD_PROXY_USERNAME_KEY = '_dd.proxy.username';\n private static readonly DD_PROXY_PASSWORD_KEY = '_dd.proxy.password';\n\n private static readonly DD_NATIVE_LONG_TASK_THRESHOLD_KEY =\n '_dd.long_task.threshold';\n private static readonly NATIVE_LONG_TASK_THRESHOLD_MS = 200;\n\n private static wasInitialized = false;\n\n /**\n * Initializes the Datadog SDK.\n * @param configuration the configuration for the SDK library\n * @returns a Promise.\n */\n static initialize(\n configuration: DdSdkReactNativeConfiguration\n ): Promise<void> {\n return new Promise<void>((resolve, reject) => {\n if (DdSdkReactNative.wasInitialized) {\n InternalLog.log(\n \"Can't initialize Datadog, SDK was already initialized\",\n SdkVerbosity.WARN\n );\n resolve();\n return;\n }\n\n InternalLog.verbosity = configuration.verbosity;\n\n configuration.additionalConfig[DdSdkReactNative.DD_SOURCE_KEY] =\n 'react-native';\n configuration.additionalConfig[\n DdSdkReactNative.DD_SDK_VERSION\n ] = sdkVersion;\n configuration.additionalConfig[\n DdSdkReactNative.DD_NATIVE_VIEW_TRACKING_KEY\n ] = configuration.nativeViewTracking;\n if (configuration.verbosity) {\n configuration.additionalConfig[\n DdSdkReactNative.DD_SDK_VERBOSITY_KEY\n ] = configuration.verbosity;\n }\n\n if (configuration.proxyConfig) {\n const additionalConfig = configuration.additionalConfig;\n const proxyConfig = configuration.proxyConfig;\n\n additionalConfig[DdSdkReactNative.DD_PROXY_TYPE_KEY] =\n proxyConfig.type;\n additionalConfig[DdSdkReactNative.DD_PROXY_ADDRESS_KEY] =\n proxyConfig.address;\n additionalConfig[DdSdkReactNative.DD_PROXY_PORT_KEY] =\n proxyConfig.port;\n if (proxyConfig.username && proxyConfig.password) {\n if (proxyConfig.type === ProxyType.SOCKS) {\n console.warn(\n \"SOCKS proxy configuration doesn't support Basic authentication.\"\n );\n } else {\n additionalConfig[\n DdSdkReactNative.DD_PROXY_USERNAME_KEY\n ] = proxyConfig.username;\n additionalConfig[\n DdSdkReactNative.DD_PROXY_PASSWORD_KEY\n ] = proxyConfig.password;\n }\n }\n }\n\n if (configuration.serviceName) {\n configuration.additionalConfig[\n DdSdkReactNative.DD_SERVICE_NAME\n ] = configuration.serviceName;\n }\n\n configuration.additionalConfig[\n DdSdkReactNative.DD_NATIVE_LONG_TASK_THRESHOLD_KEY\n ] = DdSdkReactNative.NATIVE_LONG_TASK_THRESHOLD_MS;\n\n DdSdk.initialize(\n new DdSdkConfiguration(\n configuration.clientToken,\n configuration.env,\n configuration.applicationId,\n configuration.nativeCrashReportEnabled,\n configuration.sampleRate === undefined\n ? configuration.sessionSamplingRate\n : configuration.sampleRate,\n configuration.site,\n configuration.trackingConsent,\n configuration.additionalConfig\n )\n ).then(\n () => {\n InternalLog.log(\n 'Datadog SDK was initialized',\n SdkVerbosity.INFO\n );\n DdSdkReactNative.enableFeatures(configuration);\n DdSdkReactNative.wasInitialized = true;\n resolve();\n },\n rejection => {\n reject(rejection);\n }\n );\n });\n }\n\n /**\n * Sets the global context (set of attributes) attached with all future Logs, Spans and RUM events.\n * @param attributes: The global context attributes.\n * @returns a Promise.\n */\n // eslint-disable-next-line @typescript-eslint/ban-types\n static setAttributes(attributes: object): Promise<void> {\n InternalLog.log(\n `Setting attributes ${JSON.stringify(attributes)}`,\n SdkVerbosity.DEBUG\n );\n return DdSdk.setAttributes(attributes);\n }\n\n /**\n * Set the user information.\n * @param user: The user object (use builtin attributes: 'id', 'email', 'name', and/or any custom attribute).\n * @returns a Promise.\n */\n // eslint-disable-next-line @typescript-eslint/ban-types\n static setUser(user: object): Promise<void> {\n InternalLog.log(\n `Setting user ${JSON.stringify(user)}`,\n SdkVerbosity.DEBUG\n );\n return DdSdk.setUser(user);\n }\n\n /**\n * Set the tracking consent regarding the data collection.\n * @param trackingConsent: One of TrackingConsent values.\n * @returns a Promise.\n */\n static setTrackingConsent(consent: TrackingConsent): Promise<void> {\n InternalLog.log(`Setting consent ${consent}`, SdkVerbosity.DEBUG);\n return DdSdk.setTrackingConsent(consent);\n }\n\n private static enableFeatures(\n configuration: DdSdkReactNativeConfiguration\n ) {\n if (configuration.trackInteractions) {\n DdRumUserInteractionTracking.startTracking();\n }\n\n if (configuration.trackResources) {\n DdRumResourceTracking.startTracking(\n configuration.resourceTracingSamplingRate\n );\n }\n\n if (configuration.trackErrors) {\n DdRumErrorTracking.startTracking();\n }\n }\n}\n"]}
@@ -14,11 +14,18 @@ function _defineProperty(obj, key, value) { if (key in obj) { Object.definePrope
14
14
  * It will be used to configure the SDK functionality at initialization.
15
15
  */
16
16
  class DdSdkReactNativeConfiguration {
17
- constructor(clientToken, env, applicationId) {
18
- let trackInteractions = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : false;
19
- let trackResources = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : false;
20
- let trackErrors = arguments.length > 5 && arguments[5] !== undefined ? arguments[5] : false;
21
- let trackingConsent = arguments.length > 6 && arguments[6] !== undefined ? arguments[6] : _TrackingConsent.TrackingConsent.GRANTED;
17
+ /**
18
+ * @deprecated `sampleRate` has been replaced by `sessionSamplingRate` to avoid confusion with `resourceTracingSamplingRate` and will be removed in a future release.
19
+ */
20
+
21
+ /**
22
+ * Percentage of sampled RUM sessions. Range `0`-`100`.
23
+ */
24
+
25
+ /**
26
+ * Percentage of tracing integrations for network calls between your app and your backend. Range `0`-`100`.
27
+ */
28
+ constructor(clientToken, env, applicationId, trackInteractions = false, trackResources = false, trackErrors = false, trackingConsent = _TrackingConsent.TrackingConsent.GRANTED) {
22
29
  this.clientToken = clientToken;
23
30
  this.env = env;
24
31
  this.applicationId = applicationId;
@@ -29,9 +36,13 @@ class DdSdkReactNativeConfiguration {
29
36
 
30
37
  _defineProperty(this, "nativeCrashReportEnabled", false);
31
38
 
32
- _defineProperty(this, "sampleRate", 100.0);
39
+ _defineProperty(this, "sampleRate", void 0);
33
40
 
34
- _defineProperty(this, "site", "US");
41
+ _defineProperty(this, "sessionSamplingRate", 100.0);
42
+
43
+ _defineProperty(this, "resourceTracingSamplingRate", 20.0);
44
+
45
+ _defineProperty(this, "site", 'US');
35
46
 
36
47
  _defineProperty(this, "verbosity", undefined);
37
48
 
@@ -1 +1 @@
1
- {"version":3,"sources":["DdSdkReactNativeConfiguration.tsx"],"names":["DdSdkReactNativeConfiguration","constructor","clientToken","env","applicationId","trackInteractions","trackResources","trackErrors","trackingConsent","TrackingConsent","GRANTED","undefined"],"mappings":";;;;;;;AAMA;;;;AAIA;AACA;AACA;AACA;AACO,MAAMA,6BAAN,CAAoC;AAYvCC,EAAAA,WAAW,CACEC,WADF,EAEEC,GAFF,EAGEC,aAHF,EAQT;AAAA,QAJWC,iBAIX,uEAJwC,KAIxC;AAAA,QAHWC,cAGX,uEAHqC,KAGrC;AAAA,QAFWC,WAEX,uEAFkC,KAElC;AAAA,QADWC,eACX,uEAD8CC,iCAAgBC,OAC9D;AAAA,SAPWR,WAOX,GAPWA,WAOX;AAAA,SANWC,GAMX,GANWA,GAMX;AAAA,SALWC,aAKX,GALWA,aAKX;AAAA,SAJWC,iBAIX,GAJWA,iBAIX;AAAA,SAHWC,cAGX,GAHWA,cAGX;AAAA,SAFWC,WAEX,GAFWA,WAEX;AAAA,SADWC,eACX,GADWA,eACX;;AAAA,sDAlByC,KAkBzC;;AAAA,wCAjB0B,KAiB1B;;AAAA,kCAhBoB,IAgBpB;;AAAA,uCAfyCG,SAezC;;AAAA,gDAdmC,KAcnC;;AAAA,yCAbwCA,SAaxC;;AAAA,yCAZ4BA,SAY5B;;AAAA,8CAV4C,EAU5C;AAED;;AAtBsC","sourcesContent":["/*\n * Unless explicitly stated otherwise all files in this repository are licensed under the Apache License Version 2.0.\n * This product includes software developed at Datadog (https://www.datadoghq.com/).\n * Copyright 2016-Present Datadog, Inc.\n */\n\nimport { TrackingConsent } from './TrackingConsent'\nimport type { SdkVerbosity } from './SdkVerbosity'\nimport type { ProxyConfiguration } from './ProxyConfiguration';\n\n/**\n * The SDK configuration class.\n * It will be used to configure the SDK functionality at initialization.\n */\nexport class DdSdkReactNativeConfiguration {\n\n public nativeCrashReportEnabled: boolean = false;\n public sampleRate: number = 100.0;\n public site: string = \"US\"\n public verbosity: SdkVerbosity|undefined = undefined\n public nativeViewTracking: boolean = false\n public proxyConfig?: ProxyConfiguration = undefined\n public serviceName?: string = undefined\n\n public additionalConfig: {[k: string]: any} = {};\n\n constructor(\n readonly clientToken: string,\n readonly env: string,\n readonly applicationId: string,\n readonly trackInteractions: boolean = false,\n readonly trackResources: boolean = false,\n readonly trackErrors: boolean = false,\n readonly trackingConsent: TrackingConsent = TrackingConsent.GRANTED\n ) {\n\n }\n}\n"]}
1
+ {"version":3,"sources":["DdSdkReactNativeConfiguration.tsx"],"names":["DdSdkReactNativeConfiguration","constructor","clientToken","env","applicationId","trackInteractions","trackResources","trackErrors","trackingConsent","TrackingConsent","GRANTED","undefined"],"mappings":";;;;;;;AAQA;;;;AAEA;AACA;AACA;AACA;AACO,MAAMA,6BAAN,CAAoC;AAEvC;AACJ;AACA;;AAEI;AACJ;AACA;;AAEI;AACJ;AACA;AAUIC,EAAAA,WAAW,CACEC,WADF,EAEEC,GAFF,EAGEC,aAHF,EAIEC,iBAA0B,GAAG,KAJ/B,EAKEC,cAAuB,GAAG,KAL5B,EAMEC,WAAoB,GAAG,KANzB,EAOEC,eAAgC,GAAGC,iCAAgBC,OAPrD,EAQT;AAAA,SAPWR,WAOX,GAPWA,WAOX;AAAA,SANWC,GAMX,GANWA,GAMX;AAAA,SALWC,aAKX,GALWA,aAKX;AAAA,SAJWC,iBAIX,GAJWA,iBAIX;AAAA,SAHWC,cAGX,GAHWA,cAGX;AAAA,SAFWC,WAEX,GAFWA,WAEX;AAAA,SADWC,eACX,GADWA,eACX;;AAAA,sDA7ByC,KA6BzC;;AAAA;;AAAA,iDArBmC,KAqBnC;;AAAA,yDAjB2C,IAiB3C;;AAAA,kCAhBoB,IAgBpB;;AAAA,uCAf2CG,SAe3C;;AAAA,gDAdmC,KAcnC;;AAAA,yCAbwCA,SAaxC;;AAAA,yCAZ4BA,SAY5B;;AAAA,8CAV8C,EAU9C;AAAE;;AA9BmC","sourcesContent":["/*\n * Unless explicitly stated otherwise all files in this repository are licensed under the Apache License Version 2.0.\n * This product includes software developed at Datadog (https://www.datadoghq.com/).\n * Copyright 2016-Present Datadog, Inc.\n */\n\nimport type { ProxyConfiguration } from './ProxyConfiguration';\nimport type { SdkVerbosity } from './SdkVerbosity';\nimport { TrackingConsent } from './TrackingConsent';\n\n/**\n * The SDK configuration class.\n * It will be used to configure the SDK functionality at initialization.\n */\nexport class DdSdkReactNativeConfiguration {\n public nativeCrashReportEnabled: boolean = false;\n /**\n * @deprecated `sampleRate` has been replaced by `sessionSamplingRate` to avoid confusion with `resourceTracingSamplingRate` and will be removed in a future release.\n */\n public sampleRate?: number;\n /**\n * Percentage of sampled RUM sessions. Range `0`-`100`.\n */\n public sessionSamplingRate: number = 100.0;\n /**\n * Percentage of tracing integrations for network calls between your app and your backend. Range `0`-`100`.\n */\n public resourceTracingSamplingRate: number = 20.0;\n public site: string = 'US';\n public verbosity: SdkVerbosity | undefined = undefined;\n public nativeViewTracking: boolean = false;\n public proxyConfig?: ProxyConfiguration = undefined;\n public serviceName?: string = undefined;\n\n public additionalConfig: { [k: string]: any } = {};\n\n constructor(\n readonly clientToken: string,\n readonly env: string,\n readonly applicationId: string,\n readonly trackInteractions: boolean = false,\n readonly trackResources: boolean = false,\n readonly trackErrors: boolean = false,\n readonly trackingConsent: TrackingConsent = TrackingConsent.GRANTED\n ) {}\n}\n"]}
@@ -22,21 +22,21 @@ class InternalLog {
22
22
  return;
23
23
  }
24
24
 
25
- const prefixedMessage = "DATADOG: " + message;
25
+ const prefixedMessage = `DATADOG: ${message}`;
26
26
 
27
- if (verbosity == _SdkVerbosity.SdkVerbosity.ERROR && requiredLevel >= allowedLevel) {
27
+ if (verbosity === _SdkVerbosity.SdkVerbosity.ERROR && requiredLevel >= allowedLevel) {
28
28
  console.error(prefixedMessage);
29
29
  }
30
30
 
31
- if (verbosity == _SdkVerbosity.SdkVerbosity.WARN && requiredLevel >= allowedLevel) {
31
+ if (verbosity === _SdkVerbosity.SdkVerbosity.WARN && requiredLevel >= allowedLevel) {
32
32
  console.warn(prefixedMessage);
33
33
  }
34
34
 
35
- if (verbosity == _SdkVerbosity.SdkVerbosity.INFO && requiredLevel >= allowedLevel) {
35
+ if (verbosity === _SdkVerbosity.SdkVerbosity.INFO && requiredLevel >= allowedLevel) {
36
36
  console.info(prefixedMessage);
37
37
  }
38
38
 
39
- if (verbosity == _SdkVerbosity.SdkVerbosity.DEBUG && requiredLevel >= allowedLevel) {
39
+ if (verbosity === _SdkVerbosity.SdkVerbosity.DEBUG && requiredLevel >= allowedLevel) {
40
40
  console.debug(prefixedMessage);
41
41
  }
42
42
  }
@@ -1 +1 @@
1
- {"version":3,"sources":["InternalLog.tsx"],"names":["InternalLog","log","message","verbosity","undefined","requiredLevel","levelMap","get","allowedLevel","prefixedMessage","SdkVerbosity","ERROR","console","error","WARN","warn","INFO","info","DEBUG","debug","Map"],"mappings":";;;;;;;AAMA;;;;AAEO,MAAMA,WAAN,CAAkB;AAWJ,SAAHC,GAAG,CAAEC,OAAF,EAAmBC,SAAnB,EAAkD;AAC/D,QAAIH,WAAW,CAACG,SAAZ,KAA0BC,SAA9B,EAAyC;AACrC;AACH;;AACD,UAAMC,aAAa,GAAGL,WAAW,CAACM,QAAZ,CAAqBC,GAArB,CAAyBJ,SAAzB,CAAtB;AACA,UAAMK,YAAY,GAAGR,WAAW,CAACM,QAAZ,CAAqBC,GAArB,CAAyBP,WAAW,CAACG,SAArC,CAArB;;AACA,QAAIK,YAAY,KAAKJ,SAAjB,IAA8BC,aAAa,KAAKD,SAApD,EAA+D;AAC3D;AACH;;AACD,UAAMK,eAAe,GAAG,cAAcP,OAAtC;;AACA,QAAIC,SAAS,IAAIO,2BAAaC,KAA1B,IAAoCN,aAAa,IAAIG,YAAzD,EAAwE;AACpEI,MAAAA,OAAO,CAACC,KAAR,CAAcJ,eAAd;AACH;;AAED,QAAIN,SAAS,IAAIO,2BAAaI,IAA1B,IAAmCT,aAAa,IAAIG,YAAxD,EAAuE;AACnEI,MAAAA,OAAO,CAACG,IAAR,CAAaN,eAAb;AACH;;AAED,QAAIN,SAAS,IAAIO,2BAAaM,IAA1B,IAAmCX,aAAa,IAAIG,YAAxD,EAAuE;AACnEI,MAAAA,OAAO,CAACK,IAAR,CAAaR,eAAb;AACH;;AAED,QAAIN,SAAS,IAAIO,2BAAaQ,KAA1B,IAAoCb,aAAa,IAAIG,YAAzD,EAAwE;AACpEI,MAAAA,OAAO,CAACO,KAAR,CAAcV,eAAd;AACH;AACJ;;AApCoB;;;;gBAAZT,W,cAEiB,IAAIoB,GAAJ,CAA8B,CACpD,CAACV,2BAAaQ,KAAd,EAAqB,CAArB,CADoD,EAEpD,CAACR,2BAAaM,IAAd,EAAoB,CAApB,CAFoD,EAGpD,CAACN,2BAAaI,IAAd,EAAoB,CAApB,CAHoD,EAIpD,CAACJ,2BAAaC,KAAd,EAAqB,CAArB,CAJoD,CAA9B,C;;gBAFjBX,W,eASyCI,S","sourcesContent":["/*\n * Unless explicitly stated otherwise all files in this repository are licensed under the Apache License Version 2.0.\n * This product includes software developed at Datadog (https://www.datadoghq.com/).\n * Copyright 2016-Present Datadog, Inc.\n */\n\nimport {SdkVerbosity} from './SdkVerbosity'\n\nexport class InternalLog {\n\n private static levelMap = new Map<SdkVerbosity, number>([\n [SdkVerbosity.DEBUG, 1],\n [SdkVerbosity.INFO, 2],\n [SdkVerbosity.WARN, 3],\n [SdkVerbosity.ERROR, 4]\n ]);\n\n public static verbosity: SdkVerbosity|undefined = undefined\n\n public static log (message: string, verbosity: SdkVerbosity): void {\n if (InternalLog.verbosity === undefined) {\n return;\n }\n const requiredLevel = InternalLog.levelMap.get(verbosity);\n const allowedLevel = InternalLog.levelMap.get(InternalLog.verbosity);\n if (allowedLevel === undefined || requiredLevel === undefined) {\n return;\n }\n const prefixedMessage = \"DATADOG: \" + message\n if (verbosity == SdkVerbosity.ERROR && (requiredLevel >= allowedLevel)) {\n console.error(prefixedMessage)\n }\n\n if (verbosity == SdkVerbosity.WARN && (requiredLevel >= allowedLevel)) {\n console.warn(prefixedMessage)\n }\n\n if (verbosity == SdkVerbosity.INFO && (requiredLevel >= allowedLevel)) {\n console.info(prefixedMessage)\n }\n\n if (verbosity == SdkVerbosity.DEBUG && (requiredLevel >= allowedLevel)) {\n console.debug(prefixedMessage)\n }\n }\n\n\n}"]}
1
+ {"version":3,"sources":["InternalLog.tsx"],"names":["InternalLog","log","message","verbosity","undefined","requiredLevel","levelMap","get","allowedLevel","prefixedMessage","SdkVerbosity","ERROR","console","error","WARN","warn","INFO","info","DEBUG","debug","Map"],"mappings":";;;;;;;AAMA;;;;AAEO,MAAMA,WAAN,CAAkB;AAUJ,SAAHC,GAAG,CAACC,OAAD,EAAkBC,SAAlB,EAAiD;AAC9D,QAAIH,WAAW,CAACG,SAAZ,KAA0BC,SAA9B,EAAyC;AACrC;AACH;;AACD,UAAMC,aAAa,GAAGL,WAAW,CAACM,QAAZ,CAAqBC,GAArB,CAAyBJ,SAAzB,CAAtB;AACA,UAAMK,YAAY,GAAGR,WAAW,CAACM,QAAZ,CAAqBC,GAArB,CAAyBP,WAAW,CAACG,SAArC,CAArB;;AACA,QAAIK,YAAY,KAAKJ,SAAjB,IAA8BC,aAAa,KAAKD,SAApD,EAA+D;AAC3D;AACH;;AACD,UAAMK,eAAe,GAAI,YAAWP,OAAQ,EAA5C;;AACA,QAAIC,SAAS,KAAKO,2BAAaC,KAA3B,IAAoCN,aAAa,IAAIG,YAAzD,EAAuE;AACnEI,MAAAA,OAAO,CAACC,KAAR,CAAcJ,eAAd;AACH;;AAED,QAAIN,SAAS,KAAKO,2BAAaI,IAA3B,IAAmCT,aAAa,IAAIG,YAAxD,EAAsE;AAClEI,MAAAA,OAAO,CAACG,IAAR,CAAaN,eAAb;AACH;;AAED,QAAIN,SAAS,KAAKO,2BAAaM,IAA3B,IAAmCX,aAAa,IAAIG,YAAxD,EAAsE;AAClEI,MAAAA,OAAO,CAACK,IAAR,CAAaR,eAAb;AACH;;AAED,QAAIN,SAAS,KAAKO,2BAAaQ,KAA3B,IAAoCb,aAAa,IAAIG,YAAzD,EAAuE;AACnEI,MAAAA,OAAO,CAACO,KAAR,CAAcV,eAAd;AACH;AACJ;;AAnCoB;;;;gBAAZT,W,cACiB,IAAIoB,GAAJ,CAA8B,CACpD,CAACV,2BAAaQ,KAAd,EAAqB,CAArB,CADoD,EAEpD,CAACR,2BAAaM,IAAd,EAAoB,CAApB,CAFoD,EAGpD,CAACN,2BAAaI,IAAd,EAAoB,CAApB,CAHoD,EAIpD,CAACJ,2BAAaC,KAAd,EAAqB,CAArB,CAJoD,CAA9B,C;;gBADjBX,W,eAQ2CI,S","sourcesContent":["/*\n * Unless explicitly stated otherwise all files in this repository are licensed under the Apache License Version 2.0.\n * This product includes software developed at Datadog (https://www.datadoghq.com/).\n * Copyright 2016-Present Datadog, Inc.\n */\n\nimport { SdkVerbosity } from './SdkVerbosity';\n\nexport class InternalLog {\n private static levelMap = new Map<SdkVerbosity, number>([\n [SdkVerbosity.DEBUG, 1],\n [SdkVerbosity.INFO, 2],\n [SdkVerbosity.WARN, 3],\n [SdkVerbosity.ERROR, 4]\n ]);\n\n public static verbosity: SdkVerbosity | undefined = undefined;\n\n public static log(message: string, verbosity: SdkVerbosity): void {\n if (InternalLog.verbosity === undefined) {\n return;\n }\n const requiredLevel = InternalLog.levelMap.get(verbosity);\n const allowedLevel = InternalLog.levelMap.get(InternalLog.verbosity);\n if (allowedLevel === undefined || requiredLevel === undefined) {\n return;\n }\n const prefixedMessage = `DATADOG: ${message}`;\n if (verbosity === SdkVerbosity.ERROR && requiredLevel >= allowedLevel) {\n console.error(prefixedMessage);\n }\n\n if (verbosity === SdkVerbosity.WARN && requiredLevel >= allowedLevel) {\n console.warn(prefixedMessage);\n }\n\n if (verbosity === SdkVerbosity.INFO && requiredLevel >= allowedLevel) {\n console.info(prefixedMessage);\n }\n\n if (verbosity === SdkVerbosity.DEBUG && requiredLevel >= allowedLevel) {\n console.debug(prefixedMessage);\n }\n }\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"sources":["ProxyConfiguration.tsx"],"names":["ProxyConfiguration","constructor","type","address","port","username","password","ProxyType"],"mappings":";;;;;;;AAAA;AACA;AACA;AACA,MAAMA,kBAAN,CAAyB;AACrBC,EAAAA,WAAW;AACP;AACR;AACA;AACiBC,EAAAA,IAJF;AAKP;AACR;AACA;AACiBC,EAAAA,OARF;AASP;AACR;AACA;AACiBC,EAAAA,IAZF;AAaP;AACR;AACA;AACA;AACA;AACiBC,EAAAA,QAlBF;AAmBP;AACR;AACA;AACiBC,EAAAA,QAtBF,EAuBT;AAAA,SAnBWJ,IAmBX,GAnBWA,IAmBX;AAAA,SAfWC,OAeX,GAfWA,OAeX;AAAA,SAXWC,IAWX,GAXWA,IAWX;AAAA,SALWC,QAKX,GALWA,QAKX;AAAA,SADWC,QACX,GADWA,QACX;AAAG;;AAxBgB;;;IA2BpBC,S;;;WAAAA,S;AAAAA,EAAAA,S;AAAAA,EAAAA,S;AAAAA,EAAAA,S;GAAAA,S,yBAAAA,S","sourcesContent":["/**\n * Proxy server configuration.\n */\nclass ProxyConfiguration {\n constructor(\n /**\n * Proxy type.\n */\n readonly type: ProxyType,\n /**\n * Proxy address. Can be either in the IP address format, ex. \"1.1.1.1\", or hostname, ex. \"example.com\".\n */\n readonly address: string,\n /**\n * Proxy port.\n */\n readonly port: number,\n /**\n * Username for Basic authentication scheme.\n *\n * Note: \"SOCKS + authentication\" scheme is not supported.\n */\n readonly username?: string,\n /**\n * Password for Basic authentication scheme.\n */\n readonly password?: string\n ) { }\n}\n\nenum ProxyType {\n HTTP = \"http\",\n HTTPS = \"https\",\n SOCKS = \"socks\"\n}\n\nexport { ProxyConfiguration, ProxyType }\n"]}
1
+ {"version":3,"sources":["ProxyConfiguration.tsx"],"names":["ProxyConfiguration","constructor","type","address","port","username","password","ProxyType"],"mappings":";;;;;;;AAAA;AACA;AACA;AACA,MAAMA,kBAAN,CAAyB;AACrBC,EAAAA,WAAW;AACP;AACR;AACA;AACiBC,EAAAA,IAJF;AAKP;AACR;AACA;AACiBC,EAAAA,OARF;AASP;AACR;AACA;AACiBC,EAAAA,IAZF;AAaP;AACR;AACA;AACA;AACA;AACiBC,EAAAA,QAlBF;AAmBP;AACR;AACA;AACiBC,EAAAA,QAtBF,EAuBT;AAAA,SAnBWJ,IAmBX,GAnBWA,IAmBX;AAAA,SAfWC,OAeX,GAfWA,OAeX;AAAA,SAXWC,IAWX,GAXWA,IAWX;AAAA,SALWC,QAKX,GALWA,QAKX;AAAA,SADWC,QACX,GADWA,QACX;AAAE;;AAxBiB;;;IA2BpBC,S;;;WAAAA,S;AAAAA,EAAAA,S;AAAAA,EAAAA,S;AAAAA,EAAAA,S;GAAAA,S,yBAAAA,S","sourcesContent":["/**\n * Proxy server configuration.\n */\nclass ProxyConfiguration {\n constructor(\n /**\n * Proxy type.\n */\n readonly type: ProxyType,\n /**\n * Proxy address. Can be either in the IP address format, ex. \"1.1.1.1\", or hostname, ex. \"example.com\".\n */\n readonly address: string,\n /**\n * Proxy port.\n */\n readonly port: number,\n /**\n * Username for Basic authentication scheme.\n *\n * Note: \"SOCKS + authentication\" scheme is not supported.\n */\n readonly username?: string,\n /**\n * Password for Basic authentication scheme.\n */\n readonly password?: string\n ) {}\n}\n\nenum ProxyType {\n HTTP = 'http',\n HTTPS = 'https',\n SOCKS = 'socks'\n}\n\nexport { ProxyConfiguration, ProxyType };\n"]}
@@ -1 +1 @@
1
- {"version":3,"sources":["SdkVerbosity.tsx"],"names":["SdkVerbosity"],"mappings":";;;;;;;AAAA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;IACYA,Y;;;WAAAA,Y;AAAAA,EAAAA,Y;AAAAA,EAAAA,Y;AAAAA,EAAAA,Y;AAAAA,EAAAA,Y;GAAAA,Y,4BAAAA,Y","sourcesContent":["/*\n * Unless explicitly stated otherwise all files in this repository are licensed under the Apache License Version 2.0.\n * This product includes software developed at Datadog (https://www.datadoghq.com/).\n * Copyright 2016-Present Datadog, Inc.\n */\n\n/**\n * Enum specifying possible log levels for DD SDK.\n */\nexport enum SdkVerbosity {\n DEBUG = \"debug\",\n INFO = \"info\",\n WARN = \"warn\",\n ERROR = \"error\"\n}\n"]}
1
+ {"version":3,"sources":["SdkVerbosity.tsx"],"names":["SdkVerbosity"],"mappings":";;;;;;;AAAA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;IACYA,Y;;;WAAAA,Y;AAAAA,EAAAA,Y;AAAAA,EAAAA,Y;AAAAA,EAAAA,Y;AAAAA,EAAAA,Y;GAAAA,Y,4BAAAA,Y","sourcesContent":["/*\n * Unless explicitly stated otherwise all files in this repository are licensed under the Apache License Version 2.0.\n * This product includes software developed at Datadog (https://www.datadoghq.com/).\n * Copyright 2016-Present Datadog, Inc.\n */\n\n/**\n * Enum specifying possible log levels for DD SDK.\n */\nexport enum SdkVerbosity {\n DEBUG = 'debug',\n INFO = 'info',\n WARN = 'warn',\n ERROR = 'error'\n}\n"]}
@@ -0,0 +1,72 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.TimeProvider = void 0;
7
+
8
+ function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
9
+
10
+ /*
11
+ * Unless explicitly stated otherwise all files in this repository are licensed under the Apache License Version 2.0.
12
+ * This product includes software developed at Datadog (https://www.datadoghq.com/).
13
+ * Copyright 2016-Present Datadog, Inc.
14
+ */
15
+
16
+ /**
17
+ * A Timestamp structure holding the
18
+ */
19
+
20
+ /**
21
+ * Simple class providing timestamps in milliseconds.
22
+ * If available, it will use the `performance.now()` method, and will fallback on `Date.now()` otherwise.
23
+ */
24
+ class TimeProvider {
25
+ /** Keeps an average offset between the unix time and the provided timestamp. */
26
+ constructor() {
27
+ _defineProperty(this, "canUsePerformanceNow", // eslint-disable-next-line @typescript-eslint/ban-ts-comment
28
+ // @ts-ignore
29
+ global.performance && typeof performance.now === 'function');
30
+
31
+ _defineProperty(this, "baseOffset", void 0);
32
+
33
+ const timestamp = this.getTimestamp();
34
+
35
+ if (timestamp.react_native == null) {
36
+ this.baseOffset = 0;
37
+ } else {
38
+ this.baseOffset = timestamp.unix - timestamp.react_native;
39
+ }
40
+ }
41
+
42
+ getTimestamp() {
43
+ return {
44
+ unix: Date.now(),
45
+ react_native: this.performanceNow()
46
+ };
47
+ }
48
+
49
+ now() {
50
+ const timestamp = this.getTimestamp();
51
+
52
+ if (timestamp.react_native == null) {
53
+ return timestamp.unix;
54
+ } else {
55
+ return this.baseOffset + timestamp.react_native;
56
+ }
57
+ }
58
+
59
+ performanceNow() {
60
+ if (this.canUsePerformanceNow) {
61
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
62
+ // @ts-ignore
63
+ return performance.now();
64
+ }
65
+
66
+ return null;
67
+ }
68
+
69
+ }
70
+
71
+ exports.TimeProvider = TimeProvider;
72
+ //# sourceMappingURL=TimeProvider.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["TimeProvider.tsx"],"names":["TimeProvider","constructor","global","performance","now","timestamp","getTimestamp","react_native","baseOffset","unix","Date","performanceNow","canUsePerformanceNow"],"mappings":";;;;;;;;;AAAA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;;AASA;AACA;AACA;AACA;AACO,MAAMA,YAAN,CAAmB;AAMtB;AAGAC,EAAAA,WAAW,GAAG;AAAA,kDAPV;AACA;AACAC,IAAAA,MAAM,CAACC,WAAP,IAAsB,OAAOA,WAAW,CAACC,GAAnB,KAA2B,UAKvC;;AAAA;;AACV,UAAMC,SAAS,GAAG,KAAKC,YAAL,EAAlB;;AACA,QAAID,SAAS,CAACE,YAAV,IAA0B,IAA9B,EAAoC;AAChC,WAAKC,UAAL,GAAkB,CAAlB;AACH,KAFD,MAEO;AACH,WAAKA,UAAL,GAAkBH,SAAS,CAACI,IAAV,GAAiBJ,SAAS,CAACE,YAA7C;AACH;AACJ;;AAEDD,EAAAA,YAAY,GAAc;AACtB,WAAO;AACHG,MAAAA,IAAI,EAAEC,IAAI,CAACN,GAAL,EADH;AAEHG,MAAAA,YAAY,EAAE,KAAKI,cAAL;AAFX,KAAP;AAIH;;AAEDP,EAAAA,GAAG,GAAW;AACV,UAAMC,SAAS,GAAG,KAAKC,YAAL,EAAlB;;AACA,QAAID,SAAS,CAACE,YAAV,IAA0B,IAA9B,EAAoC;AAChC,aAAOF,SAAS,CAACI,IAAjB;AACH,KAFD,MAEO;AACH,aAAO,KAAKD,UAAL,GAAkBH,SAAS,CAACE,YAAnC;AACH;AACJ;;AAEOI,EAAAA,cAAc,GAAkB;AACpC,QAAI,KAAKC,oBAAT,EAA+B;AAC3B;AACA;AACA,aAAOT,WAAW,CAACC,GAAZ,EAAP;AACH;;AACD,WAAO,IAAP;AACH;;AAzCqB","sourcesContent":["/*\n * Unless explicitly stated otherwise all files in this repository are licensed under the Apache License Version 2.0.\n * This product includes software developed at Datadog (https://www.datadoghq.com/).\n * Copyright 2016-Present Datadog, Inc.\n */\n\n/**\n * A Timestamp structure holding the\n */\nexport type Timestamp = {\n // Result of Date API. Unix timestamp in ms.\n unix: number;\n // Result of performance.now API. Timestamp in ms (with microsecond precision)\n // since JS context start.\n react_native: number | null;\n};\n\n/**\n * Simple class providing timestamps in milliseconds.\n * If available, it will use the `performance.now()` method, and will fallback on `Date.now()` otherwise.\n */\nexport class TimeProvider {\n private canUsePerformanceNow =\n // eslint-disable-next-line @typescript-eslint/ban-ts-comment\n // @ts-ignore\n global.performance && typeof performance.now === 'function';\n\n /** Keeps an average offset between the unix time and the provided timestamp. */\n private baseOffset: number;\n\n constructor() {\n const timestamp = this.getTimestamp();\n if (timestamp.react_native == null) {\n this.baseOffset = 0;\n } else {\n this.baseOffset = timestamp.unix - timestamp.react_native;\n }\n }\n\n getTimestamp(): Timestamp {\n return {\n unix: Date.now(),\n react_native: this.performanceNow()\n };\n }\n\n now(): number {\n const timestamp = this.getTimestamp();\n if (timestamp.react_native == null) {\n return timestamp.unix;\n } else {\n return this.baseOffset + timestamp.react_native;\n }\n }\n\n private performanceNow(): number | null {\n if (this.canUsePerformanceNow) {\n // eslint-disable-next-line @typescript-eslint/ban-ts-comment\n // @ts-ignore\n return performance.now();\n }\n return null;\n }\n}\n"]}
@@ -5,18 +5,24 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  exports.default = void 0;
7
7
 
8
+ var _TimeProvider = require("./TimeProvider");
9
+
8
10
  function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
9
11
 
10
- const START_LABEL = "__start";
11
- const STOP_LABEL = "__stop";
12
+ const START_LABEL = '__start';
13
+ const STOP_LABEL = '__stop';
12
14
  /**
13
15
  * Simple timer which records time ticks. Shouldn't be re-used once stopped.
14
16
  * All timestamps/durations returned are in milliseconds.
15
17
  */
16
18
 
17
19
  class Timer {
18
- constructor() {
20
+ constructor(timeProvider = new _TimeProvider.TimeProvider()) {
21
+ _defineProperty(this, "timeProvider", void 0);
22
+
19
23
  _defineProperty(this, "times", {});
24
+
25
+ this.timeProvider = timeProvider;
20
26
  }
21
27
 
22
28
  get startTime() {
@@ -36,10 +42,7 @@ class Timer {
36
42
  }
37
43
 
38
44
  recordTick(label) {
39
- this.times[label] = {
40
- unix: Date.now(),
41
- react_native: this.performanceNow()
42
- };
45
+ this.times[label] = this.timeProvider.getTimestamp();
43
46
  }
44
47
 
45
48
  hasTickFor(label) {
@@ -71,22 +74,6 @@ class Timer {
71
74
  return end.unix - start.unix;
72
75
  }
73
76
 
74
- performanceNow() {
75
- if (this.canUsePerformanceNow()) {
76
- // eslint-disable-next-line @typescript-eslint/ban-ts-comment
77
- // @ts-ignore
78
- return performance.now();
79
- }
80
-
81
- return null;
82
- }
83
-
84
- canUsePerformanceNow() {
85
- // eslint-disable-next-line @typescript-eslint/ban-ts-comment
86
- // @ts-ignore
87
- return global.performance && typeof performance.now === 'function';
88
- }
89
-
90
77
  checkLabelExists(label) {
91
78
  if (!this.hasTickFor(label)) {
92
79
  throw new Error(`Label ${label} is not registered`);
@@ -1 +1 @@
1
- {"version":3,"sources":["Timer.ts"],"names":["START_LABEL","STOP_LABEL","Timer","startTime","times","unix","stopTime","durationBetween","start","recordTick","stop","label","Date","now","react_native","performanceNow","hasTickFor","startLabel","endLabel","checkLabelExists","startTick","endTick","durationBetweenTicks","timeAt","reset","end","canUsePerformanceNow","performance","global","Error"],"mappings":";;;;;;;;;AAQA,MAAMA,WAAW,GAAG,SAApB;AACA,MAAMC,UAAU,GAAG,QAAnB;AAEA;AACA;AACA;AACA;;AACe,MAAMC,KAAN,CAAY;AAAA;AAAA,mCAEoB,EAFpB;AAAA;;AAIV,MAATC,SAAS,GAAW;AACpB,WAAO,KAAKC,KAAL,CAAWJ,WAAX,EAAwBK,IAA/B;AACH;;AAEW,MAARC,QAAQ,GAAW;AACnB,WAAO,KAAKH,SAAL,GAA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AACH;;AACD,WAAOW,GAAG,CAACpB,IAAJ,GAAWG,KAAK,CAACH,IAAxB;AACH;;AAGOU,EAAAA,cAAc,GAAkB;AACpC,QAAI,KAAKW,oBAAL,EAAJ,EAAiC;AAC7B;AACA;AACA,aAAOC,WAAW,CAACd,GAAZ,EAAP;AACH;;AACD,WAAO,IAAP;AACH;;AAEOa,EAAAA,oBAAoB,GAAY;AACpC;AACA;AACA,WAAOE,MAAM,CAACD,WAAP,IAAsB,OAAOA,WAAW,CAACd,GAAnB,KAA2B,UAAxD;AACH;;AAEOM,EAAAA,gBAAgB,CAACR,KAAD,EAAgB;AACpC,QAAI,CAAC,KAAKK,UAAL,CAAgBL,KAAhB,CAAL,EAA6B;AACzB,YAAM,IAAIkB,KAAJ,CAAW,SAAQlB,KAAM,oBAAzB,CAAN;AACH;AACJ;;AA9EsB","sourcesContent":["type Timestamp = {\n // Result of Date API. Unix timestamp in ms.\n unix: number,\n // Result of performance.now API. Timestamp in ms (with microsecond precision)\n // since JS context start.\n react_native: number | null\n}\n\nconst START_LABEL = \"__start\"\nconst STOP_LABEL = \"__stop\"\n\n/**\n * Simple timer which records time ticks. Shouldn't be re-used once stopped.\n * All timestamps/durations returned are in milliseconds.\n */\nexport default class Timer {\n\n private times: Record<string, Timestamp> = {};\n\n get startTime(): number {\n return this.times[START_LABEL].unix\n }\n\n get stopTime(): number {\n return this.startTime + this.durationBetween(START_LABEL, STOP_LABEL)\n }\n\n start(): void {\n this.recordTick(START_LABEL);\n }\n\n stop(): void {\n this.recordTick(STOP_LABEL)\n }\n\n recordTick(label: string): void {\n this.times[label] = {\n unix: Date.now(),\n react_native: this.performanceNow()\n }\n }\n\n hasTickFor(label: string): boolean {\n return label in this.times;\n }\n\n durationBetween(startLabel: string, endLabel: string): number {\n this.checkLabelExists(startLabel);\n this.checkLabelExists(endLabel);\n\n const startTick = this.times[startLabel];\n const endTick = this.times[endLabel];\n\n return this.durationBetweenTicks(startTick, endTick);\n }\n\n timeAt(label: string): number {\n this.checkLabelExists(label);\n\n return this.startTime + this.durationBetween(START_LABEL, label)\n }\n\n reset(): void {\n this.times = {};\n }\n\n private durationBetweenTicks(start: Timestamp, end: Timestamp): number {\n if (start.react_native != null && end.react_native != null) {\n return end.react_native - start.react_native;\n }\n return end.unix - start.unix;\n }\n\n\n private performanceNow(): number | null {\n if (this.canUsePerformanceNow()) {\n // eslint-disable-next-line @typescript-eslint/ban-ts-comment\n // @ts-ignore\n return performance.now();\n }\n return null;\n }\n\n private canUsePerformanceNow(): boolean {\n // eslint-disable-next-line @typescript-eslint/ban-ts-comment\n // @ts-ignore\n return global.performance && typeof performance.now === 'function';\n }\n\n private checkLabelExists(label: string) {\n if (!this.hasTickFor(label)) {\n throw new Error(`Label ${label} is not registered`);\n }\n }\n\n}\n"]}
1
+ {"version":3,"sources":["Timer.ts"],"names":["START_LABEL","STOP_LABEL","Timer","constructor","timeProvider","TimeProvider","startTime","times","unix","stopTime","durationBetween","start","recordTick","stop","label","getTimestamp","hasTickFor","startLabel","endLabel","checkLabelExists","startTick","endTick","durationBetweenTicks","timeAt","reset","end","react_native","Error"],"mappings":";;;;;;;AAOA;;;;AAEA,MAAMA,WAAW,GAAG,SAApB;AACA,MAAMC,UAAU,GAAG,QAAnB;AAEA;AACA;AACA;AACA;;AACe,MAAMC,KAAN,CAAY;AAIvBC,EAAAA,WAAW,CAACC,YAA0B,GAAG,IAAIC,0BAAJ,EAA9B,EAAkD;AAAA;;AAAA,mCAFlB,EAEkB;;AACzD,SAAKD,YAAL,GAAoBA,YAApB;AACH;;AAEY,MAATE,SAAS,GAAW;AACpB,WAAO,KAAKC,KAAL,CAAWP,WAAX,EAAwBQ,IAA/B;AACH;;AAEW,MAARC,QAAQ,GAAW;AACnB,WAAO,KAAKH,SAAL,GAAiB,KAAKI,eAAL,CAAqBV,WAArB,EAAkCC,UAAlC,CAAxB;AACH;;AAEDU,EAAAA,KAAK,GAAS;AACV,SAAKC,UAAL,CAAgBZ,WAAhB;AACH;;AA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Qb,KAAM,oBAAzB,CAAN;AACH;AACJ;;AA/DsB","sourcesContent":["/*\n * Unless explicitly stated otherwise all files in this repository are licensed under the Apache License Version 2.0.\n * This product includes software developed at Datadog (https://www.datadoghq.com/).\n * Copyright 2016-Present Datadog, Inc.\n */\n\nimport type { Timestamp } from './TimeProvider';\nimport { TimeProvider } from './TimeProvider';\n\nconst START_LABEL = '__start';\nconst STOP_LABEL = '__stop';\n\n/**\n * Simple timer which records time ticks. Shouldn't be re-used once stopped.\n * All timestamps/durations returned are in milliseconds.\n */\nexport default class Timer {\n private timeProvider: TimeProvider;\n private times: Record<string, Timestamp> = {};\n\n constructor(timeProvider: TimeProvider = new TimeProvider()) {\n this.timeProvider = timeProvider;\n }\n\n get startTime(): number {\n return this.times[START_LABEL].unix;\n }\n\n get stopTime(): number {\n return this.startTime + this.durationBetween(START_LABEL, STOP_LABEL);\n }\n\n start(): void {\n this.recordTick(START_LABEL);\n }\n\n stop(): void {\n this.recordTick(STOP_LABEL);\n }\n\n recordTick(label: string): void {\n this.times[label] = this.timeProvider.getTimestamp();\n }\n\n hasTickFor(label: string): boolean {\n return label in this.times;\n }\n\n durationBetween(startLabel: string, endLabel: string): number {\n this.checkLabelExists(startLabel);\n this.checkLabelExists(endLabel);\n\n const startTick = this.times[startLabel];\n const endTick = this.times[endLabel];\n\n return this.durationBetweenTicks(startTick, endTick);\n }\n\n timeAt(label: string): number {\n this.checkLabelExists(label);\n\n return this.startTime + this.durationBetween(START_LABEL, label);\n }\n\n reset(): void {\n this.times = {};\n }\n\n private durationBetweenTicks(start: Timestamp, end: Timestamp): number {\n if (start.react_native != null && end.react_native != null) {\n return end.react_native - start.react_native;\n }\n return end.unix - start.unix;\n }\n\n private checkLabelExists(label: string) {\n if (!this.hasTickFor(label)) {\n throw new Error(`Label ${label} is not registered`);\n }\n }\n}\n"]}