@datadog/mobile-react-native 1.0.0-rc4 → 1.0.0-rc7

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 (124) hide show
  1. package/DatadogSDKReactNative.podspec +1 -1
  2. package/README.md +47 -16
  3. package/android/build.gradle +1 -1
  4. package/android/gradle.properties +4 -4
  5. package/lib/commonjs/DdSdkReactNative.js +38 -23
  6. package/lib/commonjs/DdSdkReactNative.js.map +1 -1
  7. package/lib/commonjs/DdSdkReactNativeConfiguration.js +17 -2
  8. package/lib/commonjs/DdSdkReactNativeConfiguration.js.map +1 -1
  9. package/lib/commonjs/InternalLog.js +56 -0
  10. package/lib/commonjs/InternalLog.js.map +1 -0
  11. package/lib/commonjs/ProxyConfiguration.js.map +1 -1
  12. package/lib/commonjs/SdkVerbosity.js +26 -0
  13. package/lib/commonjs/SdkVerbosity.js.map +1 -0
  14. package/lib/commonjs/TimeProvider.js +72 -0
  15. package/lib/commonjs/TimeProvider.js.map +1 -0
  16. package/lib/commonjs/Timer.js +10 -23
  17. package/lib/commonjs/Timer.js.map +1 -1
  18. package/lib/commonjs/TrackingConsent.js.map +1 -1
  19. package/lib/commonjs/foundation.js +51 -11
  20. package/lib/commonjs/foundation.js.map +1 -1
  21. package/lib/commonjs/index.js +34 -18
  22. package/lib/commonjs/index.js.map +1 -1
  23. package/lib/commonjs/rum/instrumentation/DdEventsInterceptor.js +14 -5
  24. package/lib/commonjs/rum/instrumentation/DdEventsInterceptor.js.map +1 -1
  25. package/lib/commonjs/rum/instrumentation/DdRumErrorTracking.js +34 -23
  26. package/lib/commonjs/rum/instrumentation/DdRumErrorTracking.js.map +1 -1
  27. package/lib/commonjs/rum/instrumentation/DdRumResourceTracking.js +62 -36
  28. package/lib/commonjs/rum/instrumentation/DdRumResourceTracking.js.map +1 -1
  29. package/lib/commonjs/rum/instrumentation/DdRumUserInteractionTracking.js +46 -7
  30. package/lib/commonjs/rum/instrumentation/DdRumUserInteractionTracking.js.map +1 -1
  31. package/lib/commonjs/rum/instrumentation/NoOpEventsInterceptor.js.map +1 -1
  32. package/lib/commonjs/rum/instrumentation/ShallowObjectEqualityChecker.js +34 -0
  33. package/lib/commonjs/rum/instrumentation/ShallowObjectEqualityChecker.js.map +1 -0
  34. package/lib/commonjs/rum/instrumentation/TraceIdentifier.js.map +1 -1
  35. package/lib/commonjs/types.js.map +1 -1
  36. package/lib/commonjs/version.js +1 -1
  37. package/lib/commonjs/version.js.map +1 -1
  38. package/lib/module/DdSdkReactNative.js +31 -23
  39. package/lib/module/DdSdkReactNative.js.map +1 -1
  40. package/lib/module/DdSdkReactNativeConfiguration.js +18 -3
  41. package/lib/module/DdSdkReactNativeConfiguration.js.map +1 -1
  42. package/lib/module/InternalLog.js +52 -0
  43. package/lib/module/InternalLog.js.map +1 -0
  44. package/lib/module/ProxyConfiguration.js.map +1 -1
  45. package/lib/module/SdkVerbosity.js +18 -0
  46. package/lib/module/SdkVerbosity.js.map +1 -0
  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 +31 -11
  53. package/lib/module/foundation.js.map +1 -1
  54. package/lib/module/index.js +4 -2
  55. package/lib/module/index.js.map +1 -1
  56. package/lib/module/rum/instrumentation/DdEventsInterceptor.js +11 -5
  57. package/lib/module/rum/instrumentation/DdEventsInterceptor.js.map +1 -1
  58. package/lib/module/rum/instrumentation/DdRumErrorTracking.js +30 -23
  59. package/lib/module/rum/instrumentation/DdRumErrorTracking.js.map +1 -1
  60. package/lib/module/rum/instrumentation/DdRumResourceTracking.js +57 -34
  61. package/lib/module/rum/instrumentation/DdRumResourceTracking.js.map +1 -1
  62. package/lib/module/rum/instrumentation/DdRumUserInteractionTracking.js +41 -6
  63. package/lib/module/rum/instrumentation/DdRumUserInteractionTracking.js.map +1 -1
  64. package/lib/module/rum/instrumentation/NoOpEventsInterceptor.js.map +1 -1
  65. package/lib/module/rum/instrumentation/ShallowObjectEqualityChecker.js +25 -0
  66. package/lib/module/rum/instrumentation/ShallowObjectEqualityChecker.js.map +1 -0
  67. package/lib/module/rum/instrumentation/TraceIdentifier.js.map +1 -1
  68. package/lib/module/types.js.map +1 -1
  69. package/lib/module/version.js +1 -1
  70. package/lib/module/version.js.map +1 -1
  71. package/lib/typescript/DdSdkReactNative.d.ts +6 -6
  72. package/lib/typescript/DdSdkReactNativeConfiguration.d.ts +15 -4
  73. package/lib/typescript/InternalLog.d.ts +11 -0
  74. package/lib/typescript/SdkVerbosity.d.ts +9 -0
  75. package/lib/typescript/TimeProvider.d.ts +20 -0
  76. package/lib/typescript/Timer.d.ts +3 -2
  77. package/lib/typescript/index.d.ts +4 -2
  78. package/lib/typescript/rum/instrumentation/DdEventsInterceptor.d.ts +1 -0
  79. package/lib/typescript/rum/instrumentation/DdRumErrorTracking.d.ts +2 -2
  80. package/lib/typescript/rum/instrumentation/DdRumResourceTracking.d.ts +10 -9
  81. package/lib/typescript/rum/instrumentation/DdRumUserInteractionTracking.d.ts +3 -3
  82. package/lib/typescript/rum/instrumentation/DdRumXhr.d.ts +13 -3
  83. package/lib/typescript/rum/instrumentation/ShallowObjectEqualityChecker.d.ts +4 -0
  84. package/lib/typescript/version.d.ts +1 -1
  85. package/package.json +6 -3
  86. package/src/DdSdkReactNative.tsx +112 -62
  87. package/src/DdSdkReactNativeConfiguration.tsx +22 -14
  88. package/src/InternalLog.tsx +50 -0
  89. package/src/ProxyConfiguration.tsx +5 -5
  90. package/src/{NativeSdkVerbosity.tsx → SdkVerbosity.tsx} +6 -6
  91. package/src/TimeProvider.tsx +64 -0
  92. package/src/Timer.ts +20 -35
  93. package/src/TrackingConsent.tsx +3 -3
  94. package/src/__mocks__/InternalLog.tsx +9 -0
  95. package/src/__tests__/DdRumWrapper.test.tsx +40 -33
  96. package/src/__tests__/DdSdkReactNative.test.tsx +697 -513
  97. package/src/__tests__/InternalLog.test.tsx +379 -0
  98. package/src/__tests__/TimeProvider.test.tsx +75 -0
  99. package/src/__tests__/Timer.test.ts +148 -57
  100. package/src/__tests__/rum/instrumentation/DdEventsInterceptor.test.tsx +151 -92
  101. package/src/__tests__/rum/instrumentation/DdRumErrorTracking.test.tsx +179 -106
  102. package/src/__tests__/rum/instrumentation/DdRumResourceTracking.test.tsx +714 -644
  103. package/src/__tests__/rum/instrumentation/DdRumUserInteractionTracking.test.tsx +239 -85
  104. package/src/__tests__/rum/instrumentation/ShallowObjectEqualityChecker.test.ts +31 -0
  105. package/src/__tests__/rum/instrumentation/TraceIdentifier.test.tsx +13 -15
  106. package/src/__tests__/rum/instrumentation/__utils__/XMLHttpRequestMock.ts +97 -0
  107. package/src/foundation.tsx +80 -61
  108. package/src/index.tsx +15 -3
  109. package/src/rum/instrumentation/DdEventsInterceptor.tsx +51 -35
  110. package/src/rum/instrumentation/DdRumErrorTracking.tsx +61 -49
  111. package/src/rum/instrumentation/DdRumResourceTracking.tsx +307 -233
  112. package/src/rum/instrumentation/DdRumUserInteractionTracking.tsx +72 -25
  113. package/src/rum/instrumentation/DdRumXhr.tsx +21 -11
  114. package/src/rum/instrumentation/EventsInterceptor.tsx +3 -3
  115. package/src/rum/instrumentation/NoOpEventsInterceptor.tsx +2 -2
  116. package/src/rum/instrumentation/ShallowObjectEqualityChecker.ts +24 -0
  117. package/src/rum/instrumentation/TraceIdentifier.tsx +19 -19
  118. package/src/types.tsx +199 -158
  119. package/src/version.ts +1 -1
  120. package/lib/commonjs/NativeSdkVerbosity.js +0 -26
  121. package/lib/commonjs/NativeSdkVerbosity.js.map +0 -1
  122. package/lib/module/NativeSdkVerbosity.js +0 -18
  123. package/lib/module/NativeSdkVerbosity.js.map +0 -1
  124. package/lib/typescript/NativeSdkVerbosity.d.ts +0 -9
