@utk09/ui-observability 0.9.3 → 0.9.5

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 (227) hide show
  1. package/CHANGELOG.md +90 -0
  2. package/README.md +199 -96
  3. package/dist/batch-BQFtb3i5.cjs +2 -0
  4. package/dist/batch-BQFtb3i5.cjs.map +1 -0
  5. package/dist/{batch-DDgxg16_.js → batch-BUJh-1jZ.js} +6 -4
  6. package/dist/batch-BUJh-1jZ.js.map +1 -0
  7. package/dist/bus/bus.d.ts +76 -2
  8. package/dist/bus/links.d.ts +9 -2
  9. package/dist/bus/validation.d.ts +7 -0
  10. package/dist/bus-BW6N-pY8.cjs +2 -0
  11. package/dist/bus-BW6N-pY8.cjs.map +1 -0
  12. package/dist/bus-DeOPHWaD.js +647 -0
  13. package/dist/bus-DeOPHWaD.js.map +1 -0
  14. package/dist/capture/network.d.ts +1 -0
  15. package/dist/capture/storm.d.ts +2 -1
  16. package/dist/capture/types.d.ts +5 -0
  17. package/dist/capture/web-socket.d.ts +40 -0
  18. package/dist/{console-BSusX_M-.cjs → console-Ce6heqZZ.cjs} +2 -2
  19. package/dist/console-Ce6heqZZ.cjs.map +1 -0
  20. package/dist/{console-Dv5GfaNn.js → console-DbAZYJuy.js} +4 -4
  21. package/dist/console-DbAZYJuy.js.map +1 -0
  22. package/dist/constants-CN7GE1Lt.js +246 -0
  23. package/dist/constants-CN7GE1Lt.js.map +1 -0
  24. package/dist/constants-CW-MlHdY.cjs +2 -0
  25. package/dist/constants-CW-MlHdY.cjs.map +1 -0
  26. package/dist/constants.d.ts +63 -11
  27. package/dist/context-storage-BjzeBSxH.cjs +2 -0
  28. package/dist/context-storage-BjzeBSxH.cjs.map +1 -0
  29. package/dist/context-storage-DxZf4Gfh.js +52 -0
  30. package/dist/context-storage-DxZf4Gfh.js.map +1 -0
  31. package/dist/core/breadcrumbs.d.ts +10 -3
  32. package/dist/core/context.d.ts +2 -0
  33. package/dist/core/diagnostics.d.ts +11 -3
  34. package/dist/core/journey.d.ts +7 -0
  35. package/dist/core/meter.d.ts +25 -2
  36. package/dist/core/pipeline.d.ts +41 -6
  37. package/dist/core/record.d.ts +42 -9
  38. package/dist/core/remote-sampling.d.ts +7 -3
  39. package/dist/core/runtime.d.ts +153 -6
  40. package/dist/core/sampling.d.ts +35 -2
  41. package/dist/core/sender.d.ts +43 -1
  42. package/dist/core/spans.d.ts +34 -0
  43. package/dist/deadline-5_PecIl5.js +26 -0
  44. package/dist/deadline-5_PecIl5.js.map +1 -0
  45. package/dist/deadline-XSnm95pg.cjs +2 -0
  46. package/dist/deadline-XSnm95pg.cjs.map +1 -0
  47. package/dist/emergency-queue-BYUyDHGD.js +69 -0
  48. package/dist/emergency-queue-BYUyDHGD.js.map +1 -0
  49. package/dist/emergency-queue-Cs1hrjsC.cjs +2 -0
  50. package/dist/emergency-queue-Cs1hrjsC.cjs.map +1 -0
  51. package/dist/{errors-DCZWcHkd.js → errors-BhC7HTSt.js} +8 -9
  52. package/dist/errors-BhC7HTSt.js.map +1 -0
  53. package/dist/errors-CgY633cG.cjs +3 -0
  54. package/dist/errors-CgY633cG.cjs.map +1 -0
  55. package/dist/factory-C5TujXlU.js +280 -0
  56. package/dist/factory-C5TujXlU.js.map +1 -0
  57. package/dist/factory-CNj4DH3n.cjs +2 -0
  58. package/dist/factory-CNj4DH3n.cjs.map +1 -0
  59. package/dist/fixed-window-CtaFHanJ.js +12 -0
  60. package/dist/fixed-window-CtaFHanJ.js.map +1 -0
  61. package/dist/fixed-window-CvESpFYV.cjs +2 -0
  62. package/dist/fixed-window-CvESpFYV.cjs.map +1 -0
  63. package/dist/identity-8vKkyAWm.js +103 -0
  64. package/dist/identity-8vKkyAWm.js.map +1 -0
  65. package/dist/identity-Da9TkuKd.cjs +2 -0
  66. package/dist/identity-Da9TkuKd.cjs.map +1 -0
  67. package/dist/index.cjs +1 -1
  68. package/dist/index.cjs.map +1 -1
  69. package/dist/index.d.ts +66 -6
  70. package/dist/index.js +1253 -595
  71. package/dist/index.js.map +1 -1
  72. package/dist/indexeddb-storage-BTfIFRHF.cjs +2 -0
  73. package/dist/indexeddb-storage-BTfIFRHF.cjs.map +1 -0
  74. package/dist/{indexeddb-storage-T9YIYVYC.js → indexeddb-storage-CCA1LvtO.js} +45 -30
  75. package/dist/indexeddb-storage-CCA1LvtO.js.map +1 -0
  76. package/dist/{interactions-BLH_tX87.js → interactions-BUDLxbv1.js} +16 -12
  77. package/dist/interactions-BUDLxbv1.js.map +1 -0
  78. package/dist/interactions-NHbLKrqe.cjs +2 -0
  79. package/dist/interactions-NHbLKrqe.cjs.map +1 -0
  80. package/dist/{journey-yALMEWF7.js → journey-BUJ4WJxP.js} +37 -34
  81. package/dist/journey-BUJ4WJxP.js.map +1 -0
  82. package/dist/journey-B_tTnvac.cjs +2 -0
  83. package/dist/journey-B_tTnvac.cjs.map +1 -0
  84. package/dist/keys-BHhw_0Wh.cjs +2 -0
  85. package/dist/keys-BHhw_0Wh.cjs.map +1 -0
  86. package/dist/keys-D5r_GH9q.js +17 -0
  87. package/dist/keys-D5r_GH9q.js.map +1 -0
  88. package/dist/{library-request-CQD4HUiP.js → library-request-BKOcaKtQ.js} +3 -3
  89. package/dist/{library-request-CQD4HUiP.js.map → library-request-BKOcaKtQ.js.map} +1 -1
  90. package/dist/{library-request-BcAxuwsf.cjs → library-request-BaZOi4eg.cjs} +2 -2
  91. package/dist/{library-request-BcAxuwsf.cjs.map → library-request-BaZOi4eg.cjs.map} +1 -1
  92. package/dist/{long-frames-D4Bm3Zkz.cjs → long-frames-CF3qiSAX.cjs} +2 -2
  93. package/dist/long-frames-CF3qiSAX.cjs.map +1 -0
  94. package/dist/{long-frames-DD_Um9_4.js → long-frames-DI5ypfAF.js} +5 -5
  95. package/dist/long-frames-DI5ypfAF.js.map +1 -0
  96. package/dist/models/batch.d.ts +4 -0
  97. package/dist/models/bus.d.ts +32 -9
  98. package/dist/models/config.d.ts +401 -12
  99. package/dist/models/drop.d.ts +1 -1
  100. package/dist/models/health.d.ts +27 -0
  101. package/dist/models/log-record.d.ts +1 -1
  102. package/dist/models/plugin.d.ts +47 -0
  103. package/dist/models/stats.d.ts +11 -0
  104. package/dist/models/storage.d.ts +13 -0
  105. package/dist/network-CF8UO5PK.cjs +2 -0
  106. package/dist/network-CF8UO5PK.cjs.map +1 -0
  107. package/dist/{network--GoE7_Or.js → network-DdzXDI3J.js} +47 -31
  108. package/dist/network-DdzXDI3J.js.map +1 -0
  109. package/dist/openfin-BwEN0uj4.js.map +1 -1
  110. package/dist/openfin-DtH2f7zX.cjs.map +1 -1
  111. package/dist/{platform-GaM6h7XM.js → platform-Bw1btWCT.js} +21 -10
  112. package/dist/platform-Bw1btWCT.js.map +1 -0
  113. package/dist/platform-DBSKTvFn.cjs +2 -0
  114. package/dist/platform-DBSKTvFn.cjs.map +1 -0
  115. package/dist/remote-rules-DIcC5vVC.js +91 -0
  116. package/dist/remote-rules-DIcC5vVC.js.map +1 -0
  117. package/dist/remote-rules-DpFmOef2.cjs +2 -0
  118. package/dist/remote-rules-DpFmOef2.cjs.map +1 -0
  119. package/dist/sampling-BVjspJWu.cjs +2 -0
  120. package/dist/sampling-BVjspJWu.cjs.map +1 -0
  121. package/dist/sampling-Cm3WhI0a.js +76 -0
  122. package/dist/sampling-Cm3WhI0a.js.map +1 -0
  123. package/dist/{sanitize-DP0xDPrt.js → sanitize-C-ahCFsG.js} +2 -2
  124. package/dist/{sanitize-DP0xDPrt.js.map → sanitize-C-ahCFsG.js.map} +1 -1
  125. package/dist/{sanitize--_e4oOPX.cjs → sanitize-DHucKGdi.cjs} +2 -2
  126. package/dist/{sanitize--_e4oOPX.cjs.map → sanitize-DHucKGdi.cjs.map} +1 -1
  127. package/dist/sender-D3fRCR8d.cjs +3 -0
  128. package/dist/sender-D3fRCR8d.cjs.map +1 -0
  129. package/dist/sender-DUUmSglb.js +1163 -0
  130. package/dist/sender-DUUmSglb.js.map +1 -0
  131. package/dist/storage/context-storage.d.ts +89 -0
  132. package/dist/storage/emergency-queue.d.ts +9 -1
  133. package/dist/storage/factory.d.ts +7 -1
  134. package/dist/storage/idb-driver.d.ts +13 -0
  135. package/dist/storage/indexeddb-storage.d.ts +13 -0
  136. package/dist/storage/local-storage.d.ts +21 -1
  137. package/dist/storage/memory-storage.d.ts +13 -0
  138. package/dist/storage-BA9RqRO-.cjs +2 -0
  139. package/dist/storage-BA9RqRO-.cjs.map +1 -0
  140. package/dist/storage-w7Tslvlq.js +17 -0
  141. package/dist/storage-w7Tslvlq.js.map +1 -0
  142. package/dist/storm-CNZjsw4T.cjs +2 -0
  143. package/dist/storm-CNZjsw4T.cjs.map +1 -0
  144. package/dist/storm-Daq2jGHU.js +10 -0
  145. package/dist/storm-Daq2jGHU.js.map +1 -0
  146. package/dist/transport/exit-flush.d.ts +6 -0
  147. package/dist/transport/http-transport.d.ts +2 -1
  148. package/dist/transport/retry-engine.d.ts +7 -2
  149. package/dist/transport/serializers/otlp-traces.d.ts +3 -0
  150. package/dist/transport/serializers/select.d.ts +8 -5
  151. package/dist/transport/status-transport.d.ts +24 -0
  152. package/dist/types-BR9t_w28.js +8 -0
  153. package/dist/types-BR9t_w28.js.map +1 -0
  154. package/dist/types-C7WNpnG1.cjs +2 -0
  155. package/dist/types-C7WNpnG1.cjs.map +1 -0
  156. package/dist/utils/fixed-window.d.ts +9 -0
  157. package/dist/utils/identity.d.ts +20 -2
  158. package/dist/utils/lock.d.ts +8 -0
  159. package/dist/utils/openfin.d.ts +1 -1
  160. package/dist/utils/platform.d.ts +10 -0
  161. package/dist/utils/tracing.d.ts +82 -4
  162. package/dist/web-socket-BacvKOvD.cjs +2 -0
  163. package/dist/web-socket-BacvKOvD.cjs.map +1 -0
  164. package/dist/web-socket-CpsD8WAa.js +105 -0
  165. package/dist/web-socket-CpsD8WAa.js.map +1 -0
  166. package/package.json +1 -1
  167. package/dist/batch-D5qvsMQ_.cjs +0 -2
  168. package/dist/batch-D5qvsMQ_.cjs.map +0 -1
  169. package/dist/batch-DDgxg16_.js.map +0 -1
  170. package/dist/bus-C6RwKzPW.js +0 -478
  171. package/dist/bus-C6RwKzPW.js.map +0 -1
  172. package/dist/bus-WPVDFw2y.cjs +0 -2
  173. package/dist/bus-WPVDFw2y.cjs.map +0 -1
  174. package/dist/console-BSusX_M-.cjs.map +0 -1
  175. package/dist/console-Dv5GfaNn.js.map +0 -1
  176. package/dist/constants-Cb92egPS.cjs +0 -2
  177. package/dist/constants-Cb92egPS.cjs.map +0 -1
  178. package/dist/constants-DhH6VI5a.js +0 -144
  179. package/dist/constants-DhH6VI5a.js.map +0 -1
  180. package/dist/deadline-CUrH0Hd8.cjs +0 -2
  181. package/dist/deadline-CUrH0Hd8.cjs.map +0 -1
  182. package/dist/deadline-DeqXEliN.js +0 -31
  183. package/dist/deadline-DeqXEliN.js.map +0 -1
  184. package/dist/errors-DCZWcHkd.js.map +0 -1
  185. package/dist/errors-ERu-su8m.cjs +0 -3
  186. package/dist/errors-ERu-su8m.cjs.map +0 -1
  187. package/dist/fixed-window-BR0bu32Y.cjs +0 -2
  188. package/dist/fixed-window-BR0bu32Y.cjs.map +0 -1
  189. package/dist/fixed-window-Re7jIRJH.js +0 -9
  190. package/dist/fixed-window-Re7jIRJH.js.map +0 -1
  191. package/dist/identity-C1WLItSl.cjs +0 -2
  192. package/dist/identity-C1WLItSl.cjs.map +0 -1
  193. package/dist/identity-Di-QXGCC.js +0 -88
  194. package/dist/identity-Di-QXGCC.js.map +0 -1
  195. package/dist/indexeddb-storage-DX18p39D.cjs +0 -2
  196. package/dist/indexeddb-storage-DX18p39D.cjs.map +0 -1
  197. package/dist/indexeddb-storage-T9YIYVYC.js.map +0 -1
  198. package/dist/interactions-BLH_tX87.js.map +0 -1
  199. package/dist/interactions-_hfOerfC.cjs +0 -2
  200. package/dist/interactions-_hfOerfC.cjs.map +0 -1
  201. package/dist/journey-BRUj0hqD.cjs +0 -2
  202. package/dist/journey-BRUj0hqD.cjs.map +0 -1
  203. package/dist/journey-yALMEWF7.js.map +0 -1
  204. package/dist/long-frames-D4Bm3Zkz.cjs.map +0 -1
  205. package/dist/long-frames-DD_Um9_4.js.map +0 -1
  206. package/dist/network--GoE7_Or.js.map +0 -1
  207. package/dist/network-DcuS2H1P.cjs +0 -2
  208. package/dist/network-DcuS2H1P.cjs.map +0 -1
  209. package/dist/platform-GaM6h7XM.js.map +0 -1
  210. package/dist/platform-kIL5AZB7.cjs +0 -2
  211. package/dist/platform-kIL5AZB7.cjs.map +0 -1
  212. package/dist/remote-rules-6ePq8CrI.js +0 -84
  213. package/dist/remote-rules-6ePq8CrI.js.map +0 -1
  214. package/dist/remote-rules-CI3gbRCL.cjs +0 -2
  215. package/dist/remote-rules-CI3gbRCL.cjs.map +0 -1
  216. package/dist/sampling-C-M8p3FK.cjs +0 -2
  217. package/dist/sampling-C-M8p3FK.cjs.map +0 -1
  218. package/dist/sampling-Ud_WiuU9.js +0 -65
  219. package/dist/sampling-Ud_WiuU9.js.map +0 -1
  220. package/dist/sender-BESHz6my.cjs +0 -3
  221. package/dist/sender-BESHz6my.cjs.map +0 -1
  222. package/dist/sender-BUBWLn5i.js +0 -1244
  223. package/dist/sender-BUBWLn5i.js.map +0 -1
  224. package/dist/storm-DhHGHhOc.cjs +0 -2
  225. package/dist/storm-DhHGHhOc.cjs.map +0 -1
  226. package/dist/storm-OD5J6Ylm.js +0 -10
  227. package/dist/storm-OD5J6Ylm.js.map +0 -1
