@utk09/ui-observability 0.1.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/LICENSE +202 -0
- package/README.md +217 -0
- package/dist/bus/bus.d.ts +134 -0
- package/dist/bus/links.d.ts +106 -0
- package/dist/capture/errors.d.ts +34 -0
- package/dist/capture/interactions.d.ts +29 -0
- package/dist/capture/network.d.ts +40 -0
- package/dist/capture/types.d.ts +78 -0
- package/dist/capture/web-vitals.d.ts +21 -0
- package/dist/constants-D8-4Ged5.cjs +2 -0
- package/dist/constants-D8-4Ged5.cjs.map +1 -0
- package/dist/constants-DbvMIryP.js +110 -0
- package/dist/constants-DbvMIryP.js.map +1 -0
- package/dist/constants.d.ts +339 -0
- package/dist/core/breadcrumbs.d.ts +48 -0
- package/dist/core/config.d.ts +16 -0
- package/dist/core/context.d.ts +35 -0
- package/dist/core/diagnostics.d.ts +76 -0
- package/dist/core/journey.d.ts +112 -0
- package/dist/core/logger.d.ts +117 -0
- package/dist/core/pipeline.d.ts +75 -0
- package/dist/core/record.d.ts +72 -0
- package/dist/core/runtime.d.ts +146 -0
- package/dist/core/sampling.d.ts +9 -0
- package/dist/index.cjs +4 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.ts +167 -0
- package/dist/index.js +2577 -0
- package/dist/index.js.map +1 -0
- package/dist/indexeddb-storage-DvsvCUlO.cjs +2 -0
- package/dist/indexeddb-storage-DvsvCUlO.cjs.map +1 -0
- package/dist/indexeddb-storage-DwpCDRnX.js +88 -0
- package/dist/indexeddb-storage-DwpCDRnX.js.map +1 -0
- package/dist/models/batch.d.ts +22 -0
- package/dist/models/bus.d.ts +97 -0
- package/dist/models/config.d.ts +528 -0
- package/dist/models/log-record.d.ts +54 -0
- package/dist/models/serializer.d.ts +23 -0
- package/dist/models/storage.d.ts +62 -0
- package/dist/storage/emergency-queue.d.ts +16 -0
- package/dist/storage/factory.d.ts +13 -0
- package/dist/storage/indexeddb-storage.d.ts +69 -0
- package/dist/storage/keys.d.ts +8 -0
- package/dist/storage/local-storage.d.ts +80 -0
- package/dist/storage/memory-storage.d.ts +52 -0
- package/dist/transport/compression.d.ts +7 -0
- package/dist/transport/errors.d.ts +29 -0
- package/dist/transport/exit-flush.d.ts +63 -0
- package/dist/transport/http-transport.d.ts +63 -0
- package/dist/transport/retry-engine.d.ts +69 -0
- package/dist/transport/serializers/ecs.d.ts +3 -0
- package/dist/transport/serializers/otlp.d.ts +3 -0
- package/dist/utils/console.d.ts +24 -0
- package/dist/utils/identity.d.ts +36 -0
- package/dist/utils/lock.d.ts +15 -0
- package/dist/utils/platform.d.ts +36 -0
- package/dist/utils/sanitize.d.ts +47 -0
- package/dist/utils/sequence.d.ts +15 -0
- package/dist/utils/timer.d.ts +19 -0
- package/dist/utils/tracing.d.ts +55 -0
- package/dist/utils/unref.d.ts +9 -0
- package/package.json +106 -0
|
@@ -0,0 +1,528 @@
|
|
|
1
|
+
import type { DiagnosticHandler } from "../core/diagnostics";
|
|
2
|
+
import type { LogLevel, LogRecord } from "./log-record";
|
|
3
|
+
import type { LogSerializer } from "./serializer";
|
|
4
|
+
/** Backing store for undelivered records. "auto" picks the best one the host supports. */
|
|
5
|
+
export type StorageStrategy = "auto" | "indexeddb" | "localstorage" | "memory" | "none";
|
|
6
|
+
/** What this context does with its records: `sender` delivers its own, `forwarder` hands them to another context, `auto` decides, `off` does neither. */
|
|
7
|
+
export type BusMode = "auto" | "sender" | "forwarder" | "off";
|
|
8
|
+
/** Structural type for the `web-vitals` package's metric shape, so this library has no hard dependency on the package. */
|
|
9
|
+
export interface WebVitalsMetric {
|
|
10
|
+
/** Measurement value, in the metric's own unit. */
|
|
11
|
+
value: number;
|
|
12
|
+
/** Rating: "good", "needs-improvement", or "poor". */
|
|
13
|
+
rating?: string;
|
|
14
|
+
/** Metric instance id, for matching a later update to its first report. */
|
|
15
|
+
id: string;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Callback `web-vitals` invokes with a measurement.
|
|
19
|
+
* @param metric The measurement being reported.
|
|
20
|
+
*/
|
|
21
|
+
export type WebVitalsReporter = (metric: WebVitalsMetric) => void;
|
|
22
|
+
/** The five `web-vitals` entry points this library subscribes to. */
|
|
23
|
+
export interface WebVitalsModule {
|
|
24
|
+
/**
|
|
25
|
+
* Largest Contentful Paint.
|
|
26
|
+
* @param report Callback invoked with the LCP measurement.
|
|
27
|
+
*/
|
|
28
|
+
onLCP: (report: WebVitalsReporter) => void;
|
|
29
|
+
/**
|
|
30
|
+
* Cumulative Layout Shift.
|
|
31
|
+
* @param report Callback invoked with the CLS measurement.
|
|
32
|
+
*/
|
|
33
|
+
onCLS: (report: WebVitalsReporter) => void;
|
|
34
|
+
/**
|
|
35
|
+
* Interaction to Next Paint.
|
|
36
|
+
* @param report Callback invoked with the INP measurement.
|
|
37
|
+
*/
|
|
38
|
+
onINP: (report: WebVitalsReporter) => void;
|
|
39
|
+
/**
|
|
40
|
+
* First Contentful Paint.
|
|
41
|
+
* @param report Callback invoked with the FCP measurement.
|
|
42
|
+
*/
|
|
43
|
+
onFCP: (report: WebVitalsReporter) => void;
|
|
44
|
+
/**
|
|
45
|
+
* Time to First Byte.
|
|
46
|
+
* @param report Callback invoked with the TTFB measurement.
|
|
47
|
+
*/
|
|
48
|
+
onTTFB: (report: WebVitalsReporter) => void;
|
|
49
|
+
}
|
|
50
|
+
/** Batching policy for one record stream (logs or metrics). */
|
|
51
|
+
export interface StreamOptions {
|
|
52
|
+
/** Max time a partial batch waits before it is sent, in milliseconds. */
|
|
53
|
+
flushIntervalMs: number;
|
|
54
|
+
/** Max records per batch before it is sent early. */
|
|
55
|
+
batchSize: number;
|
|
56
|
+
}
|
|
57
|
+
/** The two record streams, batched independently. */
|
|
58
|
+
export interface StreamsOptions {
|
|
59
|
+
/** Log stream batching. */
|
|
60
|
+
logs: StreamOptions;
|
|
61
|
+
/** Metric stream batching. */
|
|
62
|
+
metrics: StreamOptions;
|
|
63
|
+
}
|
|
64
|
+
/** Storage policy for undelivered records. */
|
|
65
|
+
export interface StorageOptions {
|
|
66
|
+
/**
|
|
67
|
+
* Backing store.
|
|
68
|
+
* @default "auto"
|
|
69
|
+
*/
|
|
70
|
+
strategy: StorageStrategy;
|
|
71
|
+
/**
|
|
72
|
+
* IndexedDB database name. Used only when the strategy resolves to indexeddb.
|
|
73
|
+
* @default "UiObservability"
|
|
74
|
+
*/
|
|
75
|
+
dbName: string;
|
|
76
|
+
/**
|
|
77
|
+
* Max batches held at once. Oldest are evicted past this.
|
|
78
|
+
* @default 500
|
|
79
|
+
*/
|
|
80
|
+
maxBatches: number;
|
|
81
|
+
/**
|
|
82
|
+
* Max batch age before it is dropped rather than retried, in milliseconds.
|
|
83
|
+
* @default 24 * 60 * 60 * 1000
|
|
84
|
+
*/
|
|
85
|
+
maxAgeMs: number;
|
|
86
|
+
/**
|
|
87
|
+
* Max delivery attempts before a batch is dead-lettered.
|
|
88
|
+
* @default 5
|
|
89
|
+
*/
|
|
90
|
+
maxAttempts: number;
|
|
91
|
+
}
|
|
92
|
+
/** Backoff schedule for redelivering a stored batch. */
|
|
93
|
+
export interface RetryOptions {
|
|
94
|
+
/**
|
|
95
|
+
* First backoff step, in milliseconds. Each attempt doubles it.
|
|
96
|
+
* @default 2000
|
|
97
|
+
*/
|
|
98
|
+
baseDelayMs: number;
|
|
99
|
+
/**
|
|
100
|
+
* Backoff ceiling, in milliseconds.
|
|
101
|
+
* @default 60000
|
|
102
|
+
*/
|
|
103
|
+
maxDelayMs: number;
|
|
104
|
+
/**
|
|
105
|
+
* How often to check for stored work when nothing has failed recently, in milliseconds.
|
|
106
|
+
* @default 30000
|
|
107
|
+
*/
|
|
108
|
+
idleDelayMs: number;
|
|
109
|
+
}
|
|
110
|
+
/** Sampling policy: which records survive. */
|
|
111
|
+
export interface SamplingOptions {
|
|
112
|
+
/**
|
|
113
|
+
* Default fraction of records kept, 0 to 1.
|
|
114
|
+
* @default 1
|
|
115
|
+
*/
|
|
116
|
+
defaultRate: number;
|
|
117
|
+
/**
|
|
118
|
+
* Per-namespace override, keyed by `app.namespace`. Most specific prefix wins.
|
|
119
|
+
* @default {}
|
|
120
|
+
*/
|
|
121
|
+
rates: Record<string, number>;
|
|
122
|
+
/**
|
|
123
|
+
* Log types always kept, regardless of sampling rate.
|
|
124
|
+
* @default ["action"]
|
|
125
|
+
*/
|
|
126
|
+
alwaysSampleTypes: string[];
|
|
127
|
+
}
|
|
128
|
+
/** Lifetime rules for a journey (one user task spanning several contexts). */
|
|
129
|
+
export interface JourneyOptions {
|
|
130
|
+
/**
|
|
131
|
+
* Max time a journey stays open before it's treated as abandoned, in milliseconds.
|
|
132
|
+
* @default 30 * 60 * 1000
|
|
133
|
+
*/
|
|
134
|
+
maxAgeMs: number;
|
|
135
|
+
/**
|
|
136
|
+
* Whether closing the owning context ends the journey for everyone.
|
|
137
|
+
* @default false
|
|
138
|
+
*/
|
|
139
|
+
endOnOwnerClose: boolean;
|
|
140
|
+
/**
|
|
141
|
+
* Query parameter checked at boot for a seeded journey token.
|
|
142
|
+
* @default "__uiobs_journey"
|
|
143
|
+
*/
|
|
144
|
+
urlParam: string;
|
|
145
|
+
}
|
|
146
|
+
/** Bus settings: how this context discovers, trusts, and messages the others. */
|
|
147
|
+
export interface BusOptions {
|
|
148
|
+
/**
|
|
149
|
+
* This context's role.
|
|
150
|
+
* @default "auto"
|
|
151
|
+
*/
|
|
152
|
+
mode: BusMode;
|
|
153
|
+
/**
|
|
154
|
+
* BroadcastChannel name for the control plane.
|
|
155
|
+
* @default "ui_observability_control"
|
|
156
|
+
*/
|
|
157
|
+
channelName: string;
|
|
158
|
+
/**
|
|
159
|
+
* Origins allowed to send postMessage records to this document. Required for any document receiving them from a cross-origin iframe.
|
|
160
|
+
* @default []
|
|
161
|
+
*/
|
|
162
|
+
trustedOrigins: string[];
|
|
163
|
+
/**
|
|
164
|
+
* Max time a forwarder waits for an owner to answer before applying the orphan policy, in milliseconds.
|
|
165
|
+
* @default 1500
|
|
166
|
+
*/
|
|
167
|
+
handshakeTimeoutMs: number;
|
|
168
|
+
/**
|
|
169
|
+
* Which OpenFin context owns delivery.
|
|
170
|
+
* @default "provider"
|
|
171
|
+
*/
|
|
172
|
+
openFinHost: "provider" | "self";
|
|
173
|
+
/**
|
|
174
|
+
* Which OpenFin context this is. Only the platform provider answers a
|
|
175
|
+
* handshake, so setting this wrong makes every view send for itself.
|
|
176
|
+
* "auto" treats the window whose name equals its application uuid as the
|
|
177
|
+
* provider.
|
|
178
|
+
* @default "auto"
|
|
179
|
+
*/
|
|
180
|
+
openFinRole: "auto" | "provider" | "client";
|
|
181
|
+
/**
|
|
182
|
+
* Max records a context buffers before its bus role is determined.
|
|
183
|
+
* @default 500
|
|
184
|
+
*/
|
|
185
|
+
maxBootBufferRecords: number;
|
|
186
|
+
/**
|
|
187
|
+
* Forwarder behavior when no owner answers: `auto` retries in a
|
|
188
|
+
* cross-origin frame and promotes elsewhere, `promote` becomes a sender
|
|
189
|
+
* immediately, `retry` retries then promotes as a last resort.
|
|
190
|
+
* @default "auto"
|
|
191
|
+
*/
|
|
192
|
+
orphanPolicy: "auto" | "promote" | "retry";
|
|
193
|
+
/**
|
|
194
|
+
* Handshake attempts allowed before promoting under the "retry" policy.
|
|
195
|
+
* @default 3
|
|
196
|
+
*/
|
|
197
|
+
maxHandshakeAttempts: number;
|
|
198
|
+
}
|
|
199
|
+
/** What the library instruments automatically. Everything but errors is off by default. */
|
|
200
|
+
export interface CaptureOptions {
|
|
201
|
+
/**
|
|
202
|
+
* Log uncaught errors from `window.onerror`.
|
|
203
|
+
* @default true
|
|
204
|
+
*/
|
|
205
|
+
errors: boolean;
|
|
206
|
+
/**
|
|
207
|
+
* Log unhandled promise rejections.
|
|
208
|
+
* @default true
|
|
209
|
+
*/
|
|
210
|
+
rejections: boolean;
|
|
211
|
+
/**
|
|
212
|
+
* Log failed image, script, and stylesheet loads.
|
|
213
|
+
* @default false
|
|
214
|
+
*/
|
|
215
|
+
resourceErrors: boolean;
|
|
216
|
+
/**
|
|
217
|
+
* Wrap `fetch` to log requests. The ingest endpoint itself is never logged.
|
|
218
|
+
* @default false
|
|
219
|
+
*/
|
|
220
|
+
fetch: boolean;
|
|
221
|
+
/**
|
|
222
|
+
* Wrap `XMLHttpRequest` to log requests.
|
|
223
|
+
* @default false
|
|
224
|
+
*/
|
|
225
|
+
xhr: boolean;
|
|
226
|
+
/**
|
|
227
|
+
* Log clicks and other interactions as breadcrumbs.
|
|
228
|
+
* @default false
|
|
229
|
+
*/
|
|
230
|
+
interactions: boolean;
|
|
231
|
+
/**
|
|
232
|
+
* Log route changes, including single-page-application navigation.
|
|
233
|
+
* @default false
|
|
234
|
+
*/
|
|
235
|
+
navigation: boolean;
|
|
236
|
+
/**
|
|
237
|
+
* Report web vitals as metrics. Requires the `web-vitals` peer or `webVitalsLoader`.
|
|
238
|
+
* @default false
|
|
239
|
+
*/
|
|
240
|
+
webVitals: boolean;
|
|
241
|
+
/**
|
|
242
|
+
* Breadcrumbs kept as context for the next error.
|
|
243
|
+
* @default 50
|
|
244
|
+
*/
|
|
245
|
+
maxBreadcrumbs: number;
|
|
246
|
+
/**
|
|
247
|
+
* URLs excluded from logging. The ingest endpoint is always included.
|
|
248
|
+
* @default []
|
|
249
|
+
*/
|
|
250
|
+
ignoreUrls: (string | RegExp)[];
|
|
251
|
+
/**
|
|
252
|
+
* Targets that receive a `traceparent` header. A catch-all breaks CORS on third-party endpoints.
|
|
253
|
+
* @default []
|
|
254
|
+
*/
|
|
255
|
+
propagateTraceHeaderTo: (string | RegExp)[];
|
|
256
|
+
/**
|
|
257
|
+
* Window within which identical errors are counted but not re-sent, in milliseconds.
|
|
258
|
+
* @default 5000
|
|
259
|
+
*/
|
|
260
|
+
errorDedupeMs: number;
|
|
261
|
+
/**
|
|
262
|
+
* Supplies the `web-vitals` module without a hard dependency on the package.
|
|
263
|
+
* @returns A promise resolving to the `web-vitals` module.
|
|
264
|
+
*/
|
|
265
|
+
webVitalsLoader?: () => Promise<WebVitalsModule>;
|
|
266
|
+
}
|
|
267
|
+
/** Per-record size caps. */
|
|
268
|
+
export interface LimitOptions {
|
|
269
|
+
/**
|
|
270
|
+
* Max record body length, in characters.
|
|
271
|
+
* @default 4096
|
|
272
|
+
*/
|
|
273
|
+
maxBodyChars: number;
|
|
274
|
+
/**
|
|
275
|
+
* Max length of a single string attribute, in characters.
|
|
276
|
+
* @default 8192
|
|
277
|
+
*/
|
|
278
|
+
maxAttributeChars: number;
|
|
279
|
+
/**
|
|
280
|
+
* Max attributes per record.
|
|
281
|
+
* @default 128
|
|
282
|
+
*/
|
|
283
|
+
maxAttributeCount: number;
|
|
284
|
+
/**
|
|
285
|
+
* Max stack trace length, in characters. Larger than `maxAttributeChars`.
|
|
286
|
+
* @default 8192
|
|
287
|
+
*/
|
|
288
|
+
maxStackChars: number;
|
|
289
|
+
/**
|
|
290
|
+
* Max depth walked into a nested value before truncating.
|
|
291
|
+
* @default 6
|
|
292
|
+
*/
|
|
293
|
+
maxDepth: number;
|
|
294
|
+
/**
|
|
295
|
+
* Max items kept from an array, set, or map.
|
|
296
|
+
* @default 100
|
|
297
|
+
*/
|
|
298
|
+
maxArrayLength: number;
|
|
299
|
+
/**
|
|
300
|
+
* Max total attribute bytes per record, checked after sanitize and redact.
|
|
301
|
+
* @default 32768
|
|
302
|
+
*/
|
|
303
|
+
maxRecordBytes: number;
|
|
304
|
+
}
|
|
305
|
+
/** Console mirroring, for development. */
|
|
306
|
+
export interface ConsoleOptions {
|
|
307
|
+
/**
|
|
308
|
+
* Whether to mirror at all.
|
|
309
|
+
* @default false
|
|
310
|
+
*/
|
|
311
|
+
enabled: boolean;
|
|
312
|
+
/**
|
|
313
|
+
* Min level to mirror. Independent of `minLevel`.
|
|
314
|
+
* @default "DEBUG"
|
|
315
|
+
*/
|
|
316
|
+
level: LogLevel;
|
|
317
|
+
}
|
|
318
|
+
/** Options passed to `configure()`. Only `endpoint` is required. */
|
|
319
|
+
export interface ObservabilityConfig {
|
|
320
|
+
/** Ingest endpoint URL. Required. */
|
|
321
|
+
endpoint: string;
|
|
322
|
+
/**
|
|
323
|
+
* Reported as `service.name`.
|
|
324
|
+
* @default ""
|
|
325
|
+
*/
|
|
326
|
+
serviceName?: string;
|
|
327
|
+
/**
|
|
328
|
+
* Reported as `service.version`.
|
|
329
|
+
* @default ""
|
|
330
|
+
*/
|
|
331
|
+
serviceVersion?: string;
|
|
332
|
+
/**
|
|
333
|
+
* Reported as `deployment.environment`.
|
|
334
|
+
* @default ""
|
|
335
|
+
*/
|
|
336
|
+
environment?: string;
|
|
337
|
+
/**
|
|
338
|
+
* Master switch. False makes every log call a no-op.
|
|
339
|
+
* @default true
|
|
340
|
+
*/
|
|
341
|
+
enabled?: boolean;
|
|
342
|
+
/**
|
|
343
|
+
* Min level logged.
|
|
344
|
+
* @default "INFO"
|
|
345
|
+
*/
|
|
346
|
+
minLevel?: LogLevel;
|
|
347
|
+
/** Per-stream batching. */
|
|
348
|
+
streams?: {
|
|
349
|
+
/**
|
|
350
|
+
* Log stream batching.
|
|
351
|
+
* @default { flushIntervalMs: 2000, batchSize: 100 }
|
|
352
|
+
*/
|
|
353
|
+
logs?: Partial<StreamOptions>;
|
|
354
|
+
/**
|
|
355
|
+
* Metric stream batching.
|
|
356
|
+
* @default { flushIntervalMs: 10000, batchSize: 500 }
|
|
357
|
+
*/
|
|
358
|
+
metrics?: Partial<StreamOptions>;
|
|
359
|
+
};
|
|
360
|
+
/**
|
|
361
|
+
* Max concurrent ingest requests, across both streams.
|
|
362
|
+
* @default 2
|
|
363
|
+
*/
|
|
364
|
+
maxConcurrentRequests?: number;
|
|
365
|
+
/**
|
|
366
|
+
* Max time one ingest request may take before it is aborted and retried, in milliseconds.
|
|
367
|
+
* @default 15000
|
|
368
|
+
*/
|
|
369
|
+
requestTimeoutMs?: number;
|
|
370
|
+
/**
|
|
371
|
+
* Whether to gzip a payload past `compressionThresholdBytes`.
|
|
372
|
+
* @default "gzip"
|
|
373
|
+
*/
|
|
374
|
+
compression?: "gzip" | "none";
|
|
375
|
+
/**
|
|
376
|
+
* Min payload size to compress, in bytes.
|
|
377
|
+
* @default 1024
|
|
378
|
+
*/
|
|
379
|
+
compressionThresholdBytes?: number;
|
|
380
|
+
/**
|
|
381
|
+
* Wire format: a name, or a custom implementation.
|
|
382
|
+
* @default "otlp"
|
|
383
|
+
*/
|
|
384
|
+
serializer?: "otlp" | "ecs" | LogSerializer;
|
|
385
|
+
/**
|
|
386
|
+
* Passed to `fetch`.
|
|
387
|
+
* @default "include"
|
|
388
|
+
*/
|
|
389
|
+
credentials?: RequestCredentials;
|
|
390
|
+
/** Extra request headers, or a function returning them. */
|
|
391
|
+
headers?: Record<string, string> | (() => Record<string, string> | Promise<Record<string, string>>);
|
|
392
|
+
/**
|
|
393
|
+
* Storage policy for undelivered records.
|
|
394
|
+
* @see {@link StorageOptions}
|
|
395
|
+
*/
|
|
396
|
+
storage?: Partial<StorageOptions>;
|
|
397
|
+
/**
|
|
398
|
+
* Backoff schedule for redelivering them.
|
|
399
|
+
* @see {@link RetryOptions}
|
|
400
|
+
*/
|
|
401
|
+
retry?: Partial<RetryOptions>;
|
|
402
|
+
/**
|
|
403
|
+
* Sampling policy.
|
|
404
|
+
* @see {@link SamplingOptions}
|
|
405
|
+
*/
|
|
406
|
+
sampling?: Partial<SamplingOptions>;
|
|
407
|
+
/**
|
|
408
|
+
* Journey lifetime rules.
|
|
409
|
+
* @see {@link JourneyOptions}
|
|
410
|
+
*/
|
|
411
|
+
journey?: Partial<JourneyOptions>;
|
|
412
|
+
/**
|
|
413
|
+
* Bus discovery, trust, and messaging settings.
|
|
414
|
+
* @see {@link BusOptions}
|
|
415
|
+
*/
|
|
416
|
+
bus?: Partial<BusOptions>;
|
|
417
|
+
/**
|
|
418
|
+
* Automatic instrumentation.
|
|
419
|
+
* @see {@link CaptureOptions}
|
|
420
|
+
*/
|
|
421
|
+
capture?: Partial<CaptureOptions>;
|
|
422
|
+
/**
|
|
423
|
+
* Per-record size caps.
|
|
424
|
+
* @see {@link LimitOptions}
|
|
425
|
+
*/
|
|
426
|
+
limits?: Partial<LimitOptions>;
|
|
427
|
+
/**
|
|
428
|
+
* Console mirroring.
|
|
429
|
+
* @see {@link ConsoleOptions}
|
|
430
|
+
*/
|
|
431
|
+
console?: Partial<ConsoleOptions>;
|
|
432
|
+
/**
|
|
433
|
+
* Rewrites or drops a record before it's sent.
|
|
434
|
+
* @param record The record about to be sent.
|
|
435
|
+
* @returns The record to send, or `null` to drop it.
|
|
436
|
+
*/
|
|
437
|
+
redact?: (record: LogRecord) => LogRecord | null;
|
|
438
|
+
/**
|
|
439
|
+
* Reports this library's own faults.
|
|
440
|
+
* @see {@link DiagnosticHandler}
|
|
441
|
+
*/
|
|
442
|
+
onDiagnostic?: DiagnosticHandler;
|
|
443
|
+
}
|
|
444
|
+
/** Fully resolved config, held by the runtime. */
|
|
445
|
+
export interface ResolvedConfig {
|
|
446
|
+
/** Ingest endpoint URL. */
|
|
447
|
+
endpoint: string;
|
|
448
|
+
/** Reported as `service.name`. */
|
|
449
|
+
serviceName: string;
|
|
450
|
+
/** Reported as `service.version`. */
|
|
451
|
+
serviceVersion: string;
|
|
452
|
+
/** Reported as `deployment.environment`. */
|
|
453
|
+
environment: string;
|
|
454
|
+
/** Master switch. False makes every log call a no-op. */
|
|
455
|
+
enabled: boolean;
|
|
456
|
+
/** Min level logged. */
|
|
457
|
+
minLevel: LogLevel;
|
|
458
|
+
/**
|
|
459
|
+
* Per-stream batching.
|
|
460
|
+
* @see {@link StreamsOptions}
|
|
461
|
+
*/
|
|
462
|
+
streams: StreamsOptions;
|
|
463
|
+
/** Max concurrent ingest requests, across both streams. */
|
|
464
|
+
maxConcurrentRequests: number;
|
|
465
|
+
/** Max time one ingest request may take before it is aborted and retried, in milliseconds. */
|
|
466
|
+
requestTimeoutMs: number;
|
|
467
|
+
/** Whether to gzip a payload past `compressionThresholdBytes`. */
|
|
468
|
+
compression: "gzip" | "none";
|
|
469
|
+
/** Min payload size to compress, in bytes. */
|
|
470
|
+
compressionThresholdBytes: number;
|
|
471
|
+
/** Passed to `fetch`. */
|
|
472
|
+
credentials: RequestCredentials;
|
|
473
|
+
/**
|
|
474
|
+
* Storage policy for undelivered records.
|
|
475
|
+
* @see {@link StorageOptions}
|
|
476
|
+
*/
|
|
477
|
+
storage: StorageOptions;
|
|
478
|
+
/**
|
|
479
|
+
* Backoff schedule for redelivering a stored batch.
|
|
480
|
+
* @see {@link RetryOptions}
|
|
481
|
+
*/
|
|
482
|
+
retry: RetryOptions;
|
|
483
|
+
/**
|
|
484
|
+
* Sampling policy.
|
|
485
|
+
* @see {@link SamplingOptions}
|
|
486
|
+
*/
|
|
487
|
+
sampling: SamplingOptions;
|
|
488
|
+
/**
|
|
489
|
+
* Journey lifetime rules.
|
|
490
|
+
* @see {@link JourneyOptions}
|
|
491
|
+
*/
|
|
492
|
+
journey: JourneyOptions;
|
|
493
|
+
/**
|
|
494
|
+
* Bus discovery, trust, and messaging settings.
|
|
495
|
+
* @see {@link BusOptions}
|
|
496
|
+
*/
|
|
497
|
+
bus: BusOptions;
|
|
498
|
+
/**
|
|
499
|
+
* Automatic instrumentation.
|
|
500
|
+
* @see {@link CaptureOptions}
|
|
501
|
+
*/
|
|
502
|
+
capture: CaptureOptions;
|
|
503
|
+
/**
|
|
504
|
+
* Per-record size caps.
|
|
505
|
+
* @see {@link LimitOptions}
|
|
506
|
+
*/
|
|
507
|
+
limits: LimitOptions;
|
|
508
|
+
/**
|
|
509
|
+
* Console mirroring.
|
|
510
|
+
* @see {@link ConsoleOptions}
|
|
511
|
+
*/
|
|
512
|
+
console: ConsoleOptions;
|
|
513
|
+
/** Wire format implementation, resolved from a name or passed directly. */
|
|
514
|
+
serializer: LogSerializer;
|
|
515
|
+
/** Extra request headers, or a function returning them. */
|
|
516
|
+
headers?: ObservabilityConfig["headers"];
|
|
517
|
+
/**
|
|
518
|
+
* Rewrites or drops a record before it's sent.
|
|
519
|
+
* @param record The record about to be sent.
|
|
520
|
+
* @returns The record to send, or `null` to drop it.
|
|
521
|
+
*/
|
|
522
|
+
redact?: ObservabilityConfig["redact"];
|
|
523
|
+
/**
|
|
524
|
+
* Reports this library's own faults.
|
|
525
|
+
* @see {@link DiagnosticHandler}
|
|
526
|
+
*/
|
|
527
|
+
onDiagnostic?: DiagnosticHandler;
|
|
528
|
+
}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
/** OpenTelemetry severity levels, in ascending order. */
|
|
2
|
+
export type LogLevel = "TRACE" | "DEBUG" | "INFO" | "WARN" | "ERROR" | "FATAL";
|
|
3
|
+
/**
|
|
4
|
+
* Kind of thing a record describes: `action` (something a person did),
|
|
5
|
+
* `event` (something the application did), `metric` (a measurement), or
|
|
6
|
+
* `system` (this library's own diagnostic output).
|
|
7
|
+
*/
|
|
8
|
+
export type LogType = "action" | "event" | "metric" | "system";
|
|
9
|
+
/** Metric value type: level, running total, or distribution. */
|
|
10
|
+
export type MetricType = "gauge" | "counter" | "histogram";
|
|
11
|
+
/** Internal record shape, converted to wire format by a serializer. */
|
|
12
|
+
export interface LogRecord {
|
|
13
|
+
/**
|
|
14
|
+
* Event time, nanoseconds since epoch, as a decimal string.
|
|
15
|
+
* @see {@link nowUnixNano}
|
|
16
|
+
*/
|
|
17
|
+
timeUnixNano: string;
|
|
18
|
+
/** Time this library received the event, if different from `timeUnixNano` (e.g. on a forwarded record). */
|
|
19
|
+
observedTimeUnixNano?: string;
|
|
20
|
+
/** Distributed trace id. */
|
|
21
|
+
traceId: string;
|
|
22
|
+
/** Span id within the trace. */
|
|
23
|
+
spanId: string;
|
|
24
|
+
/** OpenTelemetry trace flags. Only the sampled bit is used. */
|
|
25
|
+
traceFlags: number;
|
|
26
|
+
/** OpenTelemetry severity number for `severityText`. */
|
|
27
|
+
severityNumber: number;
|
|
28
|
+
/** Log level. */
|
|
29
|
+
severityText: LogLevel;
|
|
30
|
+
/** Log message. */
|
|
31
|
+
body: string;
|
|
32
|
+
/** Structured attributes, sanitized and size-capped. */
|
|
33
|
+
attributes: Record<string, unknown>;
|
|
34
|
+
/** Resource attributes, shared by every record from one context. */
|
|
35
|
+
resource: Record<string, unknown>;
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Returns the current time as a Unix nanosecond timestamp.
|
|
39
|
+
* Concatenates rather than multiplies: `Date.now() * 1e6` overflows
|
|
40
|
+
* `Number.MAX_SAFE_INTEGER` and silently corrupts digits. Trailing zeros are
|
|
41
|
+
* unknown precision, not real.
|
|
42
|
+
* @returns Epoch timestamp in nanoseconds, as a decimal string.
|
|
43
|
+
*/
|
|
44
|
+
export declare function nowUnixNano(): string;
|
|
45
|
+
/**
|
|
46
|
+
* Checks whether a value has the shape `LogRecord` requires.
|
|
47
|
+
* Used to validate records arriving from another realm, since a malformed
|
|
48
|
+
* one throws during serialization. `severityText` is checked as a string,
|
|
49
|
+
* not a known level, so an unrecognised level from a newer version still
|
|
50
|
+
* passes.
|
|
51
|
+
* @param value The value to check.
|
|
52
|
+
* @returns Whether `value` has the shape `LogRecord` requires.
|
|
53
|
+
*/
|
|
54
|
+
export declare function isLogRecord(value: unknown): value is LogRecord;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import type { LogRecord } from "./log-record";
|
|
2
|
+
/**
|
|
3
|
+
* Serialized batch payload with its content type.
|
|
4
|
+
* @see {@link LogSerializer}
|
|
5
|
+
*/
|
|
6
|
+
export interface SerializedBatch {
|
|
7
|
+
/** Request body bytes. */
|
|
8
|
+
body: string;
|
|
9
|
+
/** Content-Type header value. */
|
|
10
|
+
contentType: string;
|
|
11
|
+
}
|
|
12
|
+
/** Log record serializer interface. */
|
|
13
|
+
export interface LogSerializer {
|
|
14
|
+
/** Serializer name used in configuration. */
|
|
15
|
+
name: string;
|
|
16
|
+
/**
|
|
17
|
+
* Serializes a batch of records to wire-format bytes.
|
|
18
|
+
* Called once per delivery attempt, not once per batch, so a retry re-encodes.
|
|
19
|
+
* @param records Batch records, in log order.
|
|
20
|
+
* @returns Serialized batch ready for transport.
|
|
21
|
+
*/
|
|
22
|
+
serialize(records: LogRecord[]): SerializedBatch;
|
|
23
|
+
}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import type { LogBatch } from "./batch";
|
|
2
|
+
/** Persistent batch storage interface. All methods must resolve and never throw. */
|
|
3
|
+
export interface StorageAdapter {
|
|
4
|
+
/** Adapter identifier name. */
|
|
5
|
+
readonly name: string;
|
|
6
|
+
/**
|
|
7
|
+
* Persists a batch to storage.
|
|
8
|
+
* @param batch The batch to store.
|
|
9
|
+
*/
|
|
10
|
+
save(batch: LogBatch): Promise<void>;
|
|
11
|
+
/**
|
|
12
|
+
* Reads up to `limit` batches in FIFO order without removing them.
|
|
13
|
+
* @param limit Maximum number of batches to retrieve.
|
|
14
|
+
* @returns Oldest persisted batches.
|
|
15
|
+
*/
|
|
16
|
+
take(limit: number): Promise<LogBatch[]>;
|
|
17
|
+
/**
|
|
18
|
+
* Removes a batch by ID. Non-existent IDs resolve without error.
|
|
19
|
+
* @param id Batch identifier.
|
|
20
|
+
*/
|
|
21
|
+
remove(id: string): Promise<void>;
|
|
22
|
+
/**
|
|
23
|
+
* Updates the total delivery attempts for a batch.
|
|
24
|
+
* @param id Batch identifier.
|
|
25
|
+
* @param attempts Absolute attempt count.
|
|
26
|
+
*/
|
|
27
|
+
bumpAttempts(id: string, attempts: number): Promise<void>;
|
|
28
|
+
/**
|
|
29
|
+
* Deletes expired and over-capacity batches.
|
|
30
|
+
* @returns Prune summary metrics.
|
|
31
|
+
*/
|
|
32
|
+
prune(): Promise<PruneResult>;
|
|
33
|
+
/** Returns the total number of stored batches. */
|
|
34
|
+
count(): Promise<number>;
|
|
35
|
+
/** Deletes all batches in storage. */
|
|
36
|
+
clear(): Promise<void>;
|
|
37
|
+
/** Closes storage connections and releases resources. */
|
|
38
|
+
close(): Promise<void>;
|
|
39
|
+
}
|
|
40
|
+
/** Capacity and retention thresholds enforced by a storage adapter. */
|
|
41
|
+
export interface StorageLimits {
|
|
42
|
+
/** Maximum batch capacity before FIFO eviction. */
|
|
43
|
+
maxBatches: number;
|
|
44
|
+
/** Maximum time-to-live for a stored batch in milliseconds. */
|
|
45
|
+
maxAgeMs: number;
|
|
46
|
+
/** Maximum delivery attempts before dead-letter drop. */
|
|
47
|
+
maxAttempts: number;
|
|
48
|
+
}
|
|
49
|
+
/** Metrics for batches and records dropped during storage pruning. */
|
|
50
|
+
export interface PruneResult {
|
|
51
|
+
/** Total batches dropped. */
|
|
52
|
+
batches: number;
|
|
53
|
+
/** Total records dropped within evicted batches. */
|
|
54
|
+
records: number;
|
|
55
|
+
/** Eviction reason that triggered the prune. If more than one rule fired, this is the last one. */
|
|
56
|
+
reason: "expired" | "over_capacity" | "quota";
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Callback invoked when dropped records create a telemetry gap.
|
|
60
|
+
* @param result Summary of evicted data.
|
|
61
|
+
*/
|
|
62
|
+
export type GapReporter = (result: PruneResult) => void;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { Diagnostics } from "../core/diagnostics";
|
|
2
|
+
import type { LogBatch } from "../models/batch";
|
|
3
|
+
import type { StorageAdapter } from "../models/storage";
|
|
4
|
+
/**
|
|
5
|
+
* Synchronously writes an unsent batch to the emergency queue during document unload.
|
|
6
|
+
* @param batch Oversized log batch.
|
|
7
|
+
* @param diagnostics Diagnostics reporter.
|
|
8
|
+
*/
|
|
9
|
+
export declare function saveToEmergencyQueue(batch: LogBatch, diagnostics: Diagnostics): void;
|
|
10
|
+
/**
|
|
11
|
+
* Recovers batches parked in emergency storage during prior shutdowns.
|
|
12
|
+
* @param storage Destination storage adapter.
|
|
13
|
+
* @param diagnostics Diagnostics reporter.
|
|
14
|
+
* @returns Promise resolving to the number of recovered batches.
|
|
15
|
+
*/
|
|
16
|
+
export declare function drainEmergencyQueue(storage: StorageAdapter, diagnostics: Diagnostics): Promise<number>;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { Diagnostics } from "../core/diagnostics";
|
|
2
|
+
import type { StorageStrategy } from "../models/config";
|
|
3
|
+
import type { GapReporter, StorageAdapter, StorageLimits } from "../models/storage";
|
|
4
|
+
/**
|
|
5
|
+
* Instantiates the requested storage adapter, degrading gracefully if dependencies are unavailable.
|
|
6
|
+
* @param strategy Configured persistence strategy.
|
|
7
|
+
* @param dbName IndexedDB database name.
|
|
8
|
+
* @param limits Storage retention and capacity thresholds.
|
|
9
|
+
* @param diagnostics Diagnostics reporter.
|
|
10
|
+
* @param onGap Optional callback for telemetry gap reporting.
|
|
11
|
+
* @returns Promise resolving to the selected StorageAdapter instance.
|
|
12
|
+
*/
|
|
13
|
+
export declare function createStorage(strategy: StorageStrategy, dbName: string, limits: StorageLimits, diagnostics: Diagnostics, onGap?: GapReporter): Promise<StorageAdapter>;
|