@@ -5,12 +5,14 @@ function _defineProperty(obj, key, value) { if (key in obj) { Object.definePrope
5
5
  * This product includes software developed at Datadog (https://www.datadoghq.com/).
6
6
  * Copyright 2016-Present Datadog, Inc.
7
7
  */
8
- import { DdSdkConfiguration } from "./types";
9
- import { DdSdk } from "./foundation";
10
- import { DdRumUserInteractionTracking } from './rum/instrumentation/DdRumUserInteractionTracking';
8
+ import { InternalLog } from './InternalLog';
9
+ import { ProxyType } from './ProxyConfiguration';
10
+ import { SdkVerbosity } from './SdkVerbosity';
11
+ import { DdSdk } from './foundation';
11
12
  import { DdRumErrorTracking } from './rum/instrumentation/DdRumErrorTracking';
12
13
  import { DdRumResourceTracking } from './rum/instrumentation/DdRumResourceTracking';
13
- import { ProxyType } from "./ProxyConfiguration";
14
+ import { DdRumUserInteractionTracking } from './rum/instrumentation/DdRumUserInteractionTracking';
15
+ import { DdSdkConfiguration } from './types';
14
16
  import { version as sdkVersion } from './version';
15
17
  /**
16
18
  * This class initializes the Datadog SDK, and sets up communication with the server.
@@ -20,22 +22,24 @@ export class DdSdkReactNative {
20
22
  // Proxy
21
23
 
22
24
  /**
23
- * Initializes the Datadog SDK.
24
- * @param configuration the configuration for the SDK library
25
- * @returns a Promise.
26
- */
25
+ * Initializes the Datadog SDK.
26
+ * @param configuration the configuration for the SDK library
27
+ * @returns a Promise.
28
+ */
27
29
  static initialize(configuration) {
28
30
  return new Promise((resolve, reject) => {
29
31
  if (DdSdkReactNative.wasInitialized) {
32
+ InternalLog.log("Can't initialize Datadog, SDK was already initialized", SdkVerbosity.WARN);
30
33
  resolve();
31
34
  return;
32
35
  }
33
36
 
37
+ InternalLog.verbosity = configuration.verbosity;
34
38
  configuration.additionalConfig[DdSdkReactNative.DD_SOURCE_KEY] = 'react-native';
35
39
  configuration.additionalConfig[DdSdkReactNative.DD_SDK_VERSION] = sdkVersion;
36
40
  configuration.additionalConfig[DdSdkReactNative.DD_NATIVE_VIEW_TRACKING_KEY] = configuration.nativeViewTracking;
37
41
 
38
- if (configuration.verbosity != undefined) {
42
+ if (configuration.verbosity) {
39
43
  configuration.additionalConfig[DdSdkReactNative.DD_SDK_VERBOSITY_KEY] = configuration.verbosity;
40
44
  }
41
45
 
@@ -47,7 +51,7 @@ export class DdSdkReactNative {
47
51
  additionalConfig[DdSdkReactNative.DD_PROXY_PORT_KEY] = proxyConfig.port;
48
52
 
49
53
  if (proxyConfig.username && proxyConfig.password) {
50
- if (proxyConfig.type == ProxyType.SOCKS) {
54
+ if (proxyConfig.type === ProxyType.SOCKS) {
51
55
  console.warn("SOCKS proxy configuration doesn't support Basic authentication.");
52
56
  } else {
53
57
  additionalConfig[DdSdkReactNative.DD_PROXY_USERNAME_KEY] = proxyConfig.username;
@@ -61,7 +65,8 @@ export class DdSdkReactNative {
61
65
  }
62
66
 
63
67
  configuration.additionalConfig[DdSdkReactNative.DD_NATIVE_LONG_TASK_THRESHOLD_KEY] = DdSdkReactNative.NATIVE_LONG_TASK_THRESHOLD_MS;
64
- DdSdk.initialize(new DdSdkConfiguration(configuration.clientToken, configuration.env, configuration.applicationId, configuration.nativeCrashReportEnabled, configuration.sampleRate, configuration.site, configuration.trackingConsent, configuration.additionalConfig)).then(() => {
68
+ DdSdk.initialize(new DdSdkConfiguration(configuration.clientToken, configuration.env, configuration.applicationId, configuration.nativeCrashReportEnabled, configuration.sampleRate === undefined ? configuration.sessionSamplingRate : configuration.sampleRate, configuration.site, configuration.trackingConsent, configuration.additionalConfig)).then(() => {
69
+ InternalLog.log('Datadog SDK was initialized', SdkVerbosity.INFO);
65
70
  DdSdkReactNative.enableFeatures(configuration);
66
71
  DdSdkReactNative.wasInitialized = true;
67
72
  resolve();
@@ -79,6 +84,7 @@ export class DdSdkReactNative {
79
84
 
80
85
 
81
86
  static setAttributes(attributes) {
87
+ InternalLog.log(`Setting attributes ${JSON.stringify(attributes)}`, SdkVerbosity.DEBUG);
82
88
  return DdSdk.setAttributes(attributes);
83
89
  }
84
90
  /**
@@ -90,6 +96,7 @@ export class DdSdkReactNative {
90
96
 
91
97
 
92
98
  static setUser(user) {
99
+ InternalLog.log(`Setting user ${JSON.stringify(user)}`, SdkVerbosity.DEBUG);
93
100
  return DdSdk.setUser(user);
94
101
  }
95
102
  /**
@@ -100,6 +107,7 @@ export class DdSdkReactNative {
100
107
 
101
108
 
102
109
  static setTrackingConsent(consent) {
110
+ InternalLog.log(`Setting consent ${consent}`, SdkVerbosity.DEBUG);
103
111
  return DdSdk.setTrackingConsent(consent);
104
112
  }
105
113
 
@@ -109,7 +117,7 @@ export class DdSdkReactNative {
109
117
  }
110
118
 
111
119
  if (configuration.trackResources) {
112
- DdRumResourceTracking.startTracking();
120
+ DdRumResourceTracking.startTracking(configuration.resourceTracingSamplingRate);
113
121
  }
114
122
 
115
123
  if (configuration.trackErrors) {
@@ -119,27 +127,27 @@ export class DdSdkReactNative {
119
127
 
120
128
  }
121
129
 
122
- _defineProperty(DdSdkReactNative, "DD_SOURCE_KEY", "_dd.source");
130
+ _defineProperty(DdSdkReactNative, "DD_SOURCE_KEY", '_dd.source');
123
131
 
124
- _defineProperty(DdSdkReactNative, "DD_SDK_VERSION", "_dd.sdk_version");
132
+ _defineProperty(DdSdkReactNative, "DD_SDK_VERSION", '_dd.sdk_version');
125
133
 
126
- _defineProperty(DdSdkReactNative, "DD_SERVICE_NAME", "_dd.service_name");
134
+ _defineProperty(DdSdkReactNative, "DD_SERVICE_NAME", '_dd.service_name');
127
135
 
128
- _defineProperty(DdSdkReactNative, "DD_SDK_VERBOSITY_KEY", "_dd.sdk_verbosity");
136
+ _defineProperty(DdSdkReactNative, "DD_SDK_VERBOSITY_KEY", '_dd.sdk_verbosity');
129
137
 
130
- _defineProperty(DdSdkReactNative, "DD_NATIVE_VIEW_TRACKING_KEY", "_dd.native_view_tracking");
138
+ _defineProperty(DdSdkReactNative, "DD_NATIVE_VIEW_TRACKING_KEY", '_dd.native_view_tracking');
131
139
 
132
- _defineProperty(DdSdkReactNative, "DD_PROXY_TYPE_KEY", "_dd.proxy.type");
140
+ _defineProperty(DdSdkReactNative, "DD_PROXY_TYPE_KEY", '_dd.proxy.type');
133
141
 
134
- _defineProperty(DdSdkReactNative, "DD_PROXY_ADDRESS_KEY", "_dd.proxy.address");
142
+ _defineProperty(DdSdkReactNative, "DD_PROXY_ADDRESS_KEY", '_dd.proxy.address');
135
143
 
136
- _defineProperty(DdSdkReactNative, "DD_PROXY_PORT_KEY", "_dd.proxy.port");
144
+ _defineProperty(DdSdkReactNative, "DD_PROXY_PORT_KEY", '_dd.proxy.port');
137
145
 
138
- _defineProperty(DdSdkReactNative, "DD_PROXY_USERNAME_KEY", "_dd.proxy.username");
146
+ _defineProperty(DdSdkReactNative, "DD_PROXY_USERNAME_KEY", '_dd.proxy.username');
139
147
 
140
- _defineProperty(DdSdkReactNative, "DD_PROXY_PASSWORD_KEY", "_dd.proxy.password");
148
+ _defineProperty(DdSdkReactNative, "DD_PROXY_PASSWORD_KEY", '_dd.proxy.password');
141
149
 
142
- _defineProperty(DdSdkReactNative, "DD_NATIVE_LONG_TASK_THRESHOLD_KEY", "_dd.long_task.threshold");
150
+ _defineProperty(DdSdkReactNative, "DD_NATIVE_LONG_TASK_THRESHOLD_KEY", '_dd.long_task.threshold');
143
151
 
144
152
  _defineProperty(DdSdkReactNative, "NATIVE_LONG_TASK_THRESHOLD_MS", 200);
145
153
 
@@ -1 +1 @@
1
- {"version":3,"sources":["DdSdkReactNative.tsx"],"names":["DdSdkConfiguration","DdSdk","DdRumUserInteractionTracking","DdRumErrorTracking","DdRumResourceTracking","ProxyType","version","sdkVersion","DdSdkReactNative","initialize","configuration","Promise","resolve","reject","wasInitialized","additionalConfig","DD_SOURCE_KEY","DD_SDK_VERSION","DD_NATIVE_VIEW_TRACKING_KEY","nativeViewTracking","verbosity","undefined","DD_SDK_VERBOSITY_KEY","proxyConfig","DD_PROXY_TYPE_KEY","type","DD_PROXY_ADDRESS_KEY","address","DD_PROXY_PORT_KEY","port","username","password","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","clientToken","env","applicationId","nativeCrashReportEnabled","sampleRate","site","trackingConsent","then","enableFeatures","rejection","setAttributes","attributes","setUser","user","setTrackingConsent","consent","trackInteractions","startTracking","trackResources","trackErrors"],"mappings":";;AAAA;AACA;AACA;AACA;AACA;AAGA,SAASA,kBAAT,QAAmC,SAAnC;AACA,SAASC,KAAT,QAAsB,cAAtB;AACA,SAASC,4BAAT,QAA6C,oDAA7C;AACA,SAASC,kBAAT,QAAmC,0CAAnC;AACA,SAASC,qBAAT,QAAsC,6CAAtC;AAEA,SAASC,SAAT,QAA0B,sBAA1B;AAEA,SAAQC,OAAO,IAAIC,UAAnB,QAAqC,WAArC;AAEA;AACA;AACA;;AACA,OAAO,MAAMC,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;AACjCF,QAAAA,OAAO;AACP;AACH;;AAEDF,MAAAA,aAAa,CAACK,gBAAd,CAA+BP,gBAAgB,CAACQ,aAAhD,IAAiE,cAAjE;AACAN,MAAAA,aAAa,CAACK,gBAAd,CAA+BP,gBAAgB,CAACS,cAAhD,IAAkEV,UAAlE;AACAG,MAAAA,aAAa,CAACK,gBAAd,CAA+BP,gBAAgB,CAACU,2BAAhD,IAA+ER,aAAa,CAACS,kBAA7F;;AACA,UAAIT,aAAa,CAACU,SAAd,IAA2BC,SAA/B,EAA0C;AACtCX,QAAAA,aAAa,CAACK,gBAAd,CAA+BP,gBAAgB,CAACc,oBAAhD,IAAwEZ,aAAa,CAACU,SAAtF;AACH;;AAED,UAAIV,aAAa,CAACa,WAAlB,EAA+B;AAC3B,cAAMR,gBAAgB,GAAGL,aAAa,CAACK,gBAAvC;AACA,cAAMQ,W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A,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\"\n\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\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 resolve()\n return\n }\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 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 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 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 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":["InternalLog","ProxyType","SdkVerbosity","DdSdk","DdRumErrorTracking","DdRumResourceTracking","DdRumUserInteractionTracking","DdSdkConfiguration","version","sdkVersion","DdSdkReactNative","initialize","configuration","Promise","resolve","reject","wasInitialized","log","WARN","verbosity","additionalConfig","DD_SOURCE_KEY","DD_SDK_VERSION","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","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","clientToken","env","applicationId","nativeCrashReportEnabled","sampleRate","undefined","sessionSamplingRate","site","trackingConsent","then","INFO","enableFeatures","rejection","setAttributes","attributes","JSON","stringify","DEBUG","setUser","user","setTrackingConsent","consent","trackInteractions","startTracking","trackResources","resourceTracingSamplingRate","trackErrors"],"mappings":";;AAAA;AACA;AACA;AACA;AACA;AAGA,SAASA,WAAT,QAA4B,eAA5B;AACA,SAASC,SAAT,QAA0B,sBAA1B;AACA,SAASC,YAAT,QAA6B,gBAA7B;AAEA,SAASC,KAAT,QAAsB,cAAtB;AACA,SAASC,kBAAT,QAAmC,0CAAnC;AACA,SAASC,qBAAT,QAAsC,6CAAtC;AACA,SAASC,4BAAT,QAA6C,oDAA7C;AACA,SAASC,kBAAT,QAAmC,SAAnC;AACA,SAASC,OAAO,IAAIC,UAApB,QAAsC,WAAtC;AAEA;AACA;AACA;;AACA,OAAO,MAAMC,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;AACjChB,QAAAA,WAAW,CAACiB,GAAZ,CACI,uDADJ,EAEIf,YAAY,CAACgB,IAFjB;AAIAJ,QAAAA,OAAO;AACP;AACH;;AAEDd,MAAAA,WAAW,CAACmB,SAAZ,GAAwBP,aAAa,CAACO,SAAtC;AAEAP,MAAAA,aAAa,CAACQ,gBAAd,CAA+BV,gBAAgB,CAACW,aAAhD,IACI,cADJ;AAEAT,MAAAA,aAAa,CAACQ,gBAAd,CACIV,gBAAgB,CAACY,cADrB,IAEIb,UAFJ;AAGAG,MAAAA,aAAa,CAACQ,gBAAd,CACIV,gBAAgB,CAACa,2BADrB,IAEIX,aAAa,CAACY,kBAFlB;;AAGA,UAAIZ,aAAa,CAACO,SAAlB,EAA6B;AACzBP,QAA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D,YAAY,CAAC2D,KAA3D;AACA,WAAO1D,KAAK,CAAC6D,kBAAN,CAAyBC,OAAzB,CAAP;AACH;;AAE4B,SAAdV,cAAc,CACzB3C,aADyB,EAE3B;AACE,QAAIA,aAAa,CAACsD,iBAAlB,EAAqC;AACjC5D,MAAAA,4BAA4B,CAAC6D,aAA7B;AACH;;AAED,QAAIvD,aAAa,CAACwD,cAAlB,EAAkC;AAC9B/D,MAAAA,qBAAqB,CAAC8D,aAAtB,CACIvD,aAAa,CAACyD,2BADlB;AAGH;;AAED,QAAIzD,aAAa,CAAC0D,WAAlB,EAA+B;AAC3BlE,MAAAA,kBAAkB,CAAC+D,aAAnB;AACH;AACJ;;AA/KyB;;gBAAjBzD,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"]}
@@ -6,12 +6,23 @@ function _defineProperty(obj, key, value) { if (key in obj) { Object.definePrope
6
6
  * Copyright 2016-Present Datadog, Inc.
7
7
  */
8
8
  import { TrackingConsent } from './TrackingConsent';
9
-
10
9
  /**
11
10
  * The SDK configuration class.
12
11
  * It will be used to configure the SDK functionality at initialization.
13
12
  */
13
+
14
14
  export class DdSdkReactNativeConfiguration {
15
+ /**
16
+ * @deprecated `sampleRate` has been replaced by `sessionSamplingRate` to avoid confusion with `resourceTracingSamplingRate` and will be removed in a future release.
17
+ */
18
+
19
+ /**
20
+ * Percentage of sampled RUM sessions. Range `0`-`100`.
21
+ */
22
+
23
+ /**
24
+ * Percentage of tracing integrations for network calls between your app and your backend. Range `0`-`100`.
25
+ */
15
26
  constructor(clientToken, env, applicationId, trackInteractions = false, trackResources = false, trackErrors = false, trackingConsent = TrackingConsent.GRANTED) {
16
27
  this.clientToken = clientToken;
17
28
  this.env = env;
@@ -23,9 +34,13 @@ export class DdSdkReactNativeConfiguration {
23
34
 
24
35
  _defineProperty(this, "nativeCrashReportEnabled", false);
25
36
 
26
- _defineProperty(this, "sampleRate", 100.0);
37
+ _defineProperty(this, "sampleRate", void 0);
38
+
39
+ _defineProperty(this, "sessionSamplingRate", 100.0);
40
+
41
+ _defineProperty(this, "resourceTracingSamplingRate", 20.0);
27
42
 
28
- _defineProperty(this, "site", "US");
43
+ _defineProperty(this, "site", 'US');
29
44
 
30
45
  _defineProperty(this, "verbosity", undefined);
31
46
 
@@ -1 +1 @@
1
- {"version":3,"sources":["DdSdkReactNativeConfiguration.tsx"],"names":["TrackingConsent","DdSdkReactNativeConfiguration","constructor","clientToken","env","applicationId","trackInteractions","trackResources","trackErrors","trackingConsent","GRANTED","undefined"],"mappings":";;AAAA;AACA;AACA;AACA;AACA;AAEA,SAASA,eAAT,QAAgC,mBAAhC;;AAIA;AACA;AACA;AACA;AACA,OAAO,MAAMC,6BAAN,CAAoC;AAYvCC,EAAAA,WAAW,CACEC,WADF,EAEEC,GAFF,EAGEC,aAHF,EAIEC,iBAA0B,GAAG,KAJ/B,EAKEC,cAAuB,GAAG,KAL5B,EAMEC,WAAoB,GAAG,KANzB,EAOEC,eAAgC,GAAGT,eAAe,CAACU,OAPrD,EAQT;AAAA,SAPWP,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,uCAf+CE,SAe/C;;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 { NativeSdkVerbosity } from './NativeSdkVerbosity'\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: NativeSdkVerbosity|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":["TrackingConsent","DdSdkReactNativeConfiguration","constructor","clientToken","env","applicationId","trackInteractions","trackResources","trackErrors","trackingConsent","GRANTED","undefined"],"mappings":";;AAAA;AACA;AACA;AACA;AACA;AAIA,SAASA,eAAT,QAAgC,mBAAhC;AAEA;AACA;AACA;AACA;;AACA,OAAO,MAAMC,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,GAAGT,eAAe,CAACU,OAPrD,EAQT;AAAA,SAPWP,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,uCAf2CE,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"]}
@@ -0,0 +1,52 @@
1
+ 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; }
2
+
3
+ /*
4
+ * Unless explicitly stated otherwise all files in this repository are licensed under the Apache License Version 2.0.
5
+ * This product includes software developed at Datadog (https://www.datadoghq.com/).
6
+ * Copyright 2016-Present Datadog, Inc.
7
+ */
8
+ import { SdkVerbosity } from './SdkVerbosity';
9
+ /**
10
+ * /!\ DO NOT USE THIS IN YOUR APP /!\\
11
+ *
12
+ * This logger is only for debugging the Datadog SDK.
13
+ */
14
+
15
+ export class InternalLog {
16
+ static log(message, verbosity) {
17
+ if (InternalLog.verbosity === undefined) {
18
+ return;
19
+ }
20
+
21
+ const requiredLevel = InternalLog.levelMap.get(verbosity);
22
+ const allowedLevel = InternalLog.levelMap.get(InternalLog.verbosity);
23
+
24
+ if (allowedLevel === undefined || requiredLevel === undefined) {
25
+ return;
26
+ }
27
+
28
+ const prefixedMessage = `DATADOG: ${message}`;
29
+
30
+ if (verbosity === SdkVerbosity.ERROR && requiredLevel >= allowedLevel) {
31
+ console.error(prefixedMessage);
32
+ }
33
+
34
+ if (verbosity === SdkVerbosity.WARN && requiredLevel >= allowedLevel) {
35
+ console.warn(prefixedMessage);
36
+ }
37
+
38
+ if (verbosity === SdkVerbosity.INFO && requiredLevel >= allowedLevel) {
39
+ console.info(prefixedMessage);
40
+ }
41
+
42
+ if (verbosity === SdkVerbosity.DEBUG && requiredLevel >= allowedLevel) {
43
+ console.debug(prefixedMessage);
44
+ }
45
+ }
46
+
47
+ }
48
+
49
+ _defineProperty(InternalLog, "levelMap", new Map([[SdkVerbosity.DEBUG, 1], [SdkVerbosity.INFO, 2], [SdkVerbosity.WARN, 3], [SdkVerbosity.ERROR, 4]]));
50
+
51
+ _defineProperty(InternalLog, "verbosity", undefined);
52
+ //# sourceMappingURL=InternalLog.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["InternalLog.tsx"],"names":["SdkVerbosity","InternalLog","log","message","verbosity","undefined","requiredLevel","levelMap","get","allowedLevel","prefixedMessage","ERROR","console","error","WARN","warn","INFO","info","DEBUG","debug","Map"],"mappings":";;AAAA;AACA;AACA;AACA;AACA;AAEA,SAASA,YAAT,QAA6B,gBAA7B;AAEA;AACA;AACA;AACA;AACA;;AACA,OAAO,MAAMC,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,KAAKJ,YAAY,CAACW,KAA3B,IAAoCL,aAAa,IAAIG,YAAzD,EAAuE;AACnEG,MAAAA,OAAO,CAACC,KAAR,CAAcH,eAAd;AACH;;AAED,QAAIN,SAAS,KAAKJ,YAAY,CAACc,IAA3B,IAAmCR,aAAa,IAAIG,YAAxD,EAAsE;AAClEG,MAAAA,OAAO,CAACG,IAAR,CAAaL,eAAb;AACH;;AAED,QAAIN,SAAS,KAAKJ,YAAY,CAACgB,IAA3B,IAAmCV,aAAa,IAAIG,YAAxD,EAAsE;AAClEG,MAAAA,OAAO,CAACK,IAAR,CAAaP,eAAb;AACH;;AAED,QAAIN,SAAS,KAAKJ,YAAY,CAACkB,KAA3B,IAAoCZ,aAAa,IAAIG,YAAzD,EAAuE;AACnEG,MAAAA,OAAO,CAACO,KAAR,CAAcT,eAAd;AACH;AACJ;;AAnCoB;;gBAAZT,W,cACiB,IAAImB,GAAJ,CAA8B,CACpD,CAACpB,YAAY,CAACkB,KAAd,EAAqB,CAArB,CADoD,EAEpD,CAAClB,YAAY,CAACgB,IAAd,EAAoB,CAApB,CAFoD,EAGpD,CAAChB,YAAY,CAACc,IAAd,EAAoB,CAApB,CAHoD,EAIpD,CAACd,YAAY,CAACW,KAAd,EAAqB,CAArB,CAJoD,CAA9B,C;;gBADjBV,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\n/**\n * /!\\ DO NOT USE THIS IN YOUR APP /!\\\\\n *\n * This logger is only for debugging the Datadog SDK.\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,KAAAA,S;;AAML,SAASP,kBAAT,EAA6BO,SAA7B","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,KAAAA,S;;AAML,SAASP,kBAAT,EAA6BO,SAA7B","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"]}
@@ -0,0 +1,18 @@
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
+ * Enum specifying possible log levels for DD SDK.
9
+ */
10
+ export let SdkVerbosity;
11
+
12
+ (function (SdkVerbosity) {
13
+ SdkVerbosity["DEBUG"] = "debug";
14
+ SdkVerbosity["INFO"] = "info";
15
+ SdkVerbosity["WARN"] = "warn";
16
+ SdkVerbosity["ERROR"] = "error";
17
+ })(SdkVerbosity || (SdkVerbosity = {}));
18
+ //# sourceMappingURL=SdkVerbosity.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["SdkVerbosity.tsx"],"names":["SdkVerbosity"],"mappings":"AAAA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA,WAAYA,YAAZ;;WAAYA,Y;AAAAA,EAAAA,Y;AAAAA,EAAAA,Y;AAAAA,EAAAA,Y;AAAAA,EAAAA,Y;GAAAA,Y,KAAAA,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,63 @@
1
+ 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; }
2
+
3
+ /*
4
+ * Unless explicitly stated otherwise all files in this repository are licensed under the Apache License Version 2.0.
5
+ * This product includes software developed at Datadog (https://www.datadoghq.com/).
6
+ * Copyright 2016-Present Datadog, Inc.
7
+ */
8
+
9
+ /**
10
+ * A Timestamp structure holding the
11
+ */
12
+
13
+ /**
14
+ * Simple class providing timestamps in milliseconds.
15
+ * If available, it will use the `performance.now()` method, and will fallback on `Date.now()` otherwise.
16
+ */
17
+ export class TimeProvider {
18
+ /** Keeps an average offset between the unix time and the provided timestamp. */
19
+ constructor() {
20
+ _defineProperty(this, "canUsePerformanceNow", // eslint-disable-next-line @typescript-eslint/ban-ts-comment
21
+ // @ts-ignore
22
+ global.performance && typeof performance.now === 'function');
23
+
24
+ _defineProperty(this, "baseOffset", void 0);
25
+
26
+ const timestamp = this.getTimestamp();
27
+
28
+ if (timestamp.react_native == null) {
29
+ this.baseOffset = 0;
30
+ } else {
31
+ this.baseOffset = timestamp.unix - timestamp.react_native;
32
+ }
33
+ }
34
+
35
+ getTimestamp() {
36
+ return {
37
+ unix: Date.now(),
38
+ react_native: this.performanceNow()
39
+ };
40
+ }
41
+
42
+ now() {
43
+ const timestamp = this.getTimestamp();
44
+
45
+ if (timestamp.react_native == null) {
46
+ return timestamp.unix;
47
+ } else {
48
+ return this.baseOffset + timestamp.react_native;
49
+ }
50
+ }
51
+
52
+ performanceNow() {
53
+ if (this.canUsePerformanceNow) {
54
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
55
+ // @ts-ignore
56
+ return performance.now();
57
+ }
58
+
59
+ return null;
60
+ }
61
+
62
+ }
63
+ //# 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;AACA,OAAO,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"]}
@@ -1,15 +1,25 @@
1
1
  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; }
2
2
 
3
- const START_LABEL = "__start";
4
- const STOP_LABEL = "__stop";
3
+ /*
4
+ * Unless explicitly stated otherwise all files in this repository are licensed under the Apache License Version 2.0.
5
+ * This product includes software developed at Datadog (https://www.datadoghq.com/).
6
+ * Copyright 2016-Present Datadog, Inc.
7
+ */
8
+ import { TimeProvider } from './TimeProvider';
9
+ const START_LABEL = '__start';
10
+ const STOP_LABEL = '__stop';
5
11
  /**
6
12
  * Simple timer which records time ticks. Shouldn't be re-used once stopped.
7
13
  * All timestamps/durations returned are in milliseconds.
8
14
  */
9
15
 
10
16
  export default class Timer {
11
- constructor() {
17
+ constructor(timeProvider = new TimeProvider()) {
18
+ _defineProperty(this, "timeProvider", void 0);
19
+
12
20
  _defineProperty(this, "times", {});
21
+
22
+ this.timeProvider = timeProvider;
13
23
  }
14
24
 
15
25
  get startTime() {
@@ -29,10 +39,7 @@ export default class Timer {
29
39
  }
30
40
 
31
41
  recordTick(label) {
32
- this.times[label] = {
33
- unix: Date.now(),
34
- react_native: this.performanceNow()
35
- };
42
+ this.times[label] = this.timeProvider.getTimestamp();
36
43
  }
37
44
 
38
45
  hasTickFor(label) {
@@ -64,22 +71,6 @@ export default class Timer {
64
71
  return end.unix - start.unix;
65
72
  }
66
73
 
67
- performanceNow() {
68
- if (this.canUsePerformanceNow()) {
69
- // eslint-disable-next-line @typescript-eslint/ban-ts-comment
70
- // @ts-ignore
71
- return performance.now();
72
- }
73
-
74
- return null;
75
- }
76
-
77
- canUsePerformanceNow() {
78
- // eslint-disable-next-line @typescript-eslint/ban-ts-comment
79
- // @ts-ignore
80
- return global.performance && typeof performance.now === 'function';
81
- }
82
-
83
74
  checkLabelExists(label) {
84
75
  if (!this.hasTickFor(label)) {
85
76
  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;;AACA,eAAe,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,GAAiB,KAAKI,eAAL,CAAqBP,WAArB,EAAkCC,UAAlC,CAAxB;AACH;;AAEDO,EAAAA,KAAK,GAAS;AACV,SAAKC,UAAL,CAAgBT,WAAhB;AACH;;AAEDU,EAAAA,IAAI,GAAS;AACT,SAAKD,UAAL,CAAgBR,UAAhB;AACH;;AAEDQ,EAAAA,UAAU,CAACE,KAAD,EAAsB;AAC5B,SAAKP,KAAL,CAAWO,KAAX,IAAoB;AAChBN,MAAAA,IAAI,EAAEO,IAAI,CAACC,GAAL,EADU;AAEhBC,MAAAA,YAAY,EAAE,KAAKC,cAAL;AAFE,KAApB;AAIH;;AAEDC,EAAAA,UAAU,CAACL,KAAD,EAAyB;AAC/B,WAAOA,KAAK,IAAI,KAAKP,KAArB;AACH;;AAEDG,EAAAA,eAAe,CAACU,UAAD,EAAqBC,QAArB,EAA+C;AAC1D,SAAKC,gBAAL,CAAsBF,UAAtB;AACA,SAAKE,gBAAL,CAAsBD,QAAtB;AAEA,UAAME,SAAS,GAAG,KAAKhB,KAAL,CAAWa,UAAX,CAAlB;AACA,UAAMI,OAAO,GAAG,KAAKjB,KAAL,CAAWc,QAAX,CAAhB;AAEA,WAAO,KAAKI,oBAAL,CAA0BF,SAA1B,EAAqCC,OAArC,CAAP;AACH;;AAEDE,EAAAA,MAAM,CAACZ,KAAD,EAAwB;AAC1B,SAAKQ,gBAAL,CAAsBR,KAAtB;AAEA,WAAO,KAAKR,SAAL,GAAiB,KAAKI,eAAL,CAAqBP,WAArB,EAAkCW,KAAlC,CAAxB;AACH;;AAEDa,EAAAA,KAAK,GAAS;AACV,SAAKpB,KAAL,GAAa,EAAb;AACH;;AAEOkB,EAAAA,oBAAoB,CAACd,KAAD,EAAmBiB,GAAnB,EAA2C;AACnE,QAAIjB,KAAK,CAACM,YAAN,IAAsB,IAAtB,IAA8BW,GAAG,CAACX,YAAJ,IAAoB,IAAtD,EAA4D;AACxD,aAAOW,GAAG,CAACX,YAAJ,GAAmBN,KAAK,CAACM,YAAhC;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":["TimeProvider","START_LABEL","STOP_LABEL","Timer","constructor","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":";;AAAA;AACA;AACA;AACA;AACA;AAGA,SAASA,YAAT,QAA6B,gBAA7B;AAEA,MAAMC,WAAW,GAAG,SAApB;AACA,MAAMC,UAAU,GAAG,QAAnB;AAEA;AACA;AACA;AACA;;AACA,eAAe,MAAMC,KAAN,CAAY;AAIvBC,EAAAA,WAAW,CAACC,YAA0B,GAAG,IAAIL,YAAJ,EAA9B,EAAkD;AAAA;;AAAA,mCAFlB,EAEkB;;AACzD,SAAKK,YAAL,GAAoBA,YAApB;AACH;;AAEY,MAATC,SAAS,GAAW;AACpB,WAAO,KAAKC,KAAL,CAAWN,WAAX,EAAwBO,IAA/B;AACH;;AAEW,MAARC,QAAQ,GAAW;AACnB,WAAO,KAAKH,SAAL,GAAiB,KAAKI,eAAL,CAAqBT,WAArB,EAAkCC,UAAlC,CAAxB;AACH;;AAEDS,EAAAA,KAAK,GAAS;AACV,SAAKC,UAAL,CAAgBX,WAAhB;AACH;;AAEDY,EAAAA,IAAI,GAAS;AACT,SAAKD,UAAL,CAAgBV,UAAhB;AACH;;AAEDU,EAAAA,UAAU,CAACE,KAAD,EAAsB;AAC5B,SAAKP,KAAL,CAAWO,KAAX,IAAoB,KAAKT,YAAL,CAAkBU,YAAlB,EAApB;AACH;;AAEDC,EAAAA,UAAU,CAACF,KAAD,EAAyB;AAC/B,WAAOA,KAAK,IAAI,KAAKP,KAArB;AACH;;AAEDG,EAAAA,eAAe,CAACO,UAAD,EAAqBC,QAArB,EAA+C;AAC1D,SAAKC,gBAAL,CAAsBF,UAAtB;AACA,SAAKE,gBAAL,CAAsBD,QAAtB;AAEA,UAAME,SAAS,GAAG,KAAKb,KAAL,CAAWU,UAAX,CAAlB;AACA,UAAMI,OAAO,GAAG,KAAKd,KAAL,CAAWW,QAAX,CAAhB;AAEA,WAAO,KAAKI,oBAAL,CAA0BF,SAA1B,EAAqCC,OAArC,CAAP;AACH;;AAEDE,EAAAA,MAAM,CAACT,KAAD,EAAwB;AAC1B,SAAKK,gBAAL,CAAsBL,KAAtB;AAEA,WAAO,KAAKR,SAAL,GAAiB,KAAKI,eAAL,CAAqBT,WAArB,EAAkCa,KAAlC,CAAxB;AACH;;AAEDU,EAAAA,KAAK,GAAS;AACV,SAAKjB,KAAL,GAAa,EAAb;AACH;;AAEOe,EAAAA,oBAAoB,CAACX,KAAD,EAAmBc,GAAnB,EAA2C;AACnE,QAAId,KAAK,CAACe,YAAN,IAAsB,IAAtB,IAA8BD,GAAG,CAACC,YAAJ,IAAoB,IAAtD,EAA4D;AACxD,aAAOD,GAAG,CAACC,YAAJ,GAAmBf,KAAK,CAACe,YAAhC;AACH;;AACD,WAAOD,GAAG,CAACjB,IAAJ,GAAWG,KAAK,CAACH,IAAxB;AACH;;AAEOW,EAAAA,gBAAgB,CAACL,KAAD,EAAgB;AACpC,QAAI,CAAC,KAAKE,UAAL,CAAgBF,KAAhB,CAAL,EAA6B;AACzB,YAAM,IAAIa,KAAJ,CAAW,SAAQb,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"]}
@@ -1 +1 @@
1
- {"version":3,"sources":["TrackingConsent.tsx"],"names":["TrackingConsent"],"mappings":"AAAA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA,WAAYA,eAAZ;;WAAYA,e;AAAAA,EAAAA,e;AAAAA,EAAAA,e;AAAAA,EAAAA,e;GAAAA,e,KAAAA,e","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 consent options for DD SDK.\n */\nexport enum TrackingConsent {\n PENDING = \"pending\",\n GRANTED = \"granted\",\n NOT_GRANTED = \"not_granted\"\n}\n"]}
1
+ {"version":3,"sources":["TrackingConsent.tsx"],"names":["TrackingConsent"],"mappings":"AAAA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA,WAAYA,eAAZ;;WAAYA,e;AAAAA,EAAAA,e;AAAAA,EAAAA,e;AAAAA,EAAAA,e;GAAAA,e,KAAAA,e","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 consent options for DD SDK.\n */\nexport enum TrackingConsent {\n PENDING = 'pending',\n GRANTED = 'granted',\n NOT_GRANTED = 'not_granted'\n}\n"]}