@@ -1,6 +1,7 @@
1
1
  import type { DiagnosticHandler } from "../core/diagnostics";
2
2
  import type { DropSummary } from "./drop";
3
3
  import type { LogLevel, LogRecord } from "./log-record";
4
+ import type { CapturePlugin } from "./plugin";
4
5
  import type { LogSerializer } from "./serializer";
5
6
  /** Backing store for undelivered records. "auto" picks the best one the host supports. */
6
7
  export type StorageStrategy = "auto" | "indexeddb" | "localstorage" | "memory" | "none";
@@ -141,14 +142,46 @@ export interface SamplingOptions {
141
142
  }
142
143
  /** Bus settings. They control how this context finds, trusts, and sends messages to others. */
143
144
  export interface BusOptions {
145
+ /**
146
+ * Rule for accepting child windows. "registered" requires a window registration.
147
+ * "trusted-origin" accepts child windows from a trusted origin.
148
+ * @default "registered"
149
+ */
150
+ sourcePolicy: "registered" | "trusted-origin";
151
+ /**
152
+ * Message checks. "strict" checks each record and control message.
153
+ * "envelope" checks the protocol tag only.
154
+ * @default "strict"
155
+ */
156
+ validation: "strict" | "envelope";
157
+ /**
158
+ * Maximum encoded bytes in one message. Set 0 for no size limit.
159
+ * @default 262144
160
+ */
161
+ maxMessageBytes: number;
162
+ /**
163
+ * Maximum records in one message. Set 0 for no record limit.
164
+ * @default 100
165
+ */
166
+ maxRecordsPerMessage: number;
167
+ /**
168
+ * Maximum messages from one source in one second. Set 0 for no rate limit.
169
+ * @default 100
170
+ */
171
+ maxMessagesPerSecond: number;
172
+ /**
173
+ * Maximum named sources to track, for example OpenFin identities. Set 0 for no limit.
174
+ * @default 256
175
+ */
176
+ maxTrackedSources: number;
144
177
  /**
145
178
  * This context's role.
146
179
  * @default "auto"
147
180
  */
148
181
  mode: BusMode;
149
182
  /**
150
- * Origins that can send postMessage records to this document.
151
- * A document that gets records from a cross-origin iframe must list the iframe origin.
183
+ * Additional trusted parent origins. With sourcePolicy "trusted-origin", the list also
184
+ * permits child origins. A registered child uses the exact origin in its registration.
152
185
  * The library does not accept "null". A sandboxed frame must set `mode: "sender"`.
153
186
  * @default []
154
187
  */
@@ -285,11 +318,91 @@ export interface LimitOptions {
285
318
  }
286
319
  /** Console method that the console capture can wrap. */
287
320
  export type CapturedConsoleMethod = "error" | "warn" | "info" | "log";
321
+ /** Click settings. An object turns on capture. With true, capture uses the defaults below. */
322
+ export interface InteractionOptions {
323
+ /**
324
+ * Record the textContent of the clicked element.
325
+ * @default false
326
+ */
327
+ text?: boolean;
328
+ /**
329
+ * Record a DOM selector. Its attributes can identify a user or an account.
330
+ * @default false
331
+ */
332
+ selector?: boolean;
333
+ /**
334
+ * CSS selector for regions to exclude. Set null to include all regions.
335
+ * @default "[data-observability-ignore]"
336
+ */
337
+ ignoreSelector?: string | null;
338
+ /**
339
+ * Maximum click text length, in characters.
340
+ * @default 50
341
+ */
342
+ maxTextChars?: number;
343
+ /**
344
+ * Attribute that names the click action, for example "data-testid". The closest element with
345
+ * the attribute gives the breadcrumb message. Use letters, digits, hyphens and underscores.
346
+ * @default "data-observability-action"
347
+ */
348
+ actionAttribute?: string;
349
+ }
350
+ /** Cache settings. A logger that the app holds stays valid after removal from the cache. */
351
+ export interface LoggerCacheOptions {
352
+ /**
353
+ * Maximum cached loggers. The cache removes the least recently used logger first.
354
+ * Set 0 for no cache. Set null for no cache limit.
355
+ * @default 256
356
+ */
357
+ maxEntries: number | null;
358
+ }
359
+ /** Identity of one delivery context. Do not put secrets or personal data in the id. */
360
+ export interface SecurityContextOptions {
361
+ /** Stable id for delivery after a page reload. An empty id gives this runtime a new id. */
362
+ id: string;
363
+ /**
364
+ * Keep stored batches in separate contexts. With true, change delivery settings through
365
+ * rotateSecurityContext() instead of configure().
366
+ * @default true
367
+ */
368
+ isolation: boolean;
369
+ }
370
+ /** Delivery settings that the runtime replaces together when the security context changes. */
371
+ export type DeliveryOptions = Pick<ObservabilityConfig, "endpoint" | "metricsEndpoint" | "tracesEndpoint" | "headers" | "credentials" | "transport" | "transportOnExit">;
372
+ /** New security context. A delivery field that is not supplied resets to its default. */
373
+ export interface SecurityContextUpdate {
374
+ /** New delivery context id. If not supplied, the runtime makes a new id. */
375
+ id?: string;
376
+ /** New delivery settings. A field that is not supplied resets to its default. */
377
+ delivery: DeliveryOptions;
378
+ /** New ambient attributes. If not supplied, the runtime removes the old attributes. */
379
+ context?: Record<string, unknown>;
380
+ }
381
+ /** Policy for old records. */
382
+ export interface SecurityContextRotationOptions {
383
+ /**
384
+ * Rule for old records. "discard" removes them. "flush" tries delivery, then removes them.
385
+ * "retain" keeps them in the old context. "carry" gives them to the new context.
386
+ * @default "discard"
387
+ */
388
+ pending?: "discard" | "flush" | "retain" | "carry";
389
+ /**
390
+ * Maximum wait for a flush of old records, in milliseconds.
391
+ * @default 5000
392
+ */
393
+ timeoutMs?: number;
394
+ }
288
395
  /**
289
396
  * What the library instruments automatically. By default, only `errors` and `rejections`
290
397
  * are on.
291
398
  */
292
399
  export interface CaptureOptions {
400
+ /**
401
+ * Changes a URL before capture records it. Applies to page, HTTP, resource and WebSocket URLs.
402
+ * @param url Original URL, before the default URL changes.
403
+ * @returns URL to record. Null, an invalid result or an exception gives an empty URL.
404
+ */
405
+ urlTransform?: (url: string) => string | null;
293
406
  /**
294
407
  * Log uncaught errors from `window.onerror`.
295
408
  * @default true
@@ -325,7 +438,7 @@ export interface CaptureOptions {
325
438
  * Log clicks and other interactions as breadcrumbs.
326
439
  * @default false
327
440
  */
328
- interactions: boolean;
441
+ interactions: boolean | InteractionOptions;
329
442
  /**
330
443
  * Log route changes, including single-page-application navigation.
331
444
  * @default false
@@ -372,6 +485,17 @@ export interface CaptureOptions {
372
485
  * @default []
373
486
  */
374
487
  propagateTraceHeaderTo: (string | RegExp)[];
488
+ /**
489
+ * Record the open, close and error events of each WebSocket, and count its messages in the
490
+ * counter `ui.websocket.messages`. The library never records the content of a message.
491
+ * @default false
492
+ */
493
+ webSocket: boolean;
494
+ /**
495
+ * Capture modules from the app. A new list replaces the list in force.
496
+ * @default []
497
+ */
498
+ plugins: CapturePlugin[];
375
499
  /**
376
500
  * Supplies the `web-vitals` module without a hard dependency on the package.
377
501
  * @returns A promise that resolves to the `web-vitals` module.
@@ -411,12 +535,17 @@ export interface ResolvedConsole {
411
535
  }
412
536
  /**
413
537
  * Kind of a batch. A batch of metric records is "metrics" when `metricsEndpoint` is set. Its body
414
- * is then an OTLP `ExportMetricsServiceRequest`.
538
+ * is then an OTLP `ExportMetricsServiceRequest`. A batch of span records is "traces". Its body is
539
+ * an OTLP `ExportTraceServiceRequest`.
415
540
  */
416
- export type BatchKind = "logs" | "metrics";
541
+ export type BatchKind = "logs" | "metrics" | "traces";
417
542
  /** One batch that the library gives to a custom transport. */
418
543
  export interface TransportRequest {
419
- /** Kind of the batch. Send a "metrics" body to your metrics endpoint. */
544
+ /** Abort signal for this delivery context. A custom transport must check it to cancel its work. */
545
+ signal?: AbortSignal;
546
+ /** Delivery context of this batch. */
547
+ routingContextId?: string;
548
+ /** Kind of the batch. Send a "metrics" body to your metrics endpoint, and a "traces" body to your traces endpoint. */
420
549
  kind: BatchKind;
421
550
  /** Serialized batch from the configured serializer. The library does not compress it. */
422
551
  body: string;
@@ -459,8 +588,207 @@ export type Transport = (request: TransportRequest) => Promise<TransportResponse
459
588
  * @returns True if the channel accepted the batch. False puts the batch in the emergency queue.
460
589
  */
461
590
  export type ExitTransport = (request: TransportRequest) => boolean;
591
+ /** Request timing, retry timing and delivery capacity. Durations are in milliseconds. */
592
+ export interface DeliveryPolicy {
593
+ /**
594
+ * Maximum wait for one request. The value must be at least 1.
595
+ * @default 15000
596
+ */
597
+ requestTimeoutMs: number;
598
+ /**
599
+ * Maximum requests that have not completed. The value must be at least 1.
600
+ * @default 2
601
+ */
602
+ maxConcurrentRequests: number;
603
+ /**
604
+ * First retry delay. Set 0 for an immediate retry.
605
+ * @default 2000
606
+ */
607
+ retryBaseDelayMs: number;
608
+ /**
609
+ * Maximum retry delay. It must be at least retryBaseDelayMs.
610
+ * @default 60000
611
+ */
612
+ retryMaxDelayMs: number;
613
+ /**
614
+ * Wait before the next check for stored work.
615
+ * @default 30000
616
+ */
617
+ retryIdleDelayMs: number;
618
+ /**
619
+ * Maximum batches in one delivery pass. The value must be at least 1.
620
+ * @default 20
621
+ */
622
+ batchesPerDrain: number;
623
+ }
624
+ /** Record and byte limits for the live delivery buffers. */
625
+ export interface BufferingPolicy {
626
+ /**
627
+ * Maximum records in the buffers and requests. Set 0 for no record limit.
628
+ * @default 10000
629
+ */
630
+ maxPendingRecords: number;
631
+ /**
632
+ * Maximum encoded JSON bytes in the buffers and requests. Set 0 for no byte limit.
633
+ * @default 16777216
634
+ */
635
+ maxPendingBytes: number;
636
+ /**
637
+ * Rule when a new record does not fit. Remove old records, drop the new record, or try storage.
638
+ * @default "drop-oldest"
639
+ */
640
+ overflow: "drop-oldest" | "drop-newest" | "persist";
641
+ }
642
+ /** Metric capacity in one collection interval. */
643
+ export interface MetricsPolicy {
644
+ /**
645
+ * Maximum histogram boundaries. Set 0 for no limit.
646
+ * @default 50
647
+ */
648
+ maxHistogramBoundaries: number;
649
+ /**
650
+ * Maximum attribute sets per instrument. Extra sets use the overflow set. Set 0 for no limit.
651
+ * @default 100
652
+ */
653
+ maxSeries: number;
654
+ /**
655
+ * Maximum instrument names. Drop extra names. Set 0 for no limit.
656
+ * @default 1000
657
+ */
658
+ maxInstruments: number;
659
+ }
660
+ /** Session and trace timing. The runtime sets these values at startup. */
661
+ export interface CorrelationPolicy {
662
+ /**
663
+ * Maximum idle time of a stored session, in milliseconds. Set 0 for no idle expiration.
664
+ * @default 1800000
665
+ */
666
+ sessionIdleMs: number;
667
+ /**
668
+ * Minimum wait between session activity writes, in milliseconds. Set 0 to write each time.
669
+ * @default 60000
670
+ */
671
+ sessionTouchMs: number;
672
+ /**
673
+ * Maximum idle time of an ambient trace, in milliseconds. Set 0 for no idle expiration.
674
+ * @default 300000
675
+ */
676
+ traceMaxAgeMs: number;
677
+ }
678
+ /** Rules for diagnostic reports and the console fallback. */
679
+ export interface DiagnosticsPolicy {
680
+ /**
681
+ * Minimum wait between reports of one code, in milliseconds. Set 0 to report each event.
682
+ * @default 1000
683
+ */
684
+ throttleMs: number;
685
+ /**
686
+ * Print a fixed warning if onDiagnostic throws. Do not print the exception.
687
+ * @default false
688
+ */
689
+ consoleFallback: boolean;
690
+ }
691
+ /** Application storage settings. The runtime sets these values at startup. */
692
+ export interface PersistencePolicy {
693
+ /**
694
+ * Namespace for batch storage and emergency queues. An empty value uses the previous storage keys.
695
+ * @default ""
696
+ */
697
+ namespace: string;
698
+ }
699
+ /** Resource and page fields that the SDK records. */
700
+ export interface MetadataPolicy {
701
+ /**
702
+ * Record the page URL. With false, page.url is empty.
703
+ * @default true
704
+ */
705
+ pageUrl: boolean;
706
+ /**
707
+ * Include browser.user_agent in resource attributes.
708
+ * @default true
709
+ */
710
+ userAgent: boolean;
711
+ /**
712
+ * Include the OpenFin application uuid and window name in resource attributes.
713
+ * @default true
714
+ */
715
+ openfin: boolean;
716
+ }
717
+ /** Capture capacity, duplicate checks and rate limits. */
718
+ export interface CapturePolicy {
719
+ /**
720
+ * Maximum breadcrumbs to keep. Set 0 to keep none.
721
+ * @default 50
722
+ */
723
+ breadcrumbs: number;
724
+ /**
725
+ * Time to suppress repeated errors, in milliseconds. Set 0 to report each error.
726
+ * @default 5000
727
+ */
728
+ errorDedupeMs: number;
729
+ /**
730
+ * Maximum error signatures to keep for duplicate checks. Set 0 for no limit.
731
+ * @default 200
732
+ */
733
+ maxErrorSignatures: number;
734
+ /**
735
+ * Maximum captured errors in one window. Set 0 for no limit.
736
+ * @default 20
737
+ */
738
+ errorsPerWindow: number;
739
+ /**
740
+ * Maximum captured console records in one window. Set 0 for no limit.
741
+ * @default 20
742
+ */
743
+ consolePerWindow: number;
744
+ /**
745
+ * Maximum long frames in one window. Set 0 for no limit.
746
+ * @default 20
747
+ */
748
+ longFramesPerWindow: number;
749
+ /**
750
+ * Maximum WebSocket events in one window. Set 0 for no limit.
751
+ * @default 20
752
+ */
753
+ webSocketPerWindow: number;
754
+ /**
755
+ * Rate limit window, in milliseconds. Set 0 to reset the window for each event.
756
+ * @default 10000
757
+ */
758
+ windowMs: number;
759
+ /**
760
+ * Maximum pipeline ERROR and FATAL records in one window. Set 0 for no limit.
761
+ * @default 500
762
+ */
763
+ errorCeiling: number;
764
+ }
462
765
  /** Options passed to `configure()`. */
463
766
  export interface ObservabilityConfig {
767
+ /** Capture capacity and rate limits. */
768
+ capturePolicy?: Partial<CapturePolicy>;
769
+ /** Resource and page fields to record. */
770
+ metadata?: Partial<MetadataPolicy>;
771
+ /** Application storage namespace. */
772
+ persistence?: Partial<PersistencePolicy>;
773
+ /** Diagnostic report and console fallback settings. */
774
+ diagnostics?: Partial<DiagnosticsPolicy>;
775
+ /** Session and trace timing. */
776
+ correlation?: Partial<CorrelationPolicy>;
777
+ /** Metric capacity in one interval. */
778
+ metrics?: Partial<MetricsPolicy>;
779
+ /** Live buffer capacity and the overflow rule. */
780
+ buffering?: Partial<BufferingPolicy>;
781
+ /** Request timing and delivery capacity. */
782
+ delivery?: Partial<DeliveryPolicy>;
783
+ /**
784
+ * Refuse changes through configure(). Call setConfigurationLocked(false) to permit changes again.
785
+ * @default false
786
+ */
787
+ lockConfiguration?: boolean;
788
+ /** Logger cache capacity. The app can change it until configuration is locked. */
789
+ loggerCache?: Partial<LoggerCacheOptions>;
790
+ /** Delivery identity and isolation rule. Use rotateSecurityContext() to change the identity. */
791
+ securityContext?: Partial<SecurityContextOptions>;
464
792
  /**
465
793
  * Ingest endpoint URL. Set `null` for console-only mode.
466
794
  * In console-only mode, the library sends nothing. It writes records to the console
@@ -476,6 +804,15 @@ export interface ObservabilityConfig {
476
804
  * @default ""
477
805
  */
478
806
  metricsEndpoint?: string;
807
+ /**
808
+ * OTLP traces endpoint URL, for example `"https://ingest.example/v1/traces"`. With this key, the
809
+ * library records one root span for each trace of the library, and one CLIENT span for each
810
+ * request that gets `traceparent`. It sends them there as an OTLP `ExportTraceServiceRequest`.
811
+ * Without it, the library sends no span. The key needs `serializer: "otlp"`. Set `""` to turn
812
+ * it off.
813
+ * @default ""
814
+ */
815
+ tracesEndpoint?: string;
479
816
  /**
480
817
  * The library reports this value as `service.name`.
481
818
  * @default ""
@@ -501,6 +838,13 @@ export interface ObservabilityConfig {
501
838
  * @default "INFO"
502
839
  */
503
840
  minLevel?: LogLevel;
841
+ /**
842
+ * Minimum level for each namespace prefix. The longest matching prefix wins. For example,
843
+ * `{ "trading.ticks": "DEBUG" }` logs the DEBUG records of `trading.ticks` and of its child
844
+ * namespaces. A namespace with no match uses `minLevel`. A new map replaces the map in force.
845
+ * @default {}
846
+ */
847
+ minLevels?: Record<string, LogLevel>;
504
848
  /**
505
849
  * Set "gzip" to compress a payload that is larger than the compression threshold.
506
850
  * Set "none" for an ingest endpoint that rejects gzip.
@@ -592,9 +936,24 @@ export interface ObservabilityConfig {
592
936
  */
593
937
  otelLoader?: OtelLoader;
594
938
  /**
595
- * Rewrites or drops a record before the library sends it. If the hook throws or returns a
939
+ * Gives attributes for each record that the library builds. Its values override `setContext()`
940
+ * values. The logger scope and the call payload override its values. The library calls it for
941
+ * each built record. This includes records used only for the console or breadcrumbs.
942
+ * Keep it fast and synchronous. If it throws or returns a value that is not an object,
943
+ * it adds nothing to the record.
944
+ * @returns The attributes, or undefined for none.
945
+ */
946
+ contextProvider?: () => Record<string, unknown> | undefined;
947
+ /**
948
+ * Changes or drops a record. The processors run in list order, before `redact`. A processor has
949
+ * the contract of `redact`. If it throws or returns a value that is not a record, the library
950
+ * drops the record.
951
+ */
952
+ processors?: ((record: LogRecord) => LogRecord | null)[];
953
+ /**
954
+ * Changes or drops a record before the SDK prints or sends it. If the hook throws or returns a
596
955
  * value that is not a record, the library drops the record.
597
- * @param record The record that the library is about to send.
956
+ * @param record Record to process. It can be used only for the console or breadcrumbs.
598
957
  * @returns The record to send, or `null` to drop it.
599
958
  */
600
959
  redact?: (record: LogRecord) => LogRecord | null;
@@ -604,8 +963,8 @@ export interface ObservabilityConfig {
604
963
  */
605
964
  onDiagnostic?: DiagnosticHandler;
606
965
  /**
607
- * Receives a summary when the library loses records that it built. Sampling, `minLevel` and
608
- * `redact` do not cause a loss. The library joins the losses of one reason in one task.
966
+ * Receives a summary when the library loses records that it built. Sampling, `minLevel`,
967
+ * `processors` and `redact` do not cause a loss. The library joins the losses of one reason in one task.
609
968
  * Do not log through the library in the hook. A record from the hook can evict a stored batch.
610
969
  * A batch that storage evicts during its send can still reach the server.
611
970
  * @param summary Reason, record count, batch ids, journey ids and action names of the loss.
@@ -615,10 +974,34 @@ export interface ObservabilityConfig {
615
974
  }
616
975
  /** Fully resolved configuration that the runtime holds. */
617
976
  export interface ResolvedConfig {
977
+ /** Capture capacity and rate limits. */
978
+ capturePolicy: CapturePolicy;
979
+ /** Resource and page fields to record. */
980
+ metadata: MetadataPolicy;
981
+ /** Application storage namespace. */
982
+ persistence: PersistencePolicy;
983
+ /** Diagnostic report and console fallback settings. */
984
+ diagnostics: DiagnosticsPolicy;
985
+ /** Session and trace timing. */
986
+ correlation: CorrelationPolicy;
987
+ /** Metric capacity in one interval. */
988
+ metrics: MetricsPolicy;
989
+ /** Live buffer capacity and the overflow rule. */
990
+ buffering: BufferingPolicy;
991
+ /** Request timing and delivery capacity. */
992
+ delivery: DeliveryPolicy;
993
+ /** True if configure() must refuse changes to the active settings. */
994
+ lockConfiguration: boolean;
995
+ /** Capacity of the logger cache. */
996
+ loggerCache: LoggerCacheOptions;
997
+ /** Active delivery context id and isolation rule. */
998
+ securityContext: SecurityContextOptions;
618
999
  /** Ingest endpoint URL, or null in console-only mode. */
619
1000
  endpoint: string | null;
620
1001
  /** OTLP metrics endpoint URL. An empty string sends metric records as log records. */
621
1002
  metricsEndpoint: string;
1003
+ /** OTLP traces endpoint URL, or "" when the library sends no span. */
1004
+ tracesEndpoint: string;
622
1005
  /** The library reports this value as `service.name`. */
623
1006
  serviceName: string;
624
1007
  /** The library reports this value as `service.version`. */
@@ -629,6 +1012,10 @@ export interface ResolvedConfig {
629
1012
  enabled: boolean;
630
1013
  /** Minimum level that the library logs. */
631
1014
  minLevel: LogLevel;
1015
+ /** Minimum level for each namespace prefix. */
1016
+ minLevels: Record<string, LogLevel>;
1017
+ /** Hooks that change or drop a record before `redact`. */
1018
+ processors: NonNullable<ObservabilityConfig["processors"]>;
632
1019
  /** "gzip" compresses a payload that is larger than the compression threshold. */
633
1020
  compression: "gzip" | "none";
634
1021
  /** The library passes this value to `fetch`. */
@@ -684,9 +1071,11 @@ export interface ResolvedConfig {
684
1071
  transportOnExit?: ExitTransport;
685
1072
  /** Supplies the `@opentelemetry/api` module in place of importing it. */
686
1073
  otelLoader?: OtelLoader;
1074
+ /** Gives attributes for each record that the library builds. */
1075
+ contextProvider?: ObservabilityConfig["contextProvider"];
687
1076
  /**
688
- * Rewrites or drops a record before the library sends it.
689
- * @param record The record that the library is about to send.
1077
+ * Changes or drops a record before the SDK prints or sends it.
1078
+ * @param record Record to process. It can be used only for the console or breadcrumbs.
690
1079
  * @returns The record to send, or `null` to drop it.
691
1080
  */
692
1081
  redact?: ObservabilityConfig["redact"];
@@ -13,7 +13,7 @@ import type { LogRecord } from "./log-record";
13
13
  * - "not_stored": storage did not keep a batch after a failed send. The cause is a write error or
14
14
  * `storage: "none"`.
15
15
  */
16
- export type LossReason = "buffer_full" | "expired" | "over_capacity" | "quota" | "max_attempts" | "rejected" | "unserializable" | "exit_queue_full" | "load_failed" | "not_stored";
16
+ export type LossReason = "security_context" | "buffer_full" | "expired" | "over_capacity" | "quota" | "max_attempts" | "rejected" | "unserializable" | "exit_queue_full" | "load_failed" | "not_stored";
17
17
  /**
18
18
  * One report of lost records. The library joins the losses of one reason in one task.
19
19
  * Each list holds at most 20 different values.
@@ -0,0 +1,27 @@
1
+ import type { DeliveryStats } from "./stats";
2
+ import type { BusOptions, LoggerCacheOptions, SecurityContextOptions } from "./config";
3
+ /** State of this SDK copy. A configured console-only runtime can have the status "ready". */
4
+ export interface ObservabilityHealth extends DeliveryStats {
5
+ /** Version of this SDK copy. */
6
+ sdkVersion: string;
7
+ /** Version of a different SDK copy that owns the page runtime, or null. */
8
+ owningSdkVersion: string | null;
9
+ /** Current runtime state. A configured console-only runtime can be ready. */
10
+ status: "starting" | "ready" | "rotating" | "degraded" | "stopped";
11
+ /** Delivery role of this context. */
12
+ mode: "sender" | "forwarder" | "console-only";
13
+ /** True if the local sender is ready and the runtime has not stopped. */
14
+ senderReady: boolean;
15
+ /** True if configure() cannot change the current settings. */
16
+ configurationLocked: boolean;
17
+ /** Codes of the current runtime or context failures. */
18
+ issues: ("runtime.version_mismatch" | "sender.unavailable" | "security.context_mismatch")[];
19
+ /** Logger cache capacity and the number of cached loggers. */
20
+ loggerCache: LoggerCacheOptions & {
21
+ size: number;
22
+ };
23
+ /** Active delivery context id and isolation rule. */
24
+ securityContext: SecurityContextOptions;
25
+ /** Source, validation and capacity rules of the bus. */
26
+ bus: Pick<BusOptions, "sourcePolicy" | "validation" | "maxMessageBytes" | "maxRecordsPerMessage" | "maxMessagesPerSecond" | "maxTrackedSources">;
27
+ }
@@ -5,7 +5,7 @@ export type LogLevel = "TRACE" | "DEBUG" | "INFO" | "WARN" | "ERROR" | "FATAL";
5
5
  * `event` is something that the application did. `metric` is a measurement.
6
6
  * `log` is a log call of the application. `system` is the output of this library.
7
7
  */
8
- export type LogType = "action" | "event" | "metric" | "log" | "system";
8
+ export type LogType = "action" | "event" | "metric" | "log" | "system" | "span";
9
9
  /** Metric value type: level, running total, or distribution. */
10
10
  export type MetricType = "gauge" | "counter" | "histogram";
11
11
  /** Internal record shape. A serializer converts it to the payload format. */
@@ -0,0 +1,47 @@
1
+ import type { OneLogger } from "../core/logger";
2
+ import type { Counter, Histogram, HistogramOptions, InstrumentOptions } from "./metric";
3
+ /** Tools that the library gives to a capture plugin. */
4
+ export interface PluginContext {
5
+ /** Logger for the namespace `uiobs.capture.<plugin name>`. */
6
+ logger: OneLogger;
7
+ /**
8
+ * Gives a counter. It is the same as `counter()`.
9
+ * @param name Metric name.
10
+ * @param options Unit of the values.
11
+ * @returns The counter.
12
+ */
13
+ counter(name: string, options?: InstrumentOptions): Counter;
14
+ /**
15
+ * Gives a histogram. It is the same as `histogram()`.
16
+ * @param name Metric name.
17
+ * @param options Unit of the values and the bucket boundaries.
18
+ * @returns The histogram.
19
+ */
20
+ histogram(name: string, options?: HistogramOptions): Histogram;
21
+ /**
22
+ * Adds a breadcrumb with the category `custom`. It is the same as `addBreadcrumb()`.
23
+ * @param message Description of the event.
24
+ * @param data Optional metadata.
25
+ */
26
+ addBreadcrumb(message: string, data?: Record<string, unknown>): void;
27
+ /**
28
+ * Runs a function. The network capture does not record a request that the function starts
29
+ * synchronously, and does not add `traceparent` to it. Use it for the requests of the plugin.
30
+ * @param fn Function that starts the request.
31
+ * @returns The return value of the function.
32
+ */
33
+ ownRequest<T>(fn: () => T): T;
34
+ }
35
+ /** Capture module from the app. The library installs it with the built-in capture modules. */
36
+ export interface CapturePlugin {
37
+ /** Name of the plugin. Its logger namespace and its diagnostic messages use it. */
38
+ readonly name: string;
39
+ /**
40
+ * Starts the capture. A later `configure()` that changes the capture section calls
41
+ * `uninstall()`, then calls `install()` again.
42
+ * @param ctx Tools of the plugin.
43
+ */
44
+ install(ctx: PluginContext): void;
45
+ /** Stops the capture. Restore each function that the plugin replaced. */
46
+ uninstall(): void;
47
+ }
@@ -0,0 +1,11 @@
1
+ /** Delivery state of this context. A forwarder reports only its own buffers. */
2
+ export interface DeliveryStats {
3
+ /** Records in a buffer of the library. No request carries them yet. */
4
+ pending: number;
5
+ /** Records in requests that have not completed. */
6
+ inFlight: number;
7
+ /** Batches in storage that wait for a retry. */
8
+ stored: number;
9
+ /** Epoch time in milliseconds when the server last accepted a batch, or null. */
10
+ lastSendAt: number | null;
11
+ }
@@ -15,6 +15,19 @@ export interface StorageAdapter {
15
15
  * @returns Oldest persisted batches.
16
16
  */
17
17
  take(limit: number): Promise<LogBatch[]>;
18
+ /**
19
+ * Reads batches of one context without loading batches of other contexts.
20
+ * @param id Delivery context id.
21
+ * @param limit Maximum batches to return.
22
+ * @returns Batches of this context, oldest first.
23
+ */
24
+ takeContext?(id: string, limit: number): Promise<LogBatch[]>;
25
+ /**
26
+ * Counts batches of one context without loading them.
27
+ * @param id Delivery context id.
28
+ * @returns Number of batches in this context.
29
+ */
30
+ countContext?(id: string): Promise<number>;
18
31
  /**
19
32
  * Removes a batch by ID. A call with an unknown ID resolves without error.
20
33
  * @param id Batch identifier.
@@ -0,0 +1,2 @@
1
+ const e=require("./error-like-gGRx2s36.cjs"),t=require("./library-request-BaZOi4eg.cjs"),n=require("./platform-DBSKTvFn.cjs"),r=require("./patch-BX8KrPCT.cjs"),i=require("./types-C7WNpnG1.cjs");var a=1e3,o={name:`http.client.request.duration`,kind:`histogram`,unit:`s`,boundaries:[.005,.01,.025,.05,.075,.1,.25,.5,.75,1,2.5,5,7.5,10]};function s(t,n,r,i){let a=typeof location<`u`?location.href:void 0,o={"http.request.method":t,"server.address":new URL(n,a).hostname};if(r===0){let t=e.r(i)?i.name:``;return o[`error.type`]=t===``?`_OTHER`:t,o}return o[`http.response.status_code`]=r,r>=400&&(o[`error.type`]=String(r)),o}function c(){return XMLHttpRequest.prototype}function l(e){if(typeof e==`string`)return e;if(e instanceof URL)return e.href;if(typeof e==`object`&&e){let{url:t}=e;if(typeof t==`string`)return t}return String(e)}function u(e,t){let n=t?.method;return n===void 0&&typeof e==`object`&&e&&(n=e.method),f(n??`GET`)}function d(e){return typeof e==`object`&&!(e instanceof URL)&&!(e instanceof Request)}function f(e){return typeof e==`string`?e.toUpperCase():String(e)}var p=class{ctx;name=`network`;installed=!1;restores=[];warnedTransport=!1;constructor(e){this.ctx=e}install(){this.installed||(this.installed=!0,this.ctx.config.capture.fetch&&this.installFetch(),this.ctx.config.capture.xhr&&this.installXhr())}uninstall(){if(this.installed){this.installed=!1;for(let e of this.restores.splice(0))e()}}ignored(e){return t.t()||i.t(e,this.ctx.config.capture.ignoreUrls)}propagates(e){let t=this.ctx.config.capture.propagateTraceHeaderTo;if(t.length===0)return!1;let n=this.ctx.diagnostics.guard(`capture.header_failed`,`The library could not read the origin of a request URL. Only a RegExp target can match it.`,()=>new URL(e,location.href).origin);return t.some(t=>typeof t==`string`?t===n:t.test(e))}installFetch(){if(typeof globalThis.fetch!=`function`)return;let e=!0,t=(e,t)=>this.prepareFetch(e,t),n=(e,t,n,r)=>{this.record(e.method,e.url,t,n,r,e.span,e.routingContextId)},i=r.t(globalThis,`fetch`,r=>{let i=r.bind(globalThis);return async function(r,a){let o=e?t(r,a):void 0;if(!o)return i(r,a);let s=performance.now();try{let e=await i(o.input,o.init);return n(o,e.status,performance.now()-s,void 0),e}catch(e){throw n(o,0,performance.now()-s,e),e}}});this.restores.push(()=>{e=!1,i()})}prepareFetch(e,t){let n=this.ctx.diagnostics.guard(`capture.record_failed`,`The library could not read a fetch request. It sends the request unchanged.`,()=>{let n=l(e);if(!this.ignored(n))return{method:u(e,t),url:n,propagate:this.propagates(n)}});if(!n)return;let{method:r,url:i}=n,a={method:r,url:i,input:e,init:t,routingContextId:this.ctx.config.securityContext.id};if(!n.propagate||d(e))return a;try{let n=this.ctx.tracing.request(),r=Object.entries(n.headers);if(e instanceof Request){let t=new Headers(e.headers);for(let[e,n]of r)t.set(e,n);a.input=new Request(e,{headers:t})}else{let e=new Headers(t?.headers);for(let[t,n]of r)e.set(t,n);a.init={...t,headers:e}}a.span=n.span}catch(n){a.input=e,a.init=t,this.ctx.diagnostics.report(`capture.header_failed`,`The library could not add the traceparent header. It sends the request unchanged.`,{url:i},n)}return a}installXhr(){if(typeof XMLHttpRequest>`u`)return;let e=!0,t=this.ctx,n=e=>this.ignored(e),i=e=>this.propagates(e),a=(e,t,n)=>{this.record(e.method,e.url,t,n,void 0,e.span,e.routingContextId)},o=c(),s=r.t(o,`open`,n=>function(r,i,...a){e&&t.diagnostics.guard(`capture.record_failed`,`The library could not read an XMLHttpRequest. It does not record the request.`,()=>{this.__uiobs={method:f(r),url:l(i),startedAt:0}}),n.apply(this,[r,i,...a])}),u=r.t(o,`send`,r=>function(...o){let s=e?this.__uiobs:void 0;s&&t.diagnostics.guard(`capture.record_failed`,`The library could not record ${s.method} ${s.url}.`,()=>{n(s.url)||(s.startedAt=performance.now(),s.routingContextId=t.config.securityContext.id,this.addEventListener(`loadend`,()=>{a(s,this.status,performance.now()-s.startedAt)},{once:!0}),i(s.url)&&(s.span=m(this,s.url,t)))}),r.apply(this,o)});this.restores.push(()=>{e=!1,s(),u()})}record(e,r,i,c,l,u,d){if(this.ctx.isActive?.()===!1||this.ctx.config.securityContext.isolation&&d!==void 0&&d!==this.ctx.config.securityContext.id)return;let f=n.i(r,this.ctx.config.capture.fullUrls,this.ctx.config.capture.urlTransform,this.ctx.diagnostics);!this.warnedTransport&&t.n()&&(this.warnedTransport=!0,this.ctx.diagnostics.report(`capture.transport_request`,`Network capture saw ${e} ${f} during a custom transport call. If the transport sends this request, add its URL to capture.ignoreUrls.`)),this.ctx.config.capture.httpMetrics&&this.ctx.diagnostics.guard(`capture.record_failed`,`The library could not record the duration of ${e} ${f}.`,()=>{let t=s(e,r,i,l);this.ctx.recordMetric(o,c/a,t)}),u&&this.ctx.diagnostics.guard(`capture.record_failed`,`The library could not record the span of ${e} ${f}.`,()=>{let t=Date.now();this.ctx.recordSpan({...u,name:e,kind:`client`,startMs:t-c,endMs:t,error:i===0||i>=400,attributes:{...s(e,r,i,l),"url.full":f}})}),this.ctx.diagnostics.guard(`capture.record_failed`,`The library could not record ${e} ${f}.`,()=>{let t=Math.round(c);this.ctx.breadcrumbs.push({t:Date.now(),category:`http`,message:`${e} ${f} ${i===0?`failed`:String(i)}`,data:{durationMs:t}});let n={"http.request.method":e,"url.full":f,"http.response.status_code":i,"http.duration_ms":t};i===0?this.ctx.logger.error(`${e} ${f} failed`,l,n):i>=400?this.ctx.logger.warn(`${e} ${f} returned ${String(i)}`,n):this.ctx.logger.debug(`${e} ${f}`,n)})}};function m(e,t,n){try{let t=n.tracing.request();for(let[n,r]of Object.entries(t.headers))e.setRequestHeader(n,r);return t.span}catch(e){n.diagnostics.report(`capture.header_failed`,`The library could not add the traceparent header. It sends the request unchanged.`,{url:t},e);return}}exports.NetworkCapture=p;
2
+ //# sourceMappingURL=network-CF8UO5PK.cjs.map