@utk09/ui-observability 0.5.0 → 0.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (123) hide show
  1. package/CHANGELOG.md +31 -0
  2. package/README.md +119 -60
  3. package/dist/bus/bus.d.ts +10 -10
  4. package/dist/bus/links.d.ts +1 -1
  5. package/dist/bus-DeZzr2bx.cjs +2 -0
  6. package/dist/bus-DeZzr2bx.cjs.map +1 -0
  7. package/dist/{bus-D3OO0OcL.js → bus-DfAbg_pg.js} +19 -19
  8. package/dist/bus-DfAbg_pg.js.map +1 -0
  9. package/dist/capture/network.d.ts +2 -2
  10. package/dist/capture/types.d.ts +10 -10
  11. package/dist/capture/web-vitals.d.ts +3 -3
  12. package/dist/constants-C8nZQBmQ.js +86 -0
  13. package/dist/constants-C8nZQBmQ.js.map +1 -0
  14. package/dist/constants-IBL_jd5R.cjs +2 -0
  15. package/dist/constants-IBL_jd5R.cjs.map +1 -0
  16. package/dist/constants.d.ts +56 -43
  17. package/dist/core/breadcrumbs.d.ts +14 -14
  18. package/dist/core/config.d.ts +5 -4
  19. package/dist/core/context.d.ts +2 -2
  20. package/dist/core/diagnostics.d.ts +10 -9
  21. package/dist/core/journey.d.ts +23 -20
  22. package/dist/core/logger.d.ts +7 -7
  23. package/dist/core/pipeline.d.ts +34 -29
  24. package/dist/core/record.d.ts +6 -6
  25. package/dist/core/runtime.d.ts +20 -18
  26. package/dist/core/sampling.d.ts +15 -16
  27. package/dist/core/sender.d.ts +1 -1
  28. package/dist/{errors-Dme9tz-6.js → errors-4MQyjZVj.js} +4 -4
  29. package/dist/errors-4MQyjZVj.js.map +1 -0
  30. package/dist/{errors-DPju_xSI.cjs → errors-CUdShXe7.cjs} +2 -2
  31. package/dist/errors-CUdShXe7.cjs.map +1 -0
  32. package/dist/index.cjs +1 -1
  33. package/dist/index.cjs.map +1 -1
  34. package/dist/index.d.ts +7 -5
  35. package/dist/index.js +136 -115
  36. package/dist/index.js.map +1 -1
  37. package/dist/{indexeddb-storage-nxs_rxGx.js → indexeddb-storage-0LtUALBg.js} +16 -16
  38. package/dist/indexeddb-storage-0LtUALBg.js.map +1 -0
  39. package/dist/indexeddb-storage-CcEJlq2l.cjs +2 -0
  40. package/dist/indexeddb-storage-CcEJlq2l.cjs.map +1 -0
  41. package/dist/{interactions-DP0-rIPJ.cjs → interactions-BMNPQ3WH.cjs} +2 -2
  42. package/dist/interactions-BMNPQ3WH.cjs.map +1 -0
  43. package/dist/{interactions-C1romMpE.js → interactions-BaCmoGLB.js} +2 -2
  44. package/dist/interactions-BaCmoGLB.js.map +1 -0
  45. package/dist/models/batch.d.ts +12 -9
  46. package/dist/models/bus.d.ts +12 -13
  47. package/dist/models/config.d.ts +85 -44
  48. package/dist/models/log-record.d.ts +12 -10
  49. package/dist/models/serializer.d.ts +3 -2
  50. package/dist/models/storage.d.ts +2 -2
  51. package/dist/network-DBNvxCE3.cjs +2 -0
  52. package/dist/network-DBNvxCE3.cjs.map +1 -0
  53. package/dist/{network-au-Tqt1n.js → network-jQ2t8rU4.js} +4 -4
  54. package/dist/network-jQ2t8rU4.js.map +1 -0
  55. package/dist/platform-ByQllE_W.cjs +2 -0
  56. package/dist/platform-ByQllE_W.cjs.map +1 -0
  57. package/dist/{platform-DMYo3AX3.js → platform-YuByH8A5.js} +8 -8
  58. package/dist/platform-YuByH8A5.js.map +1 -0
  59. package/dist/{sampling-ByI5H44E.js → sampling-CbYySsZ1.js} +21 -18
  60. package/dist/sampling-CbYySsZ1.js.map +1 -0
  61. package/dist/sampling-Cs50xsZl.cjs +2 -0
  62. package/dist/sampling-Cs50xsZl.cjs.map +1 -0
  63. package/dist/{sender-R7lOpyNc.js → sender-BIob8eZz.js} +60 -60
  64. package/dist/sender-BIob8eZz.js.map +1 -0
  65. package/dist/sender-iOjzcueM.cjs +3 -0
  66. package/dist/sender-iOjzcueM.cjs.map +1 -0
  67. package/dist/storage/emergency-queue.d.ts +2 -2
  68. package/dist/storage/factory.d.ts +2 -1
  69. package/dist/storage/idb-driver.d.ts +19 -19
  70. package/dist/storage/indexeddb-storage.d.ts +18 -17
  71. package/dist/storage/keys.d.ts +1 -1
  72. package/dist/storage/local-storage.d.ts +19 -18
  73. package/dist/storage/memory-storage.d.ts +12 -11
  74. package/dist/transport/compression.d.ts +2 -2
  75. package/dist/transport/errors.d.ts +8 -7
  76. package/dist/transport/exit-flush.d.ts +27 -24
  77. package/dist/transport/http-transport.d.ts +18 -11
  78. package/dist/transport/retry-engine.d.ts +33 -28
  79. package/dist/transport/serializers/ecs.d.ts +1 -1
  80. package/dist/transport/serializers/otlp.d.ts +1 -1
  81. package/dist/unref-16maCyKA.js.map +1 -1
  82. package/dist/unref-CU9Nyz_9.cjs.map +1 -1
  83. package/dist/utils/console.d.ts +7 -6
  84. package/dist/utils/identity.d.ts +6 -5
  85. package/dist/utils/lock.d.ts +4 -4
  86. package/dist/utils/platform.d.ts +5 -3
  87. package/dist/utils/sanitize.d.ts +5 -2
  88. package/dist/utils/sequence.d.ts +2 -2
  89. package/dist/utils/tracing.d.ts +8 -7
  90. package/dist/web-vitals-B2FYsEAU.cjs +2 -0
  91. package/dist/web-vitals-B2FYsEAU.cjs.map +1 -0
  92. package/dist/{web-vitals-DwWdLBq6.js → web-vitals-DHZ0yA_H.js} +4 -4
  93. package/dist/web-vitals-DHZ0yA_H.js.map +1 -0
  94. package/package.json +4 -2
  95. package/dist/bus-D3OO0OcL.js.map +0 -1
  96. package/dist/bus-OdRJVUzr.cjs +0 -2
  97. package/dist/bus-OdRJVUzr.cjs.map +0 -1
  98. package/dist/constants-B6kdsCzF.js +0 -75
  99. package/dist/constants-B6kdsCzF.js.map +0 -1
  100. package/dist/constants-DZH04585.cjs +0 -2
  101. package/dist/constants-DZH04585.cjs.map +0 -1
  102. package/dist/errors-DPju_xSI.cjs.map +0 -1
  103. package/dist/errors-Dme9tz-6.js.map +0 -1
  104. package/dist/indexeddb-storage-lGdoHGHy.cjs +0 -2
  105. package/dist/indexeddb-storage-lGdoHGHy.cjs.map +0 -1
  106. package/dist/indexeddb-storage-nxs_rxGx.js.map +0 -1
  107. package/dist/interactions-C1romMpE.js.map +0 -1
  108. package/dist/interactions-DP0-rIPJ.cjs.map +0 -1
  109. package/dist/network-DDVIJSHd.cjs +0 -2
  110. package/dist/network-DDVIJSHd.cjs.map +0 -1
  111. package/dist/network-au-Tqt1n.js.map +0 -1
  112. package/dist/platform-DMYo3AX3.js.map +0 -1
  113. package/dist/platform-g99Kn755.cjs +0 -2
  114. package/dist/platform-g99Kn755.cjs.map +0 -1
  115. package/dist/sampling-ByI5H44E.js.map +0 -1
  116. package/dist/sampling-Dui-Fp3u.cjs +0 -2
  117. package/dist/sampling-Dui-Fp3u.cjs.map +0 -1
  118. package/dist/sender-R7lOpyNc.js.map +0 -1
  119. package/dist/sender-vLcbQhiB.cjs +0 -3
  120. package/dist/sender-vLcbQhiB.cjs.map +0 -1
  121. package/dist/web-vitals-DM2nvcMJ.cjs +0 -2
  122. package/dist/web-vitals-DM2nvcMJ.cjs.map +0 -1
  123. package/dist/web-vitals-DwWdLBq6.js.map +0 -1
