@utk09/ui-observability 0.4.1 → 0.6.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.
- package/CHANGELOG.md +63 -0
- package/README.md +114 -59
- package/dist/bus/bus.d.ts +10 -10
- package/dist/bus/links.d.ts +1 -1
- package/dist/bus-BTMuVkDk.js +378 -0
- package/dist/bus-BTMuVkDk.js.map +1 -0
- package/dist/bus-ChIXDAWD.cjs +2 -0
- package/dist/bus-ChIXDAWD.cjs.map +1 -0
- package/dist/capture/network.d.ts +2 -2
- package/dist/capture/types.d.ts +10 -10
- package/dist/capture/web-vitals.d.ts +7 -4
- package/dist/{constants-DVbpJ1tv.js → constants-0-YchbAL.js} +9 -8
- package/dist/constants-0-YchbAL.js.map +1 -0
- package/dist/constants-TUFcy95w.cjs +2 -0
- package/dist/constants-TUFcy95w.cjs.map +1 -0
- package/dist/constants.d.ts +55 -40
- package/dist/core/breadcrumbs.d.ts +14 -14
- package/dist/core/config.d.ts +5 -4
- package/dist/core/context.d.ts +2 -2
- package/dist/core/diagnostics.d.ts +10 -9
- package/dist/core/journey.d.ts +28 -22
- package/dist/core/logger.d.ts +29 -10
- package/dist/core/pipeline.d.ts +34 -29
- package/dist/core/record.d.ts +6 -6
- package/dist/core/runtime.d.ts +119 -35
- package/dist/core/sampling.d.ts +15 -16
- package/dist/core/sender.d.ts +58 -0
- package/dist/errors-DRXBRqvm.cjs +3 -0
- package/dist/errors-DRXBRqvm.cjs.map +1 -0
- package/dist/errors-Dwm2SzBa.js +76 -0
- package/dist/errors-Dwm2SzBa.js.map +1 -0
- package/dist/index.cjs +1 -3
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +6 -5
- package/dist/index.js +476 -2247
- package/dist/index.js.map +1 -1
- package/dist/indexeddb-storage-B5dwq4hW.cjs +2 -0
- package/dist/indexeddb-storage-B5dwq4hW.cjs.map +1 -0
- package/dist/{indexeddb-storage-B6uqejZb.js → indexeddb-storage-DjY4Ml6t.js} +18 -22
- package/dist/indexeddb-storage-DjY4Ml6t.js.map +1 -0
- package/dist/interactions-DVom6eYn.cjs +2 -0
- package/dist/interactions-DVom6eYn.cjs.map +1 -0
- package/dist/interactions-DZmLu7l2.js +67 -0
- package/dist/interactions-DZmLu7l2.js.map +1 -0
- package/dist/models/batch.d.ts +12 -9
- package/dist/models/bus.d.ts +12 -13
- package/dist/models/config.d.ts +84 -49
- package/dist/models/log-record.d.ts +12 -10
- package/dist/models/serializer.d.ts +3 -2
- package/dist/models/storage.d.ts +2 -2
- package/dist/network-C4d2uw2Z.js +111 -0
- package/dist/network-C4d2uw2Z.js.map +1 -0
- package/dist/network-CuqWadNn.cjs +2 -0
- package/dist/network-CuqWadNn.cjs.map +1 -0
- package/dist/platform-CXio0W2n.cjs +2 -0
- package/dist/platform-CXio0W2n.cjs.map +1 -0
- package/dist/platform-CY8S3hUs.js +48 -0
- package/dist/platform-CY8S3hUs.js.map +1 -0
- package/dist/sampling-CEthcmEX.cjs +2 -0
- package/dist/sampling-CEthcmEX.cjs.map +1 -0
- package/dist/sampling-CJsI_24L.js +251 -0
- package/dist/sampling-CJsI_24L.js.map +1 -0
- package/dist/sender-ByFAkXVd.cjs +3 -0
- package/dist/sender-ByFAkXVd.cjs.map +1 -0
- package/dist/sender-dpvR_bHM.js +907 -0
- package/dist/sender-dpvR_bHM.js.map +1 -0
- package/dist/storage/emergency-queue.d.ts +2 -2
- package/dist/storage/factory.d.ts +2 -1
- package/dist/storage/idb-driver.d.ts +19 -19
- package/dist/storage/indexeddb-storage.d.ts +18 -17
- package/dist/storage/keys.d.ts +1 -1
- package/dist/storage/local-storage.d.ts +19 -18
- package/dist/storage/memory-storage.d.ts +12 -11
- package/dist/transport/compression.d.ts +2 -2
- package/dist/transport/errors.d.ts +8 -7
- package/dist/transport/exit-flush.d.ts +27 -24
- package/dist/transport/http-transport.d.ts +19 -10
- package/dist/transport/retry-engine.d.ts +33 -28
- package/dist/transport/serializers/ecs.d.ts +1 -1
- package/dist/transport/serializers/otlp.d.ts +1 -1
- package/dist/transport/serializers/select.d.ts +8 -0
- package/dist/unref-16maCyKA.js +8 -0
- package/dist/unref-16maCyKA.js.map +1 -0
- package/dist/unref-CU9Nyz_9.cjs +2 -0
- package/dist/unref-CU9Nyz_9.cjs.map +1 -0
- package/dist/utils/console.d.ts +11 -3
- package/dist/utils/identity.d.ts +53 -8
- package/dist/utils/lock.d.ts +4 -4
- package/dist/utils/platform.d.ts +5 -3
- package/dist/utils/sanitize.d.ts +5 -2
- package/dist/utils/sequence.d.ts +2 -2
- package/dist/utils/tracing.d.ts +14 -12
- package/dist/web-vitals-B2FYsEAU.cjs +2 -0
- package/dist/web-vitals-B2FYsEAU.cjs.map +1 -0
- package/dist/web-vitals-DHZ0yA_H.js +51 -0
- package/dist/web-vitals-DHZ0yA_H.js.map +1 -0
- package/package.json +21 -11
- package/dist/constants-DVbpJ1tv.js.map +0 -1
- package/dist/constants-tQpoTzkY.cjs +0 -2
- package/dist/constants-tQpoTzkY.cjs.map +0 -1
- package/dist/indexeddb-storage-B6uqejZb.js.map +0 -1
- package/dist/indexeddb-storage-CgT1GLYj.cjs +0 -2
- package/dist/indexeddb-storage-CgT1GLYj.cjs.map +0 -1
package/dist/core/runtime.d.ts
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { Bus } from "../bus/bus";
|
|
2
1
|
import type { Receive, WorkerLike } from "../bus/links";
|
|
3
2
|
import type { BusMessage } from "../models/bus";
|
|
4
3
|
import type { ObservabilityConfig, ResolvedConfig } from "../models/config";
|
|
@@ -13,16 +12,20 @@ import { ContextStore } from "./context";
|
|
|
13
12
|
import { Diagnostics } from "./diagnostics";
|
|
14
13
|
import { JourneyEngine } from "./journey";
|
|
15
14
|
import { RecordBuilder } from "./record";
|
|
16
|
-
/**
|
|
15
|
+
/** Manages subsystem lifecycles, bus coordination and record delivery. */
|
|
17
16
|
export declare class ObservabilityRuntime {
|
|
18
17
|
/** Diagnostics reporter for internal faults. */
|
|
19
18
|
readonly diagnostics: Diagnostics;
|
|
20
|
-
/** Active configuration instance
|
|
19
|
+
/** Active configuration instance. A reconfigure changes it in place. */
|
|
21
20
|
readonly config: ResolvedConfig;
|
|
22
21
|
/** Detected host platform metadata. */
|
|
23
22
|
readonly platform: PlatformMetadata;
|
|
24
23
|
/** Identity context containing session, tab, and context identifiers. */
|
|
25
24
|
readonly identity: Identity;
|
|
25
|
+
/** Stores for identity and journey keys. The runtime sets them at startup. */
|
|
26
|
+
private readonly stores;
|
|
27
|
+
/** Identity strategy that the runtime used to make the stores. */
|
|
28
|
+
private readonly identityBuiltAs;
|
|
26
29
|
/** Throttled writer of the session's last-seen timestamp. */
|
|
27
30
|
private readonly sessionTouch;
|
|
28
31
|
/** Store for ambient application context attributes. */
|
|
@@ -39,22 +42,27 @@ export declare class ObservabilityRuntime {
|
|
|
39
42
|
readonly builder: RecordBuilder;
|
|
40
43
|
/** Console sink for local developer output. */
|
|
41
44
|
readonly console: ConsoleSink;
|
|
42
|
-
/**
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
45
|
+
/**
|
|
46
|
+
* Cross-realm communication bus. It is null until its chunk loads.
|
|
47
|
+
* In bus.mode "off", it loads only when a child frame or a worker needs it.
|
|
48
|
+
*/
|
|
49
|
+
private bus;
|
|
50
|
+
/** Load and construction of the bus. It is undefined until the first need. */
|
|
51
|
+
private busBuilt?;
|
|
52
|
+
/** Load and start of the bus. It is undefined until the first need. */
|
|
53
|
+
private busLoad?;
|
|
54
|
+
/** Storage strategy of the adapter. The runtime sets it when the build starts. */
|
|
47
55
|
private storageBuiltAs?;
|
|
48
|
-
/**
|
|
49
|
-
private
|
|
50
|
-
/**
|
|
51
|
-
private
|
|
52
|
-
/**
|
|
53
|
-
private
|
|
54
|
-
/** Exit flush handler executing atomic batch delivery on unload (sender role only). */
|
|
55
|
-
private exitFlush?;
|
|
56
|
+
/** Delivery stack. The runtime sets it in the sender role with an endpoint, after the chunk loads. */
|
|
57
|
+
private sender?;
|
|
58
|
+
/** Load of the delivery stack. It is undefined when nothing loads. A record then has no destination. */
|
|
59
|
+
private senderLoad?;
|
|
60
|
+
/** Records that arrive while the delivery stack loads. */
|
|
61
|
+
private pendingRecords;
|
|
56
62
|
/** Active auto-capture instrumentation modules. */
|
|
57
63
|
private readonly captures;
|
|
64
|
+
/** Count of capture installs. An install that a later install replaced stops after its load. */
|
|
65
|
+
private captureGeneration;
|
|
58
66
|
/** Capture work that a rebuild of the capture modules must not repeat. */
|
|
59
67
|
private readonly captureOnce;
|
|
60
68
|
/** Queue buffering records created before bus role resolution. */
|
|
@@ -63,9 +71,11 @@ export declare class ObservabilityRuntime {
|
|
|
63
71
|
private forwardBuffer;
|
|
64
72
|
/** Indicates whether a microtask drain is scheduled for the forward buffer. */
|
|
65
73
|
private forwardScheduled;
|
|
74
|
+
/** Indicates whether startup has decided the bus role. A sender load waits for it. */
|
|
75
|
+
private roleResolved;
|
|
66
76
|
/** Indicates whether asynchronous initialization has completed. */
|
|
67
77
|
private ready;
|
|
68
|
-
/** Indicates whether the runtime
|
|
78
|
+
/** Indicates whether shutdown stopped the runtime. */
|
|
69
79
|
private destroyed;
|
|
70
80
|
/** Timestamp of the last reported storage gap warning in epoch milliseconds. */
|
|
71
81
|
private lastGapAt;
|
|
@@ -74,7 +84,7 @@ export declare class ObservabilityRuntime {
|
|
|
74
84
|
*/
|
|
75
85
|
private constructor();
|
|
76
86
|
/**
|
|
77
|
-
*
|
|
87
|
+
* Receives direct messages from same-origin child frames.
|
|
78
88
|
* @param message Inbound bus message.
|
|
79
89
|
* @param reply Direct response callback.
|
|
80
90
|
*/
|
|
@@ -84,6 +94,16 @@ export declare class ObservabilityRuntime {
|
|
|
84
94
|
* @returns Active runtime instance or null.
|
|
85
95
|
*/
|
|
86
96
|
static current(): ObservabilityRuntime | null;
|
|
97
|
+
/**
|
|
98
|
+
* Returns the runtime that shutdown() stopped, until the next configure().
|
|
99
|
+
* @returns Stopped runtime instance or null.
|
|
100
|
+
*/
|
|
101
|
+
static stopped(): ObservabilityRuntime | null;
|
|
102
|
+
/**
|
|
103
|
+
* Tests whether shutdown() stopped this runtime.
|
|
104
|
+
* @returns True after destroy() starts.
|
|
105
|
+
*/
|
|
106
|
+
isDestroyed(): boolean;
|
|
87
107
|
/**
|
|
88
108
|
* Initializes a new runtime instance or updates the existing singleton.
|
|
89
109
|
* @param input Consumer configuration options.
|
|
@@ -96,19 +116,69 @@ export declare class ObservabilityRuntime {
|
|
|
96
116
|
*/
|
|
97
117
|
private reconfigure;
|
|
98
118
|
/**
|
|
99
|
-
* Restores the storage strategy the adapter
|
|
100
|
-
* live
|
|
101
|
-
*
|
|
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.
|
|
102
122
|
*/
|
|
103
123
|
private keepBuiltStorage;
|
|
124
|
+
/**
|
|
125
|
+
* Refuses to remove the endpoint once the delivery stack exists. Without an endpoint,
|
|
126
|
+
* the retry engine removes each stored batch as delivered.
|
|
127
|
+
* @param input Partial configuration to merge.
|
|
128
|
+
* @returns Input with the endpoint removal taken out.
|
|
129
|
+
*/
|
|
130
|
+
private keepEndpoint;
|
|
131
|
+
/**
|
|
132
|
+
* Restores the identity strategy from startup. The ids exist from startup.
|
|
133
|
+
* A later change cannot move them to another store.
|
|
134
|
+
*/
|
|
135
|
+
private keepBuiltIdentity;
|
|
104
136
|
/** Initializes asynchronous subsystems and flushes the boot buffer. */
|
|
105
137
|
private init;
|
|
106
|
-
/**
|
|
107
|
-
|
|
108
|
-
|
|
138
|
+
/**
|
|
139
|
+
* Starts the load of the bus one time.
|
|
140
|
+
* @returns Promise resolving to the started bus, or null if it did not load.
|
|
141
|
+
*/
|
|
142
|
+
private ensureBus;
|
|
143
|
+
/**
|
|
144
|
+
* Loads and constructs the bus one time. It does not call start().
|
|
145
|
+
* @returns Promise resolving to the constructed bus, or null if it did not load.
|
|
146
|
+
*/
|
|
147
|
+
private constructBus;
|
|
148
|
+
/**
|
|
149
|
+
* Starts the constructed bus. It never rejects.
|
|
150
|
+
* @returns Promise resolving to the started bus, or null if it did not load or start.
|
|
151
|
+
*/
|
|
152
|
+
private startBus;
|
|
153
|
+
/** Imports and constructs the bus. It never rejects. */
|
|
154
|
+
private buildBus;
|
|
155
|
+
/**
|
|
156
|
+
* Reads the bus role. Without a bus, this context is the sender.
|
|
157
|
+
* @returns Active bus role.
|
|
158
|
+
*/
|
|
159
|
+
private role;
|
|
160
|
+
/**
|
|
161
|
+
* Loads the delivery stack if this context is the sender and has an endpoint.
|
|
162
|
+
* @returns Promise resolving when the load completes, or immediately when nothing loads.
|
|
163
|
+
*/
|
|
164
|
+
private syncSender;
|
|
165
|
+
/**
|
|
166
|
+
* Starts the load of the delivery stack one time.
|
|
167
|
+
* @returns Promise resolving when the load completes or fails.
|
|
168
|
+
*/
|
|
169
|
+
private loadSender;
|
|
170
|
+
/** Imports and builds the delivery stack. It then moves the held records into it. It never rejects. */
|
|
171
|
+
private buildSender;
|
|
172
|
+
/** Loads, builds and installs the enabled capture modules. It never rejects. */
|
|
109
173
|
private installCaptures;
|
|
110
|
-
/** Uninstalls active capture modules
|
|
111
|
-
private
|
|
174
|
+
/** Uninstalls the active capture modules. */
|
|
175
|
+
private uninstallCaptures;
|
|
176
|
+
/**
|
|
177
|
+
* Imports one capture module. A failed import reports and skips that module only.
|
|
178
|
+
* @param name Capture module name.
|
|
179
|
+
* @returns Promise resolving to the class, or undefined if the import failed.
|
|
180
|
+
*/
|
|
181
|
+
private loadCapture;
|
|
112
182
|
/**
|
|
113
183
|
* Attaches a Web Worker or MessagePort to the bus for record forwarding.
|
|
114
184
|
* @param worker Target Worker or MessagePort instance.
|
|
@@ -118,38 +188,52 @@ export declare class ObservabilityRuntime {
|
|
|
118
188
|
destroy(): Promise<void>;
|
|
119
189
|
/**
|
|
120
190
|
* Routes a completed log record to the pipeline or forward buffer.
|
|
121
|
-
* @param record Log record to emit, or null
|
|
191
|
+
* @param record Log record to emit, or null when the build dropped it.
|
|
122
192
|
*/
|
|
123
193
|
emit(record: LogRecord | null): void;
|
|
124
194
|
/**
|
|
125
|
-
*
|
|
195
|
+
* Sends a record to the forward buffer or to the local pipeline. The bus role selects
|
|
196
|
+
* the path.
|
|
126
197
|
* @param record Log record to route.
|
|
127
198
|
*/
|
|
128
199
|
private route;
|
|
200
|
+
/**
|
|
201
|
+
* Hands a record to the delivery stack. Holds the record while the stack loads.
|
|
202
|
+
* Drops the record when nothing loads, for example in console-only mode.
|
|
203
|
+
* @param record Log record to deliver.
|
|
204
|
+
*/
|
|
205
|
+
private deliver;
|
|
206
|
+
/**
|
|
207
|
+
* Adds a record to a hold buffer. It drops the oldest record when the buffer is full.
|
|
208
|
+
* @param buffer Hold buffer.
|
|
209
|
+
* @param record Record to hold.
|
|
210
|
+
*/
|
|
211
|
+
private pushCapped;
|
|
129
212
|
/**
|
|
130
213
|
* Batches records for asynchronous transmission to the upstream sender.
|
|
131
214
|
* @param record Log record to forward.
|
|
132
215
|
*/
|
|
133
216
|
private forward;
|
|
134
217
|
/**
|
|
135
|
-
* Validates, samples and
|
|
136
|
-
* A forwarded record arrives built
|
|
137
|
-
*
|
|
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.
|
|
138
221
|
* @param records Inbound payload from bus.
|
|
139
222
|
*/
|
|
140
223
|
private ingestForwarded;
|
|
141
|
-
/** Flushes
|
|
224
|
+
/** Flushes the startup records. It adds the active journey to records without a journey. */
|
|
142
225
|
private releaseBootBuffer;
|
|
143
226
|
/**
|
|
144
|
-
* Emits a warning
|
|
227
|
+
* Emits a warning record when storage evicts batches.
|
|
145
228
|
* @param result Storage prune summary metrics.
|
|
146
229
|
*/
|
|
147
230
|
private readonly reportGap;
|
|
148
|
-
/**
|
|
231
|
+
/** Makes and stores a new tab ID after a tab ID collision. */
|
|
149
232
|
private regenerateTabId;
|
|
150
233
|
/**
|
|
151
234
|
* Counts the batches held in storage after a failed or deferred delivery.
|
|
152
|
-
* @returns Promise resolving to the number of stored batches. A forwarder
|
|
235
|
+
* @returns Promise resolving to the number of stored batches. A forwarder stores
|
|
236
|
+
* nothing and reports 0.
|
|
153
237
|
*/
|
|
154
238
|
queueDepth(): Promise<number>;
|
|
155
239
|
/**
|
package/dist/core/sampling.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { ResolvedConfig } from "../models/config";
|
|
2
2
|
import type { LogRecord } from "../models/log-record";
|
|
3
|
-
/**
|
|
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
|
|
11
|
+
/** Active journey ID. It is empty when no journey runs. */
|
|
12
12
|
journeyId: string;
|
|
13
|
-
/** Trace
|
|
13
|
+
/** Trace ID. It is the sampling key when no journey runs. */
|
|
14
14
|
traceId: string;
|
|
15
15
|
}
|
|
16
16
|
/**
|
|
17
|
-
*
|
|
18
|
-
*
|
|
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
|
|
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
|
-
*
|
|
27
|
-
*
|
|
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
|
|
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
|
-
*
|
|
33
|
+
* Sets a fixed-window limit on the ERROR and FATAL records that bypass sampling.
|
|
35
34
|
*
|
|
36
|
-
*
|
|
37
|
-
*
|
|
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
|
|
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
|
-
*
|
|
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
|
|
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
|
}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import type { ResolvedConfig } from "../models/config";
|
|
2
|
+
import type { LogRecord } from "../models/log-record";
|
|
3
|
+
import type { GapReporter } from "../models/storage";
|
|
4
|
+
import type { Diagnostics } from "./diagnostics";
|
|
5
|
+
/** Inputs to build the delivery stack. */
|
|
6
|
+
export interface SenderDeps {
|
|
7
|
+
/** Active configuration instance. */
|
|
8
|
+
config: ResolvedConfig;
|
|
9
|
+
/** Diagnostics reporter. */
|
|
10
|
+
diagnostics: Diagnostics;
|
|
11
|
+
/** Receives a report when storage drops batches before delivery. */
|
|
12
|
+
onGap: GapReporter;
|
|
13
|
+
}
|
|
14
|
+
/** Delivery stack for one sender runtime. */
|
|
15
|
+
export declare class Sender {
|
|
16
|
+
private readonly storage;
|
|
17
|
+
private readonly transport;
|
|
18
|
+
private readonly retry;
|
|
19
|
+
private readonly pipeline;
|
|
20
|
+
private readonly exitFlush;
|
|
21
|
+
private readonly diagnostics;
|
|
22
|
+
/**
|
|
23
|
+
* @param storage Storage adapter for undelivered batches.
|
|
24
|
+
* @param transport HTTP transport for live delivery.
|
|
25
|
+
* @param retry Retry engine for stored batches.
|
|
26
|
+
* @param pipeline Pipeline that batches records.
|
|
27
|
+
* @param exitFlush Handler that sends pending records on unload.
|
|
28
|
+
* @param diagnostics Diagnostics reporter.
|
|
29
|
+
*/
|
|
30
|
+
private constructor();
|
|
31
|
+
/**
|
|
32
|
+
* Builds the delivery stack, drains the emergency queue and starts the retry loop.
|
|
33
|
+
* @param deps Configuration, diagnostics and gap reporter.
|
|
34
|
+
* @returns Promise resolving to the started sender.
|
|
35
|
+
*/
|
|
36
|
+
static create(deps: SenderDeps): Promise<Sender>;
|
|
37
|
+
/**
|
|
38
|
+
* Adds a record to the pipeline.
|
|
39
|
+
* @param record Record to deliver.
|
|
40
|
+
*/
|
|
41
|
+
push(record: LogRecord): void;
|
|
42
|
+
/**
|
|
43
|
+
* Sends the records held in the stream buffers.
|
|
44
|
+
* @returns Promise resolving when the batch is sent or stored for retry.
|
|
45
|
+
*/
|
|
46
|
+
flush(): Promise<void>;
|
|
47
|
+
/**
|
|
48
|
+
* Counts the batches held in storage.
|
|
49
|
+
* @returns Promise resolving to the batch count, or 0 if storage fails.
|
|
50
|
+
*/
|
|
51
|
+
queueDepth(): Promise<number>;
|
|
52
|
+
/**
|
|
53
|
+
* Sends pending records and stops all timers and listeners. Then it closes storage.
|
|
54
|
+
* The synchronous steps run before the first await. The runtime relies on this order.
|
|
55
|
+
* @returns Promise resolving when storage is closed.
|
|
56
|
+
*/
|
|
57
|
+
destroy(): Promise<void>;
|
|
58
|
+
}
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
const e=require("./constants-TUFcy95w.cjs"),t=require("./platform-CXio0W2n.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
|
+
`)[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-DRXBRqvm.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors-DRXBRqvm.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,WAAkB,CACX,KAAK,YAGV,KAAK,UAAY,GAEjB,oBAAoB,QAAS,KAAK,QAAS,EAAI,EAC/C,oBAAoB,qBAAsB,KAAK,WAAW,EAC1D,KAAK,KAAK,MAAM,EAClB,CAGA,QAA4B,GAAoC,CAC9D,IAAMC,EAASC,EAAM,OACfC,EAAcF,GAAQ,KAAOA,GAAQ,MAAQ,GAGnD,GACEA,IAAW,MACXA,IAAY,YACZE,IAAgB,GAChB,CACA,GAAI,CAAC,KAAK,IAAI,OAAO,QAAQ,eAC3B,OAKF,IAAMC,EAAM,KAAK,IAAI,OAAO,QAAQ,SAAWD,EAAcR,EAAAA,EAAcQ,CAAW,EAEtF,KAAK,IAAI,YAAY,KAAK,CACxB,EAAG,KAAK,IAAI,EACZ,SAAU,OACV,QAAS,oBAAoBC,GAC/B,CAAC,EACD,KAAK,IAAI,OAAO,KAAK,0BAA2B,CAC9C,aAAc,WACd,eAAgBA,EAChB,eAAgBH,EAAO,QAAQ,YAAY,CAC7C,CAAC,EACD,MACF,CAEA,GAAI,CAAC,KAAK,IAAI,OAAO,QAAQ,OAC3B,OAGF,IAAMI,EAAaH,EACbI,EAAWD,EAAW,UAAY,GAAK,gBAAkBA,EAAW,QAEpEE,EADkBF,EAAW,OACP,MAAMC,CAAQ,EAE1C,KAAK,OAAO,iBAAkBC,EAAO,CACnC,eAAgBF,EAAW,SAC3B,aAAcA,EAAW,OACzB,eAAgBA,EAAW,KAC7B,CAAC,CACH,EAGA,YAAgC,GAAuC,CAChE,KAAK,IAAI,OAAO,QAAQ,YAI7B,KAAK,OAAO,qBAAsBH,EAAM,OAAQ,CAC9C,aAAc,oBAChB,CAAC,CACH,EAQA,OAAe,EAAgB,EAAgB,EAAsC,CACnF,IAAMM,EAAM,KAAK,IAAI,EAQrB,GANIA,EAAM,KAAK,YAAA,MACb,KAAK,YAAcA,EACnB,KAAK,YAAc,GAGrB,KAAK,cACD,KAAK,YAAA,GAA0C,CAGjD,KAAK,IAAI,YAAY,OACnB,uBACA,mCAAsE,OAAOZ,EAAAA,CAAqB,EAAE,0DACtG,EACA,MACF,CAEA,IAAMa,EAAUF,aAAiB,MAAQA,EAAY,MAAM,OAAOA,CAAK,CAAC,EAClEG,GAASD,EAAQ,OAAS,GAAA,CAAI,MAAM;CAAI,CAAC,CAAC,IAAM,GAChDE,EAAM,GAAGF,EAAQ,KAAK,GAAGA,EAAQ,QAAQ,GAAGC,IAC5CE,EAAW,KAAK,KAAK,IAAID,CAAG,EAElC,GAAIC,GAAYJ,EAAMI,EAAS,GAAA,IAAsB,CACnD,EAAS,QACT,EAAS,GAAKJ,EACd,MACF,CAIA,IAAMK,EAAaD,EAAWA,EAAS,MAAQ,EAAI,EASnD,GALA,KAAK,KAAK,OAAOD,CAAG,EACpB,KAAK,KAAK,IAAIA,EAAK,CAAE,GAAIH,EAAK,MAAO,CAAE,CAAC,EAIpC,KAAK,KAAK,KAAA,IAAqC,CACjD,GAAM,CAACM,GAAU,KAAK,KAAK,KAAK,EAChC,KAAK,KAAK,OAAOA,CAAM,CACzB,CAEA,KAAK,IAAI,OAAO,MAAML,EAAQ,UAAY,GAAKM,EAASN,EAAQ,QAASA,EAAS,CAChF,GAAGO,EACH,oBAAqBD,EACrB,yBAA0BF,CAC5B,CAAC,CACH,CACF"}
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import { V as e } from "./constants-0-YchbAL.js";
|
|
2
|
+
import { r as t } from "./platform-CY8S3hUs.js";
|
|
3
|
+
//#region src/capture/errors.ts
|
|
4
|
+
var n = class {
|
|
5
|
+
ctx;
|
|
6
|
+
name = "errors";
|
|
7
|
+
installed = !1;
|
|
8
|
+
seen = /* @__PURE__ */ new Map();
|
|
9
|
+
windowStart = 0;
|
|
10
|
+
windowCount = 0;
|
|
11
|
+
constructor(e) {
|
|
12
|
+
this.ctx = e;
|
|
13
|
+
}
|
|
14
|
+
install() {
|
|
15
|
+
this.installed || typeof addEventListener > "u" || (this.installed = !0, addEventListener("error", this.onError, !0), addEventListener("unhandledrejection", this.onRejection));
|
|
16
|
+
}
|
|
17
|
+
uninstall() {
|
|
18
|
+
this.installed && (this.installed = !1, removeEventListener("error", this.onError, !0), removeEventListener("unhandledrejection", this.onRejection), this.seen.clear());
|
|
19
|
+
}
|
|
20
|
+
onError = (e) => {
|
|
21
|
+
let n = e.target, r = n?.src ?? n?.href ?? "";
|
|
22
|
+
if (n !== null && n !== globalThis && r !== "") {
|
|
23
|
+
if (!this.ctx.config.capture.resourceErrors) return;
|
|
24
|
+
let e = this.ctx.config.capture.fullUrls ? r : t(r);
|
|
25
|
+
this.ctx.breadcrumbs.push({
|
|
26
|
+
t: Date.now(),
|
|
27
|
+
category: "http",
|
|
28
|
+
message: `resource failed: ${e}`
|
|
29
|
+
}), this.ctx.logger.warn("resource failed to load", {
|
|
30
|
+
"error.type": "resource",
|
|
31
|
+
"resource.url": e,
|
|
32
|
+
"resource.tag": n.tagName.toLowerCase()
|
|
33
|
+
});
|
|
34
|
+
return;
|
|
35
|
+
}
|
|
36
|
+
if (!this.ctx.config.capture.errors) return;
|
|
37
|
+
let i = e, a = i.message === "" ? "unknown error" : i.message, o = i.error ?? Error(a);
|
|
38
|
+
this.report("window.onerror", o, {
|
|
39
|
+
"error.source": i.filename,
|
|
40
|
+
"error.line": i.lineno,
|
|
41
|
+
"error.column": i.colno
|
|
42
|
+
});
|
|
43
|
+
};
|
|
44
|
+
onRejection = (e) => {
|
|
45
|
+
this.ctx.config.capture.rejections && this.report("unhandledrejection", e.reason, { "error.type": "unhandledrejection" });
|
|
46
|
+
};
|
|
47
|
+
report(t, n, r) {
|
|
48
|
+
let i = Date.now();
|
|
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 occurred in ${String(e)} ms. The library ignores the other errors in this window.`);
|
|
51
|
+
return;
|
|
52
|
+
}
|
|
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);
|
|
54
|
+
if (c && i - c.at < 5e3) {
|
|
55
|
+
c.count++, c.at = i;
|
|
56
|
+
return;
|
|
57
|
+
}
|
|
58
|
+
let l = c ? c.count - 1 : 0;
|
|
59
|
+
if (this.seen.delete(s), this.seen.set(s, {
|
|
60
|
+
at: i,
|
|
61
|
+
count: 1
|
|
62
|
+
}), this.seen.size > 200) {
|
|
63
|
+
let [e] = this.seen.keys();
|
|
64
|
+
this.seen.delete(e);
|
|
65
|
+
}
|
|
66
|
+
this.ctx.logger.error(a.message === "" ? t : a.message, a, {
|
|
67
|
+
...r,
|
|
68
|
+
"error.captured_by": t,
|
|
69
|
+
"error.suppressed_count": l
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
};
|
|
73
|
+
//#endregion
|
|
74
|
+
export { n as ErrorCapture };
|
|
75
|
+
|
|
76
|
+
//# sourceMappingURL=errors-Dwm2SzBa.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors-Dwm2SzBa.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":"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"}
|