@utk09/ui-observability 0.1.2 → 0.3.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 +95 -0
- package/README.md +58 -46
- package/dist/bus/bus.d.ts +11 -23
- package/dist/capture/network.d.ts +1 -1
- package/dist/constants-BmO0GRWM.cjs +2 -0
- package/dist/constants-BmO0GRWM.cjs.map +1 -0
- package/dist/constants-CQr0wwbQ.js +69 -0
- package/dist/constants-CQr0wwbQ.js.map +1 -0
- package/dist/constants.d.ts +80 -7
- package/dist/core/breadcrumbs.d.ts +1 -6
- package/dist/core/diagnostics.d.ts +1 -1
- package/dist/core/journey.d.ts +11 -1
- package/dist/core/pipeline.d.ts +56 -22
- package/dist/core/record.d.ts +10 -0
- package/dist/core/runtime.d.ts +3 -1
- package/dist/core/sampling.d.ts +42 -1
- package/dist/index.cjs +3 -3
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +2 -2
- package/dist/index.js +645 -565
- package/dist/index.js.map +1 -1
- package/dist/indexeddb-storage-DeEh8Ag-.cjs +2 -0
- package/dist/indexeddb-storage-DeEh8Ag-.cjs.map +1 -0
- package/dist/indexeddb-storage-bibcl7ZS.js +154 -0
- package/dist/indexeddb-storage-bibcl7ZS.js.map +1 -0
- package/dist/models/config.d.ts +76 -253
- package/dist/storage/idb-driver.d.ts +67 -0
- package/dist/storage/indexeddb-storage.d.ts +1 -1
- package/dist/transport/exit-flush.d.ts +1 -1
- package/dist/utils/console.d.ts +5 -8
- package/dist/utils/platform.d.ts +7 -0
- package/dist/utils/tracing.d.ts +17 -1
- package/package.json +10 -8
- package/dist/constants-CYedFKrL.js +0 -110
- package/dist/constants-CYedFKrL.js.map +0 -1
- package/dist/constants-CeqjB0Aa.cjs +0 -2
- package/dist/constants-CeqjB0Aa.cjs.map +0 -1
- package/dist/indexeddb-storage-3oT4si-p.js +0 -88
- package/dist/indexeddb-storage-3oT4si-p.js.map +0 -1
- package/dist/indexeddb-storage-K3DhJWgu.cjs +0 -2
- package/dist/indexeddb-storage-K3DhJWgu.cjs.map +0 -1
package/dist/constants.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { ResolvedConfig } from "./models/config";
|
|
2
2
|
import type { LogLevel, LogType } from "./models/log-record";
|
|
3
|
+
import type { StorageLimits } from "./models/storage";
|
|
3
4
|
/** Prefix on console messages this library writes. */
|
|
4
5
|
export declare const LIBRARY_LOG_PREFIX = "[ui-observability]";
|
|
5
6
|
/** Throttle window per diagnostic code, in milliseconds. Limits how often an error loop can spam the handler. */
|
|
@@ -137,7 +138,7 @@ export declare const TELEMETRY_SDK_NAME = "@utk09/ui-observability";
|
|
|
137
138
|
* Value of `telemetry.sdk.version`. A literal, not read from package.json. Bump by hand alongside package.json.
|
|
138
139
|
* @see {@link RESOURCE_TELEMETRY_SDK_VERSION}
|
|
139
140
|
*/
|
|
140
|
-
export declare const TELEMETRY_SDK_VERSION = "0.
|
|
141
|
+
export declare const TELEMETRY_SDK_VERSION = "0.3.0";
|
|
141
142
|
/**
|
|
142
143
|
* Value of `telemetry.sdk.language`.
|
|
143
144
|
* @see {@link RESOURCE_TELEMETRY_SDK_LANGUAGE}
|
|
@@ -214,8 +215,17 @@ export declare const STORAGE_PROBE_KEY = "ui-observability.probe";
|
|
|
214
215
|
export declare const QUOTA_EVICTION_DIVISOR = 4;
|
|
215
216
|
/** DOMException name for a full store. */
|
|
216
217
|
export declare const QUOTA_EXCEEDED_ERROR = "QuotaExceededError";
|
|
217
|
-
/**
|
|
218
|
-
|
|
218
|
+
/**
|
|
219
|
+
* Native IndexedDB version. It starts at 11 because Dexie, which this replaced,
|
|
220
|
+
* opened the same database at ten times its own declared version. Anything below
|
|
221
|
+
* 11 makes open() fail with VersionError for an existing installation and every
|
|
222
|
+
* batch already stored there is stranded.
|
|
223
|
+
*/
|
|
224
|
+
export declare const INDEXEDDB_SCHEMA_VERSION = 11;
|
|
225
|
+
/** IndexedDB object store holding batches. Named by Dexie before it was removed. */
|
|
226
|
+
export declare const INDEXEDDB_STORE_NAME = "batches";
|
|
227
|
+
/** Index on the batch store that orders reads by creation time. */
|
|
228
|
+
export declare const INDEXEDDB_CREATED_AT_INDEX = "createdAt";
|
|
219
229
|
/** IndexedDB adapter/strategy name. */
|
|
220
230
|
export declare const STORAGE_NAME_INDEXEDDB = "indexeddb";
|
|
221
231
|
/** localStorage adapter/strategy name. */
|
|
@@ -278,6 +288,11 @@ export declare const TRACE_MAX_AGE_MS: number;
|
|
|
278
288
|
export declare const TRACE_FLAGS_SAMPLED = 1;
|
|
279
289
|
/** Mask for the one-byte trace-flags field. */
|
|
280
290
|
export declare const TRACE_FLAGS_MASK = 255;
|
|
291
|
+
/**
|
|
292
|
+
* W3C trace context header name
|
|
293
|
+
* @see {@link TRACEPARENT_VERSION}
|
|
294
|
+
*/
|
|
295
|
+
export declare const TRACEPARENT_HEADER = "traceparent";
|
|
281
296
|
/** traceparent header version prefix. */
|
|
282
297
|
export declare const TRACEPARENT_VERSION = "00";
|
|
283
298
|
/** Smallest valid breadcrumb buffer capacity. */
|
|
@@ -290,8 +305,6 @@ export declare const FNV_PRIME = 16777619;
|
|
|
290
305
|
export declare const UINT32_MAX = 4294967295;
|
|
291
306
|
/** Record kind routed to the metric stream. */
|
|
292
307
|
export declare const LOG_TYPE_METRIC: LogType;
|
|
293
|
-
/** Batches held per stream buffer before the oldest is dropped. */
|
|
294
|
-
export declare const PENDING_BUFFER_BATCHES = 10;
|
|
295
308
|
/** Protocol identifier for bus envelopes. Mismatched versions are dropped. */
|
|
296
309
|
export declare const BUS_PROTOCOL = "ui-observability/1";
|
|
297
310
|
/** Global window property key used to locate a same-origin runtime instance. */
|
|
@@ -300,6 +313,12 @@ export declare const RUNTIME_GLOBAL_KEY = "ui-observability.runtime";
|
|
|
300
313
|
export declare const ERROR_STORM_MAX_PER_WINDOW = 20;
|
|
301
314
|
/** Error rate-limiting window duration in milliseconds. */
|
|
302
315
|
export declare const ERROR_STORM_WINDOW_MS = 10000;
|
|
316
|
+
/**
|
|
317
|
+
* Max ERROR and FATAL records admitted to the pipeline per storm window.
|
|
318
|
+
* A backstop against a render loop, not a shaper: ERROR and FATAL bypass sampling,
|
|
319
|
+
* and a direct logger.error call has no other limit.
|
|
320
|
+
*/
|
|
321
|
+
export declare const ERROR_CEILING_MAX_PER_WINDOW = 500;
|
|
303
322
|
/** Maximum distinct error signatures tracked for deduplication before LRU eviction. */
|
|
304
323
|
export declare const MAX_TRACKED_ERROR_SIGNATURES = 200;
|
|
305
324
|
/** Maximum character length retained from clicked element text in breadcrumbs. */
|
|
@@ -335,12 +354,12 @@ export declare const SAMPLING_RATE_FALLBACK = 1;
|
|
|
335
354
|
* Config keys with no default, excluded from `DEFAULT_CONFIG`.
|
|
336
355
|
* @see {@link DEFAULT_CONFIG}
|
|
337
356
|
*/
|
|
338
|
-
export declare const UNDEFAULTED_CONFIG_KEYS: readonly ["redact", "onDiagnostic", "headers", "serializer"];
|
|
357
|
+
export declare const UNDEFAULTED_CONFIG_KEYS: readonly ["redact", "onDiagnostic", "headers", "serializer", "otelLoader"];
|
|
339
358
|
/**
|
|
340
359
|
* Nested config section keys.
|
|
341
360
|
* @see {@link ResolvedConfig}
|
|
342
361
|
*/
|
|
343
|
-
export declare const CONFIG_SECTIONS: readonly ["
|
|
362
|
+
export declare const CONFIG_SECTIONS: readonly ["sampling", "bus", "capture"];
|
|
344
363
|
/**
|
|
345
364
|
* Default runtime config, before a consumer's `configure()` call.
|
|
346
365
|
* Excludes `serializer`; `resolveConfig` supplies its default to avoid a circular import.
|
|
@@ -348,3 +367,57 @@ export declare const CONFIG_SECTIONS: readonly ["streams", "storage", "retry", "
|
|
|
348
367
|
* @see {@link UNDEFAULTED_CONFIG_KEYS}
|
|
349
368
|
*/
|
|
350
369
|
export declare const DEFAULT_CONFIG: Omit<ResolvedConfig, "serializer">;
|
|
370
|
+
/** Console mirroring level used when a consumer passes `console: true`. */
|
|
371
|
+
export declare const CONSOLE_DEFAULT_LEVEL: LogLevel;
|
|
372
|
+
/** Max time a partial log batch waits before it is sent, in milliseconds. */
|
|
373
|
+
export declare const LOG_FLUSH_INTERVAL_MS = 2000;
|
|
374
|
+
/** Max records per log batch before it is sent early. */
|
|
375
|
+
export declare const LOG_BATCH_SIZE = 100;
|
|
376
|
+
/** Max time a partial metric batch waits before it is sent, in milliseconds. Metrics batch harder than logs: higher volume, nothing waits on them. */
|
|
377
|
+
export declare const METRIC_FLUSH_INTERVAL_MS = 10000;
|
|
378
|
+
/** Max records per metric batch before it is sent early. */
|
|
379
|
+
export declare const METRIC_BATCH_SIZE = 500;
|
|
380
|
+
/** Max concurrent ingest requests, across both streams. */
|
|
381
|
+
export declare const MAX_CONCURRENT_REQUESTS = 2;
|
|
382
|
+
/** Max time one ingest request may take before it is aborted and retried, in milliseconds. */
|
|
383
|
+
export declare const REQUEST_TIMEOUT_MS = 15000;
|
|
384
|
+
/** Min payload size to compress, in bytes. */
|
|
385
|
+
export declare const COMPRESSION_THRESHOLD_BYTES = 1024;
|
|
386
|
+
/** IndexedDB database name. */
|
|
387
|
+
export declare const STORAGE_DB_NAME = "UiObservability";
|
|
388
|
+
/** Capacity and retention thresholds every storage adapter enforces. */
|
|
389
|
+
export declare const STORAGE_LIMITS: StorageLimits;
|
|
390
|
+
/** First backoff step, in milliseconds. Each attempt doubles it. */
|
|
391
|
+
export declare const RETRY_BASE_DELAY_MS = 2000;
|
|
392
|
+
/** Backoff ceiling, in milliseconds. */
|
|
393
|
+
export declare const RETRY_MAX_DELAY_MS = 60000;
|
|
394
|
+
/** How often to check for stored work when nothing has failed recently, in milliseconds. */
|
|
395
|
+
export declare const RETRY_IDLE_DELAY_MS = 30000;
|
|
396
|
+
/** Max time a journey stays open before it is treated as abandoned, in milliseconds. */
|
|
397
|
+
export declare const JOURNEY_MAX_AGE_MS: number;
|
|
398
|
+
/** Whether closing the owning context ends the journey for everyone. */
|
|
399
|
+
export declare const JOURNEY_END_ON_OWNER_CLOSE = false;
|
|
400
|
+
/** Query parameter checked at boot for a seeded journey token. */
|
|
401
|
+
export declare const JOURNEY_URL_PARAM = "__uiobs_journey";
|
|
402
|
+
/** BroadcastChannel name for the control plane. */
|
|
403
|
+
export declare const BUS_CHANNEL_NAME = "ui_observability_control";
|
|
404
|
+
/** Max time a forwarder waits for an owner to answer before it promotes itself, in milliseconds. */
|
|
405
|
+
export declare const BUS_HANDSHAKE_TIMEOUT_MS = 1500;
|
|
406
|
+
/** Handshake attempts allowed before a cross-origin forwarder promotes itself to sender. */
|
|
407
|
+
export declare const BUS_MAX_HANDSHAKE_ATTEMPTS = 3;
|
|
408
|
+
/** Max records a context buffers before its bus role is determined. */
|
|
409
|
+
export declare const BUS_MAX_BOOT_BUFFER_RECORDS = 500;
|
|
410
|
+
/** Breadcrumbs kept as context for the next error. */
|
|
411
|
+
export declare const MAX_BREADCRUMBS = 50;
|
|
412
|
+
/** Window within which identical errors are counted but not re-sent, in milliseconds. */
|
|
413
|
+
export declare const ERROR_DEDUPE_MS = 5000;
|
|
414
|
+
/** Size caps applied to every record, enforced after sanitize and after redact. */
|
|
415
|
+
export declare const RECORD_LIMITS: {
|
|
416
|
+
maxBodyChars: number;
|
|
417
|
+
maxAttributeChars: number;
|
|
418
|
+
maxAttributeCount: number;
|
|
419
|
+
maxStackChars: number;
|
|
420
|
+
maxDepth: number;
|
|
421
|
+
maxArrayLength: number;
|
|
422
|
+
maxRecordBytes: number;
|
|
423
|
+
};
|
|
@@ -23,16 +23,11 @@ export declare class BreadcrumbBuffer {
|
|
|
23
23
|
*/
|
|
24
24
|
private filled;
|
|
25
25
|
/** Maximum number of breadcrumbs retained in memory. */
|
|
26
|
-
private capacity;
|
|
26
|
+
private readonly capacity;
|
|
27
27
|
/**
|
|
28
28
|
* @param capacity Maximum breadcrumb capacity, clamped to minimum allowed size.
|
|
29
29
|
*/
|
|
30
30
|
constructor(capacity: number);
|
|
31
|
-
/**
|
|
32
|
-
* Resizes buffer capacity while preserving the newest breadcrumbs.
|
|
33
|
-
* @param capacity New maximum capacity.
|
|
34
|
-
*/
|
|
35
|
-
resize(capacity: number): void;
|
|
36
31
|
/**
|
|
37
32
|
* Appends a breadcrumb, overwriting the oldest entry when capacity is reached.
|
|
38
33
|
* @param crumb Breadcrumb event to append.
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/** Closed set of diagnostic event codes emitted by library subsystems. */
|
|
2
|
-
export type DiagnosticCode = "config.invalid" | "config.reconfigured" | "record.sanitize_failed" | "record.truncated" | "record.dropped_by_level" | "record.dropped_by_sampling" | "record.
|
|
2
|
+
export type DiagnosticCode = "config.invalid" | "config.reconfigured" | "record.sanitize_failed" | "record.truncated" | "record.dropped_by_level" | "record.dropped_by_sampling" | "record.dropped_by_ceiling" | "record.dropped_by_redact" | "record.dropped_boot_buffer_full" | "record.dropped_malformed" | "journey.expired" | "journey.adopted" | "journey.token_too_large" | "trace.otel_failed" | "bus.role_resolved" | "bus.no_owner" | "bus.handshake_timeout" | "bus.untrusted_origin" | "bus.send_failed" | "transport.http_error" | "transport.timeout" | "transport.batch_split" | "transport.throttled" | "transport.dropped_permanent" | "transport.rejected_credentials" | "transport.serialize_failed" | "storage.unavailable" | "storage.degraded" | "storage.quota_exceeded" | "storage.evicted" | "storage.dead_lettered" | "pipeline.crashed" | "capture.install_failed" | "capture.rate_limited" | "capture.header_failed" | "capture.record_failed" | "openfin.unavailable" | "handler.threw";
|
|
3
3
|
/** Diagnostic event payload dispatched to consumer handlers. */
|
|
4
4
|
export interface DiagnosticEvent {
|
|
5
5
|
/** Diagnostic fault code. */
|
package/dist/core/journey.d.ts
CHANGED
|
@@ -1,5 +1,15 @@
|
|
|
1
|
-
import type { JourneyOptions } from "../models/config";
|
|
2
1
|
import type { Diagnostics } from "./diagnostics";
|
|
2
|
+
/** Lifetime rules for a journey (one user task spanning several contexts). */
|
|
3
|
+
export interface JourneyOptions {
|
|
4
|
+
/** Max time a journey stays open before it is treated as abandoned, in milliseconds. */
|
|
5
|
+
maxAgeMs: number;
|
|
6
|
+
/** Whether closing the owning context ends the journey for everyone. */
|
|
7
|
+
endOnOwnerClose: boolean;
|
|
8
|
+
/** Query parameter checked at boot for a seeded journey token. */
|
|
9
|
+
urlParam: string;
|
|
10
|
+
}
|
|
11
|
+
/** Journey lifetime policy in force. Tests build an engine with shorter values. */
|
|
12
|
+
export declare const JOURNEY_OPTIONS: JourneyOptions;
|
|
3
13
|
/** User journey workflow context shared across windows and applications. */
|
|
4
14
|
export interface Journey {
|
|
5
15
|
/** Unique journey correlation identifier. */
|
package/dist/core/pipeline.d.ts
CHANGED
|
@@ -1,6 +1,4 @@
|
|
|
1
|
-
import { Subject } from "rxjs";
|
|
2
1
|
import type { LogBatch } from "../models/batch";
|
|
3
|
-
import type { ResolvedConfig } from "../models/config";
|
|
4
2
|
import { type LogRecord } from "../models/log-record";
|
|
5
3
|
import type { StorageAdapter } from "../models/storage";
|
|
6
4
|
import type { HttpTransport } from "../transport/http-transport";
|
|
@@ -8,36 +6,55 @@ import type { RetryEngine } from "../transport/retry-engine";
|
|
|
8
6
|
import type { Diagnostics } from "./diagnostics";
|
|
9
7
|
/** Pipeline stream classification for logs versus metrics. */
|
|
10
8
|
export type StreamName = "logs" | "metrics";
|
|
9
|
+
/** Batching policy for one record stream. */
|
|
10
|
+
export interface StreamOptions {
|
|
11
|
+
/** Max time a partial batch waits before it is sent, in milliseconds. */
|
|
12
|
+
flushIntervalMs: number;
|
|
13
|
+
/** Max records per batch before it is sent early. */
|
|
14
|
+
batchSize: number;
|
|
15
|
+
}
|
|
16
|
+
/** Batching policy per stream. Metrics batch harder: higher volume, nothing waits on them. */
|
|
17
|
+
export declare const STREAM_OPTIONS: Record<StreamName, StreamOptions>;
|
|
11
18
|
/** Pipeline orchestrating log and metric stream buffering, batch creation, and HTTP dispatch. */
|
|
12
19
|
export declare class LogPipeline {
|
|
13
|
-
private readonly config;
|
|
14
20
|
private readonly transport;
|
|
15
21
|
private readonly storage;
|
|
16
22
|
private readonly retry;
|
|
17
23
|
private readonly diagnostics;
|
|
18
|
-
/** Ingress Subject receiving records pushed into the pipeline. */
|
|
19
|
-
readonly records$: Subject<LogRecord>;
|
|
20
24
|
/** Buffer instances for logs and metrics streams. */
|
|
21
25
|
private readonly streams;
|
|
22
|
-
/** Active RxJS subscription managing the pipeline stream. */
|
|
23
|
-
private subscription;
|
|
24
26
|
/** Unconfirmed in-flight batches tracked for exit flush recovery. */
|
|
25
27
|
private readonly unconfirmed;
|
|
28
|
+
/** Closed batches waiting for a free dispatch slot. */
|
|
29
|
+
private readonly queue;
|
|
30
|
+
/** Ceiling on the ERROR and FATAL records that bypass sampling. */
|
|
31
|
+
private readonly ceiling;
|
|
32
|
+
/** Dispatches currently in flight, capped at MAX_CONCURRENT_REQUESTS. */
|
|
33
|
+
private inFlight;
|
|
34
|
+
/** Indicates a pump is already queued, so one microtask drains a burst. */
|
|
35
|
+
private pumpScheduled;
|
|
26
36
|
/** Indicates whether the pipeline has been destroyed. */
|
|
27
37
|
private stopped;
|
|
28
38
|
/**
|
|
29
|
-
* @param config Active configuration instance.
|
|
30
39
|
* @param transport HTTP transport for live batch delivery.
|
|
31
40
|
* @param storage Storage adapter for offline batch persistence.
|
|
32
41
|
* @param retry Retry engine for redelivering persisted batches.
|
|
33
42
|
* @param diagnostics Diagnostics reporter.
|
|
43
|
+
* @param streamOptions Batching policy per stream.
|
|
34
44
|
*/
|
|
35
|
-
constructor(
|
|
45
|
+
constructor(transport: HttpTransport, storage: StorageAdapter, retry: RetryEngine, diagnostics: Diagnostics, streamOptions?: Record<StreamName, StreamOptions>);
|
|
36
46
|
/**
|
|
37
47
|
* Stamps observed timestamp and enqueues a record into the pipeline.
|
|
38
48
|
* @param record Record to push.
|
|
39
49
|
*/
|
|
40
50
|
push(record: LogRecord): void;
|
|
51
|
+
/**
|
|
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
|
+
* @returns Combined LogBatch or null if no records are buffered.
|
|
56
|
+
*/
|
|
57
|
+
drainPending(): LogBatch | null;
|
|
41
58
|
/**
|
|
42
59
|
* Atomically drains all buffered and unconfirmed in-flight records into a single
|
|
43
60
|
* exit batch. Records already handed to fetch go out again under a new batch id,
|
|
@@ -45,26 +62,43 @@ export declare class LogPipeline {
|
|
|
45
62
|
* A document being closed cannot confirm delivery, so this is by design.
|
|
46
63
|
* @returns Combined LogBatch or null if no records are pending.
|
|
47
64
|
*/
|
|
48
|
-
|
|
49
|
-
/**
|
|
50
|
-
refresh(): void;
|
|
51
|
-
/** Terminates pipeline subscriptions and completes the ingress stream. */
|
|
65
|
+
drainForExit(): LogBatch | null;
|
|
66
|
+
/** Stops the flush timers and refuses further records. */
|
|
52
67
|
destroy(): void;
|
|
53
|
-
/** Assembles and subscribes the partitioned RxJS stream pipeline. */
|
|
54
|
-
private subscribe;
|
|
55
68
|
/**
|
|
56
|
-
*
|
|
57
|
-
* @param
|
|
58
|
-
* @
|
|
59
|
-
|
|
69
|
+
* Wraps drained records in a batch.
|
|
70
|
+
* @param records Records taken from the buffers, in delivery order.
|
|
71
|
+
* @returns New LogBatch, or null when nothing was drained.
|
|
72
|
+
*/
|
|
73
|
+
private toBatch;
|
|
74
|
+
/**
|
|
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
|
+
* @param record Record to sort.
|
|
60
80
|
*/
|
|
61
|
-
private
|
|
81
|
+
private route;
|
|
62
82
|
/**
|
|
63
|
-
* Drains
|
|
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.
|
|
64
86
|
* @param stream Stream buffer to drain.
|
|
65
|
-
* @returns Created LogBatch or null if stream was empty.
|
|
66
87
|
*/
|
|
67
88
|
private claim;
|
|
89
|
+
/**
|
|
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.
|
|
92
|
+
* @param batch Batch ready for delivery.
|
|
93
|
+
*/
|
|
94
|
+
private enqueue;
|
|
95
|
+
/** Starts queued dispatches up to the concurrency limit. */
|
|
96
|
+
private pump;
|
|
97
|
+
/**
|
|
98
|
+
* Delivers one batch and frees its concurrency slot.
|
|
99
|
+
* @param batch Batch to deliver.
|
|
100
|
+
*/
|
|
101
|
+
private run;
|
|
68
102
|
/**
|
|
69
103
|
* Sends a batch over HTTP transport or persists it to offline storage if throttled or failed.
|
|
70
104
|
* @param batch Batch to deliver.
|
package/dist/core/record.d.ts
CHANGED
|
@@ -2,6 +2,7 @@ import type { ResolvedConfig } from "../models/config";
|
|
|
2
2
|
import { type LogLevel, type LogRecord, type LogType } from "../models/log-record";
|
|
3
3
|
import type { Identity } from "../utils/identity";
|
|
4
4
|
import { type PlatformMetadata } from "../utils/platform";
|
|
5
|
+
import { type SanitizeLimits } from "../utils/sanitize";
|
|
5
6
|
import type { Sequence } from "../utils/sequence";
|
|
6
7
|
import type { TraceEngine } from "../utils/tracing";
|
|
7
8
|
import type { ContextStore } from "./context";
|
|
@@ -11,6 +12,8 @@ import type { JourneyEngine } from "./journey";
|
|
|
11
12
|
export interface RecordBuilderDeps {
|
|
12
13
|
/** Active configuration object reference. */
|
|
13
14
|
config: ResolvedConfig;
|
|
15
|
+
/** Per-record size caps. */
|
|
16
|
+
limits: RecordLimits;
|
|
14
17
|
/** Diagnostics reporter instance. */
|
|
15
18
|
diagnostics: Diagnostics;
|
|
16
19
|
/** Ambient context store. */
|
|
@@ -26,6 +29,13 @@ export interface RecordBuilderDeps {
|
|
|
26
29
|
/** Detected host platform metadata. */
|
|
27
30
|
platform: PlatformMetadata;
|
|
28
31
|
}
|
|
32
|
+
/** Per-record size caps, applied after sanitize and again after redact. */
|
|
33
|
+
export interface RecordLimits extends SanitizeLimits {
|
|
34
|
+
/** Max record body length, in characters. */
|
|
35
|
+
maxBodyChars: number;
|
|
36
|
+
/** Max total attribute bytes per record. */
|
|
37
|
+
maxRecordBytes: number;
|
|
38
|
+
}
|
|
29
39
|
/** Input parameters for constructing a single log record. */
|
|
30
40
|
export interface BuildInput {
|
|
31
41
|
/** Severity level of the log entry. */
|
package/dist/core/runtime.d.ts
CHANGED
|
@@ -120,7 +120,9 @@ export declare class ObservabilityRuntime {
|
|
|
120
120
|
*/
|
|
121
121
|
private forward;
|
|
122
122
|
/**
|
|
123
|
-
* Validates and enqueues records received from child frames or workers.
|
|
123
|
+
* Validates, samples and enqueues records received from child frames or workers.
|
|
124
|
+
* A forwarded record arrives built, so this is the first point in this context
|
|
125
|
+
* where sampling can run. A local record is sampled in RecordBuilder instead.
|
|
124
126
|
* @param records Inbound payload from bus.
|
|
125
127
|
*/
|
|
126
128
|
private ingestForwarded;
|
package/dist/core/sampling.d.ts
CHANGED
|
@@ -1,9 +1,50 @@
|
|
|
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. */
|
|
4
|
+
export interface SampleInput {
|
|
5
|
+
/** Severity level of the entry. */
|
|
6
|
+
level: string;
|
|
7
|
+
/** Telemetry type classification. */
|
|
8
|
+
type: string;
|
|
9
|
+
/** Originating application namespace. */
|
|
10
|
+
namespace: string;
|
|
11
|
+
/** Active journey id, empty when no journey is running. */
|
|
12
|
+
journeyId: string;
|
|
13
|
+
/** Trace id, the sampling key when no journey is running. */
|
|
14
|
+
traceId: string;
|
|
15
|
+
}
|
|
3
16
|
/**
|
|
4
|
-
* Evaluates whether
|
|
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.
|
|
20
|
+
* @param input Fields the sampling decision reads.
|
|
21
|
+
* @param config Active configuration instance.
|
|
22
|
+
* @returns True if the entry should be retained and transmitted.
|
|
23
|
+
*/
|
|
24
|
+
export declare function shouldSampleInput(input: SampleInput, config: ResolvedConfig): boolean;
|
|
25
|
+
/**
|
|
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.
|
|
5
28
|
* @param record Record to evaluate.
|
|
6
29
|
* @param config Active configuration instance.
|
|
7
30
|
* @returns True if the record should be retained and transmitted.
|
|
8
31
|
*/
|
|
9
32
|
export declare function shouldSample(record: LogRecord, config: ResolvedConfig): boolean;
|
|
33
|
+
/**
|
|
34
|
+
* Fixed-window ceiling on the ERROR and FATAL records that bypass sampling.
|
|
35
|
+
*
|
|
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.
|
|
38
|
+
*/
|
|
39
|
+
export declare class ErrorCeiling {
|
|
40
|
+
/** Start of the window currently counting, in epoch milliseconds. */
|
|
41
|
+
private windowStart;
|
|
42
|
+
/** ERROR and FATAL records admitted in the current window. */
|
|
43
|
+
private count;
|
|
44
|
+
/**
|
|
45
|
+
* Admits a record against the ceiling, counting only ERROR and FATAL.
|
|
46
|
+
* @param record Record about to enter a stream.
|
|
47
|
+
* @returns False when the window is spent and the record must be dropped.
|
|
48
|
+
*/
|
|
49
|
+
allow(record: LogRecord): boolean;
|
|
50
|
+
}
|