@utk09/ui-observability 0.9.2 → 0.9.4
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 +51 -0
- package/README.md +108 -33
- package/dist/batch-C4oF6XZT.cjs +2 -0
- package/dist/batch-C4oF6XZT.cjs.map +1 -0
- package/dist/{batch-4xKzzSCj.js → batch-D-4xl7op.js} +8 -5
- package/dist/batch-D-4xl7op.js.map +1 -0
- package/dist/bus/bus.d.ts +0 -4
- package/dist/{bus-DrixwdiX.js → bus-Cyvq-Ngx.js} +59 -62
- package/dist/bus-Cyvq-Ngx.js.map +1 -0
- package/dist/bus-rOhVuRee.cjs +2 -0
- package/dist/bus-rOhVuRee.cjs.map +1 -0
- package/dist/capture/network.d.ts +1 -0
- package/dist/capture/storm.d.ts +2 -7
- package/dist/capture/types.d.ts +3 -0
- package/dist/capture/web-socket.d.ts +40 -0
- package/dist/{console-B3vGRW5p.js → console-BT7mcgU6.js} +3 -3
- package/dist/{console-B3vGRW5p.js.map → console-BT7mcgU6.js.map} +1 -1
- package/dist/{console-ChfuJlf9.cjs → console-Boqa7new.cjs} +2 -2
- package/dist/{console-ChfuJlf9.cjs.map → console-Boqa7new.cjs.map} +1 -1
- package/dist/constants-BgRS6MB0.cjs +2 -0
- package/dist/constants-BgRS6MB0.cjs.map +1 -0
- package/dist/constants-L_d5YvvQ.js +160 -0
- package/dist/constants-L_d5YvvQ.js.map +1 -0
- package/dist/constants.d.ts +36 -5
- package/dist/core/breadcrumbs.d.ts +4 -4
- package/dist/core/context.d.ts +0 -8
- package/dist/core/diagnostics.d.ts +1 -3
- package/dist/core/journey.d.ts +7 -0
- package/dist/core/meter.d.ts +19 -1
- package/dist/core/pipeline.d.ts +12 -4
- package/dist/core/record.d.ts +40 -8
- package/dist/core/remote-sampling.d.ts +7 -3
- package/dist/core/runtime.d.ts +62 -3
- package/dist/core/sampling.d.ts +33 -4
- package/dist/core/sender.d.ts +8 -0
- package/dist/core/spans.d.ts +34 -0
- package/dist/{errors-BGs5NOrw.js → errors-BDI96zKc.js} +6 -6
- package/dist/errors-BDI96zKc.js.map +1 -0
- package/dist/errors-_xEsCVXn.cjs +3 -0
- package/dist/errors-_xEsCVXn.cjs.map +1 -0
- package/dist/fixed-window-BR0bu32Y.cjs +2 -0
- package/dist/fixed-window-BR0bu32Y.cjs.map +1 -0
- package/dist/fixed-window-Re7jIRJH.js +9 -0
- package/dist/fixed-window-Re7jIRJH.js.map +1 -0
- package/dist/identity-Bwku7zzN.cjs +2 -0
- package/dist/identity-Bwku7zzN.cjs.map +1 -0
- package/dist/{identity-rpEyjvVg.js → identity-Dtv917nz.js} +33 -23
- package/dist/identity-Dtv917nz.js.map +1 -0
- package/dist/index.cjs +1 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +23 -1
- package/dist/index.js +804 -537
- package/dist/index.js.map +1 -1
- package/dist/indexeddb-storage-Cvavrf-y.cjs +2 -0
- package/dist/indexeddb-storage-Cvavrf-y.cjs.map +1 -0
- package/dist/{indexeddb-storage-Q9fDYlyn.js → indexeddb-storage-HgkQUTyS.js} +57 -68
- package/dist/indexeddb-storage-HgkQUTyS.js.map +1 -0
- package/dist/{interactions-BAGRmtrv.cjs → interactions-Bhe1ft8P.cjs} +2 -2
- package/dist/interactions-Bhe1ft8P.cjs.map +1 -0
- package/dist/{interactions-B8zjCjga.js → interactions-Ck01cEij.js} +3 -3
- package/dist/interactions-Ck01cEij.js.map +1 -0
- package/dist/journey-Co9OlzrW.cjs +2 -0
- package/dist/journey-Co9OlzrW.cjs.map +1 -0
- package/dist/{journey-_dQQ1eMP.js → journey-DRK0A8u_.js} +37 -33
- package/dist/journey-DRK0A8u_.js.map +1 -0
- package/dist/{library-request-DX6ev9oG.js → library-request-ChCar5F8.js} +3 -3
- package/dist/{library-request-DX6ev9oG.js.map → library-request-ChCar5F8.js.map} +1 -1
- package/dist/{library-request-BIG3Xpx3.cjs → library-request-gMFOCNcn.cjs} +2 -2
- package/dist/{library-request-BIG3Xpx3.cjs.map → library-request-gMFOCNcn.cjs.map} +1 -1
- package/dist/log-record-cwFiLyPY.js +17 -0
- package/dist/log-record-cwFiLyPY.js.map +1 -0
- package/dist/log-record-jX9eWUP8.cjs +2 -0
- package/dist/log-record-jX9eWUP8.cjs.map +1 -0
- package/dist/{long-frames-Cq2LgNnp.cjs → long-frames-Bky6nZDF.cjs} +2 -2
- package/dist/long-frames-Bky6nZDF.cjs.map +1 -0
- package/dist/{long-frames-B0tKuChx.js → long-frames-DDumopji.js} +4 -4
- package/dist/long-frames-DDumopji.js.map +1 -0
- package/dist/models/batch.d.ts +6 -0
- package/dist/models/config.d.ts +56 -5
- package/dist/models/log-record.d.ts +1 -1
- package/dist/models/plugin.d.ts +47 -0
- package/dist/models/stats.d.ts +11 -0
- package/dist/{network-CMnEvGJB.js → network-BsBZ6_-Q.js} +43 -29
- package/dist/network-BsBZ6_-Q.js.map +1 -0
- package/dist/network-_4csBGBM.cjs +2 -0
- package/dist/network-_4csBGBM.cjs.map +1 -0
- package/dist/openfin-BwEN0uj4.js +8 -0
- package/dist/openfin-BwEN0uj4.js.map +1 -0
- package/dist/openfin-DtH2f7zX.cjs +2 -0
- package/dist/openfin-DtH2f7zX.cjs.map +1 -0
- package/dist/platform-4yYjMD-B.js +57 -0
- package/dist/platform-4yYjMD-B.js.map +1 -0
- package/dist/platform-o7r1ocOu.cjs +2 -0
- package/dist/platform-o7r1ocOu.cjs.map +1 -0
- package/dist/remote-rules-1KqfVBIu.js +91 -0
- package/dist/remote-rules-1KqfVBIu.js.map +1 -0
- package/dist/remote-rules-BHgEGlYi.cjs +2 -0
- package/dist/remote-rules-BHgEGlYi.cjs.map +1 -0
- package/dist/sampling-C4my-ma0.cjs +2 -0
- package/dist/sampling-C4my-ma0.cjs.map +1 -0
- package/dist/sampling-nYIWP_vP.js +86 -0
- package/dist/sampling-nYIWP_vP.js.map +1 -0
- package/dist/{sanitize-BNwgPj_B.js → sanitize-BiUKCUG6.js} +2 -2
- package/dist/{sanitize-BNwgPj_B.js.map → sanitize-BiUKCUG6.js.map} +1 -1
- package/dist/{sanitize-BqzPc4Jg.cjs → sanitize-BxuPSXOk.cjs} +2 -2
- package/dist/{sanitize-BqzPc4Jg.cjs.map → sanitize-BxuPSXOk.cjs.map} +1 -1
- package/dist/sender-6vrT9fFL.cjs +3 -0
- package/dist/sender-6vrT9fFL.cjs.map +1 -0
- package/dist/{sender--0_VzPbN.js → sender-DFQMF39P.js} +380 -278
- package/dist/sender-DFQMF39P.js.map +1 -0
- package/dist/storage/gap.d.ts +20 -0
- package/dist/storage/indexeddb-storage.d.ts +1 -7
- package/dist/storage/keys.d.ts +9 -0
- package/dist/storage/local-storage.d.ts +0 -6
- package/dist/storage/memory-storage.d.ts +1 -1
- package/dist/storm-6YYbXzT_.cjs +2 -0
- package/dist/storm-6YYbXzT_.cjs.map +1 -0
- package/dist/storm-CfO0Sam2.js +10 -0
- package/dist/storm-CfO0Sam2.js.map +1 -0
- package/dist/transport/exit-flush.d.ts +6 -0
- package/dist/transport/http-transport.d.ts +2 -1
- package/dist/transport/serializers/otlp-traces.d.ts +3 -0
- package/dist/transport/serializers/select.d.ts +8 -5
- package/dist/transport/status-transport.d.ts +7 -0
- package/dist/types-BR9t_w28.js +8 -0
- package/dist/types-BR9t_w28.js.map +1 -0
- package/dist/types-C7WNpnG1.cjs +2 -0
- package/dist/types-C7WNpnG1.cjs.map +1 -0
- package/dist/utils/fixed-window.d.ts +15 -0
- package/dist/utils/guards.d.ts +6 -0
- package/dist/utils/identity.d.ts +11 -0
- package/dist/utils/openfin.d.ts +48 -0
- package/dist/utils/platform.d.ts +13 -0
- package/dist/utils/tracing.d.ts +82 -4
- package/dist/web-socket-Ar4cZxmd.js +102 -0
- package/dist/web-socket-Ar4cZxmd.js.map +1 -0
- package/dist/web-socket-BwJdwSHl.cjs +2 -0
- package/dist/web-socket-BwJdwSHl.cjs.map +1 -0
- package/package.json +2 -3
- package/dist/batch-4xKzzSCj.js.map +0 -1
- package/dist/batch-cys7e53Q.cjs +0 -2
- package/dist/batch-cys7e53Q.cjs.map +0 -1
- package/dist/bus-B6vzPmQM.cjs +0 -2
- package/dist/bus-B6vzPmQM.cjs.map +0 -1
- package/dist/bus-DrixwdiX.js.map +0 -1
- package/dist/constants-Be83LICb.cjs +0 -2
- package/dist/constants-Be83LICb.cjs.map +0 -1
- package/dist/constants-CQ_D7jIW.js +0 -144
- package/dist/constants-CQ_D7jIW.js.map +0 -1
- package/dist/deadline-5_PecIl5.js +0 -26
- package/dist/deadline-5_PecIl5.js.map +0 -1
- package/dist/deadline-XSnm95pg.cjs +0 -2
- package/dist/deadline-XSnm95pg.cjs.map +0 -1
- package/dist/errors-BGs5NOrw.js.map +0 -1
- package/dist/errors-BMJm7KZZ.cjs +0 -3
- package/dist/errors-BMJm7KZZ.cjs.map +0 -1
- package/dist/identity-DXyV86o-.cjs +0 -2
- package/dist/identity-DXyV86o-.cjs.map +0 -1
- package/dist/identity-rpEyjvVg.js.map +0 -1
- package/dist/indexeddb-storage-BXaPVPyG.cjs +0 -2
- package/dist/indexeddb-storage-BXaPVPyG.cjs.map +0 -1
- package/dist/indexeddb-storage-Q9fDYlyn.js.map +0 -1
- package/dist/interactions-B8zjCjga.js.map +0 -1
- package/dist/interactions-BAGRmtrv.cjs.map +0 -1
- package/dist/journey-BGSyy8Es.cjs +0 -2
- package/dist/journey-BGSyy8Es.cjs.map +0 -1
- package/dist/journey-_dQQ1eMP.js.map +0 -1
- package/dist/long-frames-B0tKuChx.js.map +0 -1
- package/dist/long-frames-Cq2LgNnp.cjs.map +0 -1
- package/dist/network-C6kJbW6K.cjs +0 -2
- package/dist/network-C6kJbW6K.cjs.map +0 -1
- package/dist/network-CMnEvGJB.js.map +0 -1
- package/dist/platform-DNOJjpOm.cjs +0 -2
- package/dist/platform-DNOJjpOm.cjs.map +0 -1
- package/dist/platform-j0uMPwHi.js +0 -48
- package/dist/platform-j0uMPwHi.js.map +0 -1
- package/dist/remote-rules-DgoBJxZL.cjs +0 -2
- package/dist/remote-rules-DgoBJxZL.cjs.map +0 -1
- package/dist/remote-rules-UggoZqfP.js +0 -86
- package/dist/remote-rules-UggoZqfP.js.map +0 -1
- package/dist/sampling-BLMD8EGM.js +0 -64
- package/dist/sampling-BLMD8EGM.js.map +0 -1
- package/dist/sampling-MthcVXXU.cjs +0 -2
- package/dist/sampling-MthcVXXU.cjs.map +0 -1
- package/dist/sender--0_VzPbN.js.map +0 -1
- package/dist/sender-SPGMqZjD.cjs +0 -3
- package/dist/sender-SPGMqZjD.cjs.map +0 -1
- package/dist/storm-CTy1dfvs.cjs +0 -2
- package/dist/storm-CTy1dfvs.cjs.map +0 -1
- package/dist/storm-knaj4GUH.js +0 -10
- package/dist/storm-knaj4GUH.js.map +0 -1
|
@@ -12,7 +12,8 @@ export declare class HttpTransport extends StatusTransport {
|
|
|
12
12
|
*/
|
|
13
13
|
private cachedHeaders;
|
|
14
14
|
/**
|
|
15
|
-
* Sends one log batch over HTTP. A metrics batch goes to metricsEndpoint.
|
|
15
|
+
* Sends one log batch over HTTP. A metrics batch goes to metricsEndpoint. A traces batch goes to
|
|
16
|
+
* tracesEndpoint. A batch without an endpoint goes nowhere.
|
|
16
17
|
* @param batch Batch to send.
|
|
17
18
|
* @param onKeepalive Runs when a request of the batch starts with keepalive.
|
|
18
19
|
* @throws TransportError on transient, throttled, 413, or permanent network failures.
|
|
@@ -9,23 +9,26 @@ import type { LogSerializer, SerializedBatch } from "../../models/serializer";
|
|
|
9
9
|
*/
|
|
10
10
|
export declare function serializerFor(choice: SerializerChoice): LogSerializer;
|
|
11
11
|
/**
|
|
12
|
-
* Gives the kind of a batch. Only a batch of metric records goes to metricsEndpoint. A
|
|
13
|
-
*
|
|
12
|
+
* Gives the kind of a batch. Only a batch of metric records goes to metricsEndpoint. A batch of
|
|
13
|
+
* span records is always "traces". It must not go to endpoint as log records. A stored record
|
|
14
|
+
* can be corrupt. It then is not a metric or a span.
|
|
14
15
|
* @param batch Batch to test.
|
|
15
16
|
* @param config Active configuration.
|
|
16
|
-
* @returns "metrics" with metricsEndpoint set and only metric records,
|
|
17
|
+
* @returns "metrics" with metricsEndpoint set and only metric records, "traces" for only span
|
|
18
|
+
* records, else "logs".
|
|
17
19
|
*/
|
|
18
20
|
export declare function batchKind(batch: LogBatch, config: ResolvedConfig): BatchKind;
|
|
19
21
|
/**
|
|
20
22
|
* Gives the endpoint of a batch kind.
|
|
21
23
|
* @param kind Kind of the batch.
|
|
22
24
|
* @param config Active configuration.
|
|
23
|
-
* @returns metricsEndpoint for a metrics batch, else
|
|
25
|
+
* @returns metricsEndpoint for a metrics batch, tracesEndpoint for a traces batch, else
|
|
26
|
+
* endpoint. "" means that the batch has no destination.
|
|
24
27
|
*/
|
|
25
28
|
export declare function endpointFor(kind: BatchKind, config: ResolvedConfig): string | null;
|
|
26
29
|
/**
|
|
27
30
|
* Serializes a batch. It reports a serializer that throws, and the caller drops the batch.
|
|
28
|
-
* A metrics batch gets the OTLP metrics format.
|
|
31
|
+
* A metrics batch gets the OTLP metrics format. A traces batch gets the OTLP traces format.
|
|
29
32
|
* @param config Active configuration.
|
|
30
33
|
* @param batch Batch to serialize.
|
|
31
34
|
* @param diagnostics Diagnostics reporter.
|
|
@@ -40,6 +40,8 @@ export declare abstract class StatusTransport implements BatchTransport {
|
|
|
40
40
|
* metricsEndpoint must not stop the log batches.
|
|
41
41
|
*/
|
|
42
42
|
private readonly throttledUntil;
|
|
43
|
+
/** Epoch time in milliseconds when the server last accepted a batch, or null. */
|
|
44
|
+
private acceptedAt;
|
|
43
45
|
/**
|
|
44
46
|
* @param config Active configuration instance.
|
|
45
47
|
* @param diagnostics Diagnostics reporter.
|
|
@@ -60,6 +62,11 @@ export declare abstract class StatusTransport implements BatchTransport {
|
|
|
60
62
|
* @returns Milliseconds remaining in throttle window, or 0 if unthrottled.
|
|
61
63
|
*/
|
|
62
64
|
throttledForMs(batch: LogBatch): number;
|
|
65
|
+
/**
|
|
66
|
+
* Returns the time when the server last accepted a batch.
|
|
67
|
+
* @returns Epoch time in milliseconds, or null before the first accepted batch.
|
|
68
|
+
*/
|
|
69
|
+
lastSendAt(): number | null;
|
|
63
70
|
/**
|
|
64
71
|
* Serializes a batch with the configured serializer. A metrics batch gets the OTLP metrics
|
|
65
72
|
* format. It reports a serializer that throws.
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types-BR9t_w28.js","names":["matchesAny","url","patterns","pattern"],"sources":["../src/capture/types.ts"],"sourcesContent":["// src/capture/types.ts\n//\n// Shared interfaces, logger abstractions, and utility helpers for auto-capture modules.\n\nimport type { BreadcrumbBuffer } from \"../core/breadcrumbs\";\nimport type { Diagnostics } from \"../core/diagnostics\";\nimport type { SpanData } from \"../core/spans\";\nimport type { ResolvedConfig } from \"../models/config\";\nimport type { MetricType } from \"../models/log-record\";\nimport type { InstrumentDef, MetricAttributes } from \"../models/metric\";\nimport type { TraceEngine } from \"../utils/tracing\";\n\n/**\n * Logging interface that auto-capture modules use. A reference to the runtime class\n * here causes an import cycle. The runtime installs the capture modules.\n */\nexport interface CaptureLogger {\n /**\n * Logs an error event with an associated error instance or reason.\n * @param message Error description.\n * @param error Caught error instance or reason.\n * @param payload Optional attributes.\n */\n error(message: string, error?: unknown, payload?: Record<string, unknown>): void;\n\n /**\n * Logs a warning event.\n * @param message Warning description.\n * @param payload Optional attributes.\n */\n warn(message: string, payload?: Record<string, unknown>): void;\n\n /**\n * Logs a discrete lifecycle or user event.\n * @param name Event identifier.\n * @param payload Optional attributes.\n */\n logEvent(name: string, payload?: Record<string, unknown>): void;\n\n /**\n * Logs a numerical metric measurement.\n * @param name Metric name.\n * @param value Numerical measurement.\n * @param unit Unit of measurement.\n * @param type Metric type classification.\n * @param attrs Optional metric attributes.\n */\n logMetric(\n name: string,\n value: number,\n unit?: string,\n type?: MetricType,\n attrs?: Record<string, unknown>,\n ): void;\n\n /**\n * Logs a diagnostic debug message.\n * @param message Debug message.\n * @param payload Optional attributes.\n */\n debug(message: string, payload?: Record<string, unknown>): void;\n}\n\n/**\n * Capture work that runs one time for each document, not one time for each\n * install. A reconfigure builds new capture instances. Thus instance state\n * cannot hold these flags. web-vitals has no unsubscribe. A second subscription\n * reports each metric two times.\n */\nexport interface CaptureOnce {\n /** True after the library subscribes the web-vitals reporters. */\n webVitals: boolean;\n /** True after the library reports navigation timing. */\n navigationTiming: boolean;\n /** True after the first long frame install. Only that install reads buffered frames. */\n longFrames: boolean;\n}\n\n/** Shared runtime dependencies provided to auto-capture instances. */\nexport interface CaptureContext {\n /** Active runtime configuration. */\n config: ResolvedConfig;\n /** Diagnostics reporter for capture faults. */\n diagnostics: Diagnostics;\n /** Logger instance for recorded telemetry. */\n logger: CaptureLogger;\n /** Buffer for recording contextual breadcrumbs. */\n breadcrumbs: BreadcrumbBuffer;\n /** Active trace context provider. */\n tracing: TraceEngine;\n /** Guards for the capture work that a reinstall must not repeat. */\n once: CaptureOnce;\n /** Adds a value to a counter or a histogram of the runtime. */\n recordMetric: (def: InstrumentDef, value: number, attributes?: MetricAttributes) => void;\n /** Records a span. The runtime drops it when spans are off. */\n recordSpan: (span: SpanData) => void;\n}\n\n/** Lifecycle interface for browser instrumentation modules. */\nexport interface Capture {\n /** Module identifier used in diagnostics. */\n readonly name: string;\n /**\n * Attaches instrumentation listeners and patches target APIs. A second patch on a\n * patched function adds a second wrapper and doubles each record. A second call\n * must do nothing.\n */\n install(): void;\n /** Restores native APIs and removes registered listeners. */\n uninstall(): void;\n}\n\n/**\n * Tests if a URL matches any string substring or regular expression pattern.\n * @param url Target URL to test. A value that is not a string matches nothing.\n * @param patterns Substrings and regular expressions to test against.\n * @returns True if any pattern matches the URL.\n */\nexport function matchesAny(url: unknown, patterns: (string | RegExp)[]): boolean {\n // Guard against a URL that is not a string. includes() on it throws in the call of the host.\n if (typeof url !== \"string\") {\n return false;\n }\n\n return patterns.some((pattern) =>\n typeof pattern === \"string\" ? url.includes(pattern) : pattern.test(url),\n );\n}\n"],"mappings":";AAsHA,SAAgBA,EAAW,GAAc,GAAwC;CAM/E,OAJI,OAAOC,KAAQ,YAIZC,EAAS,MAAM,MACpB,OAAOC,KAAY,WAAWF,EAAI,SAASE,CAAO,IAAIA,EAAQ,KAAKF,CAAG,CACxE;AACF"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types-C7WNpnG1.cjs","names":["matchesAny","url","patterns","pattern"],"sources":["../src/capture/types.ts"],"sourcesContent":["// src/capture/types.ts\n//\n// Shared interfaces, logger abstractions, and utility helpers for auto-capture modules.\n\nimport type { BreadcrumbBuffer } from \"../core/breadcrumbs\";\nimport type { Diagnostics } from \"../core/diagnostics\";\nimport type { SpanData } from \"../core/spans\";\nimport type { ResolvedConfig } from \"../models/config\";\nimport type { MetricType } from \"../models/log-record\";\nimport type { InstrumentDef, MetricAttributes } from \"../models/metric\";\nimport type { TraceEngine } from \"../utils/tracing\";\n\n/**\n * Logging interface that auto-capture modules use. A reference to the runtime class\n * here causes an import cycle. The runtime installs the capture modules.\n */\nexport interface CaptureLogger {\n /**\n * Logs an error event with an associated error instance or reason.\n * @param message Error description.\n * @param error Caught error instance or reason.\n * @param payload Optional attributes.\n */\n error(message: string, error?: unknown, payload?: Record<string, unknown>): void;\n\n /**\n * Logs a warning event.\n * @param message Warning description.\n * @param payload Optional attributes.\n */\n warn(message: string, payload?: Record<string, unknown>): void;\n\n /**\n * Logs a discrete lifecycle or user event.\n * @param name Event identifier.\n * @param payload Optional attributes.\n */\n logEvent(name: string, payload?: Record<string, unknown>): void;\n\n /**\n * Logs a numerical metric measurement.\n * @param name Metric name.\n * @param value Numerical measurement.\n * @param unit Unit of measurement.\n * @param type Metric type classification.\n * @param attrs Optional metric attributes.\n */\n logMetric(\n name: string,\n value: number,\n unit?: string,\n type?: MetricType,\n attrs?: Record<string, unknown>,\n ): void;\n\n /**\n * Logs a diagnostic debug message.\n * @param message Debug message.\n * @param payload Optional attributes.\n */\n debug(message: string, payload?: Record<string, unknown>): void;\n}\n\n/**\n * Capture work that runs one time for each document, not one time for each\n * install. A reconfigure builds new capture instances. Thus instance state\n * cannot hold these flags. web-vitals has no unsubscribe. A second subscription\n * reports each metric two times.\n */\nexport interface CaptureOnce {\n /** True after the library subscribes the web-vitals reporters. */\n webVitals: boolean;\n /** True after the library reports navigation timing. */\n navigationTiming: boolean;\n /** True after the first long frame install. Only that install reads buffered frames. */\n longFrames: boolean;\n}\n\n/** Shared runtime dependencies provided to auto-capture instances. */\nexport interface CaptureContext {\n /** Active runtime configuration. */\n config: ResolvedConfig;\n /** Diagnostics reporter for capture faults. */\n diagnostics: Diagnostics;\n /** Logger instance for recorded telemetry. */\n logger: CaptureLogger;\n /** Buffer for recording contextual breadcrumbs. */\n breadcrumbs: BreadcrumbBuffer;\n /** Active trace context provider. */\n tracing: TraceEngine;\n /** Guards for the capture work that a reinstall must not repeat. */\n once: CaptureOnce;\n /** Adds a value to a counter or a histogram of the runtime. */\n recordMetric: (def: InstrumentDef, value: number, attributes?: MetricAttributes) => void;\n /** Records a span. The runtime drops it when spans are off. */\n recordSpan: (span: SpanData) => void;\n}\n\n/** Lifecycle interface for browser instrumentation modules. */\nexport interface Capture {\n /** Module identifier used in diagnostics. */\n readonly name: string;\n /**\n * Attaches instrumentation listeners and patches target APIs. A second patch on a\n * patched function adds a second wrapper and doubles each record. A second call\n * must do nothing.\n */\n install(): void;\n /** Restores native APIs and removes registered listeners. */\n uninstall(): void;\n}\n\n/**\n * Tests if a URL matches any string substring or regular expression pattern.\n * @param url Target URL to test. A value that is not a string matches nothing.\n * @param patterns Substrings and regular expressions to test against.\n * @returns True if any pattern matches the URL.\n */\nexport function matchesAny(url: unknown, patterns: (string | RegExp)[]): boolean {\n // Guard against a URL that is not a string. includes() on it throws in the call of the host.\n if (typeof url !== \"string\") {\n return false;\n }\n\n return patterns.some((pattern) =>\n typeof pattern === \"string\" ? url.includes(pattern) : pattern.test(url),\n );\n}\n"],"mappings":"AAsHA,SAAgBA,EAAW,EAAc,EAAwC,CAM/E,OAJI,OAAOC,GAAQ,UAIZC,EAAS,KAAM,GACpB,OAAOC,GAAY,SAAWF,EAAI,SAASE,CAAO,EAAIA,EAAQ,KAAKF,CAAG,CACxE,CACF"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/** State of one fixed window. Counters that share a limit share one object. */
|
|
2
|
+
export interface StormWindow {
|
|
3
|
+
/** Start of the current window, in epoch milliseconds. */
|
|
4
|
+
start: number;
|
|
5
|
+
/** Events counted in the current window. */
|
|
6
|
+
count: number;
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* Counts one event in a fixed window.
|
|
10
|
+
* @param window Window state to change.
|
|
11
|
+
* @param limit Maximum events in each window.
|
|
12
|
+
* @param windowMs Length of the window, in milliseconds.
|
|
13
|
+
* @returns False when the window has no allowance left. The caller must drop the event.
|
|
14
|
+
*/
|
|
15
|
+
export declare function countInWindow(window: StormWindow, limit: number, windowMs: number): boolean;
|
package/dist/utils/identity.d.ts
CHANGED
|
@@ -89,4 +89,15 @@ export declare class SessionTouch {
|
|
|
89
89
|
* @param sessionId Active session identifier.
|
|
90
90
|
*/
|
|
91
91
|
touch(sessionId: string): void;
|
|
92
|
+
/**
|
|
93
|
+
* Writes a new session id to the local store now. The throttle does not apply.
|
|
94
|
+
* @param sessionId New session identifier.
|
|
95
|
+
*/
|
|
96
|
+
restart(sessionId: string): void;
|
|
97
|
+
/**
|
|
98
|
+
* Writes the session record and starts a new throttle window.
|
|
99
|
+
* @param sessionId Session identifier.
|
|
100
|
+
* @param now Epoch time in milliseconds.
|
|
101
|
+
*/
|
|
102
|
+
private write;
|
|
92
103
|
}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
/** The InterApplicationBus operations that the bus link uses. */
|
|
2
|
+
export interface FinIab {
|
|
3
|
+
/**
|
|
4
|
+
* Publishes a message to all topic subscribers.
|
|
5
|
+
* @param topic Topic name.
|
|
6
|
+
* @param message Message payload.
|
|
7
|
+
*/
|
|
8
|
+
publish(topic: string, message: unknown): Promise<void>;
|
|
9
|
+
/**
|
|
10
|
+
* Subscribes a listener to a topic for matching application identities.
|
|
11
|
+
* @param identity Target application identity.
|
|
12
|
+
* @param topic Topic name.
|
|
13
|
+
* @param listener Message callback.
|
|
14
|
+
*/
|
|
15
|
+
subscribe(identity: {
|
|
16
|
+
uuid: string;
|
|
17
|
+
}, topic: string, listener: (message: unknown) => void): Promise<void>;
|
|
18
|
+
}
|
|
19
|
+
/** The members of fin.me that the library reads. */
|
|
20
|
+
export interface FinMe {
|
|
21
|
+
/** True in an OpenFin view. */
|
|
22
|
+
isView?: boolean;
|
|
23
|
+
/** Identity of the window or view. */
|
|
24
|
+
identity?: {
|
|
25
|
+
uuid?: string;
|
|
26
|
+
name?: string;
|
|
27
|
+
};
|
|
28
|
+
/** Resolves the creation options of the window, with customData. */
|
|
29
|
+
getOptions?: () => Promise<{
|
|
30
|
+
customData?: Record<string, unknown>;
|
|
31
|
+
}>;
|
|
32
|
+
/** Adds a window event listener. */
|
|
33
|
+
on?: (event: string, listener: () => void) => void;
|
|
34
|
+
/** Removes a window event listener. */
|
|
35
|
+
removeListener?: (event: string, listener: () => void) => void;
|
|
36
|
+
}
|
|
37
|
+
/** The members of the OpenFin global that the library reads. */
|
|
38
|
+
export interface FinLike {
|
|
39
|
+
/** The window or view of this document. */
|
|
40
|
+
me?: FinMe;
|
|
41
|
+
/** The message bus of the OpenFin runtime. */
|
|
42
|
+
InterApplicationBus?: FinIab;
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Gives the OpenFin global.
|
|
46
|
+
* @returns The fin global, or undefined outside OpenFin.
|
|
47
|
+
*/
|
|
48
|
+
export declare function getFin(): FinLike | undefined;
|
package/dist/utils/platform.d.ts
CHANGED
|
@@ -34,6 +34,14 @@ export declare function isTopLevel(diagnostics: Diagnostics): boolean;
|
|
|
34
34
|
* @returns Current location.href or empty string.
|
|
35
35
|
*/
|
|
36
36
|
export declare function currentUrl(diagnostics: Diagnostics): string;
|
|
37
|
+
/**
|
|
38
|
+
* Gives the form of a URL that the library records. It always removes the user info, which is a
|
|
39
|
+
* credential. Without fullUrls, it also removes the query and the fragment.
|
|
40
|
+
* @param url Absolute or relative URL.
|
|
41
|
+
* @param fullUrls Value of `capture.fullUrls`.
|
|
42
|
+
* @returns The URL to record.
|
|
43
|
+
*/
|
|
44
|
+
export declare function recordedUrl(url: string, fullUrls: boolean): string;
|
|
37
45
|
/**
|
|
38
46
|
* Drops the query string and fragment from a URL.
|
|
39
47
|
* It cuts the string and does not parse a URL. A relative request target has no base URL.
|
|
@@ -41,5 +49,10 @@ export declare function currentUrl(diagnostics: Diagnostics): string;
|
|
|
41
49
|
* @returns The URL up to the first "?" or "#".
|
|
42
50
|
*/
|
|
43
51
|
export declare function stripUrlQuery(url: string): string;
|
|
52
|
+
/**
|
|
53
|
+
* Tests if the browser can reach the network. A host without navigator.onLine counts as online.
|
|
54
|
+
* @returns False only when navigator.onLine is false.
|
|
55
|
+
*/
|
|
56
|
+
export declare function isOnline(): boolean;
|
|
44
57
|
/** Resets the cached platform metadata for testing. */
|
|
45
58
|
export declare function resetPlatformCache(): void;
|
package/dist/utils/tracing.d.ts
CHANGED
|
@@ -11,6 +11,54 @@ export interface TraceContext {
|
|
|
11
11
|
}
|
|
12
12
|
/** Cause of a rotation of the ambient trace context. */
|
|
13
13
|
export type RotateReason = "start" | "interaction" | "navigation" | "explicit" | "maxAge";
|
|
14
|
+
/** Ambient trace that ended. Its root span covers it. */
|
|
15
|
+
export interface EndedTrace {
|
|
16
|
+
/** Trace ID. */
|
|
17
|
+
traceId: string;
|
|
18
|
+
/** Span ID of the root span. */
|
|
19
|
+
spanId: string;
|
|
20
|
+
/** Cause of the start of the trace. */
|
|
21
|
+
reason: RotateReason;
|
|
22
|
+
/** Start time in epoch milliseconds. */
|
|
23
|
+
startedAt: number;
|
|
24
|
+
/** End time in epoch milliseconds. */
|
|
25
|
+
endedAt: number;
|
|
26
|
+
}
|
|
27
|
+
/** Client span that a traceparent header names. */
|
|
28
|
+
export interface ClientSpan {
|
|
29
|
+
/** Trace ID. */
|
|
30
|
+
traceId: string;
|
|
31
|
+
/** Span ID of the client span. */
|
|
32
|
+
spanId: string;
|
|
33
|
+
/** Span ID of the root span of the trace. */
|
|
34
|
+
parentSpanId: string;
|
|
35
|
+
}
|
|
36
|
+
/** Headers of one request, and the client span that they name. */
|
|
37
|
+
export interface RequestTrace {
|
|
38
|
+
/** Header map containing traceparent. */
|
|
39
|
+
headers: Record<string, string>;
|
|
40
|
+
/** Client span of the request. It is undefined when the library records no span for it. */
|
|
41
|
+
span?: ClientSpan;
|
|
42
|
+
}
|
|
43
|
+
/** Span decisions of the runtime. */
|
|
44
|
+
export interface SpanHooks {
|
|
45
|
+
/**
|
|
46
|
+
* Tests if the library records spans.
|
|
47
|
+
* @returns True with a traces endpoint.
|
|
48
|
+
*/
|
|
49
|
+
enabled(): boolean;
|
|
50
|
+
/**
|
|
51
|
+
* Tests if sampling keeps the spans of a trace.
|
|
52
|
+
* @param traceId Trace ID.
|
|
53
|
+
* @returns True if the library sends the spans of the trace.
|
|
54
|
+
*/
|
|
55
|
+
keeps(traceId: string): boolean;
|
|
56
|
+
/**
|
|
57
|
+
* Receives an ambient trace that ended.
|
|
58
|
+
* @param ended The trace.
|
|
59
|
+
*/
|
|
60
|
+
onEnd(ended: EndedTrace): void;
|
|
61
|
+
}
|
|
14
62
|
/**
|
|
15
63
|
* Generates a random 32-character hex string in the W3C trace ID format.
|
|
16
64
|
* Use it to start your own trace. The backend drops an id with the wrong width
|
|
@@ -28,6 +76,7 @@ export declare class TraceEngine {
|
|
|
28
76
|
private readonly diagnostics;
|
|
29
77
|
private readonly maxAgeMs;
|
|
30
78
|
private readonly load?;
|
|
79
|
+
private readonly spans?;
|
|
31
80
|
/**
|
|
32
81
|
* Active ambient trace context. The instance keeps this state, not the module. Two
|
|
33
82
|
* runtimes in one document must not share a trace id.
|
|
@@ -40,8 +89,9 @@ export declare class TraceEngine {
|
|
|
40
89
|
* @param maxAgeMs Maximum lifetime of an un-rotated ambient trace in milliseconds.
|
|
41
90
|
* @param load Loader for the OpenTelemetry API. If it is not set, OTel is off.
|
|
42
91
|
* Do not import the peer by name. The Vite dev server fails if the peer is not installed.
|
|
92
|
+
* @param spans Span decisions of the runtime. Without them, the library records no span.
|
|
43
93
|
*/
|
|
44
|
-
constructor(diagnostics: Diagnostics, maxAgeMs?: number, load?: OtelLoader | undefined);
|
|
94
|
+
constructor(diagnostics: Diagnostics, maxAgeMs?: number, load?: OtelLoader | undefined, spans?: SpanHooks | undefined);
|
|
45
95
|
/**
|
|
46
96
|
* Loads the OpenTelemetry API. Until the load completes, records use the ambient trace.
|
|
47
97
|
* If there is no loader or the load fails, all records use the ambient trace.
|
|
@@ -53,21 +103,49 @@ export declare class TraceEngine {
|
|
|
53
103
|
* @returns Active TraceContext.
|
|
54
104
|
*/
|
|
55
105
|
resolve(): TraceContext;
|
|
106
|
+
/**
|
|
107
|
+
* Reads the ambient trace. It rotates a trace that is too old.
|
|
108
|
+
* @returns Ambient TraceContext.
|
|
109
|
+
*/
|
|
110
|
+
private ambientContext;
|
|
56
111
|
/**
|
|
57
112
|
* Reads the active span of the host if the peer module loaded and a span runs.
|
|
58
113
|
* @returns Trace context of the active span, or undefined.
|
|
59
114
|
*/
|
|
60
115
|
private activeSpanContext;
|
|
61
116
|
/**
|
|
62
|
-
* Rotates the ambient trace context to mark the start of a new logical operation.
|
|
63
|
-
*
|
|
117
|
+
* Rotates the ambient trace context to mark the start of a new logical operation. It ends the
|
|
118
|
+
* root span of the old trace.
|
|
119
|
+
* @param reason Event reason triggering the rotation.
|
|
64
120
|
* @returns Newly created TraceContext.
|
|
65
121
|
*/
|
|
66
|
-
rotate(
|
|
122
|
+
rotate(reason: RotateReason): TraceContext;
|
|
123
|
+
/**
|
|
124
|
+
* Ends the root span of the ambient trace one time. Later records can still use the trace.
|
|
125
|
+
* The exit flush calls it. A closing document has no later rotation.
|
|
126
|
+
*/
|
|
127
|
+
end(): void;
|
|
128
|
+
/**
|
|
129
|
+
* Ends the root span of a trace one time.
|
|
130
|
+
* @param ambient Trace to end.
|
|
131
|
+
*/
|
|
132
|
+
private finish;
|
|
67
133
|
/**
|
|
68
134
|
* Generates W3C traceparent headers with the registered OpenTelemetry propagators.
|
|
69
135
|
* Without a traceparent from OpenTelemetry, it uses the ambient trace.
|
|
70
136
|
* @returns Header map containing traceparent.
|
|
71
137
|
*/
|
|
72
138
|
headers(): Record<string, string>;
|
|
139
|
+
/**
|
|
140
|
+
* Generates the headers of one request of the network capture. With spans on, the traceparent
|
|
141
|
+
* names a new client span of the ambient trace.
|
|
142
|
+
* @returns The headers, and the client span that the library records.
|
|
143
|
+
*/
|
|
144
|
+
request(): RequestTrace;
|
|
145
|
+
/**
|
|
146
|
+
* Generates the trace headers.
|
|
147
|
+
* @param client True to name a new client span in the traceparent.
|
|
148
|
+
* @returns The headers, and the client span that the library records.
|
|
149
|
+
*/
|
|
150
|
+
private trace;
|
|
73
151
|
}
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
import { t as e } from "./library-request-ChCar5F8.js";
|
|
2
|
+
import { t } from "./patch-CCWfuEY7.js";
|
|
3
|
+
import { t as n } from "./storm-CfO0Sam2.js";
|
|
4
|
+
import { t as r } from "./types-BR9t_w28.js";
|
|
5
|
+
//#region src/capture/web-socket.ts
|
|
6
|
+
var i = "ui.websocket.messages";
|
|
7
|
+
function a(e) {
|
|
8
|
+
let t = new URL(e);
|
|
9
|
+
return {
|
|
10
|
+
target: `${t.protocol}//${t.host}${t.pathname}`,
|
|
11
|
+
server: t.hostname
|
|
12
|
+
};
|
|
13
|
+
}
|
|
14
|
+
function o(t, n, r) {
|
|
15
|
+
let i = t.servers.get(n), a = r === "transmit" && e();
|
|
16
|
+
if (!t.active || i === void 0 || a) return;
|
|
17
|
+
let o = {
|
|
18
|
+
"network.io.direction": r,
|
|
19
|
+
"server.address": i
|
|
20
|
+
};
|
|
21
|
+
t.messages.add(1, o);
|
|
22
|
+
}
|
|
23
|
+
var s = class {
|
|
24
|
+
diagnostics;
|
|
25
|
+
config;
|
|
26
|
+
name = "websocket";
|
|
27
|
+
restore;
|
|
28
|
+
state;
|
|
29
|
+
window = {
|
|
30
|
+
start: 0,
|
|
31
|
+
count: 0
|
|
32
|
+
};
|
|
33
|
+
constructor(e, t) {
|
|
34
|
+
this.diagnostics = e, this.config = t;
|
|
35
|
+
}
|
|
36
|
+
install(e) {
|
|
37
|
+
if (this.restore || typeof WebSocket > "u") return;
|
|
38
|
+
let n = {
|
|
39
|
+
active: !0,
|
|
40
|
+
ctx: e,
|
|
41
|
+
messages: e.counter(i),
|
|
42
|
+
servers: /* @__PURE__ */ new WeakMap()
|
|
43
|
+
};
|
|
44
|
+
this.state = n;
|
|
45
|
+
let r = (e) => {
|
|
46
|
+
this.track(e, n);
|
|
47
|
+
};
|
|
48
|
+
this.restore = t(globalThis, "WebSocket", (e) => class extends e {
|
|
49
|
+
static [Symbol.hasInstance](t) {
|
|
50
|
+
return t instanceof e;
|
|
51
|
+
}
|
|
52
|
+
constructor(e, t) {
|
|
53
|
+
super(e, t), r(this);
|
|
54
|
+
}
|
|
55
|
+
send(e) {
|
|
56
|
+
super.send(e), o(n, this, "transmit");
|
|
57
|
+
}
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
uninstall() {
|
|
61
|
+
this.state && (this.state.active = !1), this.restore && !this.restore() && this.diagnostics.report("capture.install_failed", "Another script wrapped WebSocket after the library. The library keeps that wrapper."), this.restore = void 0, this.state = void 0;
|
|
62
|
+
}
|
|
63
|
+
track(e, t) {
|
|
64
|
+
t.active && this.diagnostics.guard("capture.record_failed", "The library could not track a WebSocket. The socket works without capture.", () => {
|
|
65
|
+
if (r(e.url, this.config.capture.ignoreUrls)) return;
|
|
66
|
+
let { target: n, server: i } = a(e.url), s = {
|
|
67
|
+
"url.full": n,
|
|
68
|
+
"server.address": i
|
|
69
|
+
}, { logger: c } = t.ctx;
|
|
70
|
+
t.servers.set(e, i);
|
|
71
|
+
let l = (e) => {
|
|
72
|
+
this.allow(t) && e();
|
|
73
|
+
};
|
|
74
|
+
e.addEventListener("open", () => {
|
|
75
|
+
l(() => {
|
|
76
|
+
c.logEvent("websocket.open", s);
|
|
77
|
+
});
|
|
78
|
+
}), e.addEventListener("error", () => {
|
|
79
|
+
l(() => {
|
|
80
|
+
c.warn("websocket.error", s);
|
|
81
|
+
});
|
|
82
|
+
}), e.addEventListener("close", (e) => {
|
|
83
|
+
l(() => {
|
|
84
|
+
c.logEvent("websocket.close", {
|
|
85
|
+
...s,
|
|
86
|
+
"websocket.close.code": e.code,
|
|
87
|
+
"websocket.close.clean": e.wasClean
|
|
88
|
+
});
|
|
89
|
+
});
|
|
90
|
+
}), e.addEventListener("message", () => {
|
|
91
|
+
o(t, e, "receive");
|
|
92
|
+
});
|
|
93
|
+
});
|
|
94
|
+
}
|
|
95
|
+
allow(e) {
|
|
96
|
+
return e.active && n(this.window, 20, this.diagnostics, "WebSocket events");
|
|
97
|
+
}
|
|
98
|
+
};
|
|
99
|
+
//#endregion
|
|
100
|
+
export { s as WebSocketCapture };
|
|
101
|
+
|
|
102
|
+
//# sourceMappingURL=web-socket-Ar4cZxmd.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"web-socket-Ar4cZxmd.js","names":["isLibraryRequest","allowInWindow","matchesAny","MESSAGES_METRIC","socketTarget","parsed","url","count","server","state","socket","own","direction","attributes","WebSocketCapture","diagnostics","config","ctx","track","patch","Original","value","protocols","data","target","lifecycle","write","event"],"sources":["../src/capture/web-socket.ts"],"sourcesContent":["// src/capture/web-socket.ts\n//\n// Records the open, close and error events of each WebSocket. It counts the messages by direction\n// and server. It never reads the content of a message. It is a capture plugin, and the runtime\n// loads it as a separate chunk.\n\nimport { WEBSOCKET_MAX_PER_WINDOW } from \"../constants\";\nimport type { Diagnostics } from \"../core/diagnostics\";\nimport type { ResolvedConfig } from \"../models/config\";\nimport type { Counter, MetricAttributes } from \"../models/metric\";\nimport type { CapturePlugin, PluginContext } from \"../models/plugin\";\nimport { isLibraryRequest } from \"../utils/library-request\";\nimport { patch } from \"../utils/patch\";\nimport { allowInWindow, type StormWindow } from \"./storm\";\nimport { matchesAny } from \"./types\";\n\n/** Name of the message counter. */\nconst MESSAGES_METRIC = \"ui.websocket.messages\";\n\n/** Data of one WebSocket.send call. */\ntype SendData = Parameters<WebSocket[\"send\"]>[0];\n\n/** State of one install. A wrapper that stays after uninstall reads it and records nothing. */\ninterface InstallState {\n /** False after uninstall. */\n active: boolean;\n /** Tools of the plugin. */\n ctx: PluginContext;\n /** Counter of the messages. */\n messages: Counter;\n /** Server host name of each tracked socket. */\n servers: WeakMap<WebSocket, string>;\n}\n\n/**\n * Removes the user info, the query and the fragment from a socket URL. They can hold a token.\n * @param url Absolute URL of the socket.\n * @returns The URL to record and the host name of the server.\n */\nfunction socketTarget(url: string): { target: string; server: string } {\n const parsed = new URL(url);\n\n return {\n target: `${parsed.protocol}//${parsed.host}${parsed.pathname}`,\n server: parsed.hostname,\n };\n}\n\n/**\n * Counts one message of a tracked socket.\n * @param state State of the install that made the socket.\n * @param socket Socket of the message.\n * @param direction Direction of the message.\n */\nfunction count(state: InstallState, socket: WebSocket, direction: \"transmit\" | \"receive\"): void {\n const server = state.servers.get(socket);\n\n // A send of the library, for example a custom transport, must not make the next send.\n const own = direction === \"transmit\" && isLibraryRequest();\n if (!state.active || server === undefined || own) {\n return;\n }\n\n const attributes: MetricAttributes = {\n \"network.io.direction\": direction,\n \"server.address\": server,\n };\n state.messages.add(1, attributes);\n}\n\n/** Records the lifecycle and the message counts of each WebSocket that the app opens. */\nexport class WebSocketCapture implements CapturePlugin {\n /** Capture module identifier. */\n readonly name = \"websocket\";\n\n /** Restores the WebSocket constructor. Undefined when the capture is not installed. */\n private restore: (() => boolean) | undefined;\n\n /** State of the active install. */\n private state: InstallState | undefined;\n\n /** Rate limit of the lifecycle records. A reconnect loop must not flood the pipeline. */\n private readonly window: StormWindow = { start: 0, count: 0 };\n\n /**\n * @param diagnostics Diagnostics reporter.\n * @param config Active configuration. The capture reads `capture.ignoreUrls`.\n */\n constructor(\n private readonly diagnostics: Diagnostics,\n private readonly config: ResolvedConfig,\n ) {}\n\n /**\n * Replaces the WebSocket constructor with a subclass that tracks each socket.\n * @param ctx Tools of the plugin.\n */\n install(ctx: PluginContext): void {\n if (this.restore || typeof WebSocket === \"undefined\") {\n return;\n }\n\n const state: InstallState = {\n active: true,\n ctx,\n messages: ctx.counter(MESSAGES_METRIC),\n servers: new WeakMap(),\n };\n this.state = state;\n\n const track = (socket: WebSocket): void => {\n this.track(socket, state);\n };\n\n this.restore = patch(\n globalThis,\n \"WebSocket\",\n (Original) =>\n class TrackedWebSocket extends Original {\n /**\n * Keeps instanceof true for a socket that the app opened before the install.\n * @param value Value to test.\n * @returns True for each native socket.\n */\n static override [Symbol.hasInstance](value: unknown): boolean {\n return value instanceof Original;\n }\n\n /**\n * @param url URL of the server.\n * @param protocols Sub-protocols of the app.\n */\n constructor(url: string | URL, protocols?: string | string[]) {\n super(url, protocols);\n track(this);\n }\n\n /**\n * Sends the data, then counts one message. A send that throws counts nothing.\n * @param data Data of the app. The library does not read it.\n */\n override send(data: SendData): void {\n super.send(data);\n count(state, this, \"transmit\");\n }\n },\n );\n }\n\n /** Restores the WebSocket constructor and stops each tracked socket from recording. */\n uninstall(): void {\n if (this.state) {\n this.state.active = false;\n }\n\n // Another script can wrap the constructor after the library. Keep its wrapper.\n if (this.restore && !this.restore()) {\n this.diagnostics.report(\n \"capture.install_failed\",\n \"Another script wrapped WebSocket after the library. The library keeps that wrapper.\",\n );\n }\n\n this.restore = undefined;\n this.state = undefined;\n }\n\n /**\n * Adds the listeners that record the lifecycle and the received messages of one socket.\n * @param socket New socket of the app.\n * @param state State of the install that made the socket.\n */\n private track(socket: WebSocket, state: InstallState): void {\n if (!state.active) {\n return;\n }\n\n // A read here runs inside the constructor call of the app. A throw must not fail it.\n this.diagnostics.guard(\n \"capture.record_failed\",\n \"The library could not track a WebSocket. The socket works without capture.\",\n () => {\n // ignoreUrls matches the full URL. A custom transport can send over its own socket.\n if (matchesAny(socket.url, this.config.capture.ignoreUrls)) {\n return;\n }\n\n const { target, server } = socketTarget(socket.url);\n const attributes = { \"url.full\": target, \"server.address\": server };\n const { logger } = state.ctx;\n state.servers.set(socket, server);\n\n const lifecycle = (write: () => void): void => {\n if (this.allow(state)) {\n write();\n }\n };\n\n socket.addEventListener(\"open\", () => {\n lifecycle(() => {\n logger.logEvent(\"websocket.open\", attributes);\n });\n });\n socket.addEventListener(\"error\", () => {\n lifecycle(() => {\n logger.warn(\"websocket.error\", attributes);\n });\n });\n socket.addEventListener(\"close\", (event) => {\n lifecycle(() => {\n logger.logEvent(\"websocket.close\", {\n ...attributes,\n \"websocket.close.code\": event.code,\n \"websocket.close.clean\": event.wasClean,\n });\n });\n });\n socket.addEventListener(\"message\", () => {\n count(state, socket, \"receive\");\n });\n },\n );\n }\n\n /**\n * Tests if a lifecycle record can go out.\n * @param state State of the install that made the socket.\n * @returns False after uninstall, or when the window has no allowance left.\n */\n private allow(state: InstallState): boolean {\n return (\n state.active &&\n allowInWindow(this.window, WEBSOCKET_MAX_PER_WINDOW, this.diagnostics, \"WebSocket events\")\n );\n }\n}\n"],"mappings":"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"}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
const e=require("./library-request-gMFOCNcn.cjs"),t=require("./patch-BX8KrPCT.cjs"),n=require("./storm-6YYbXzT_.cjs"),r=require("./types-C7WNpnG1.cjs");var i=`ui.websocket.messages`;function a(e){let t=new URL(e);return{target:`${t.protocol}//${t.host}${t.pathname}`,server:t.hostname}}function o(t,n,r){let i=t.servers.get(n),a=r===`transmit`&&e.t();if(!t.active||i===void 0||a)return;let o={"network.io.direction":r,"server.address":i};t.messages.add(1,o)}var s=class{diagnostics;config;name=`websocket`;restore;state;window={start:0,count:0};constructor(e,t){this.diagnostics=e,this.config=t}install(e){if(this.restore||typeof WebSocket>`u`)return;let n={active:!0,ctx:e,messages:e.counter(i),servers:new WeakMap};this.state=n;let r=e=>{this.track(e,n)};this.restore=t.t(globalThis,`WebSocket`,e=>class extends e{static[Symbol.hasInstance](t){return t instanceof e}constructor(e,t){super(e,t),r(this)}send(e){super.send(e),o(n,this,`transmit`)}})}uninstall(){this.state&&(this.state.active=!1),this.restore&&!this.restore()&&this.diagnostics.report(`capture.install_failed`,`Another script wrapped WebSocket after the library. The library keeps that wrapper.`),this.restore=void 0,this.state=void 0}track(e,t){t.active&&this.diagnostics.guard(`capture.record_failed`,`The library could not track a WebSocket. The socket works without capture.`,()=>{if(r.t(e.url,this.config.capture.ignoreUrls))return;let{target:n,server:i}=a(e.url),s={"url.full":n,"server.address":i},{logger:c}=t.ctx;t.servers.set(e,i);let l=e=>{this.allow(t)&&e()};e.addEventListener(`open`,()=>{l(()=>{c.logEvent(`websocket.open`,s)})}),e.addEventListener(`error`,()=>{l(()=>{c.warn(`websocket.error`,s)})}),e.addEventListener(`close`,e=>{l(()=>{c.logEvent(`websocket.close`,{...s,"websocket.close.code":e.code,"websocket.close.clean":e.wasClean})})}),e.addEventListener(`message`,()=>{o(t,e,`receive`)})})}allow(e){return e.active&&n.t(this.window,20,this.diagnostics,`WebSocket events`)}};exports.WebSocketCapture=s;
|
|
2
|
+
//# sourceMappingURL=web-socket-BwJdwSHl.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"web-socket-BwJdwSHl.cjs","names":["isLibraryRequest","patch","matchesAny","allowInWindow","require_library_request","require_patch","require_storm","require_types","MESSAGES_METRIC","socketTarget","parsed","url","count","server","state","socket","own","direction","attributes","WebSocketCapture","diagnostics","config","ctx","track","Original","value","protocols","data","target","lifecycle","write","logger","event"],"sources":["../src/capture/web-socket.ts"],"sourcesContent":["// src/capture/web-socket.ts\n//\n// Records the open, close and error events of each WebSocket. It counts the messages by direction\n// and server. It never reads the content of a message. It is a capture plugin, and the runtime\n// loads it as a separate chunk.\n\nimport { WEBSOCKET_MAX_PER_WINDOW } from \"../constants\";\nimport type { Diagnostics } from \"../core/diagnostics\";\nimport type { ResolvedConfig } from \"../models/config\";\nimport type { Counter, MetricAttributes } from \"../models/metric\";\nimport type { CapturePlugin, PluginContext } from \"../models/plugin\";\nimport { isLibraryRequest } from \"../utils/library-request\";\nimport { patch } from \"../utils/patch\";\nimport { allowInWindow, type StormWindow } from \"./storm\";\nimport { matchesAny } from \"./types\";\n\n/** Name of the message counter. */\nconst MESSAGES_METRIC = \"ui.websocket.messages\";\n\n/** Data of one WebSocket.send call. */\ntype SendData = Parameters<WebSocket[\"send\"]>[0];\n\n/** State of one install. A wrapper that stays after uninstall reads it and records nothing. */\ninterface InstallState {\n /** False after uninstall. */\n active: boolean;\n /** Tools of the plugin. */\n ctx: PluginContext;\n /** Counter of the messages. */\n messages: Counter;\n /** Server host name of each tracked socket. */\n servers: WeakMap<WebSocket, string>;\n}\n\n/**\n * Removes the user info, the query and the fragment from a socket URL. They can hold a token.\n * @param url Absolute URL of the socket.\n * @returns The URL to record and the host name of the server.\n */\nfunction socketTarget(url: string): { target: string; server: string } {\n const parsed = new URL(url);\n\n return {\n target: `${parsed.protocol}//${parsed.host}${parsed.pathname}`,\n server: parsed.hostname,\n };\n}\n\n/**\n * Counts one message of a tracked socket.\n * @param state State of the install that made the socket.\n * @param socket Socket of the message.\n * @param direction Direction of the message.\n */\nfunction count(state: InstallState, socket: WebSocket, direction: \"transmit\" | \"receive\"): void {\n const server = state.servers.get(socket);\n\n // A send of the library, for example a custom transport, must not make the next send.\n const own = direction === \"transmit\" && isLibraryRequest();\n if (!state.active || server === undefined || own) {\n return;\n }\n\n const attributes: MetricAttributes = {\n \"network.io.direction\": direction,\n \"server.address\": server,\n };\n state.messages.add(1, attributes);\n}\n\n/** Records the lifecycle and the message counts of each WebSocket that the app opens. */\nexport class WebSocketCapture implements CapturePlugin {\n /** Capture module identifier. */\n readonly name = \"websocket\";\n\n /** Restores the WebSocket constructor. Undefined when the capture is not installed. */\n private restore: (() => boolean) | undefined;\n\n /** State of the active install. */\n private state: InstallState | undefined;\n\n /** Rate limit of the lifecycle records. A reconnect loop must not flood the pipeline. */\n private readonly window: StormWindow = { start: 0, count: 0 };\n\n /**\n * @param diagnostics Diagnostics reporter.\n * @param config Active configuration. The capture reads `capture.ignoreUrls`.\n */\n constructor(\n private readonly diagnostics: Diagnostics,\n private readonly config: ResolvedConfig,\n ) {}\n\n /**\n * Replaces the WebSocket constructor with a subclass that tracks each socket.\n * @param ctx Tools of the plugin.\n */\n install(ctx: PluginContext): void {\n if (this.restore || typeof WebSocket === \"undefined\") {\n return;\n }\n\n const state: InstallState = {\n active: true,\n ctx,\n messages: ctx.counter(MESSAGES_METRIC),\n servers: new WeakMap(),\n };\n this.state = state;\n\n const track = (socket: WebSocket): void => {\n this.track(socket, state);\n };\n\n this.restore = patch(\n globalThis,\n \"WebSocket\",\n (Original) =>\n class TrackedWebSocket extends Original {\n /**\n * Keeps instanceof true for a socket that the app opened before the install.\n * @param value Value to test.\n * @returns True for each native socket.\n */\n static override [Symbol.hasInstance](value: unknown): boolean {\n return value instanceof Original;\n }\n\n /**\n * @param url URL of the server.\n * @param protocols Sub-protocols of the app.\n */\n constructor(url: string | URL, protocols?: string | string[]) {\n super(url, protocols);\n track(this);\n }\n\n /**\n * Sends the data, then counts one message. A send that throws counts nothing.\n * @param data Data of the app. The library does not read it.\n */\n override send(data: SendData): void {\n super.send(data);\n count(state, this, \"transmit\");\n }\n },\n );\n }\n\n /** Restores the WebSocket constructor and stops each tracked socket from recording. */\n uninstall(): void {\n if (this.state) {\n this.state.active = false;\n }\n\n // Another script can wrap the constructor after the library. Keep its wrapper.\n if (this.restore && !this.restore()) {\n this.diagnostics.report(\n \"capture.install_failed\",\n \"Another script wrapped WebSocket after the library. The library keeps that wrapper.\",\n );\n }\n\n this.restore = undefined;\n this.state = undefined;\n }\n\n /**\n * Adds the listeners that record the lifecycle and the received messages of one socket.\n * @param socket New socket of the app.\n * @param state State of the install that made the socket.\n */\n private track(socket: WebSocket, state: InstallState): void {\n if (!state.active) {\n return;\n }\n\n // A read here runs inside the constructor call of the app. A throw must not fail it.\n this.diagnostics.guard(\n \"capture.record_failed\",\n \"The library could not track a WebSocket. The socket works without capture.\",\n () => {\n // ignoreUrls matches the full URL. A custom transport can send over its own socket.\n if (matchesAny(socket.url, this.config.capture.ignoreUrls)) {\n return;\n }\n\n const { target, server } = socketTarget(socket.url);\n const attributes = { \"url.full\": target, \"server.address\": server };\n const { logger } = state.ctx;\n state.servers.set(socket, server);\n\n const lifecycle = (write: () => void): void => {\n if (this.allow(state)) {\n write();\n }\n };\n\n socket.addEventListener(\"open\", () => {\n lifecycle(() => {\n logger.logEvent(\"websocket.open\", attributes);\n });\n });\n socket.addEventListener(\"error\", () => {\n lifecycle(() => {\n logger.warn(\"websocket.error\", attributes);\n });\n });\n socket.addEventListener(\"close\", (event) => {\n lifecycle(() => {\n logger.logEvent(\"websocket.close\", {\n ...attributes,\n \"websocket.close.code\": event.code,\n \"websocket.close.clean\": event.wasClean,\n });\n });\n });\n socket.addEventListener(\"message\", () => {\n count(state, socket, \"receive\");\n });\n },\n );\n }\n\n /**\n * Tests if a lifecycle record can go out.\n * @param state State of the install that made the socket.\n * @returns False after uninstall, or when the window has no allowance left.\n */\n private allow(state: InstallState): boolean {\n return (\n state.active &&\n allowInWindow(this.window, WEBSOCKET_MAX_PER_WINDOW, this.diagnostics, \"WebSocket events\")\n );\n }\n}\n"],"mappings":"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"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@utk09/ui-observability",
|
|
3
|
-
"version": "0.9.
|
|
3
|
+
"version": "0.9.4",
|
|
4
4
|
"description": "UI observability and logging for browser, OpenFin and webview applications",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"keywords": [
|
|
@@ -73,11 +73,10 @@
|
|
|
73
73
|
"test:watch": "vitest",
|
|
74
74
|
"test:coverage": "vitest run --coverage",
|
|
75
75
|
"typecheck": "tsc --noEmit",
|
|
76
|
-
"check:version": "node tools/check-version-sync.mjs",
|
|
77
76
|
"check:peers": "node tools/check-peer-imports.mjs",
|
|
78
77
|
"check:size": "node tools/check-size.mjs",
|
|
79
78
|
"check:dev": "node tools/check-dev-server.mjs",
|
|
80
|
-
"verify": "npm run format:check && npm run
|
|
79
|
+
"verify": "npm run format:check && npm run typecheck && npm run build && npm run lint && npm run check:peers && npm run check:size && npm run check:dev && npm run test:coverage",
|
|
81
80
|
"prepublishOnly": "npm run verify"
|
|
82
81
|
},
|
|
83
82
|
"peerDependencies": {
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"batch-4xKzzSCj.js","names":["ATTR_LOG_TYPE","LOG_TYPE_ACTION","newId","isLogBatch","value","id","createdAt","attempts","records","splitBatch","batch","middle","halve","diagnostics","attributeOf","record","attributes","key","isActionRecord"],"sources":["../src/models/batch.ts"],"sourcesContent":["// src/models/batch.ts\n//\n// A batch of log records for delivery to the ingest endpoint.\n\nimport { ATTR_LOG_TYPE, LOG_TYPE_ACTION } from \"../constants\";\nimport type { Diagnostics } from \"../core/diagnostics\";\nimport { newId } from \"../utils/identity\";\nimport type { LogRecord } from \"./log-record\";\n\n/**\n * A batch of records with a stable id used for server-side deduplication across retries.\n * @see {@link splitBatch}\n */\nexport interface LogBatch {\n /** Deduplication key. It stays the same across retries and reloads. */\n id: string;\n /** Records to deliver, in log order. */\n records: LogRecord[];\n /** Batch creation time, in epoch milliseconds. */\n createdAt: number;\n /** Delivery attempts so far. */\n attempts: number;\n}\n\n/**\n * Tells if a value from storage has all fields of a batch. `keyOf` cannot match\n * an entry without `id` after delivery. The library then retries that entry with no\n * end, and the entry blocks each batch behind it. An entry without `attempts` counts\n * as NaN. That count never reaches `maxAttempts`. Thus the library never drops the\n * entry as a dead letter.\n * @param value Parsed storage entry.\n * @returns True when each required field is present and has the correct type.\n */\nexport function isLogBatch(value: unknown): value is LogBatch {\n if (typeof value !== \"object\" || value === null) {\n return false;\n }\n\n const id: unknown = Reflect.get(value, \"id\");\n const createdAt: unknown = Reflect.get(value, \"createdAt\");\n const attempts: unknown = Reflect.get(value, \"attempts\");\n const records: unknown = Reflect.get(value, \"records\");\n\n return (\n typeof id === \"string\" &&\n typeof createdAt === \"number\" &&\n typeof attempts === \"number\" &&\n Array.isArray(records)\n );\n}\n\n/**\n * Splits a batch that the server rejected as too large into two halves.\n * Each half gets a new id. Each half keeps the age and attempts of the original batch.\n * @param batch The rejected batch.\n * @param diagnostics Diagnostics reporter for the new batch ids.\n * @returns Two batches, or `null` if a single record is already over the limit.\n */\nexport function splitBatch(batch: LogBatch, diagnostics: Diagnostics): [LogBatch, LogBatch] | null {\n if (batch.records.length < 2) {\n return null;\n }\n\n const middle = Math.floor(batch.records.length / 2);\n const halve = (records: LogRecord[]): LogBatch => ({\n id: newId(diagnostics),\n records,\n createdAt: batch.createdAt,\n attempts: batch.attempts,\n });\n\n return [halve(batch.records.slice(0, middle)), halve(batch.records.slice(middle))];\n}\n\n/**\n * Reads one attribute of a record. A record from storage can be corrupt. It can be null or have\n * no attributes.\n * @param record Record to read.\n * @param key Attribute key.\n * @returns The attribute value, or undefined for a corrupt record.\n */\nexport function attributeOf(record: LogRecord, key: string): unknown {\n const value: unknown = record;\n if (typeof value !== \"object\" || value === null) {\n return undefined;\n }\n\n const attributes: unknown = Reflect.get(value, \"attributes\");\n if (typeof attributes !== \"object\" || attributes === null) {\n return undefined;\n }\n\n return Reflect.get(attributes, key);\n}\n\n/**\n * Tests if a record is an action. A corrupt record from storage is not an action.\n * @param record Record to test.\n * @returns True for an action record.\n */\nexport function isActionRecord(record: LogRecord): boolean {\n return attributeOf(record, ATTR_LOG_TYPE) === LOG_TYPE_ACTION;\n}\n"],"mappings":";;;AAiCA,SAAgBG,EAAW,GAAmC;CAC5D,IAAI,OAAOC,KAAU,aAAYA,GAC/B,OAAO;CAGT,IAAMC,IAAc,QAAQ,IAAID,GAAO,IAAI,GACrCE,IAAqB,QAAQ,IAAIF,GAAO,WAAW,GACnDG,IAAoB,QAAQ,IAAIH,GAAO,UAAU,GACjDI,IAAmB,QAAQ,IAAIJ,GAAO,SAAS;CAErD,OACE,OAAOC,KAAO,YACd,OAAOC,KAAc,YACrB,OAAOC,KAAa,YACpB,MAAM,QAAQC,CAAO;AAEzB;AASA,SAAgBC,EAAW,GAAiB,GAAuD;CACjG,IAAIC,EAAM,QAAQ,SAAS,GACzB,OAAO;CAGT,IAAMC,IAAS,KAAK,MAAMD,EAAM,QAAQ,SAAS,CAAC,GAC5CE,KAAS,OAAoC;EACjD,IAAIV,EAAMW,CAAW;EACrB;EACA,WAAWH,EAAM;EACjB,UAAUA,EAAM;CAClB;CAEA,OAAO,CAACE,EAAMF,EAAM,QAAQ,MAAM,GAAGC,CAAM,CAAC,GAAGC,EAAMF,EAAM,QAAQ,MAAMC,CAAM,CAAC,CAAC;AACnF;AASA,SAAgBG,EAAY,GAAmB,GAAsB;CACnE,IAAMV,IAAiBW;CACvB,IAAI,OAAOX,KAAU,aAAYA,GAC/B;CAGF,IAAMY,IAAsB,QAAQ,IAAIZ,GAAO,YAAY;CAC3D,IAAI,OAAOY,KAAe,YAAYA,GAItC,OAAO,QAAQ,IAAIA,GAAYC,CAAG;AACpC;AAOA,SAAgBC,EAAe,GAA4B;CACzD,OAAOJ,EAAYC,GAAQf,CAAa,MAAMC;AAChD"}
|
package/dist/batch-cys7e53Q.cjs
DELETED
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
const e=require("./constants-Be83LICb.cjs"),t=require("./identity-DXyV86o-.cjs");function n(e){if(typeof e!=`object`||!e)return!1;let t=Reflect.get(e,`id`),n=Reflect.get(e,`createdAt`),r=Reflect.get(e,`attempts`),i=Reflect.get(e,`records`);return typeof t==`string`&&typeof n==`number`&&typeof r==`number`&&Array.isArray(i)}function r(e,n){if(e.records.length<2)return null;let r=Math.floor(e.records.length/2),i=r=>({id:t.i(n),records:r,createdAt:e.createdAt,attempts:e.attempts});return[i(e.records.slice(0,r)),i(e.records.slice(r))]}function i(e,t){let n=e;if(typeof n!=`object`||!n)return;let r=Reflect.get(n,`attributes`);if(typeof r==`object`&&r)return Reflect.get(r,t)}function a(t){return i(t,e.d)===e.mt}Object.defineProperty(exports,"i",{enumerable:!0,get:function(){return r}}),Object.defineProperty(exports,"n",{enumerable:!0,get:function(){return a}}),Object.defineProperty(exports,"r",{enumerable:!0,get:function(){return n}}),Object.defineProperty(exports,"t",{enumerable:!0,get:function(){return i}});
|
|
2
|
-
//# sourceMappingURL=batch-cys7e53Q.cjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"batch-cys7e53Q.cjs","names":["newId","ATTR_LOG_TYPE","LOG_TYPE_ACTION","require_constants","require_identity","isLogBatch","value","id","createdAt","attempts","records","splitBatch","batch","middle","halve","diagnostics","attributeOf","record","attributes","key","isActionRecord"],"sources":["../src/models/batch.ts"],"sourcesContent":["// src/models/batch.ts\n//\n// A batch of log records for delivery to the ingest endpoint.\n\nimport { ATTR_LOG_TYPE, LOG_TYPE_ACTION } from \"../constants\";\nimport type { Diagnostics } from \"../core/diagnostics\";\nimport { newId } from \"../utils/identity\";\nimport type { LogRecord } from \"./log-record\";\n\n/**\n * A batch of records with a stable id used for server-side deduplication across retries.\n * @see {@link splitBatch}\n */\nexport interface LogBatch {\n /** Deduplication key. It stays the same across retries and reloads. */\n id: string;\n /** Records to deliver, in log order. */\n records: LogRecord[];\n /** Batch creation time, in epoch milliseconds. */\n createdAt: number;\n /** Delivery attempts so far. */\n attempts: number;\n}\n\n/**\n * Tells if a value from storage has all fields of a batch. `keyOf` cannot match\n * an entry without `id` after delivery. The library then retries that entry with no\n * end, and the entry blocks each batch behind it. An entry without `attempts` counts\n * as NaN. That count never reaches `maxAttempts`. Thus the library never drops the\n * entry as a dead letter.\n * @param value Parsed storage entry.\n * @returns True when each required field is present and has the correct type.\n */\nexport function isLogBatch(value: unknown): value is LogBatch {\n if (typeof value !== \"object\" || value === null) {\n return false;\n }\n\n const id: unknown = Reflect.get(value, \"id\");\n const createdAt: unknown = Reflect.get(value, \"createdAt\");\n const attempts: unknown = Reflect.get(value, \"attempts\");\n const records: unknown = Reflect.get(value, \"records\");\n\n return (\n typeof id === \"string\" &&\n typeof createdAt === \"number\" &&\n typeof attempts === \"number\" &&\n Array.isArray(records)\n );\n}\n\n/**\n * Splits a batch that the server rejected as too large into two halves.\n * Each half gets a new id. Each half keeps the age and attempts of the original batch.\n * @param batch The rejected batch.\n * @param diagnostics Diagnostics reporter for the new batch ids.\n * @returns Two batches, or `null` if a single record is already over the limit.\n */\nexport function splitBatch(batch: LogBatch, diagnostics: Diagnostics): [LogBatch, LogBatch] | null {\n if (batch.records.length < 2) {\n return null;\n }\n\n const middle = Math.floor(batch.records.length / 2);\n const halve = (records: LogRecord[]): LogBatch => ({\n id: newId(diagnostics),\n records,\n createdAt: batch.createdAt,\n attempts: batch.attempts,\n });\n\n return [halve(batch.records.slice(0, middle)), halve(batch.records.slice(middle))];\n}\n\n/**\n * Reads one attribute of a record. A record from storage can be corrupt. It can be null or have\n * no attributes.\n * @param record Record to read.\n * @param key Attribute key.\n * @returns The attribute value, or undefined for a corrupt record.\n */\nexport function attributeOf(record: LogRecord, key: string): unknown {\n const value: unknown = record;\n if (typeof value !== \"object\" || value === null) {\n return undefined;\n }\n\n const attributes: unknown = Reflect.get(value, \"attributes\");\n if (typeof attributes !== \"object\" || attributes === null) {\n return undefined;\n }\n\n return Reflect.get(attributes, key);\n}\n\n/**\n * Tests if a record is an action. A corrupt record from storage is not an action.\n * @param record Record to test.\n * @returns True for an action record.\n */\nexport function isActionRecord(record: LogRecord): boolean {\n return attributeOf(record, ATTR_LOG_TYPE) === LOG_TYPE_ACTION;\n}\n"],"mappings":"iFAiCA,SAAgBK,EAAW,EAAmC,CAC5D,GAAI,OAAOC,GAAU,WAAYA,EAC/B,MAAO,GAGT,IAAMC,EAAc,QAAQ,IAAID,EAAO,IAAI,EACrCE,EAAqB,QAAQ,IAAIF,EAAO,WAAW,EACnDG,EAAoB,QAAQ,IAAIH,EAAO,UAAU,EACjDI,EAAmB,QAAQ,IAAIJ,EAAO,SAAS,EAErD,OACE,OAAOC,GAAO,UACd,OAAOC,GAAc,UACrB,OAAOC,GAAa,UACpB,MAAM,QAAQC,CAAO,CAEzB,CASA,SAAgBC,EAAW,EAAiB,EAAuD,CACjG,GAAIC,EAAM,QAAQ,OAAS,EACzB,OAAO,KAGT,IAAMC,EAAS,KAAK,MAAMD,EAAM,QAAQ,OAAS,CAAC,EAC5CE,EAAS,IAAoC,CACjD,GAAId,EAAAA,EAAMe,CAAW,EACrB,UACA,UAAWH,EAAM,UACjB,SAAUA,EAAM,QAClB,GAEA,MAAO,CAACE,EAAMF,EAAM,QAAQ,MAAM,EAAGC,CAAM,CAAC,EAAGC,EAAMF,EAAM,QAAQ,MAAMC,CAAM,CAAC,CAAC,CACnF,CASA,SAAgBG,EAAY,EAAmB,EAAsB,CACnE,IAAMV,EAAiBW,EACvB,GAAI,OAAOX,GAAU,WAAYA,EAC/B,OAGF,IAAMY,EAAsB,QAAQ,IAAIZ,EAAO,YAAY,EAC3D,GAAI,OAAOY,GAAe,UAAYA,EAItC,OAAO,QAAQ,IAAIA,EAAYC,CAAG,CACpC,CAOA,SAAgBC,EAAe,EAA4B,CACzD,OAAOJ,EAAYC,EAAQhB,EAAAA,CAAa,IAAMC,EAAAA,EAChD"}
|
package/dist/bus-B6vzPmQM.cjs
DELETED
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
const e=require("./constants-Be83LICb.cjs"),t=require("./deadline-XSnm95pg.cjs"),n=require("./journey-BGSyy8Es.cjs"),r=require("./remote-rules-DgoBJxZL.cjs");function i(t){return{p:e.E,m:t}}function a(e){if(typeof e!=`object`||!e)return null;let t=e;if(t.p!==`ui-observability/1`||typeof t.m!=`object`||t.m===null)return null;let n=t.m;return typeof n.t==`string`?n:null}var o=Symbol.for(e.Zt),s=`null`;function c(e,t){return e===s?`The bus ignored ${t} from a sandboxed frame. The frame has an opaque origin. Set bus.mode: "sender" in the frame. Add allow-same-origin to the sandbox attribute only for content that you trust.`:`The bus ignored ${t} from ${e}. If you own this origin, add it to bus.trustedOrigins.`}function l(){let e=location.ancestorOrigins;if(e&&e.length>0)return e.item(0);let t=document.referrer;if(t===``)return null;try{return new URL(t).origin}catch{return null}}function u(e,t){if(typeof window>`u`||window.parent===window)return null;let n;try{n=window.parent[o]}catch{return null}if(typeof n?.busAccept!=`function`)return null;let r=n,i=!0;return{kind:`direct`,post(n){i&&t.guard(`bus.send_failed`,`The direct call into the parent runtime failed.`,()=>{r.busAccept(n,e)})},close(){i=!1}}}function d(e,t,n){if(typeof window>`u`||window.parent===window)return null;let r=location.origin;if(r===s)return n.report(`bus.untrusted_origin`,`This frame is sandboxed without allow-same-origin. It has an opaque origin. No parent can trust it. This context sends its own records. Set bus.mode: "sender" in the frame. Add allow-same-origin to the sandbox attribute only for content that you trust.`,{origin:r,type:`parent`}),null;let o=new Set([r,...t]),u=l();if(u===null||!o.has(u))return n.report(`bus.untrusted_origin`,u===null?`The origin of the parent frame is unknown. This context sends its own records.`:`The parent frame is on ${u}. This origin is not in bus.trustedOrigins. This context sends its own records.`,{origin:u??``,type:`parent`}),null;let d=new Set,f=t=>{let r=a(t.data);r&&t.source===window.parent&&(o.has(t.origin)?e(r,{link:`parent`,origin:t.origin}):d.has(t.origin)||(d.add(t.origin),n.report(`bus.untrusted_origin`,c(t.origin,`a message`),{origin:t.origin,type:r.t.slice(0,32)})))};return addEventListener(`message`,f),{kind:`parent`,post(e){n.guard(`bus.send_failed`,`The postMessage call to the parent failed.`,()=>{window.parent.postMessage(i(e),u)})},close(){removeEventListener(`message`,f)}}}function f(e,t,n){if(typeof window>`u`)return null;let r=new Set([location.origin,...t]);r.delete(s);let o=new Map,l=t=>{let i=a(t.data);i&&(r.has(t.origin)?(t.source&&o.set(t.source,t.origin),e(i,{link:`children`,origin:t.origin})):n.report(`bus.untrusted_origin`,c(t.origin,`a message`),{origin:t.origin,type:i.t.slice(0,32)}))};return addEventListener(`message`,l),{kind:`children`,post(e){for(let[t,r]of o){let a=t;a.closed?o.delete(t):n.guard(`bus.send_failed`,`The postMessage call to a child frame failed.`,()=>{a.postMessage(i(e),r)})}},close(){removeEventListener(`message`,l),o.clear()}}}function p(e,t,n){let r=globalThis.BroadcastChannel;if(r===void 0)return null;let o=n.guard(`bus.send_failed`,`The library could not open the BroadcastChannel.`,()=>new r(e));return o?(o.onmessage=e=>{let n=a(e.data);n&&t(n,{link:`broadcast`,origin:`same-origin`})},{kind:`broadcast`,post(e){n.guard(`bus.send_failed`,`The BroadcastChannel.postMessage call failed.`,()=>{o.postMessage(i(e))})},close(){n.guard(`bus.send_failed`,`The library could not close the BroadcastChannel.`,()=>{o.close()})}}):null}function m(e,t,n,r){let o=globalThis.fin?.InterApplicationBus;if(!o)return null;if(!t)return r.report(`openfin.unavailable`,`OpenFin gives no application uuid. The InterApplicationBus link stays closed.`),null;let s=`${e}.${t}`;return r.guardAsync(`bus.send_failed`,`The InterApplicationBus.subscribe call failed.`,()=>o.subscribe({uuid:t},s,e=>{let t=a(e);t&&n(t,{link:`openfin`,origin:`openfin`})})),{kind:`openfin`,post(e){r.guardAsync(`bus.send_failed`,`The InterApplicationBus.publish call failed.`,()=>o.publish(s,i(e)))},close(){}}}function h(e,t){let n=globalThis,r=n.postMessage;return n.WorkerGlobalScope===void 0||!r?null:(n.addEventListener?.(`message`,t=>{let n=a(t.data);n&&e(n,{link:`owner`,origin:`same-origin`})}),{kind:`owner`,post(e){t.guard(`bus.send_failed`,`The postMessage call of the worker failed.`,()=>{r(i(e))})},close(){}})}function g(e,t,n){let r=e=>{let n=a(e.data);n&&t(n,{link:`worker`,origin:`same-origin`})};return e.addEventListener(`message`,r),e.start?.(),{kind:`worker`,post(t){n.guard(`bus.send_failed`,`The postMessage call to a worker failed.`,()=>{e.postMessage(i(t))})},close(){e.removeEventListener(`message`,r)}}}var _={timeoutMs:e.w,maxAttempts:3},v=[`children`,`direct`,`worker`],y=class{config;diagnostics;platform;contextId;tabId;handlers;handshakeOptions;role=`sender`;upstream=null;links=[];openFinLink=null;isOpenFinProvider=!1;resolved=!1;rulesPoll;destroyed=!1;ownerId=null;awaitingWelcome=null;constructor(e,t,n,r,i,a,o=_){this.config=e,this.diagnostics=t,this.platform=n,this.contextId=r,this.tabId=i,this.handlers=a,this.handshakeOptions=o}getRole(){return this.role}isResolved(){return this.resolved}async start(){let{bus:e}=this.config;if(e.mode===`off`)return this.role=`sender`,this.resolved=!0,this.role;if(this.isOpenFinProvider=this.resolveOpenFinProvider(),e.mode===`sender`||e.mode===`forwarder`)return this.role=e.mode,this.openControlLinks(),this.role===`forwarder`&&(this.upstream=this.candidateUpstream(),this.upstream||this.diagnostics.report(`bus.no_owner`,`bus.mode is "forwarder". No owner exists. The library drops the records of this context.`)),this.resolved=!0,this.announce(),this.role;this.openControlLinks();let t=u(this.receive,this.diagnostics);if(t)return this.role=`forwarder`,this.upstream=t,this.resolved=!0,this.diagnostics.report(`bus.role_resolved`,`This context attached directly to the runtime of its same-origin parent.`,{role:`forwarder`,via:`direct`}),this.announce(),this.role;let n=this.candidateUpstream();if(!n)return this.role=`sender`,this.resolved=!0,this.diagnostics.report(`bus.role_resolved`,`No owner exists. This context sends its own records.`,{role:`sender`}),this.announce(),this.role;let r=this.orphanPolicy()===`retry`?this.handshakeOptions.maxAttempts:1,i=!1;for(let e=0;e<r&&!i;e++)i=await this.handshake(n);return this.role=i?`forwarder`:`sender`,this.upstream=i?n:null,i||(n!==this.openFinLink&&n.close(),this.diagnostics.report(`bus.handshake_timeout`,`No owner answered after ${String(r)} attempt(s) of ${String(this.handshakeOptions.timeoutMs)} ms. This context becomes the sender.`,{via:n.kind,crossOrigin:this.isCrossOriginFrame()})),this.diagnostics.report(`bus.role_resolved`,`The bus role is ${this.role}.`,{role:this.role,via:i?n.kind:`none`}),this.resolved=!0,this.announce(),this.role}sendRecords(e){this.upstream?.post({t:`records`,from:this.contextId,records:e})}acceptDirect(e,t){if(e.from===this.contextId)return;let n={link:`direct`,origin:`same-origin`};if(e.t===`hello`)this.canOwn(`direct`)&&t({t:`welcome`,from:this.contextId,to:e.from,tabId:this.tabId},n);else if(e.t===`journey?`){let r=this.handlers.onJourneyRequest();r&&this.journeyLink(`direct`)&&t({t:`journey`,from:this.contextId,to:e.from,journey:r},n)}else e.t===`sampling?`?t(this.rulesAnswer(e.from),n):this.receive(e,n)}attachWorker(e){this.links.push(g(e,this.receive,this.diagnostics))}broadcastJourney(e){this.postJourney({t:`journey`,from:this.contextId,journey:e})}destroy(){this.destroyed=!0,clearInterval(this.rulesPoll),this.rulesPoll=void 0;for(let e of this.allLinks())e.close();this.links.length=0,this.upstream=null,this.ownerId=null,this.openFinLink=null}allLinks(){return!this.upstream||this.links.includes(this.upstream)?this.links:[...this.links,this.upstream]}postOver(e,t){for(let n of this.allLinks())n.kind===e&&n.post(t)}postJourney(e){for(let t of this.allLinks())this.journeyLink(t.kind)&&t.post(e)}receive=(e,t)=>{if(e.from!==this.contextId)switch(e.t){case`hello`:this.canOwn(t.link)&&this.postOver(t.link,{t:`welcome`,from:this.contextId,to:e.from,tabId:this.tabId});break;case`welcome`:if(e.to!==this.contextId)break;this.awaitingWelcome?.link===t.link&&(this.ownerId=e.from,this.awaitingWelcome.settle(!0));break;case`records`:this.role===`sender`?this.handlers.onRecords(e.records):this.upstream&&this.canRelay(t.link)&&this.upstream.post(e);break;case`journey`:this.acceptsJourney(e,t)&&this.applyJourney(e.journey);break;case`journey?`:{let n=this.handlers.onJourneyRequest();n&&this.journeyLink(t.link)&&this.postOver(t.link,{t:`journey`,from:this.contextId,to:e.from,journey:n});break}case`sampling?`:(this.role===`forwarder`?t.link!==this.upstream?.kind:this.canOwn(t.link))&&this.postOver(t.link,this.rulesAnswer(e.from));break;case`sampling`:this.acceptsRules(e.to,t)&&this.applyRules(e.rules);break;case`tab`:t.link===`broadcast`&&e.tabId===this.tabId&&this.contextId>e.from&&this.handlers.onTabConflict()}};canRelay(e){return e===`direct`||e!==this.upstream?.kind}canOwn(e){return this.role===`sender`?e===`openfin`?this.isOpenFinProvider:v.includes(e):!1}resolveOpenFinProvider(){let e=this.config.bus.openFinRole;if(e!==`auto`)return e===`provider`;if(this.platform.platform!==`openfin`&&this.platform.platform!==`openfin_web`)return!1;let t=globalThis.fin?.me;return!t?.identity||t.isView?!1:!!(t.identity.name&&t.identity.name===t.identity.uuid)}orphanPolicy(){return this.isCrossOriginFrame()?`retry`:`promote`}isCrossOriginFrame(){if(typeof window>`u`||window.parent===window)return!1;try{return Reflect.get(window.parent,`location`),!1}catch{return!0}}candidateUpstream(){return this.platform.isWorker?h(this.receive,this.diagnostics):this.platform.isTopLevelDocument?this.platform.platform===`openfin`&&!this.isOpenFinProvider?this.ensureOpenFinLink():null:d(this.receive,this.config.bus.trustedOrigins,this.diagnostics)}openControlLinks(){let t=e=>{e&&this.links.push(e)};this.platform.isTopLevelDocument&&(t(f(this.receive,this.config.bus.trustedOrigins,this.diagnostics)),t(p(e.C,this.receive,this.diagnostics))),(this.platform.platform===`openfin`||this.platform.platform===`openfin_web`)&&t(this.ensureOpenFinLink())}ensureOpenFinLink(){return this.openFinLink??=m(e.C,this.platform.openfinUuid,this.receive,this.diagnostics),this.openFinLink}handshake(e){return new Promise(n=>{let r=!1,i=e=>{r||(r=!0,this.awaitingWelcome=null,clearTimeout(a),n(e))};this.awaitingWelcome={link:e.kind,settle:i};let a=setTimeout(()=>{i(!1)},this.handshakeOptions.timeoutMs);t.r(a),e.post({t:`hello`,from:this.contextId,tabId:this.tabId})})}announce(){this.postOver(`broadcast`,{t:`tab`,from:this.contextId,tabId:this.tabId}),this.postJourney({t:`journey?`,from:this.contextId}),this.pollRules()}journeyScope(){let{scope:e}=this.config.journey;if(e!==`auto`)return e;let{platform:t}=this.platform;return t===`openfin`||t===`openfin_web`?`origin`:`tab`}journeyLink(e){let t=this.journeyScope();return t===`context`?!1:t===`origin`||e!==`broadcast`}acceptsJourney(e,t){return!this.journeyLink(t.link)||e.to!==void 0&&e.to!==this.contextId?!1:this.journeyScope()===`origin`||this.fromOwner(e.from,t.link)}fromOwner(e,t){return this.role!==`forwarder`||t!==this.upstream?.kind?!1:this.ownerId===null||e===this.ownerId}applyJourney(e){if(e===null){this.handlers.onJourney(null);return}let t=n.r(e);t===null?this.diagnostics.report(`record.dropped_malformed`,`The bus dropped a journey message. Its payload is not a journey.`,{type:`journey`}):this.handlers.onJourney(t)}rulesAnswer(e){let t=this.handlers.remote.sampling?.wire()??null;return{t:`sampling`,from:this.contextId,to:e,rules:t}}acceptsRules(e,t){if(this.role!==`forwarder`||e!==this.contextId||t.link!==this.upstream?.kind)return!1;let{origin:n}=t;return t.link===`parent`&&n!==location.origin&&!this.config.bus.trustedOrigins.includes(n)?(this.diagnostics.report(`bus.untrusted_origin`,`The bus ignored sampling rules from ${n}. If you own this origin, add it to bus.trustedOrigins.`,{origin:n,type:`sampling`}),!1):!0}applyRules(e){if(e===null){r.t(this.handlers.remote,this.config,null);return}let t=r.n(e,this.diagnostics);t&&r.t(this.handlers.remote,this.config,t)}pollRules(){let{upstream:n}=this;if(this.destroyed||this.role!==`forwarder`||!n)return;let r=()=>{this.config.sampling.remote&&n.post({t:`sampling?`,from:this.contextId})};r(),this.rulesPoll=setInterval(r,e.Nt),t.r(this.rulesPoll)}};exports.Bus=y;
|
|
2
|
-
//# sourceMappingURL=bus-B6vzPmQM.cjs.map
|