autotel 6.4.1 → 7.0.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/README.md +30 -23
- package/dist/{attribute-redacting-processor-Pk7lAzWd.d.cts → attribute-redacting-processor-CvBE0z1p.d.cts} +33 -1
- package/dist/{attribute-redacting-processor-Pk7lAzWd.d.ts → attribute-redacting-processor-CvBE0z1p.d.ts} +33 -1
- package/dist/attribute-redacting-processor.cjs +34 -32
- package/dist/attribute-redacting-processor.d.cts +1 -1
- package/dist/attribute-redacting-processor.d.ts +1 -1
- package/dist/attribute-redacting-processor.js +35 -32
- package/dist/{attributes-aDmJYral.cjs → attributes-Cxys8tgr.cjs} +34 -35
- package/dist/{attributes-B7wix2VG.js → attributes-Dt4YUYbP.js} +34 -35
- package/dist/attributes.cjs +1 -1
- package/dist/attributes.d.cts +1 -1
- package/dist/attributes.d.ts +1 -1
- package/dist/attributes.js +1 -1
- package/dist/auto.cjs +1 -1
- package/dist/auto.js +1 -1
- package/dist/business-baggage.cjs +19 -12
- package/dist/business-baggage.d.cts +8 -3
- package/dist/business-baggage.d.ts +8 -3
- package/dist/business-baggage.js +19 -12
- package/dist/{canonical-log-line-processor-DxtBGZIi.cjs → canonical-log-line-processor-DolzdawH.cjs} +43 -32
- package/dist/{canonical-log-line-processor-B4WgG-VS.d.cts → canonical-log-line-processor-cPB4Axk-.d.ts} +4 -3
- package/dist/{canonical-log-line-processor-B0vq_QR6.js → canonical-log-line-processor-hFUmS__K.js} +43 -32
- package/dist/{canonical-log-line-processor-CL_J7gb5.d.ts → canonical-log-line-processor-l0Aqe6yp.d.cts} +4 -3
- package/dist/config.d.cts +1 -1
- package/dist/config.d.ts +1 -1
- package/dist/{correlated-events-kSwLo3mi.cjs → correlated-events-CcuknWnU.cjs} +2 -1
- package/dist/{correlated-events-Bzh5y-UB.js → correlated-events-DwMMbItg.js} +3 -1
- package/dist/correlation-id.cjs +1 -1
- package/dist/correlation-id.js +1 -1
- package/dist/db.cjs +34 -19
- package/dist/db.js +34 -19
- package/dist/decorators.cjs +4 -2
- package/dist/decorators.d.cts +16 -11
- package/dist/decorators.d.ts +16 -11
- package/dist/decorators.js +4 -2
- package/dist/{define-event-CGG048HE.d.cts → define-event-BNeuKUPv.d.cts} +1 -1
- package/dist/{define-event-B2z1SBe7.d.ts → define-event-Bd8f8mST.d.ts} +1 -1
- package/dist/diagnostics.cjs +18 -16
- package/dist/diagnostics.d.cts +14 -10
- package/dist/diagnostics.d.ts +14 -10
- package/dist/diagnostics.js +18 -16
- package/dist/{event-subscriber-CWh8sTGh.d.cts → event-subscriber-DMACQA-1.d.cts} +19 -9
- package/dist/{event-subscriber-CWh8sTGh.d.ts → event-subscriber-DMACQA-1.d.ts} +19 -9
- package/dist/event-subscriber.d.cts +2 -2
- package/dist/event-subscriber.d.ts +2 -2
- package/dist/{event-testing-D0qWfqAy.d.cts → event-testing-CBtnJXE5.d.cts} +1 -1
- package/dist/{event-testing-CA2mIx1E.d.ts → event-testing-CkPgV3Ii.d.ts} +1 -1
- package/dist/event-testing.d.cts +1 -1
- package/dist/event-testing.d.ts +1 -1
- package/dist/event.cjs +1 -1
- package/dist/event.d.cts +5 -5
- package/dist/event.d.ts +5 -5
- package/dist/event.js +1 -1
- package/dist/exception-fingerprint.cjs +133 -0
- package/dist/exception-fingerprint.d.cts +51 -0
- package/dist/exception-fingerprint.d.ts +51 -0
- package/dist/exception-fingerprint.js +126 -0
- package/dist/{functional-AT22vCw6.d.ts → functional-CJn2zY4o.d.cts} +96 -39
- package/dist/{functional-e6jw5zQj.d.cts → functional-DXy1cHFF.d.ts} +96 -39
- package/dist/{functional-qZxRcIBp.cjs → functional-Da6Yv64r.cjs} +27 -15
- package/dist/{functional-0o9xSedq.js → functional-uSbNnnxK.js} +27 -15
- package/dist/functional.cjs +1 -1
- package/dist/functional.d.cts +2 -2
- package/dist/functional.d.ts +2 -2
- package/dist/functional.js +1 -1
- package/dist/http.cjs +11 -8
- package/dist/http.js +11 -8
- package/dist/{index-DolOVX6F.d.ts → index-CwrNAsgk.d.ts} +22 -26
- package/dist/{index-BPcxVucm.d.cts → index-DQHf4cNl.d.cts} +22 -26
- package/dist/index.cjs +41 -35
- package/dist/index.d.cts +45 -30
- package/dist/index.d.ts +45 -30
- package/dist/index.js +41 -35
- package/dist/{init-CsODvlau.d.ts → init-BgnYi2sm.d.ts} +94 -90
- package/dist/{init-BnxHAi2M.cjs → init-D4m5rCmD.cjs} +142 -123
- package/dist/{init-Cc7-vvzj.d.cts → init-DrlL1eis.d.cts} +94 -90
- package/dist/{init-BxfZ3Vbw.js → init-JtX-KKz_.js} +137 -124
- package/dist/instrumentation.cjs +2 -2
- package/dist/instrumentation.js +2 -2
- package/dist/{logger-D3Ej3DII.js → logger-DdPp__xW.js} +63 -54
- package/dist/{logger-CN4xpzMd.d.cts → logger-S1Fgl0g3.d.cts} +0 -20
- package/dist/{logger-CN4xpzMd.d.ts → logger-S1Fgl0g3.d.ts} +0 -20
- package/dist/{logger-thMPLpOG.cjs → logger-Sm66cjKl.cjs} +63 -54
- package/dist/logger.cjs +1 -1
- package/dist/logger.d.cts +1 -1
- package/dist/logger.d.ts +1 -1
- package/dist/logger.js +1 -1
- package/dist/messaging-adapters.cjs +26 -12
- package/dist/messaging-adapters.d.cts +0 -30
- package/dist/messaging-adapters.d.ts +0 -30
- package/dist/messaging-adapters.js +26 -12
- package/dist/messaging.cjs +37 -34
- package/dist/messaging.d.cts +21 -62
- package/dist/messaging.d.ts +21 -62
- package/dist/messaging.js +37 -34
- package/dist/{metric-testing-CpvP3ZIa.d.cts → metric-testing-86WO1wan.d.cts} +1 -1
- package/dist/{metric-testing-CWm6UhaR.d.ts → metric-testing-CbCxdPBp.d.ts} +1 -1
- package/dist/metric-testing.d.cts +1 -1
- package/dist/metric-testing.d.ts +1 -1
- package/dist/metric.d.cts +3 -3
- package/dist/metric.d.ts +3 -3
- package/dist/{node-require-vROmTeJ8.js → node-require-DSPjaw_l.js} +3 -2
- package/dist/{node-require-PFqDihze.cjs → node-require-EifOMikz.cjs} +3 -2
- package/dist/parse-error.cjs +18 -12
- package/dist/parse-error.d.cts +2 -1
- package/dist/parse-error.d.ts +2 -1
- package/dist/parse-error.js +19 -12
- package/dist/policy.cjs +0 -0
- package/dist/policy.js +0 -0
- package/dist/processors.cjs +1 -1
- package/dist/processors.d.cts +1 -1
- package/dist/processors.d.ts +1 -1
- package/dist/processors.js +1 -1
- package/dist/{sampling-BR9fkSwx.d.cts → sampling-CM5S2Lp3.d.ts} +5 -6
- package/dist/{sampling-CP3e7-Yr.d.ts → sampling-CmRdnXUi.d.cts} +5 -6
- package/dist/sampling.cjs +3 -2
- package/dist/sampling.d.cts +1 -1
- package/dist/sampling.d.ts +1 -1
- package/dist/sampling.js +3 -2
- package/dist/semantic-helpers.cjs +9 -9
- package/dist/semantic-helpers.d.cts +1 -1
- package/dist/semantic-helpers.d.ts +1 -1
- package/dist/semantic-helpers.js +9 -9
- package/dist/{stable-hash-ChFBIhNt.js → stable-hash-BkoAYVks.js} +4 -3
- package/dist/{stable-hash-CS9BxvVQ.cjs → stable-hash-C0pOegH_.cjs} +4 -3
- package/dist/{structured-error-CHg7DoIQ.cjs → structured-error--_wXpd_C.cjs} +34 -25
- package/dist/{structured-error-9--cxBay.js → structured-error-YIuka-FE.js} +34 -25
- package/dist/test-span-collector.cjs +15 -8
- package/dist/test-span-collector.js +15 -8
- package/dist/testing.cjs +16 -18
- package/dist/testing.d.cts +7 -6
- package/dist/testing.d.ts +7 -6
- package/dist/testing.js +16 -18
- package/dist/{trace-context-IuyoPyNq.d.cts → trace-context-C1Cn1q0y.d.cts} +8 -7
- package/dist/{trace-context-IuyoPyNq.d.ts → trace-context-f89xPJbK.d.ts} +8 -7
- package/dist/trace-helpers.cjs +16 -13
- package/dist/trace-helpers.d.cts +9 -4
- package/dist/trace-helpers.d.ts +9 -4
- package/dist/trace-helpers.js +16 -13
- package/dist/tracer-provider.cjs +8 -12
- package/dist/tracer-provider.js +8 -12
- package/dist/validate.cjs +22 -20
- package/dist/validate.d.cts +3 -2
- package/dist/validate.d.ts +3 -2
- package/dist/validate.js +22 -20
- package/dist/values-BenyvWKz.js +141 -0
- package/dist/values-CeMH-mYG.d.cts +8 -0
- package/dist/values-CeMH-mYG.d.ts +8 -0
- package/dist/values-DApyq53y.cjs +267 -0
- package/dist/webhook.cjs +3 -3
- package/dist/webhook.d.cts +1 -1
- package/dist/webhook.d.ts +1 -1
- package/dist/webhook.js +3 -3
- package/dist/workflow-distributed.cjs +9 -7
- package/dist/workflow-distributed.d.cts +9 -8
- package/dist/workflow-distributed.d.ts +9 -8
- package/dist/workflow-distributed.js +9 -7
- package/dist/workflow.cjs +26 -17
- package/dist/workflow.d.cts +1 -28
- package/dist/workflow.d.ts +1 -28
- package/dist/workflow.js +26 -17
- package/dist/yaml-config.cjs +26 -11
- package/dist/yaml-config.d.cts +9 -3
- package/dist/yaml-config.d.ts +9 -3
- package/dist/yaml-config.js +26 -11
- package/package.json +6 -1
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { t as UnknownRecord } from "./values-CeMH-mYG.js";
|
|
1
2
|
import { AttributeValue, Attributes, BaggageEntry, Context, Link, Span, SpanStatusCode } from "@opentelemetry/api";
|
|
2
3
|
import { AsyncLocalStorage } from "node:async_hooks";
|
|
3
4
|
//#region src/trace-context.d.ts
|
|
@@ -44,21 +45,21 @@ interface SpanMethods {
|
|
|
44
45
|
* Replaces the deprecated `recordException` (OTEP 4430). Accepts `unknown`
|
|
45
46
|
* so it can be called directly with the value caught from a `catch` block.
|
|
46
47
|
*/
|
|
47
|
-
recordError(
|
|
48
|
+
recordError(cause: unknown): void;
|
|
48
49
|
/**
|
|
49
50
|
* Emit a tracked event correlated to this span. Equivalent to the standalone
|
|
50
51
|
* `track(event, data)` but reads naturally on `ctx`. Replaces the deprecated
|
|
51
52
|
* `ctx.addEvent` (OTEP 4430) — events become correlated logs rather than
|
|
52
53
|
* span events.
|
|
53
54
|
*/
|
|
54
|
-
track<Events extends
|
|
55
|
+
track<Events extends UnknownRecord = UnknownRecord>(event: keyof Events & string, data?: Events[keyof Events & string]): void;
|
|
55
56
|
}
|
|
56
57
|
/**
|
|
57
58
|
* Baggage methods available on trace context
|
|
58
59
|
*
|
|
59
60
|
* @template TBaggage - Optional type for typed baggage (defaults to undefined for untyped)
|
|
60
61
|
*/
|
|
61
|
-
interface BaggageMethods<TBaggage extends
|
|
62
|
+
interface BaggageMethods<TBaggage extends UnknownRecord | undefined = undefined> {
|
|
62
63
|
/**
|
|
63
64
|
* Get a baggage entry by key
|
|
64
65
|
* @param key - Baggage key
|
|
@@ -104,14 +105,14 @@ interface BaggageMethods<TBaggage extends Record<string, unknown> | undefined =
|
|
|
104
105
|
*
|
|
105
106
|
* @internal
|
|
106
107
|
*/
|
|
107
|
-
getTypedBaggage?: TBaggage extends
|
|
108
|
+
getTypedBaggage?: TBaggage extends UnknownRecord ? <T extends TBaggage>(namespace?: string) => Partial<T> | undefined : never;
|
|
108
109
|
/**
|
|
109
110
|
* Set typed baggage (only available when TBaggage is defined)
|
|
110
111
|
* This is used internally by defineBaggageSchema()
|
|
111
112
|
*
|
|
112
113
|
* @internal
|
|
113
114
|
*/
|
|
114
|
-
setTypedBaggage?: TBaggage extends
|
|
115
|
+
setTypedBaggage?: TBaggage extends UnknownRecord ? <T extends TBaggage>(namespace: string | undefined, value: Partial<T>) => void : never;
|
|
115
116
|
}
|
|
116
117
|
/**
|
|
117
118
|
* Complete trace context that merges base context, span methods, and baggage methods
|
|
@@ -140,7 +141,7 @@ interface BaggageMethods<TBaggage extends Record<string, unknown> | undefined =
|
|
|
140
141
|
* });
|
|
141
142
|
* ```
|
|
142
143
|
*/
|
|
143
|
-
type TraceContext<TBaggage extends
|
|
144
|
+
type TraceContext<TBaggage extends UnknownRecord | undefined = undefined> = TraceContextBase & SpanMethods & BaggageMethods<TBaggage>;
|
|
144
145
|
/**
|
|
145
146
|
* Define a typed baggage schema for type-safe baggage operations
|
|
146
147
|
*
|
|
@@ -179,7 +180,7 @@ type TraceContext<TBaggage extends Record<string, unknown> | undefined = undefin
|
|
|
179
180
|
* });
|
|
180
181
|
* ```
|
|
181
182
|
*/
|
|
182
|
-
declare function defineBaggageSchema<T extends
|
|
183
|
+
declare function defineBaggageSchema<T extends UnknownRecord>(namespace?: string): {
|
|
183
184
|
/**
|
|
184
185
|
* Get typed baggage from context
|
|
185
186
|
* @param ctx - Trace context
|
package/dist/trace-helpers.cjs
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
|
-
const
|
|
2
|
+
const require_values = require('./values-DApyq53y.cjs');
|
|
3
|
+
const require_node_require = require('./node-require-EifOMikz.cjs');
|
|
3
4
|
let _opentelemetry_api = require("@opentelemetry/api");
|
|
4
5
|
|
|
5
6
|
//#region src/trace-helpers.ts
|
|
@@ -379,10 +380,9 @@ function runWithSpan(span, fn) {
|
|
|
379
380
|
* }
|
|
380
381
|
* ```
|
|
381
382
|
*/
|
|
382
|
-
function finalizeSpan(span,
|
|
383
|
-
if (
|
|
384
|
-
|
|
385
|
-
else span.recordException(new Error(String(error)));
|
|
383
|
+
function finalizeSpan(span, cause) {
|
|
384
|
+
if (cause) {
|
|
385
|
+
span.recordException(require_values.toError(cause));
|
|
386
386
|
span.setStatus({ code: _opentelemetry_api.SpanStatusCode.ERROR });
|
|
387
387
|
} else span.setStatus({ code: _opentelemetry_api.SpanStatusCode.OK });
|
|
388
388
|
span.end();
|
|
@@ -593,21 +593,24 @@ function flattenMetadata(metadata, prefix = "metadata") {
|
|
|
593
593
|
for (const [key, value] of Object.entries(obj)) {
|
|
594
594
|
if (value == null) continue;
|
|
595
595
|
const attributeKey = `${currentPrefix}.${key}`;
|
|
596
|
-
|
|
597
|
-
|
|
596
|
+
const text = require_values.asString(value);
|
|
597
|
+
if (text !== void 0) {
|
|
598
|
+
flattened[attributeKey] = text;
|
|
598
599
|
continue;
|
|
599
600
|
}
|
|
600
|
-
|
|
601
|
-
|
|
601
|
+
const scalar = require_values.asNumber(value) ?? require_values.asBoolean(value);
|
|
602
|
+
if (scalar !== void 0) {
|
|
603
|
+
flattened[attributeKey] = String(scalar);
|
|
602
604
|
continue;
|
|
603
605
|
}
|
|
604
|
-
|
|
605
|
-
|
|
606
|
+
const nested = require_values.asPlainRecord(value);
|
|
607
|
+
if (nested !== void 0) {
|
|
608
|
+
if (seen.has(nested)) {
|
|
606
609
|
flattened[attributeKey] = "<circular-reference>";
|
|
607
610
|
continue;
|
|
608
611
|
}
|
|
609
|
-
seen.add(
|
|
610
|
-
flatten(
|
|
612
|
+
seen.add(nested);
|
|
613
|
+
flatten(nested, attributeKey);
|
|
611
614
|
continue;
|
|
612
615
|
}
|
|
613
616
|
try {
|
package/dist/trace-helpers.d.cts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { t as UnknownRecord } from "./values-CeMH-mYG.cjs";
|
|
1
2
|
import { Context, Span, Tracer } from "@opentelemetry/api";
|
|
2
3
|
//#region src/trace-helpers.d.ts
|
|
3
4
|
/**
|
|
@@ -78,7 +79,7 @@ declare function getTraceContext(): TraceContext | null;
|
|
|
78
79
|
* // { userId: '123' } - no trace fields added
|
|
79
80
|
* ```
|
|
80
81
|
*/
|
|
81
|
-
declare function enrichWithTraceContext<T extends
|
|
82
|
+
declare function enrichWithTraceContext<T extends UnknownRecord>(obj: T): T;
|
|
82
83
|
/**
|
|
83
84
|
* Check if currently in a trace context
|
|
84
85
|
*
|
|
@@ -303,7 +304,7 @@ declare function runWithSpan<T>(span: Span, fn: () => T): T;
|
|
|
303
304
|
* }
|
|
304
305
|
* ```
|
|
305
306
|
*/
|
|
306
|
-
declare function finalizeSpan(span: Span,
|
|
307
|
+
declare function finalizeSpan(span: Span, cause?: unknown): void;
|
|
307
308
|
/**
|
|
308
309
|
* Creates a deterministic trace ID from a seed string.
|
|
309
310
|
*
|
|
@@ -495,6 +496,10 @@ declare function createDeterministicTraceId(seed: string): Promise<string>;
|
|
|
495
496
|
* // => 'https://grafana.example.com/explore?traceId=abc123'
|
|
496
497
|
*/
|
|
497
498
|
declare function resolveTraceUrl(template: string | undefined, traceId: string): string | undefined;
|
|
498
|
-
|
|
499
|
+
/** Flattened metadata: every leaf rendered as the string an attribute holds. */
|
|
500
|
+
interface FlatMetadata {
|
|
501
|
+
[key: string]: string;
|
|
502
|
+
}
|
|
503
|
+
declare function flattenMetadata(metadata: UnknownRecord, prefix?: string): FlatMetadata;
|
|
499
504
|
//#endregion
|
|
500
|
-
export { TraceContext, createDeterministicTraceId, enrichWithTraceContext, finalizeSpan, flattenMetadata, getActiveContext, getActiveSpan, getTraceContext, getTracer, isTracing, resolveTraceUrl, runWithSpan, setSpanName };
|
|
505
|
+
export { FlatMetadata, TraceContext, createDeterministicTraceId, enrichWithTraceContext, finalizeSpan, flattenMetadata, getActiveContext, getActiveSpan, getTraceContext, getTracer, isTracing, resolveTraceUrl, runWithSpan, setSpanName };
|
package/dist/trace-helpers.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { t as UnknownRecord } from "./values-CeMH-mYG.js";
|
|
1
2
|
import { Context, Span, Tracer } from "@opentelemetry/api";
|
|
2
3
|
//#region src/trace-helpers.d.ts
|
|
3
4
|
/**
|
|
@@ -78,7 +79,7 @@ declare function getTraceContext(): TraceContext | null;
|
|
|
78
79
|
* // { userId: '123' } - no trace fields added
|
|
79
80
|
* ```
|
|
80
81
|
*/
|
|
81
|
-
declare function enrichWithTraceContext<T extends
|
|
82
|
+
declare function enrichWithTraceContext<T extends UnknownRecord>(obj: T): T;
|
|
82
83
|
/**
|
|
83
84
|
* Check if currently in a trace context
|
|
84
85
|
*
|
|
@@ -303,7 +304,7 @@ declare function runWithSpan<T>(span: Span, fn: () => T): T;
|
|
|
303
304
|
* }
|
|
304
305
|
* ```
|
|
305
306
|
*/
|
|
306
|
-
declare function finalizeSpan(span: Span,
|
|
307
|
+
declare function finalizeSpan(span: Span, cause?: unknown): void;
|
|
307
308
|
/**
|
|
308
309
|
* Creates a deterministic trace ID from a seed string.
|
|
309
310
|
*
|
|
@@ -495,6 +496,10 @@ declare function createDeterministicTraceId(seed: string): Promise<string>;
|
|
|
495
496
|
* // => 'https://grafana.example.com/explore?traceId=abc123'
|
|
496
497
|
*/
|
|
497
498
|
declare function resolveTraceUrl(template: string | undefined, traceId: string): string | undefined;
|
|
498
|
-
|
|
499
|
+
/** Flattened metadata: every leaf rendered as the string an attribute holds. */
|
|
500
|
+
interface FlatMetadata {
|
|
501
|
+
[key: string]: string;
|
|
502
|
+
}
|
|
503
|
+
declare function flattenMetadata(metadata: UnknownRecord, prefix?: string): FlatMetadata;
|
|
499
504
|
//#endregion
|
|
500
|
-
export { TraceContext, createDeterministicTraceId, enrichWithTraceContext, finalizeSpan, flattenMetadata, getActiveContext, getActiveSpan, getTraceContext, getTracer, isTracing, resolveTraceUrl, runWithSpan, setSpanName };
|
|
505
|
+
export { FlatMetadata, TraceContext, createDeterministicTraceId, enrichWithTraceContext, finalizeSpan, flattenMetadata, getActiveContext, getActiveSpan, getTraceContext, getTracer, isTracing, resolveTraceUrl, runWithSpan, setSpanName };
|
package/dist/trace-helpers.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import { t as
|
|
1
|
+
import { i as asNumber, l as asString, o as asPlainRecord, t as asBoolean, x as toError } from "./values-BenyvWKz.js";
|
|
2
|
+
import { t as requireModule } from "./node-require-DSPjaw_l.js";
|
|
2
3
|
import { SpanStatusCode, context, trace } from "@opentelemetry/api";
|
|
3
4
|
|
|
4
5
|
//#region src/trace-helpers.ts
|
|
@@ -378,10 +379,9 @@ function runWithSpan(span, fn) {
|
|
|
378
379
|
* }
|
|
379
380
|
* ```
|
|
380
381
|
*/
|
|
381
|
-
function finalizeSpan(span,
|
|
382
|
-
if (
|
|
383
|
-
|
|
384
|
-
else span.recordException(new Error(String(error)));
|
|
382
|
+
function finalizeSpan(span, cause) {
|
|
383
|
+
if (cause) {
|
|
384
|
+
span.recordException(toError(cause));
|
|
385
385
|
span.setStatus({ code: SpanStatusCode.ERROR });
|
|
386
386
|
} else span.setStatus({ code: SpanStatusCode.OK });
|
|
387
387
|
span.end();
|
|
@@ -592,21 +592,24 @@ function flattenMetadata(metadata, prefix = "metadata") {
|
|
|
592
592
|
for (const [key, value] of Object.entries(obj)) {
|
|
593
593
|
if (value == null) continue;
|
|
594
594
|
const attributeKey = `${currentPrefix}.${key}`;
|
|
595
|
-
|
|
596
|
-
|
|
595
|
+
const text = asString(value);
|
|
596
|
+
if (text !== void 0) {
|
|
597
|
+
flattened[attributeKey] = text;
|
|
597
598
|
continue;
|
|
598
599
|
}
|
|
599
|
-
|
|
600
|
-
|
|
600
|
+
const scalar = asNumber(value) ?? asBoolean(value);
|
|
601
|
+
if (scalar !== void 0) {
|
|
602
|
+
flattened[attributeKey] = String(scalar);
|
|
601
603
|
continue;
|
|
602
604
|
}
|
|
603
|
-
|
|
604
|
-
|
|
605
|
+
const nested = asPlainRecord(value);
|
|
606
|
+
if (nested !== void 0) {
|
|
607
|
+
if (seen.has(nested)) {
|
|
605
608
|
flattened[attributeKey] = "<circular-reference>";
|
|
606
609
|
continue;
|
|
607
610
|
}
|
|
608
|
-
seen.add(
|
|
609
|
-
flatten(
|
|
611
|
+
seen.add(nested);
|
|
612
|
+
flatten(nested, attributeKey);
|
|
610
613
|
continue;
|
|
611
614
|
}
|
|
612
615
|
try {
|
package/dist/tracer-provider.cjs
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
|
+
const require_values = require('./values-DApyq53y.cjs');
|
|
2
3
|
let _opentelemetry_api = require("@opentelemetry/api");
|
|
3
4
|
|
|
4
5
|
//#region src/tracer-provider.ts
|
|
@@ -34,10 +35,6 @@ function getGlobalState() {
|
|
|
34
35
|
const initialState = createState();
|
|
35
36
|
try {
|
|
36
37
|
const g = globalThis;
|
|
37
|
-
if (typeof g !== "object" || g === null) {
|
|
38
|
-
console.warn("[autotel] globalThis is not available, using fallback state");
|
|
39
|
-
return initialState;
|
|
40
|
-
}
|
|
41
38
|
if (!g[AUTOTEL_GLOBAL_SYMBOL]) Object.defineProperty(g, AUTOTEL_GLOBAL_SYMBOL, {
|
|
42
39
|
value: initialState,
|
|
43
40
|
writable: false,
|
|
@@ -188,8 +185,9 @@ function getAutotelTracerProvider() {
|
|
|
188
185
|
if (isolatedTracerProvider) return isolatedTracerProvider;
|
|
189
186
|
return _opentelemetry_api.trace.getTracerProvider();
|
|
190
187
|
}
|
|
191
|
-
|
|
192
|
-
|
|
188
|
+
/** The candidate if it can be force-flushed, or undefined. */
|
|
189
|
+
function asForceFlushable(value) {
|
|
190
|
+
return require_values.isFunction(require_values.readProperty(value, "forceFlush")) ? value : void 0;
|
|
193
191
|
}
|
|
194
192
|
/**
|
|
195
193
|
* Resolve a tracer provider that can be `forceFlush()`ed, so `flush()` and
|
|
@@ -205,14 +203,12 @@ function isForceFlushable(value) {
|
|
|
205
203
|
* @returns Something with `forceFlush()`, or `undefined` if none is registered.
|
|
206
204
|
*/
|
|
207
205
|
function getForceFlushableProvider(sdk) {
|
|
208
|
-
const candidates = [];
|
|
209
|
-
const sdkAny = sdk;
|
|
210
|
-
if (sdkAny && typeof sdkAny.getTracerProvider === "function") candidates.push(sdkAny.getTracerProvider());
|
|
206
|
+
const candidates = [require_values.asFunction(require_values.readProperty(sdk, "getTracerProvider"))?.call(sdk)];
|
|
211
207
|
const globalProvider = _opentelemetry_api.trace.getTracerProvider();
|
|
212
208
|
candidates.push(globalProvider);
|
|
213
|
-
const
|
|
214
|
-
if (
|
|
215
|
-
return candidates.find(
|
|
209
|
+
const getDelegate = require_values.asFunction(require_values.readProperty(globalProvider, "getDelegate"));
|
|
210
|
+
if (getDelegate) candidates.push(getDelegate.call(globalProvider));
|
|
211
|
+
return candidates.map(asForceFlushable).find((found) => found !== void 0);
|
|
216
212
|
}
|
|
217
213
|
/**
|
|
218
214
|
* Gets the OpenTelemetry tracer instance for Autotel.
|
package/dist/tracer-provider.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { _ as readProperty, h as isFunction, r as asFunction } from "./values-BenyvWKz.js";
|
|
1
2
|
import { trace } from "@opentelemetry/api";
|
|
2
3
|
|
|
3
4
|
//#region src/tracer-provider.ts
|
|
@@ -33,10 +34,6 @@ function getGlobalState() {
|
|
|
33
34
|
const initialState = createState();
|
|
34
35
|
try {
|
|
35
36
|
const g = globalThis;
|
|
36
|
-
if (typeof g !== "object" || g === null) {
|
|
37
|
-
console.warn("[autotel] globalThis is not available, using fallback state");
|
|
38
|
-
return initialState;
|
|
39
|
-
}
|
|
40
37
|
if (!g[AUTOTEL_GLOBAL_SYMBOL]) Object.defineProperty(g, AUTOTEL_GLOBAL_SYMBOL, {
|
|
41
38
|
value: initialState,
|
|
42
39
|
writable: false,
|
|
@@ -187,8 +184,9 @@ function getAutotelTracerProvider() {
|
|
|
187
184
|
if (isolatedTracerProvider) return isolatedTracerProvider;
|
|
188
185
|
return trace.getTracerProvider();
|
|
189
186
|
}
|
|
190
|
-
|
|
191
|
-
|
|
187
|
+
/** The candidate if it can be force-flushed, or undefined. */
|
|
188
|
+
function asForceFlushable(value) {
|
|
189
|
+
return isFunction(readProperty(value, "forceFlush")) ? value : void 0;
|
|
192
190
|
}
|
|
193
191
|
/**
|
|
194
192
|
* Resolve a tracer provider that can be `forceFlush()`ed, so `flush()` and
|
|
@@ -204,14 +202,12 @@ function isForceFlushable(value) {
|
|
|
204
202
|
* @returns Something with `forceFlush()`, or `undefined` if none is registered.
|
|
205
203
|
*/
|
|
206
204
|
function getForceFlushableProvider(sdk) {
|
|
207
|
-
const candidates = [];
|
|
208
|
-
const sdkAny = sdk;
|
|
209
|
-
if (sdkAny && typeof sdkAny.getTracerProvider === "function") candidates.push(sdkAny.getTracerProvider());
|
|
205
|
+
const candidates = [asFunction(readProperty(sdk, "getTracerProvider"))?.call(sdk)];
|
|
210
206
|
const globalProvider = trace.getTracerProvider();
|
|
211
207
|
candidates.push(globalProvider);
|
|
212
|
-
const
|
|
213
|
-
if (
|
|
214
|
-
return candidates.find(
|
|
208
|
+
const getDelegate = asFunction(readProperty(globalProvider, "getDelegate"));
|
|
209
|
+
if (getDelegate) candidates.push(getDelegate.call(globalProvider));
|
|
210
|
+
return candidates.map(asForceFlushable).find((found) => found !== void 0);
|
|
215
211
|
}
|
|
216
212
|
/**
|
|
217
213
|
* Gets the OpenTelemetry tracer instance for Autotel.
|
package/dist/validate.cjs
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
|
-
const
|
|
3
|
-
const
|
|
2
|
+
const require_values = require('./values-DApyq53y.cjs');
|
|
3
|
+
const require_structured_error = require('./structured-error--_wXpd_C.cjs');
|
|
4
|
+
const require_stable_hash = require('./stable-hash-C0pOegH_.cjs');
|
|
4
5
|
const require_metric_helpers = require('./metric-helpers.cjs');
|
|
5
6
|
const require_validation_attributes = require('./validation-attributes.cjs');
|
|
6
7
|
let _opentelemetry_api = require("@opentelemetry/api");
|
|
@@ -64,16 +65,18 @@ function recordValidationMismatch(mismatch) {
|
|
|
64
65
|
const paths = mismatch.issues.map((i) => i.path).filter(Boolean);
|
|
65
66
|
const codes = [...new Set(mismatch.issues.map((i) => i.code))];
|
|
66
67
|
const span = _opentelemetry_api.trace.getActiveSpan();
|
|
67
|
-
if (span)
|
|
68
|
-
|
|
69
|
-
[require_validation_attributes.VALIDATION_ATTR.
|
|
70
|
-
[require_validation_attributes.VALIDATION_ATTR.
|
|
71
|
-
[require_validation_attributes.VALIDATION_ATTR.
|
|
72
|
-
[require_validation_attributes.VALIDATION_ATTR.
|
|
73
|
-
[require_validation_attributes.VALIDATION_ATTR.
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
68
|
+
if (span) {
|
|
69
|
+
const attributes = {};
|
|
70
|
+
attributes[require_validation_attributes.VALIDATION_ATTR.name] = mismatch.name;
|
|
71
|
+
attributes[require_validation_attributes.VALIDATION_ATTR.boundary] = mismatch.boundary;
|
|
72
|
+
attributes[require_validation_attributes.VALIDATION_ATTR.mode] = mismatch.mode;
|
|
73
|
+
attributes[require_validation_attributes.VALIDATION_ATTR.issueCount] = mismatch.issues.length;
|
|
74
|
+
attributes[require_validation_attributes.VALIDATION_ATTR.issuePaths] = truncate(paths);
|
|
75
|
+
attributes[require_validation_attributes.VALIDATION_ATTR.issueCodes] = truncate(codes);
|
|
76
|
+
if (mismatch.hash) attributes[require_validation_attributes.VALIDATION_ATTR.hash] = mismatch.hash;
|
|
77
|
+
if (mismatch.severity) attributes[require_validation_attributes.VALIDATION_ATTR.severity] = mismatch.severity;
|
|
78
|
+
span.setAttributes(attributes);
|
|
79
|
+
}
|
|
77
80
|
try {
|
|
78
81
|
counter().add(1, {
|
|
79
82
|
boundary: mismatch.boundary,
|
|
@@ -97,17 +100,16 @@ function formatValidationIssues(error) {
|
|
|
97
100
|
return extractRawIssues(error).map((issue) => toSafeIssue(issue));
|
|
98
101
|
}
|
|
99
102
|
function extractRawIssues(error) {
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
return [];
|
|
103
|
+
const raised = require_values.asRecord(error);
|
|
104
|
+
const candidate = raised?.issues ?? raised?.errors;
|
|
105
|
+
if (!Array.isArray(candidate)) return [];
|
|
106
|
+
return candidate.map((issue) => require_values.asRecord(issue)).filter((issue) => issue !== void 0);
|
|
105
107
|
}
|
|
106
108
|
function toSafeIssue(issue) {
|
|
107
109
|
const rawPath = issue.path;
|
|
108
|
-
const path = Array.isArray(rawPath) ? rawPath.map(String).join(".") :
|
|
109
|
-
const code =
|
|
110
|
-
const expected =
|
|
110
|
+
const path = Array.isArray(rawPath) ? rawPath.map(String).join(".") : require_values.asString(rawPath) ?? "";
|
|
111
|
+
const code = require_values.asString(issue.code) ?? "invalid";
|
|
112
|
+
const expected = require_values.asString(issue.expected);
|
|
111
113
|
return expected ? {
|
|
112
114
|
path,
|
|
113
115
|
code,
|
package/dist/validate.d.cts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { t as UnknownRecord } from "./values-CeMH-mYG.cjs";
|
|
2
|
+
import { r as SchemaLike } from "./define-event-BNeuKUPv.cjs";
|
|
2
3
|
//#region src/validate.d.ts
|
|
3
4
|
type ValidationMode = 'observe' | 'reject';
|
|
4
5
|
type ValidationSeverity = 'info' | 'warning' | 'error';
|
|
@@ -54,7 +55,7 @@ interface DefineValidatorOptions<S> {
|
|
|
54
55
|
/** `reject` (default): record then throw. `observe`: record then continue. */
|
|
55
56
|
onMismatch?: ValidationMode;
|
|
56
57
|
/** Project the schema to JSON Schema for a stable `validation.hash`. */
|
|
57
|
-
toJsonSchema?: (schema: S) =>
|
|
58
|
+
toJsonSchema?: (schema: S) => UnknownRecord;
|
|
58
59
|
severity?: ValidationSeverity;
|
|
59
60
|
/** Build the error thrown in `reject` mode (defaults to a 400 structured error). */
|
|
60
61
|
onReject?: (issues: ValidationIssue[], name: string) => Error;
|
package/dist/validate.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { t as UnknownRecord } from "./values-CeMH-mYG.js";
|
|
2
|
+
import { r as SchemaLike } from "./define-event-Bd8f8mST.js";
|
|
2
3
|
//#region src/validate.d.ts
|
|
3
4
|
type ValidationMode = 'observe' | 'reject';
|
|
4
5
|
type ValidationSeverity = 'info' | 'warning' | 'error';
|
|
@@ -54,7 +55,7 @@ interface DefineValidatorOptions<S> {
|
|
|
54
55
|
/** `reject` (default): record then throw. `observe`: record then continue. */
|
|
55
56
|
onMismatch?: ValidationMode;
|
|
56
57
|
/** Project the schema to JSON Schema for a stable `validation.hash`. */
|
|
57
|
-
toJsonSchema?: (schema: S) =>
|
|
58
|
+
toJsonSchema?: (schema: S) => UnknownRecord;
|
|
58
59
|
severity?: ValidationSeverity;
|
|
59
60
|
/** Build the error thrown in `reject` mode (defaults to a 400 structured error). */
|
|
60
61
|
onReject?: (issues: ValidationIssue[], name: string) => Error;
|
package/dist/validate.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { t as
|
|
1
|
+
import { l as asString, s as asRecord } from "./values-BenyvWKz.js";
|
|
2
|
+
import { t as createStructuredError } from "./structured-error-YIuka-FE.js";
|
|
3
|
+
import { t as hashJson } from "./stable-hash-BkoAYVks.js";
|
|
3
4
|
import { createCounter } from "./metric-helpers.js";
|
|
4
5
|
import { VALIDATION_ATTR, VALIDATION_ISSUE_CAP, VALIDATION_METRICS } from "./validation-attributes.js";
|
|
5
6
|
import { trace } from "@opentelemetry/api";
|
|
@@ -63,16 +64,18 @@ function recordValidationMismatch(mismatch) {
|
|
|
63
64
|
const paths = mismatch.issues.map((i) => i.path).filter(Boolean);
|
|
64
65
|
const codes = [...new Set(mismatch.issues.map((i) => i.code))];
|
|
65
66
|
const span = trace.getActiveSpan();
|
|
66
|
-
if (span)
|
|
67
|
-
|
|
68
|
-
[VALIDATION_ATTR.
|
|
69
|
-
[VALIDATION_ATTR.
|
|
70
|
-
[VALIDATION_ATTR.
|
|
71
|
-
[VALIDATION_ATTR.
|
|
72
|
-
[VALIDATION_ATTR.
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
67
|
+
if (span) {
|
|
68
|
+
const attributes = {};
|
|
69
|
+
attributes[VALIDATION_ATTR.name] = mismatch.name;
|
|
70
|
+
attributes[VALIDATION_ATTR.boundary] = mismatch.boundary;
|
|
71
|
+
attributes[VALIDATION_ATTR.mode] = mismatch.mode;
|
|
72
|
+
attributes[VALIDATION_ATTR.issueCount] = mismatch.issues.length;
|
|
73
|
+
attributes[VALIDATION_ATTR.issuePaths] = truncate(paths);
|
|
74
|
+
attributes[VALIDATION_ATTR.issueCodes] = truncate(codes);
|
|
75
|
+
if (mismatch.hash) attributes[VALIDATION_ATTR.hash] = mismatch.hash;
|
|
76
|
+
if (mismatch.severity) attributes[VALIDATION_ATTR.severity] = mismatch.severity;
|
|
77
|
+
span.setAttributes(attributes);
|
|
78
|
+
}
|
|
76
79
|
try {
|
|
77
80
|
counter().add(1, {
|
|
78
81
|
boundary: mismatch.boundary,
|
|
@@ -96,17 +99,16 @@ function formatValidationIssues(error) {
|
|
|
96
99
|
return extractRawIssues(error).map((issue) => toSafeIssue(issue));
|
|
97
100
|
}
|
|
98
101
|
function extractRawIssues(error) {
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
return [];
|
|
102
|
+
const raised = asRecord(error);
|
|
103
|
+
const candidate = raised?.issues ?? raised?.errors;
|
|
104
|
+
if (!Array.isArray(candidate)) return [];
|
|
105
|
+
return candidate.map((issue) => asRecord(issue)).filter((issue) => issue !== void 0);
|
|
104
106
|
}
|
|
105
107
|
function toSafeIssue(issue) {
|
|
106
108
|
const rawPath = issue.path;
|
|
107
|
-
const path = Array.isArray(rawPath) ? rawPath.map(String).join(".") :
|
|
108
|
-
const code =
|
|
109
|
-
const expected =
|
|
109
|
+
const path = Array.isArray(rawPath) ? rawPath.map(String).join(".") : asString(rawPath) ?? "";
|
|
110
|
+
const code = asString(issue.code) ?? "invalid";
|
|
111
|
+
const expected = asString(issue.expected);
|
|
110
112
|
return expected ? {
|
|
111
113
|
path,
|
|
112
114
|
code,
|
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
//#region src/values.ts
|
|
2
|
+
/** The value as an object, or undefined when it is anything else. */
|
|
3
|
+
function asRecord(value) {
|
|
4
|
+
return typeof value === "object" && value !== null && !Array.isArray(value) ? value : void 0;
|
|
5
|
+
}
|
|
6
|
+
/** The string the value carries, or undefined when it carries anything else. */
|
|
7
|
+
function asString(value) {
|
|
8
|
+
return typeof value === "string" ? value : void 0;
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* The value as a map of strings - a header bag, say - or undefined when it is
|
|
12
|
+
* not an object at all. Entries whose value is not a string are left out.
|
|
13
|
+
*/
|
|
14
|
+
function asStringRecord(value) {
|
|
15
|
+
const record = asRecord(value);
|
|
16
|
+
if (record === void 0) return void 0;
|
|
17
|
+
const strings = {};
|
|
18
|
+
for (const [key, entry] of Object.entries(record)) {
|
|
19
|
+
const text = asString(entry);
|
|
20
|
+
if (text !== void 0) strings[key] = text;
|
|
21
|
+
}
|
|
22
|
+
return strings;
|
|
23
|
+
}
|
|
24
|
+
/** The scalar the value carries - string, number or boolean - or undefined. */
|
|
25
|
+
function asScalar(value) {
|
|
26
|
+
return asString(value) ?? asNumber(value) ?? asBoolean(value);
|
|
27
|
+
}
|
|
28
|
+
/** The numbers the value carries as a list, or undefined when it is not one. */
|
|
29
|
+
function asNumberArray(value) {
|
|
30
|
+
return Array.isArray(value) && value.every((v) => asNumber(v) !== void 0) ? value.map(Number) : void 0;
|
|
31
|
+
}
|
|
32
|
+
/** The booleans the value carries as a list, or undefined when it is not one. */
|
|
33
|
+
function asBooleanArray(value) {
|
|
34
|
+
return Array.isArray(value) && value.every((v) => asBoolean(v) !== void 0) ? value.map(Boolean) : void 0;
|
|
35
|
+
}
|
|
36
|
+
/** The strings the value carries as a list, or undefined when it is not one. */
|
|
37
|
+
function asStringArray(value) {
|
|
38
|
+
return Array.isArray(value) && value.every((v) => asString(v) !== void 0) ? value.map(String) : void 0;
|
|
39
|
+
}
|
|
40
|
+
/** A string with something in it - a blank one counts as absent. */
|
|
41
|
+
function nonEmptyString(value) {
|
|
42
|
+
const text = asString(value);
|
|
43
|
+
return text !== void 0 && text.trim() !== "" ? text : void 0;
|
|
44
|
+
}
|
|
45
|
+
/** The number the value carries, or undefined when it carries anything else. */
|
|
46
|
+
function asNumber(value) {
|
|
47
|
+
return typeof value === "number" && Number.isFinite(value) ? value : void 0;
|
|
48
|
+
}
|
|
49
|
+
/** The boolean the value carries, or undefined when it carries anything else. */
|
|
50
|
+
function asBoolean(value) {
|
|
51
|
+
return typeof value === "boolean" ? value : void 0;
|
|
52
|
+
}
|
|
53
|
+
/** Whether the value is callable. */
|
|
54
|
+
function isFunction(value) {
|
|
55
|
+
return typeof value === "function";
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* A config field that may be given as a value or as a function producing one,
|
|
59
|
+
* resolved to the value.
|
|
60
|
+
*/
|
|
61
|
+
function resolveValue(source) {
|
|
62
|
+
return typeof source === "function" ? source() : source;
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* An overloaded first argument that is either a name or an options object,
|
|
66
|
+
* split into the two.
|
|
67
|
+
*/
|
|
68
|
+
function splitNameOrOptions(value) {
|
|
69
|
+
return typeof value === "string" ? { name: value } : { options: value };
|
|
70
|
+
}
|
|
71
|
+
/** The value as a callable, or undefined when it is not one. */
|
|
72
|
+
function asFunction(value) {
|
|
73
|
+
if (typeof value !== "function") return void 0;
|
|
74
|
+
return value;
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* The value as a plain object - one built from a literal, not an instance of
|
|
78
|
+
* some class that has its own idea of what it is.
|
|
79
|
+
*/
|
|
80
|
+
function asPlainRecord(value) {
|
|
81
|
+
const record = asRecord(value);
|
|
82
|
+
return record !== void 0 && Object.getPrototypeOf(record) === Object.prototype ? record : void 0;
|
|
83
|
+
}
|
|
84
|
+
/** One field of a value, when the value is an object at all. */
|
|
85
|
+
function readProperty(source, key) {
|
|
86
|
+
return asRecord(source)?.[key];
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* What a value is, for a diagnostic message: the same words `typeof` uses,
|
|
90
|
+
* plus `null` and `array`, which are the two cases `typeof` answers uselessly.
|
|
91
|
+
*/
|
|
92
|
+
function describeValue(value) {
|
|
93
|
+
if (value === null) return "null";
|
|
94
|
+
return Array.isArray(value) ? "array" : typeof value;
|
|
95
|
+
}
|
|
96
|
+
/**
|
|
97
|
+
* The Error a caller's callback expects, wrapping whatever was actually
|
|
98
|
+
* thrown - a string, a number, an object with no stack.
|
|
99
|
+
*/
|
|
100
|
+
function toError(cause) {
|
|
101
|
+
return cause instanceof Error ? cause : new Error(String(cause));
|
|
102
|
+
}
|
|
103
|
+
/**
|
|
104
|
+
* A value as an OTel attribute, or undefined when it cannot be one.
|
|
105
|
+
*
|
|
106
|
+
* OTel accepts scalars and homogeneous arrays of scalars. Anything else - a
|
|
107
|
+
* nested object, a mixed array - is stringified rather than dropped, because
|
|
108
|
+
* a caller that attached it wanted to see it.
|
|
109
|
+
*/
|
|
110
|
+
function toAttributeValue(value) {
|
|
111
|
+
if (value === void 0 || value === null) return void 0;
|
|
112
|
+
const scalar = asString(value) ?? asNumber(value) ?? asBoolean(value);
|
|
113
|
+
if (scalar !== void 0) return scalar;
|
|
114
|
+
if (Array.isArray(value)) return toAttributeArray(value);
|
|
115
|
+
return JSON.stringify(value);
|
|
116
|
+
}
|
|
117
|
+
/** The scalars in an array, dropping the entries OTel cannot carry. */
|
|
118
|
+
function toAttributeArray(values) {
|
|
119
|
+
const strings = values.filter((v) => typeof v === "string");
|
|
120
|
+
if (strings.length === values.length) return strings;
|
|
121
|
+
const numbers = values.filter((v) => typeof v === "number");
|
|
122
|
+
if (numbers.length === values.length) return numbers;
|
|
123
|
+
const booleans = values.filter((v) => typeof v === "boolean");
|
|
124
|
+
if (booleans.length === values.length) return booleans;
|
|
125
|
+
return values.length > 0 ? JSON.stringify(values) : void 0;
|
|
126
|
+
}
|
|
127
|
+
/** Whether a Node-style `process` global exists at all - edge runtimes have none. */
|
|
128
|
+
function hasProcess() {
|
|
129
|
+
return typeof process !== "undefined";
|
|
130
|
+
}
|
|
131
|
+
/**
|
|
132
|
+
* Whether this build is running outside production, for warnings meant to
|
|
133
|
+
* help during development. `process` is probed because the same code runs in
|
|
134
|
+
* edge runtimes that have no such global.
|
|
135
|
+
*/
|
|
136
|
+
function isDevelopment() {
|
|
137
|
+
return hasProcess() && process.env.NODE_ENV !== "production";
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
//#endregion
|
|
141
|
+
export { readProperty as _, asNumberArray as a, toAttributeValue as b, asScalar as c, asStringRecord as d, describeValue as f, nonEmptyString as g, isFunction as h, asNumber as i, asString as l, isDevelopment as m, asBooleanArray as n, asPlainRecord as o, hasProcess as p, asFunction as r, asRecord as s, asBoolean as t, asStringArray as u, resolveValue as v, toError as x, splitNameOrOptions as y };
|