@@ -49,23 +49,23 @@ export declare class OneLogger {
49
49
  */
50
50
  warn: (message: string, payload?: Record<string, unknown>) => void;
51
51
  /**
52
- * Logs an error record with attached breadcrumb history. A plain object in the
53
- * error slot with no payload given is read as the payload.
52
+ * Logs an error record with the breadcrumb history. If payload is absent, a plain
53
+ * object in the error slot becomes the payload.
54
54
  * @param message Error description.
55
55
  * @param error Caught error instance, reason, or payload.
56
56
  * @param payload Optional contextual attributes.
57
57
  */
58
58
  error: (message: string, error?: unknown, payload?: Record<string, unknown>) => void;
59
59
  /**
60
- * Logs a fatal unrecoverable error record. A plain object in the error slot
61
- * with no payload given is read as the payload.
60
+ * Logs a fatal error record. If payload is absent, a plain object in the error slot
61
+ * becomes the payload.
62
62
  * @param message Error description.
63
63
  * @param error Caught error instance, reason, or payload.
64
64
  * @param payload Optional contextual attributes.
65
65
  */
66
66
  fatal: (message: string, error?: unknown, payload?: Record<string, unknown>) => void;
67
67
  /**
68
- * Logs a discrete user interaction action.
68
+ * Logs one user action.
69
69
  * @param name Action identifier.
70
70
  * @param payload Optional action attributes.
71
71
  */
@@ -102,7 +102,7 @@ export declare class OneLogger {
102
102
  */
103
103
  timeAsync: <T>(label: string, fn: () => Promise<T>, attributes?: Record<string, unknown>) => Promise<T>;
104
104
  /**
105
- * Builds, logs to console, and emits a standard log record.
105
+ * Builds and emits a standard log record. It also prints the record to the console.
106
106
  * @param level Severity level.
107
107
  * @param type Record classification.
108
108
  * @param body Primary message.
@@ -110,7 +110,7 @@ export declare class OneLogger {
110
110
  */
111
111
  private write;
112
112
  /**
113
- * Builds, logs to console, and emits an error record with attached breadcrumbs.
113
+ * Builds and emits an error record with breadcrumbs. It also prints the record to the console.
114
114
  * @param level Severity level ("ERROR" or "FATAL").
115
115
  * @param message Error description.
116
116
  * @param error Caught error instance, reason, or payload.
@@ -4,18 +4,21 @@ import type { StorageAdapter } from "../models/storage";
4
4
  import type { HttpTransport } from "../transport/http-transport";
5
5
  import type { RetryEngine } from "../transport/retry-engine";
6
6
  import type { Diagnostics } from "./diagnostics";
7
- /** Pipeline stream classification for logs versus metrics. */
7
+ /** Name of a pipeline stream. */
8
8
  export type StreamName = "logs" | "metrics";
9
9
  /** Batching policy for one record stream. */
10
10
  export interface StreamOptions {
11
- /** Max time a partial batch waits before it is sent, in milliseconds. */
11
+ /** Maximum time in milliseconds that a partial batch waits before the pipeline sends it. */
12
12
  flushIntervalMs: number;
13
- /** Max records per batch before it is sent early. */
13
+ /** Maximum records in a batch. At this count, the pipeline sends the batch early. */
14
14
  batchSize: number;
15
15
  }
16
- /** Batching policy per stream. Metrics batch harder: higher volume, nothing waits on them. */
16
+ /**
17
+ * Batching policy per stream. Metrics use larger batches and a longer interval.
18
+ * Metrics have a higher volume, and no process waits for them.
19
+ */
17
20
  export declare const STREAM_OPTIONS: Record<StreamName, StreamOptions>;
18
- /** Pipeline orchestrating log and metric stream buffering, batch creation, and HTTP dispatch. */
21
+ /** Buffers log and metric streams, makes batches and sends them over HTTP. */
19
22
  export declare class LogPipeline {
20
23
  private readonly transport;
21
24
  private readonly storage;
@@ -23,7 +26,7 @@ export declare class LogPipeline {
23
26
  private readonly diagnostics;
24
27
  /** Buffer instances for logs and metrics streams. */
25
28
  private readonly streams;
26
- /** Unconfirmed in-flight batches tracked for exit flush recovery. */
29
+ /** In-flight batches without delivery confirmation. The exit flush sends them again. */
27
30
  private readonly unconfirmed;
28
31
  /** Closed batches waiting for a free dispatch slot. */
29
32
  private readonly queue;
@@ -31,7 +34,7 @@ export declare class LogPipeline {
31
34
  private readonly ceiling;
32
35
  /** Dispatches currently in flight, capped at MAX_CONCURRENT_REQUESTS. */
33
36
  private inFlight;
34
- /** Indicates a pump is already queued, so one microtask drains a burst. */
37
+ /** It is true when a pump is in the queue. One microtask then drains a burst. */
35
38
  private pumpScheduled;
36
39
  /** Indicates whether the pipeline has been destroyed. */
37
40
  private stopped;
@@ -44,22 +47,23 @@ export declare class LogPipeline {
44
47
  */
45
48
  constructor(transport: HttpTransport, storage: StorageAdapter, retry: RetryEngine, diagnostics: Diagnostics, streamOptions?: Record<StreamName, StreamOptions>);
46
49
  /**
47
- * Stamps observed timestamp and enqueues a record into the pipeline.
50
+ * Sets the observed timestamp and adds a record to the pipeline.
48
51
  * @param record Record to push.
49
52
  */
50
53
  push(record: LogRecord): void;
51
54
  /**
52
- * Drains the stream buffers into one batch. In-flight batches stay where they
53
- * are. They carry their own ids and are still on their way, so taking them here
54
- * resends every record under an id the server cannot deduplicate against.
55
+ * Drains the stream buffers into one batch. It does not take in-flight batches.
56
+ * An in-flight batch has its own ID and its send is not complete. If this method
57
+ * takes it, the pipeline sends each record again under a new ID. The server cannot
58
+ * deduplicate that ID.
55
59
  * @returns Combined LogBatch or null if no records are buffered.
56
60
  */
57
61
  drainPending(): LogBatch | null;
58
62
  /**
59
- * Atomically drains all buffered and unconfirmed in-flight records into a single
60
- * exit batch. Records already handed to fetch go out again under a new batch id,
61
- * so the server cannot deduplicate them and the exit flush can deliver duplicates.
62
- * A document being closed cannot confirm delivery, so this is by design.
63
+ * Drains all buffered and unconfirmed in-flight records into one exit batch in one step.
64
+ * Records already given to fetch go again under a new batch ID. The server cannot
65
+ * deduplicate them. Thus the exit flush can deliver duplicates. This is intentional.
66
+ * A closing document cannot confirm delivery.
63
67
  * @returns Combined LogBatch or null if no records are pending.
64
68
  */
65
69
  drainForExit(): LogBatch | null;
@@ -72,23 +76,23 @@ export declare class LogPipeline {
72
76
  */
73
77
  private toBatch;
74
78
  /**
75
- * Sorts a record into its stream. Sampling already ran, in RecordBuilder for a
76
- * local record and in the runtime for a forwarded one. Every fault is contained
77
- * here: a record carrying no `attributes` makes isMetric throw, and a throw
78
- * escaping this method would surface inside the caller's own log call.
79
+ * Sorts a record into its stream. Sampling already ran. RecordBuilder samples a local
80
+ * record. The runtime samples a forwarded record. This method catches each fault.
81
+ * A record without `attributes` makes isMetric throw. An uncaught throw goes into the
82
+ * log call of the caller.
79
83
  * @param record Record to sort.
80
84
  */
81
85
  private route;
82
86
  /**
83
- * Drains a stream buffer into a new batch and queues it for dispatch. The
84
- * buffer always holds at least one record here: a timer is armed only by a
85
- * push, and every `take` disarms the timer that would have called this.
87
+ * Drains a stream buffer into a new batch and queues the batch for dispatch.
88
+ * The buffer always has one or more records here. Only a push starts a timer.
89
+ * Each `take` stops the timer that calls this method.
86
90
  * @param stream Stream buffer to drain.
87
91
  */
88
92
  private claim;
89
93
  /**
90
- * Queues a batch and schedules the pump on a microtask. Dispatching inline
91
- * would start a fetch inside the application's own log call.
94
+ * Queues a batch and schedules the pump on a microtask. An inline dispatch starts
95
+ * a fetch inside the log call of the application.
92
96
  * @param batch Batch ready for delivery.
93
97
  */
94
98
  private enqueue;
@@ -100,20 +104,21 @@ export declare class LogPipeline {
100
104
  */
101
105
  private run;
102
106
  /**
103
- * Sends a batch over HTTP transport or persists it to offline storage if throttled or failed.
107
+ * Sends a batch over the HTTP transport. If the transport throttles or fails, it stores
108
+ * the batch.
104
109
  * @param batch Batch to deliver.
105
110
  */
106
111
  private dispatch;
107
112
  /**
108
- * Persists a batch the transport refused, letting the retry engine split a 413
109
- * and drop what the server will never accept.
113
+ * Stores a batch that the transport refused. The retry engine splits a 413 and
114
+ * drops a batch that the server does not accept.
110
115
  * @param batch Batch to persist, with its attempt already counted.
111
116
  * @param error Failure thrown by the transport.
112
117
  */
113
118
  private storeFailed;
114
119
  /**
115
- * Persists an undelivered batch to storage and triggers retry engine. Bounded:
116
- * a storage call that does not settle holds this dispatch slot. Two of them
120
+ * Stores an undelivered batch and triggers the retry engine. A deadline limits the
121
+ * wait. A storage call that does not settle holds this dispatch slot. Two such calls
117
122
  * stop the pipeline.
118
123
  * @param batch Batch to persist.
119
124
  */
@@ -24,12 +24,12 @@ export interface RecordBuilderDeps {
24
24
  tracing: TraceEngine;
25
25
  /** Monotonic sequence counter. */
26
26
  sequence: Sequence;
27
- /** Context, session, and tab identity context. */
27
+ /** Context, session and tab identity. */
28
28
  identity: Identity;
29
29
  /** Detected host platform metadata. */
30
30
  platform: PlatformMetadata;
31
31
  }
32
- /** Per-record size caps, applied after sanitize and again after redact. */
32
+ /** Size limits for each record. The builder applies them after sanitize and after redact. */
33
33
  export interface RecordLimits extends SanitizeLimits {
34
34
  /** Max record body length, in characters. */
35
35
  maxBodyChars: number;
@@ -42,7 +42,7 @@ export type DropReason = "level" | "sampling" | "redact";
42
42
  export interface BuildResult {
43
43
  /** Completed record, or null when it was dropped. */
44
44
  record: LogRecord | null;
45
- /** Why it was dropped. Absent when a record was built. */
45
+ /** Reason for the drop. It is absent when the builder built a record. */
46
46
  dropped?: DropReason;
47
47
  }
48
48
  /** Input parameters for constructing a single log record. */
@@ -69,16 +69,16 @@ export declare class RecordBuilder {
69
69
  * @param deps Injected builder dependencies.
70
70
  */
71
71
  constructor(deps: RecordBuilderDeps);
72
- /** Invalidates cached resource attributes to force recomputation on next build. */
72
+ /** Clears the cached resource attributes. The next build computes them again. */
73
73
  invalidateResource(): void;
74
74
  /**
75
- * Evaluates whether a log level clears minimum severity thresholds.
75
+ * Checks if logging is on and the level is at or above minLevel.
76
76
  * @param level Target log severity level.
77
77
  * @returns True if the level is enabled.
78
78
  */
79
79
  isEnabled(level: LogLevel): boolean;
80
80
  /**
81
- * Builds a structured LogRecord from input attributes, applying sanitization and size budgeting.
81
+ * Builds a structured LogRecord from the input. It sanitizes attributes and applies size limits.
82
82
  * @param input Logger call input parameters.
83
83
  * @returns The record, or null with the reason it was dropped.
84
84
  */
@@ -12,11 +12,11 @@ import { ContextStore } from "./context";
12
12
  import { Diagnostics } from "./diagnostics";
13
13
  import { JourneyEngine } from "./journey";
14
14
  import { RecordBuilder } from "./record";
15
- /** Central runtime managing subsystem lifecycles, bus coordination, and record delivery. */
15
+ /** Manages subsystem lifecycles, bus coordination and record delivery. */
16
16
  export declare class ObservabilityRuntime {
17
17
  /** Diagnostics reporter for internal faults. */
18
18
  readonly diagnostics: Diagnostics;
19
- /** Active configuration instance mutated in place during reconfigurations. */
19
+ /** Active configuration instance. A reconfigure changes it in place. */
20
20
  readonly config: ResolvedConfig;
21
21
  /** Detected host platform metadata. */
22
22
  readonly platform: PlatformMetadata;
@@ -51,7 +51,7 @@ export declare class ObservabilityRuntime {
51
51
  private busBuilt?;
52
52
  /** Load and start of the bus. It is undefined until the first need. */
53
53
  private busLoad?;
54
- /** Storage strategy the adapter was built from, set once the build starts. */
54
+ /** Storage strategy of the adapter. The runtime sets it when the build starts. */
55
55
  private storageBuiltAs?;
56
56
  /** Delivery stack. The runtime sets it in the sender role with an endpoint, after the chunk loads. */
57
57
  private sender?;
@@ -75,7 +75,7 @@ export declare class ObservabilityRuntime {
75
75
  private roleResolved;
76
76
  /** Indicates whether asynchronous initialization has completed. */
77
77
  private ready;
78
- /** Indicates whether the runtime has been permanently shut down. */
78
+ /** Indicates whether shutdown stopped the runtime. */
79
79
  private destroyed;
80
80
  /** Timestamp of the last reported storage gap warning in epoch milliseconds. */
81
81
  private lastGapAt;
@@ -84,7 +84,7 @@ export declare class ObservabilityRuntime {
84
84
  */
85
85
  private constructor();
86
86
  /**
87
- * Direct communication receiver invoked by same-origin child frames.
87
+ * Receives direct messages from same-origin child frames.
88
88
  * @param message Inbound bus message.
89
89
  * @param reply Direct response callback.
90
90
  */
@@ -116,9 +116,9 @@ export declare class ObservabilityRuntime {
116
116
  */
117
117
  private reconfigure;
118
118
  /**
119
- * Restores the storage strategy the adapter was built from. Every other key is read
120
- * live, but the adapter is built once: swapping it strands the batches already
121
- * persisted under the old one, which is worse than refusing the change.
119
+ * Restores the storage strategy of the built adapter. The runtime reads all other keys
120
+ * live. It builds the adapter only one time. A new adapter strands the batches in the
121
+ * old adapter. That loss is worse than a refused change.
122
122
  */
123
123
  private keepBuiltStorage;
124
124
  /**
@@ -159,7 +159,7 @@ export declare class ObservabilityRuntime {
159
159
  private role;
160
160
  /**
161
161
  * Loads the delivery stack if this context is the sender and has an endpoint.
162
- * @returns Promise resolving when the load completes, or at once if nothing loads.
162
+ * @returns Promise resolving when the load completes, or immediately when nothing loads.
163
163
  */
164
164
  private syncSender;
165
165
  /**
@@ -188,11 +188,12 @@ export declare class ObservabilityRuntime {
188
188
  destroy(): Promise<void>;
189
189
  /**
190
190
  * Routes a completed log record to the pipeline or forward buffer.
191
- * @param record Log record to emit, or null if dropped during build.
191
+ * @param record Log record to emit, or null when the build dropped it.
192
192
  */
193
193
  emit(record: LogRecord | null): void;
194
194
  /**
195
- * Directs a record to the forward buffer or local pipeline based on active bus role.
195
+ * Sends a record to the forward buffer or to the local pipeline. The bus role selects
196
+ * the path.
196
197
  * @param record Log record to route.
197
198
  */
198
199
  private route;
@@ -214,24 +215,25 @@ export declare class ObservabilityRuntime {
214
215
  */
215
216
  private forward;
216
217
  /**
217
- * Validates, samples and enqueues records received from child frames or workers.
218
- * A forwarded record arrives built, so this is the first point in this context
219
- * where sampling can run. A local record is sampled in RecordBuilder instead.
218
+ * Validates, samples and queues records from child frames or workers.
219
+ * A forwarded record arrives built. This is the first point in this context where
220
+ * sampling can run. RecordBuilder samples a local record.
220
221
  * @param records Inbound payload from bus.
221
222
  */
222
223
  private ingestForwarded;
223
- /** Flushes records buffered during startup and backfills active journey metadata. */
224
+ /** Flushes the startup records. It adds the active journey to records without a journey. */
224
225
  private releaseBootBuffer;
225
226
  /**
226
- * Emits a warning log record when batches are evicted from persistent storage.
227
+ * Emits a warning record when storage evicts batches.
227
228
  * @param result Storage prune summary metrics.
228
229
  */
229
230
  private readonly reportGap;
230
- /** Generates and persists a replacement tab ID when a collision is detected. */
231
+ /** Makes and stores a new tab ID after a tab ID collision. */
231
232
  private regenerateTabId;
232
233
  /**
233
234
  * Counts the batches held in storage after a failed or deferred delivery.
234
- * @returns Promise resolving to the number of stored batches. A forwarder reports 0, because it persists nothing.
235
+ * @returns Promise resolving to the number of stored batches. A forwarder stores
236
+ * nothing and reports 0.
235
237
  */
236
238
  queueDepth(): Promise<number>;
237
239
  /**
@@ -1,6 +1,6 @@
1
1
  import type { ResolvedConfig } from "../models/config";
2
2
  import type { LogRecord } from "../models/log-record";
3
- /** Everything sampling reads, all of it known before a record is built. */
3
+ /** Fields that sampling reads. The caller knows all of them before it builds a record. */
4
4
  export interface SampleInput {
5
5
  /** Severity level of the entry. */
6
6
  level: string;
@@ -8,43 +8,42 @@ export interface SampleInput {
8
8
  type: string;
9
9
  /** Originating application namespace. */
10
10
  namespace: string;
11
- /** Active journey id, empty when no journey is running. */
11
+ /** Active journey ID. It is empty when no journey runs. */
12
12
  journeyId: string;
13
- /** Trace id, the sampling key when no journey is running. */
13
+ /** Trace ID. It is the sampling key when no journey runs. */
14
14
  traceId: string;
15
15
  }
16
16
  /**
17
- * Evaluates whether an entry should be sampled for retention. Takes the fields
18
- * rather than a record, so the verdict is available before the attribute walk
19
- * a dropped entry must not pay for.
17
+ * Decides if sampling keeps an entry. It reads fields, not a record.
18
+ * This lets the caller drop an entry before the attribute walk runs.
20
19
  * @param input Fields the sampling decision reads.
21
20
  * @param config Active configuration instance.
22
- * @returns True if the entry should be retained and transmitted.
21
+ * @returns True if the runtime keeps and sends the entry.
23
22
  */
24
23
  export declare function shouldSampleInput(input: SampleInput, config: ResolvedConfig): boolean;
25
24
  /**
26
- * Evaluates whether a built log record should be sampled for retention. Used on
27
- * records that arrive already built, from a child context over the bus.
25
+ * Decides if sampling keeps a built log record. The runtime uses it for records
26
+ * that a child context sends over the bus.
28
27
  * @param record Record to evaluate.
29
28
  * @param config Active configuration instance.
30
- * @returns True if the record should be retained and transmitted.
29
+ * @returns True if the runtime keeps and sends the record.
31
30
  */
32
31
  export declare function shouldSample(record: LogRecord, config: ResolvedConfig): boolean;
33
32
  /**
34
- * Fixed-window ceiling on the ERROR and FATAL records that bypass sampling.
33
+ * Sets a fixed-window limit on the ERROR and FATAL records that bypass sampling.
35
34
  *
36
- * Auto-captured errors are already limited inside ErrorCapture. This covers the
37
- * case nothing else does: application code calling logger.error in a render loop.
35
+ * ErrorCapture already limits auto-captured errors. This class limits the remaining case.
36
+ * An example is application code that calls logger.error in a render loop.
38
37
  */
39
38
  export declare class ErrorCeiling {
40
- /** Start of the window currently counting, in epoch milliseconds. */
39
+ /** Start of the current window, in epoch milliseconds. */
41
40
  private windowStart;
42
41
  /** ERROR and FATAL records admitted in the current window. */
43
42
  private count;
44
43
  /**
45
- * Admits a record against the ceiling, counting only ERROR and FATAL.
44
+ * Checks a record against the limit. It counts only ERROR and FATAL records.
46
45
  * @param record Record about to enter a stream.
47
- * @returns False when the window is spent and the record must be dropped.
46
+ * @returns False when the window has no allowance left. The caller must drop the record.
48
47
  */
49
48
  allow(record: LogRecord): boolean;
50
49
  }
@@ -50,7 +50,7 @@ export declare class Sender {
50
50
  */
51
51
  queueDepth(): Promise<number>;
52
52
  /**
53
- * Sends pending records, stops every timer and listener, then closes storage.
53
+ * Sends pending records and stops all timers and listeners. Then it closes storage.
54
54
  * The synchronous steps run before the first await. The runtime relies on this order.
55
55
  * @returns Promise resolving when storage is closed.
56
56
  */
@@ -1,5 +1,5 @@
1
- import { V as e } from "./constants-B6kdsCzF.js";
2
- import { r as t } from "./platform-DMYo3AX3.js";
1
+ import { V as e } from "./constants-C8nZQBmQ.js";
2
+ import { r as t } from "./platform-YuByH8A5.js";
3
3
  //#region src/capture/errors.ts
4
4
  var n = class {
5
5
  ctx;
@@ -47,7 +47,7 @@ var n = class {
47
47
  report(t, n, r) {
48
48
  let i = Date.now();
49
49
  if (i - this.windowStart > 1e4 && (this.windowStart = i, this.windowCount = 0), this.windowCount++, this.windowCount > 20) {
50
- this.ctx.diagnostics.report("capture.rate_limited", `more than 20 errors in ${String(e)}ms, suppressing the rest of this window`);
50
+ this.ctx.diagnostics.report("capture.rate_limited", `More than 20 errors occurred in ${String(e)} ms. The library ignores the other errors in this window.`);
51
51
  return;
52
52
  }
53
53
  let a = n instanceof Error ? n : Error(String(n)), o = (a.stack ?? "").split("\n")[1] ?? "", s = `${a.name}|${a.message}|${o}`, c = this.seen.get(s);
@@ -73,4 +73,4 @@ var n = class {
73
73
  //#endregion
74
74
  export { n as ErrorCapture };
75
75
 
76
- //# sourceMappingURL=errors-Dme9tz-6.js.map
76
+ //# sourceMappingURL=errors-4MQyjZVj.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"errors-4MQyjZVj.js","names":["ERROR_STORM_WINDOW_MS","stripUrlQuery","ErrorCapture","ctx","target","event","resourceUrl","url","errorEvent","fallback","error","now","asError","frame","key","previous","suppressed","oldest","source","extra"],"sources":["../src/capture/errors.ts"],"sourcesContent":["// src/capture/errors.ts\n//\n// Captures uncaught errors, unhandled rejections and failed resource loads.\n\nimport {\n ERROR_DEDUPE_MS,\n ERROR_STORM_MAX_PER_WINDOW,\n ERROR_STORM_WINDOW_MS,\n MAX_TRACKED_ERROR_SIGNATURES,\n} from \"../constants\";\nimport { stripUrlQuery } from \"../utils/platform\";\nimport type { Capture, CaptureContext } from \"./types\";\n\n/** Tracking metadata for a deduplicated error signature. */\ninterface SeenError {\n /** Time of the last report for the signature, in epoch milliseconds. */\n at: number;\n /** Occurrences recorded since the last report. */\n count: number;\n}\n\n/** Captures uncaught exceptions, unhandled promise rejections, and failed resource loads. */\nexport class ErrorCapture implements Capture {\n /** Capture module identifier. */\n readonly name = \"errors\";\n\n /** Prevents duplicate listener registration. */\n private installed = false;\n\n /** Recently reported error signatures in LRU order. */\n private readonly seen = new Map<string, SeenError>();\n\n /** Start timestamp of the active throttling window in epoch milliseconds. */\n private windowStart = 0;\n\n /** Errors reported during the active throttling window. */\n private windowCount = 0;\n\n /**\n * @param ctx Capture context containing configuration, diagnostics, logger, and breadcrumbs.\n */\n constructor(private readonly ctx: CaptureContext) {}\n\n /** Subscribes to global error and unhandledrejection events. */\n install(): void {\n if (this.installed || typeof addEventListener === \"undefined\") {\n return;\n }\n this.installed = true;\n\n // Uses capture phase to observe non-bubbling resource load errors.\n addEventListener(\"error\", this.onError, true);\n addEventListener(\"unhandledrejection\", this.onRejection);\n }\n\n /** Removes event listeners and clears tracked error signatures. */\n uninstall(): void {\n if (!this.installed) {\n return;\n }\n this.installed = false;\n\n removeEventListener(\"error\", this.onError, true);\n removeEventListener(\"unhandledrejection\", this.onRejection);\n this.seen.clear();\n }\n\n /** Routes resource load failures and uncaught script errors. */\n private readonly onError = (event: ErrorEvent | Event): void => {\n const target = event.target as (HTMLElement & { src?: string; href?: string }) | null;\n const resourceUrl = target?.src ?? target?.href ?? \"\";\n\n // Filters element-level resource load failures from script errors.\n if (\n target !== null &&\n target !== (globalThis as unknown as EventTarget) &&\n resourceUrl !== \"\"\n ) {\n if (!this.ctx.config.capture.resourceErrors) {\n return;\n }\n\n // A cache buster is noise. A signed URL is a credential.\n // The record keeps neither unless fullUrls is set.\n const url = this.ctx.config.capture.fullUrls ? resourceUrl : stripUrlQuery(resourceUrl);\n\n this.ctx.breadcrumbs.push({\n t: Date.now(),\n category: \"http\",\n message: `resource failed: ${url}`,\n });\n this.ctx.logger.warn(\"resource failed to load\", {\n \"error.type\": \"resource\",\n \"resource.url\": url,\n \"resource.tag\": target.tagName.toLowerCase(),\n });\n return;\n }\n\n if (!this.ctx.config.capture.errors) {\n return;\n }\n\n const errorEvent = event as ErrorEvent;\n const fallback = errorEvent.message === \"\" ? \"unknown error\" : errorEvent.message;\n const thrown: unknown = errorEvent.error;\n const error = thrown ?? new Error(fallback);\n\n this.report(\"window.onerror\", error, {\n \"error.source\": errorEvent.filename,\n \"error.line\": errorEvent.lineno,\n \"error.column\": errorEvent.colno,\n });\n };\n\n /** Captures unhandled promise rejections. */\n private readonly onRejection = (event: PromiseRejectionEvent): void => {\n if (!this.ctx.config.capture.rejections) {\n return;\n }\n\n this.report(\"unhandledrejection\", event.reason, {\n \"error.type\": \"unhandledrejection\",\n });\n };\n\n /**\n * Rate limits, deduplicates, and logs captured errors.\n * @param source Originating capture event name.\n * @param error Caught error instance or thrown value.\n * @param extra Contextual error attributes.\n */\n private report(source: string, error: unknown, extra: Record<string, unknown>): void {\n const now = Date.now();\n\n if (now - this.windowStart > ERROR_STORM_WINDOW_MS) {\n this.windowStart = now;\n this.windowCount = 0;\n }\n\n this.windowCount++;\n if (this.windowCount > ERROR_STORM_MAX_PER_WINDOW) {\n // A render loop that throws in requestAnimationFrame makes thousands of errors each second.\n // Sending all of them is a denial of service on the ingest endpoint.\n this.ctx.diagnostics.report(\n \"capture.rate_limited\",\n `More than ${String(ERROR_STORM_MAX_PER_WINDOW)} errors occurred in ${String(ERROR_STORM_WINDOW_MS)} ms. The library ignores the other errors in this window.`,\n );\n return;\n }\n\n const asError = error instanceof Error ? error : new Error(String(error));\n const frame = (asError.stack ?? \"\").split(\"\\n\")[1] ?? \"\";\n const key = `${asError.name}|${asError.message}|${frame}`;\n const previous = this.seen.get(key);\n\n if (previous && now - previous.at < ERROR_DEDUPE_MS) {\n previous.count++;\n previous.at = now;\n return;\n }\n\n // This is the number of occurrences that deduplication dropped since the last report.\n // Without this count, many errors look like few errors.\n const suppressed = previous ? previous.count - 1 : 0;\n\n // Delete, then set, to move the key to the end of the map. The map stays in\n // least-recently-reported order. The eviction below needs this order.\n this.seen.delete(key);\n this.seen.set(key, { at: now, count: 1 });\n\n // A page can throw with a new message at each render, for example from a template literal\n // in a loop. Without this cap, the map grows until the document closes.\n if (this.seen.size > MAX_TRACKED_ERROR_SIGNATURES) {\n const [oldest] = this.seen.keys();\n this.seen.delete(oldest);\n }\n\n this.ctx.logger.error(asError.message === \"\" ? source : asError.message, asError, {\n ...extra,\n \"error.captured_by\": source,\n \"error.suppressed_count\": suppressed,\n });\n }\n}\n"],"mappings":";;;AAsBA,IAAaE,IAAb,MAA6C;CAmBd;CAjB7B,OAAgB;CAGhB,YAAoB;CAGpB,uBAAwB,IAAI,IAAuB;CAGnD,cAAsB;CAGtB,cAAsB;CAKtB,YAAY,GAAsC;EAArB,KAAA,MAAAC;CAAsB;CAGnD,UAAgB;EACd,AAAI,KAAK,aAAa,OAAO,mBAAqB,QAGlD,KAAK,YAAY,IAGjB,iBAAiB,SAAS,KAAK,SAAS,EAAI,GAC5C,iBAAiB,sBAAsB,KAAK,WAAW;CACzD;CAGA,YAAkB;EAChB,AAAK,KAAK,cAGV,KAAK,YAAY,IAEjB,oBAAoB,SAAS,KAAK,SAAS,EAAI,GAC/C,oBAAoB,sBAAsB,KAAK,WAAW,GAC1D,KAAK,KAAK,MAAM;CAClB;CAGA,WAA4B,MAAoC;EAC9D,IAAMC,IAASC,EAAM,QACfC,IAAcF,GAAQ,OAAOA,GAAQ,QAAQ;EAGnD,IACEA,MAAW,QACXA,MAAY,cACZE,MAAgB,IAChB;GACA,IAAI,CAAC,KAAK,IAAI,OAAO,QAAQ,gBAC3B;GAKF,IAAMC,IAAM,KAAK,IAAI,OAAO,QAAQ,WAAWD,IAAcL,EAAcK,CAAW;GAOtF,AALA,KAAK,IAAI,YAAY,KAAK;IACxB,GAAG,KAAK,IAAI;IACZ,UAAU;IACV,SAAS,oBAAoBC;GAC/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AK;GAAE,IAAIH;GAAK,OAAO;EAAE,CAAC,GAIpC,KAAK,KAAK,OAAA,KAAqC;GACjD,IAAM,CAACM,KAAU,KAAK,KAAK,KAAK;GAChC,KAAK,KAAK,OAAOA,CAAM;EACzB;EAEA,KAAK,IAAI,OAAO,MAAML,EAAQ,YAAY,KAAKM,IAASN,EAAQ,SAASA,GAAS;GAChF,GAAGO;GACH,qBAAqBD;GACrB,0BAA0BF;EAC5B,CAAC;CACH;AACF"}
@@ -1,3 +1,3 @@
1
- const e=require("./constants-DZH04585.cjs"),t=require("./platform-g99Kn755.cjs");var n=class{ctx;name=`errors`;installed=!1;seen=new Map;windowStart=0;windowCount=0;constructor(e){this.ctx=e}install(){this.installed||typeof addEventListener>`u`||(this.installed=!0,addEventListener(`error`,this.onError,!0),addEventListener(`unhandledrejection`,this.onRejection))}uninstall(){this.installed&&(this.installed=!1,removeEventListener(`error`,this.onError,!0),removeEventListener(`unhandledrejection`,this.onRejection),this.seen.clear())}onError=e=>{let n=e.target,r=n?.src??n?.href??``;if(n!==null&&n!==globalThis&&r!==``){if(!this.ctx.config.capture.resourceErrors)return;let e=this.ctx.config.capture.fullUrls?r:t.r(r);this.ctx.breadcrumbs.push({t:Date.now(),category:`http`,message:`resource failed: ${e}`}),this.ctx.logger.warn(`resource failed to load`,{"error.type":`resource`,"resource.url":e,"resource.tag":n.tagName.toLowerCase()});return}if(!this.ctx.config.capture.errors)return;let i=e,a=i.message===``?`unknown error`:i.message,o=i.error??Error(a);this.report(`window.onerror`,o,{"error.source":i.filename,"error.line":i.lineno,"error.column":i.colno})};onRejection=e=>{this.ctx.config.capture.rejections&&this.report(`unhandledrejection`,e.reason,{"error.type":`unhandledrejection`})};report(t,n,r){let i=Date.now();if(i-this.windowStart>1e4&&(this.windowStart=i,this.windowCount=0),this.windowCount++,this.windowCount>20){this.ctx.diagnostics.report(`capture.rate_limited`,`more than 20 errors in ${String(e.V)}ms, suppressing the rest of this window`);return}let a=n instanceof Error?n:Error(String(n)),o=(a.stack??``).split(`
1
+ const e=require("./constants-IBL_jd5R.cjs"),t=require("./platform-ByQllE_W.cjs");var n=class{ctx;name=`errors`;installed=!1;seen=new Map;windowStart=0;windowCount=0;constructor(e){this.ctx=e}install(){this.installed||typeof addEventListener>`u`||(this.installed=!0,addEventListener(`error`,this.onError,!0),addEventListener(`unhandledrejection`,this.onRejection))}uninstall(){this.installed&&(this.installed=!1,removeEventListener(`error`,this.onError,!0),removeEventListener(`unhandledrejection`,this.onRejection),this.seen.clear())}onError=e=>{let n=e.target,r=n?.src??n?.href??``;if(n!==null&&n!==globalThis&&r!==``){if(!this.ctx.config.capture.resourceErrors)return;let e=this.ctx.config.capture.fullUrls?r:t.r(r);this.ctx.breadcrumbs.push({t:Date.now(),category:`http`,message:`resource failed: ${e}`}),this.ctx.logger.warn(`resource failed to load`,{"error.type":`resource`,"resource.url":e,"resource.tag":n.tagName.toLowerCase()});return}if(!this.ctx.config.capture.errors)return;let i=e,a=i.message===``?`unknown error`:i.message,o=i.error??Error(a);this.report(`window.onerror`,o,{"error.source":i.filename,"error.line":i.lineno,"error.column":i.colno})};onRejection=e=>{this.ctx.config.capture.rejections&&this.report(`unhandledrejection`,e.reason,{"error.type":`unhandledrejection`})};report(t,n,r){let i=Date.now();if(i-this.windowStart>1e4&&(this.windowStart=i,this.windowCount=0),this.windowCount++,this.windowCount>20){this.ctx.diagnostics.report(`capture.rate_limited`,`More than 20 errors occurred in ${String(e.V)} ms. The library ignores the other errors in this window.`);return}let a=n instanceof Error?n:Error(String(n)),o=(a.stack??``).split(`
2
2
  `)[1]??``,s=`${a.name}|${a.message}|${o}`,c=this.seen.get(s);if(c&&i-c.at<5e3){c.count++,c.at=i;return}let l=c?c.count-1:0;if(this.seen.delete(s),this.seen.set(s,{at:i,count:1}),this.seen.size>200){let[e]=this.seen.keys();this.seen.delete(e)}this.ctx.logger.error(a.message===``?t:a.message,a,{...r,"error.captured_by":t,"error.suppressed_count":l})}};exports.ErrorCapture=n;
3
- //# sourceMappingURL=errors-DPju_xSI.cjs.map
3
+ //# sourceMappingURL=errors-CUdShXe7.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"errors-CUdShXe7.cjs","names":["stripUrlQuery","ERROR_STORM_WINDOW_MS","require_constants","require_platform","ErrorCapture","ctx","target","event","resourceUrl","url","errorEvent","fallback","error","now","asError","frame","key","previous","suppressed","oldest","source","extra"],"sources":["../src/capture/errors.ts"],"sourcesContent":["// src/capture/errors.ts\n//\n// Captures uncaught errors, unhandled rejections and failed resource loads.\n\nimport {\n ERROR_DEDUPE_MS,\n ERROR_STORM_MAX_PER_WINDOW,\n ERROR_STORM_WINDOW_MS,\n MAX_TRACKED_ERROR_SIGNATURES,\n} from \"../constants\";\nimport { stripUrlQuery } from \"../utils/platform\";\nimport type { Capture, CaptureContext } from \"./types\";\n\n/** Tracking metadata for a deduplicated error signature. */\ninterface SeenError {\n /** Time of the last report for the signature, in epoch milliseconds. */\n at: number;\n /** Occurrences recorded since the last report. */\n count: number;\n}\n\n/** Captures uncaught exceptions, unhandled promise rejections, and failed resource loads. */\nexport class ErrorCapture implements Capture {\n /** Capture module identifier. */\n readonly name = \"errors\";\n\n /** Prevents duplicate listener registration. */\n private installed = false;\n\n /** Recently reported error signatures in LRU order. */\n private readonly seen = new Map<string, SeenError>();\n\n /** Start timestamp of the active throttling window in epoch milliseconds. */\n private windowStart = 0;\n\n /** Errors reported during the active throttling window. */\n private windowCount = 0;\n\n /**\n * @param ctx Capture context containing configuration, diagnostics, logger, and breadcrumbs.\n */\n constructor(private readonly ctx: CaptureContext) {}\n\n /** Subscribes to global error and unhandledrejection events. */\n install(): void {\n if (this.installed || typeof addEventListener === \"undefined\") {\n return;\n }\n this.installed = true;\n\n // Uses capture phase to observe non-bubbling resource load errors.\n addEventListener(\"error\", this.onError, true);\n addEventListener(\"unhandledrejection\", this.onRejection);\n }\n\n /** Removes event listeners and clears tracked error signatures. */\n uninstall(): void {\n if (!this.installed) {\n return;\n }\n this.installed = false;\n\n removeEventListener(\"error\", this.onError, true);\n removeEventListener(\"unhandledrejection\", this.onRejection);\n this.seen.clear();\n }\n\n /** Routes resource load failures and uncaught script errors. */\n private readonly onError = (event: ErrorEvent | Event): void => {\n const target = event.target as (HTMLElement & { src?: string; href?: string }) | null;\n const resourceUrl = target?.src ?? target?.href ?? \"\";\n\n // Filters element-level resource load failures from script errors.\n if (\n target !== null &&\n target !== (globalThis as unknown as EventTarget) &&\n resourceUrl !== \"\"\n ) {\n if (!this.ctx.config.capture.resourceErrors) {\n return;\n }\n\n // A cache buster is noise. A signed URL is a credential.\n // The record keeps neither unless fullUrls is set.\n const url = this.ctx.config.capture.fullUrls ? resourceUrl : stripUrlQuery(resourceUrl);\n\n this.ctx.breadcrumbs.push({\n t: Date.now(),\n category: \"http\",\n message: `resource failed: ${url}`,\n });\n this.ctx.logger.warn(\"resource failed to load\", {\n \"error.type\": \"resource\",\n \"resource.url\": url,\n \"resource.tag\": target.tagName.toLowerCase(),\n });\n return;\n }\n\n if (!this.ctx.config.capture.errors) {\n return;\n }\n\n const errorEvent = event as ErrorEvent;\n const fallback = errorEvent.message === \"\" ? \"unknown error\" : errorEvent.message;\n const thrown: unknown = errorEvent.error;\n const error = thrown ?? new Error(fallback);\n\n this.report(\"window.onerror\", error, {\n \"error.source\": errorEvent.filename,\n \"error.line\": errorEvent.lineno,\n \"error.column\": errorEvent.colno,\n });\n };\n\n /** Captures unhandled promise rejections. */\n private readonly onRejection = (event: PromiseRejectionEvent): void => {\n if (!this.ctx.config.capture.rejections) {\n return;\n }\n\n this.report(\"unhandledrejection\", event.reason, {\n \"error.type\": \"unhandledrejection\",\n });\n };\n\n /**\n * Rate limits, deduplicates, and logs captured errors.\n * @param source Originating capture event name.\n * @param error Caught error instance or thrown value.\n * @param extra Contextual error attributes.\n */\n private report(source: string, error: unknown, extra: Record<string, unknown>): void {\n const now = Date.now();\n\n if (now - this.windowStart > ERROR_STORM_WINDOW_MS) {\n this.windowStart = now;\n this.windowCount = 0;\n }\n\n this.windowCount++;\n if (this.windowCount > ERROR_STORM_MAX_PER_WINDOW) {\n // A render loop that throws in requestAnimationFrame makes thousands of errors each second.\n // Sending all of them is a denial of service on the ingest endpoint.\n this.ctx.diagnostics.report(\n \"capture.rate_limited\",\n `More than ${String(ERROR_STORM_MAX_PER_WINDOW)} errors occurred in ${String(ERROR_STORM_WINDOW_MS)} ms. The library ignores the other errors in this window.`,\n );\n return;\n }\n\n const asError = error instanceof Error ? error : new Error(String(error));\n const frame = (asError.stack ?? \"\").split(\"\\n\")[1] ?? \"\";\n const key = `${asError.name}|${asError.message}|${frame}`;\n const previous = this.seen.get(key);\n\n if (previous && now - previous.at < ERROR_DEDUPE_MS) {\n previous.count++;\n previous.at = now;\n return;\n }\n\n // This is the number of occurrences that deduplication dropped since the last report.\n // Without this count, many errors look like few errors.\n const suppressed = previous ? previous.count - 1 : 0;\n\n // Delete, then set, to move the key to the end of the map. The map stays in\n // least-recently-reported order. The eviction below needs this order.\n this.seen.delete(key);\n this.seen.set(key, { at: now, count: 1 });\n\n // A page can throw with a new message at each render, for example from a template literal\n // in a loop. Without this cap, the map grows until the document closes.\n if (this.seen.size > MAX_TRACKED_ERROR_SIGNATURES) {\n const [oldest] = this.seen.keys();\n this.seen.delete(oldest);\n }\n\n this.ctx.logger.error(asError.message === \"\" ? source : asError.message, asError, {\n ...extra,\n \"error.captured_by\": source,\n \"error.suppressed_count\": suppressed,\n });\n }\n}\n"],"mappings":"iFAsBA,IAAaI,EAAb,KAA6C,CAmBd,IAjB7B,KAAgB,SAGhB,UAAoB,GAGpB,KAAwB,IAAI,IAG5B,YAAsB,EAGtB,YAAsB,EAKtB,YAAY,EAAsC,CAArB,KAAA,IAAAC,CAAsB,CAGnD,SAAgB,CACV,KAAK,WAAa,OAAO,iBAAqB,MAGlD,KAAK,UAAY,GAGjB,iBAAiB,QAAS,KAAK,QAAS,EAAI,EAC5C,iBAAiB,qBAAsB,KAAK,WAAW,EACzD,CAGA,WAA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