@lunora/observability 1.0.0-alpha.110 → 1.0.0-alpha.112
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/dist/index.d.mts +53 -31
- package/dist/index.d.ts +53 -31
- package/dist/index.mjs +1 -1
- package/dist/packem_shared/createDatabaseTally-BVH6hi5W.mjs +1 -0
- package/dist/packem_shared/createMetrics-pQCAOmxn.mjs +1 -0
- package/dist/packem_shared/otlp-B-WBkikT.mjs +1 -0
- package/dist/packem_shared/resolveTraceAnchor-CTZfm9KX.mjs +1 -0
- package/dist/packem_shared/setHostSpanAttributes-DfxUKy_K.mjs +1 -0
- package/package.json +3 -3
- package/dist/packem_shared/createDatabaseTally-C0ViFQDq.mjs +0 -1
- package/dist/packem_shared/createMetrics-BmF7DdTk.mjs +0 -1
- package/dist/packem_shared/resolveTraceAnchor-Ft_Ewucb.mjs +0 -1
- package/dist/packem_shared/trace-context-d_EfGPSZ.mjs +0 -1
package/dist/index.d.mts
CHANGED
|
@@ -466,35 +466,6 @@ interface SpanEvent {
|
|
|
466
466
|
/** Acting userId, or absent when anonymous. */
|
|
467
467
|
userId?: string;
|
|
468
468
|
}
|
|
469
|
-
/**
|
|
470
|
-
* Structural shape of the `ctx.trace` span factory (see the server
|
|
471
|
-
* `LunoraTracer`). Declared here rather than imported so `@lunora/do` takes no
|
|
472
|
-
* dependency on `@lunora/server`; a cross-package assignability guard in
|
|
473
|
-
* `@lunora/testing` fails the build if the two drift apart.
|
|
474
|
-
*
|
|
475
|
-
* The body's second argument is the enclosing span's {@link SpanHandle}, through
|
|
476
|
-
* which it can attach attributes only known *after* it resolves (post-hoc). It is
|
|
477
|
-
* a trailing parameter, so a `(trace) => …` body that ignores it still conforms.
|
|
478
|
-
*/
|
|
479
|
-
type ContextTracer = <T>(name: string, function_: (trace: ContextTracer, span: SpanHandle) => Promise<T> | T, options?: LogFields | SpanOptions, identity?: SpanIdentity) => Promise<T>;
|
|
480
|
-
/** Structural shape of the `ctx.metrics` recorder (see the server `LunoraMetrics`). */
|
|
481
|
-
interface ContextMetrics {
|
|
482
|
-
count: (name: string, value?: number, attributes?: LogFields) => void;
|
|
483
|
-
gauge: (name: string, value: number, attributes?: LogFields) => void;
|
|
484
|
-
record: (name: string, value: number, attributes?: LogFields) => void;
|
|
485
|
-
}
|
|
486
|
-
/** The trace a ctx's spans hang off: the shared id, and the span they parent to. */
|
|
487
|
-
interface TraceAnchor {
|
|
488
|
-
rootSpanId: string;
|
|
489
|
-
/**
|
|
490
|
-
* The W3C `sampled` verdict for this trace, inherited from the inbound
|
|
491
|
-
* `traceparent` when there was one. Carried on the anchor rather than
|
|
492
|
-
* re-derived per outbound call so every `ctx.fetch` of one dispatch
|
|
493
|
-
* propagates the same answer.
|
|
494
|
-
*/
|
|
495
|
-
sampled?: boolean;
|
|
496
|
-
traceId: string;
|
|
497
|
-
}
|
|
498
469
|
/**
|
|
499
470
|
* Minimal structural shape of one **host-native custom span** — the object a
|
|
500
471
|
* `tracing.enterSpan(name, (span) => …)` callback receives (GA 2026-06-16). Only
|
|
@@ -518,8 +489,18 @@ interface HostSpanLike {
|
|
|
518
489
|
* a span nobody will read.
|
|
519
490
|
*/
|
|
520
491
|
readonly isTraced: boolean;
|
|
492
|
+
/**
|
|
493
|
+
* Record an OTel `exception` event on the span (CF 2026-09-25). Optional and
|
|
494
|
+
* feature-detected: older runtimes only have `setAttribute`.
|
|
495
|
+
*/
|
|
496
|
+
recordException?: (exception: {
|
|
497
|
+
message: string;
|
|
498
|
+
name: string;
|
|
499
|
+
}) => unknown;
|
|
521
500
|
/** Attach one primitive attribute to the CF span. */
|
|
522
|
-
setAttribute: (key: string, value: boolean | number | string | undefined) =>
|
|
501
|
+
setAttribute: (key: string, value: boolean | number | string | undefined) => unknown;
|
|
502
|
+
/** Attach several attributes in one call (CF 2026-09-25). Optional, like `recordException`. */
|
|
503
|
+
setAttributes?: (attributes: Record<string, boolean | number | string>) => unknown;
|
|
523
504
|
}
|
|
524
505
|
/**
|
|
525
506
|
* Minimal structural shape of the `tracing` namespace exported by
|
|
@@ -528,6 +509,11 @@ interface HostSpanLike {
|
|
|
528
509
|
*/
|
|
529
510
|
interface HostTracingLike {
|
|
530
511
|
enterSpan: <T>(name: string, callback: (span: HostSpanLike) => T) => T;
|
|
512
|
+
/**
|
|
513
|
+
* The currently active span; outside any custom span, the invocation's root
|
|
514
|
+
* span (CF 2026-09-25). Optional and feature-detected: absent on older runtimes.
|
|
515
|
+
*/
|
|
516
|
+
getActiveSpan?: () => HostSpanLike | undefined;
|
|
531
517
|
}
|
|
532
518
|
/**
|
|
533
519
|
* Resolves CF's `tracing` namespace, or `undefined` when it is unavailable —
|
|
@@ -537,6 +523,42 @@ interface HostTracingLike {
|
|
|
537
523
|
* supplies the real resolver, tests a fake or `undefined`.
|
|
538
524
|
*/
|
|
539
525
|
type HostTracingResolver = () => HostTracingLike | Promise<HostTracingLike | undefined> | undefined;
|
|
526
|
+
/**
|
|
527
|
+
* Copy an attribute bag onto a host span, best-effort: one native
|
|
528
|
+
* `setAttributes` call where the runtime has it, a `setAttribute` loop where it
|
|
529
|
+
* does not. Skipped for an untraced span; non-primitive values are dropped,
|
|
530
|
+
* since CF's setters take `string | number | boolean` only.
|
|
531
|
+
*/
|
|
532
|
+
declare const setHostSpanAttributes: (span: HostSpanLike, attributes: Record<string, LogFields[string]>) => void;
|
|
533
|
+
/**
|
|
534
|
+
* Structural shape of the `ctx.trace` span factory (see the server
|
|
535
|
+
* `LunoraTracer`). Declared here rather than imported so `@lunora/do` takes no
|
|
536
|
+
* dependency on `@lunora/server`; a cross-package assignability guard in
|
|
537
|
+
* `@lunora/testing` fails the build if the two drift apart.
|
|
538
|
+
*
|
|
539
|
+
* The body's second argument is the enclosing span's {@link SpanHandle}, through
|
|
540
|
+
* which it can attach attributes only known *after* it resolves (post-hoc). It is
|
|
541
|
+
* a trailing parameter, so a `(trace) => …` body that ignores it still conforms.
|
|
542
|
+
*/
|
|
543
|
+
type ContextTracer = <T>(name: string, function_: (trace: ContextTracer, span: SpanHandle) => Promise<T> | T, options?: LogFields | SpanOptions, identity?: SpanIdentity) => Promise<T>;
|
|
544
|
+
/** Structural shape of the `ctx.metrics` recorder (see the server `LunoraMetrics`). */
|
|
545
|
+
interface ContextMetrics {
|
|
546
|
+
count: (name: string, value?: number, attributes?: LogFields) => void;
|
|
547
|
+
gauge: (name: string, value: number, attributes?: LogFields) => void;
|
|
548
|
+
record: (name: string, value: number, attributes?: LogFields) => void;
|
|
549
|
+
}
|
|
550
|
+
/** The trace a ctx's spans hang off: the shared id, and the span they parent to. */
|
|
551
|
+
interface TraceAnchor {
|
|
552
|
+
rootSpanId: string;
|
|
553
|
+
/**
|
|
554
|
+
* The W3C `sampled` verdict for this trace, inherited from the inbound
|
|
555
|
+
* `traceparent` when there was one. Carried on the anchor rather than
|
|
556
|
+
* re-derived per outbound call so every `ctx.fetch` of one dispatch
|
|
557
|
+
* propagates the same answer.
|
|
558
|
+
*/
|
|
559
|
+
sampled?: boolean;
|
|
560
|
+
traceId: string;
|
|
561
|
+
}
|
|
540
562
|
/** What {@link createTracer} needs from the shard to build a span. */
|
|
541
563
|
interface TracerDeps {
|
|
542
564
|
/** The trace this ctx's spans belong to. */
|
|
@@ -2169,4 +2191,4 @@ type AuthMetricsBucket, type ContextFetch, type ContextLogLevel, type ContextMet
|
|
|
2169
2191
|
* mistake `@lunora/do`'s own barrel documents having made once with the search
|
|
2170
2192
|
* core. What is exported here is what a consumer actually needs.
|
|
2171
2193
|
*/
|
|
2172
|
-
type RecordAuthEventInput, type RecordFunctionMetricInput, type RequestLogEntry, type RequestLogResult, type RequestLogWriteOptions, type RequestOutcome, type SecurityAuditResult, type SecurityFinding, type SecurityFindingKind, type SecurityFindingLevel, SpanBuffer, type SpanCollection, type SpanCollector, type SpanEvent, type SpanEventPoint, type SpanHandle, type OtlpSpanKind as SpanKind, type SpanLink, type SpanOptions, type TraceAnchor, type TraceSpan, type TraceSummary, type TracedFetchDeps, type TracerDeps, appendRequestLogEntry, buildSecurityAudit, createDatabaseTally, createMetrics, createSpanCollector, createTracedFetch, createTracer, dispatchRootSpan, emitLogEvent, emitRequestLogEvent, ensureAuthMetricsTables, ensureFunctionMetricsTables, ensureRequestLogTable, explainIssue, findDanglingReferences, foldTraces, formatTally, instrumentDatabase, mergeScanAttribution, parseExplainIssueArgs, parseLogArgs, readAuthMetrics, readErrorIssues, readFunctionMetricBuckets, readFunctionMetricIndexHits, readFunctionMetricScans, readFunctionMetrics, readFunctionMetricsTotals, readMetricHistory, readQueryInsights, readQueryMetrics, readRequestLog, recordAuthEvent, recordFunctionMetric, recordMetricHistory, recordQueryMetric, redactArgs, resolveTraceAnchor, upsertIssueState };
|
|
2194
|
+
type RecordAuthEventInput, type RecordFunctionMetricInput, type RequestLogEntry, type RequestLogResult, type RequestLogWriteOptions, type RequestOutcome, type SecurityAuditResult, type SecurityFinding, type SecurityFindingKind, type SecurityFindingLevel, SpanBuffer, type SpanCollection, type SpanCollector, type SpanEvent, type SpanEventPoint, type SpanHandle, type OtlpSpanKind as SpanKind, type SpanLink, type SpanOptions, type TraceAnchor, type TraceSpan, type TraceSummary, type TracedFetchDeps, type TracerDeps, appendRequestLogEntry, buildSecurityAudit, createDatabaseTally, createMetrics, createSpanCollector, createTracedFetch, createTracer, dispatchRootSpan, emitLogEvent, emitRequestLogEvent, ensureAuthMetricsTables, ensureFunctionMetricsTables, ensureRequestLogTable, explainIssue, findDanglingReferences, foldTraces, formatTally, instrumentDatabase, mergeScanAttribution, parseExplainIssueArgs, parseLogArgs, readAuthMetrics, readErrorIssues, readFunctionMetricBuckets, readFunctionMetricIndexHits, readFunctionMetricScans, readFunctionMetrics, readFunctionMetricsTotals, readMetricHistory, readQueryInsights, readQueryMetrics, readRequestLog, recordAuthEvent, recordFunctionMetric, recordMetricHistory, recordQueryMetric, redactArgs, resolveTraceAnchor, setHostSpanAttributes, upsertIssueState };
|
package/dist/index.d.ts
CHANGED
|
@@ -466,35 +466,6 @@ interface SpanEvent {
|
|
|
466
466
|
/** Acting userId, or absent when anonymous. */
|
|
467
467
|
userId?: string;
|
|
468
468
|
}
|
|
469
|
-
/**
|
|
470
|
-
* Structural shape of the `ctx.trace` span factory (see the server
|
|
471
|
-
* `LunoraTracer`). Declared here rather than imported so `@lunora/do` takes no
|
|
472
|
-
* dependency on `@lunora/server`; a cross-package assignability guard in
|
|
473
|
-
* `@lunora/testing` fails the build if the two drift apart.
|
|
474
|
-
*
|
|
475
|
-
* The body's second argument is the enclosing span's {@link SpanHandle}, through
|
|
476
|
-
* which it can attach attributes only known *after* it resolves (post-hoc). It is
|
|
477
|
-
* a trailing parameter, so a `(trace) => …` body that ignores it still conforms.
|
|
478
|
-
*/
|
|
479
|
-
type ContextTracer = <T>(name: string, function_: (trace: ContextTracer, span: SpanHandle) => Promise<T> | T, options?: LogFields | SpanOptions, identity?: SpanIdentity) => Promise<T>;
|
|
480
|
-
/** Structural shape of the `ctx.metrics` recorder (see the server `LunoraMetrics`). */
|
|
481
|
-
interface ContextMetrics {
|
|
482
|
-
count: (name: string, value?: number, attributes?: LogFields) => void;
|
|
483
|
-
gauge: (name: string, value: number, attributes?: LogFields) => void;
|
|
484
|
-
record: (name: string, value: number, attributes?: LogFields) => void;
|
|
485
|
-
}
|
|
486
|
-
/** The trace a ctx's spans hang off: the shared id, and the span they parent to. */
|
|
487
|
-
interface TraceAnchor {
|
|
488
|
-
rootSpanId: string;
|
|
489
|
-
/**
|
|
490
|
-
* The W3C `sampled` verdict for this trace, inherited from the inbound
|
|
491
|
-
* `traceparent` when there was one. Carried on the anchor rather than
|
|
492
|
-
* re-derived per outbound call so every `ctx.fetch` of one dispatch
|
|
493
|
-
* propagates the same answer.
|
|
494
|
-
*/
|
|
495
|
-
sampled?: boolean;
|
|
496
|
-
traceId: string;
|
|
497
|
-
}
|
|
498
469
|
/**
|
|
499
470
|
* Minimal structural shape of one **host-native custom span** — the object a
|
|
500
471
|
* `tracing.enterSpan(name, (span) => …)` callback receives (GA 2026-06-16). Only
|
|
@@ -518,8 +489,18 @@ interface HostSpanLike {
|
|
|
518
489
|
* a span nobody will read.
|
|
519
490
|
*/
|
|
520
491
|
readonly isTraced: boolean;
|
|
492
|
+
/**
|
|
493
|
+
* Record an OTel `exception` event on the span (CF 2026-09-25). Optional and
|
|
494
|
+
* feature-detected: older runtimes only have `setAttribute`.
|
|
495
|
+
*/
|
|
496
|
+
recordException?: (exception: {
|
|
497
|
+
message: string;
|
|
498
|
+
name: string;
|
|
499
|
+
}) => unknown;
|
|
521
500
|
/** Attach one primitive attribute to the CF span. */
|
|
522
|
-
setAttribute: (key: string, value: boolean | number | string | undefined) =>
|
|
501
|
+
setAttribute: (key: string, value: boolean | number | string | undefined) => unknown;
|
|
502
|
+
/** Attach several attributes in one call (CF 2026-09-25). Optional, like `recordException`. */
|
|
503
|
+
setAttributes?: (attributes: Record<string, boolean | number | string>) => unknown;
|
|
523
504
|
}
|
|
524
505
|
/**
|
|
525
506
|
* Minimal structural shape of the `tracing` namespace exported by
|
|
@@ -528,6 +509,11 @@ interface HostSpanLike {
|
|
|
528
509
|
*/
|
|
529
510
|
interface HostTracingLike {
|
|
530
511
|
enterSpan: <T>(name: string, callback: (span: HostSpanLike) => T) => T;
|
|
512
|
+
/**
|
|
513
|
+
* The currently active span; outside any custom span, the invocation's root
|
|
514
|
+
* span (CF 2026-09-25). Optional and feature-detected: absent on older runtimes.
|
|
515
|
+
*/
|
|
516
|
+
getActiveSpan?: () => HostSpanLike | undefined;
|
|
531
517
|
}
|
|
532
518
|
/**
|
|
533
519
|
* Resolves CF's `tracing` namespace, or `undefined` when it is unavailable —
|
|
@@ -537,6 +523,42 @@ interface HostTracingLike {
|
|
|
537
523
|
* supplies the real resolver, tests a fake or `undefined`.
|
|
538
524
|
*/
|
|
539
525
|
type HostTracingResolver = () => HostTracingLike | Promise<HostTracingLike | undefined> | undefined;
|
|
526
|
+
/**
|
|
527
|
+
* Copy an attribute bag onto a host span, best-effort: one native
|
|
528
|
+
* `setAttributes` call where the runtime has it, a `setAttribute` loop where it
|
|
529
|
+
* does not. Skipped for an untraced span; non-primitive values are dropped,
|
|
530
|
+
* since CF's setters take `string | number | boolean` only.
|
|
531
|
+
*/
|
|
532
|
+
declare const setHostSpanAttributes: (span: HostSpanLike, attributes: Record<string, LogFields[string]>) => void;
|
|
533
|
+
/**
|
|
534
|
+
* Structural shape of the `ctx.trace` span factory (see the server
|
|
535
|
+
* `LunoraTracer`). Declared here rather than imported so `@lunora/do` takes no
|
|
536
|
+
* dependency on `@lunora/server`; a cross-package assignability guard in
|
|
537
|
+
* `@lunora/testing` fails the build if the two drift apart.
|
|
538
|
+
*
|
|
539
|
+
* The body's second argument is the enclosing span's {@link SpanHandle}, through
|
|
540
|
+
* which it can attach attributes only known *after* it resolves (post-hoc). It is
|
|
541
|
+
* a trailing parameter, so a `(trace) => …` body that ignores it still conforms.
|
|
542
|
+
*/
|
|
543
|
+
type ContextTracer = <T>(name: string, function_: (trace: ContextTracer, span: SpanHandle) => Promise<T> | T, options?: LogFields | SpanOptions, identity?: SpanIdentity) => Promise<T>;
|
|
544
|
+
/** Structural shape of the `ctx.metrics` recorder (see the server `LunoraMetrics`). */
|
|
545
|
+
interface ContextMetrics {
|
|
546
|
+
count: (name: string, value?: number, attributes?: LogFields) => void;
|
|
547
|
+
gauge: (name: string, value: number, attributes?: LogFields) => void;
|
|
548
|
+
record: (name: string, value: number, attributes?: LogFields) => void;
|
|
549
|
+
}
|
|
550
|
+
/** The trace a ctx's spans hang off: the shared id, and the span they parent to. */
|
|
551
|
+
interface TraceAnchor {
|
|
552
|
+
rootSpanId: string;
|
|
553
|
+
/**
|
|
554
|
+
* The W3C `sampled` verdict for this trace, inherited from the inbound
|
|
555
|
+
* `traceparent` when there was one. Carried on the anchor rather than
|
|
556
|
+
* re-derived per outbound call so every `ctx.fetch` of one dispatch
|
|
557
|
+
* propagates the same answer.
|
|
558
|
+
*/
|
|
559
|
+
sampled?: boolean;
|
|
560
|
+
traceId: string;
|
|
561
|
+
}
|
|
540
562
|
/** What {@link createTracer} needs from the shard to build a span. */
|
|
541
563
|
interface TracerDeps {
|
|
542
564
|
/** The trace this ctx's spans belong to. */
|
|
@@ -2169,4 +2191,4 @@ type AuthMetricsBucket, type ContextFetch, type ContextLogLevel, type ContextMet
|
|
|
2169
2191
|
* mistake `@lunora/do`'s own barrel documents having made once with the search
|
|
2170
2192
|
* core. What is exported here is what a consumer actually needs.
|
|
2171
2193
|
*/
|
|
2172
|
-
type RecordAuthEventInput, type RecordFunctionMetricInput, type RequestLogEntry, type RequestLogResult, type RequestLogWriteOptions, type RequestOutcome, type SecurityAuditResult, type SecurityFinding, type SecurityFindingKind, type SecurityFindingLevel, SpanBuffer, type SpanCollection, type SpanCollector, type SpanEvent, type SpanEventPoint, type SpanHandle, type OtlpSpanKind as SpanKind, type SpanLink, type SpanOptions, type TraceAnchor, type TraceSpan, type TraceSummary, type TracedFetchDeps, type TracerDeps, appendRequestLogEntry, buildSecurityAudit, createDatabaseTally, createMetrics, createSpanCollector, createTracedFetch, createTracer, dispatchRootSpan, emitLogEvent, emitRequestLogEvent, ensureAuthMetricsTables, ensureFunctionMetricsTables, ensureRequestLogTable, explainIssue, findDanglingReferences, foldTraces, formatTally, instrumentDatabase, mergeScanAttribution, parseExplainIssueArgs, parseLogArgs, readAuthMetrics, readErrorIssues, readFunctionMetricBuckets, readFunctionMetricIndexHits, readFunctionMetricScans, readFunctionMetrics, readFunctionMetricsTotals, readMetricHistory, readQueryInsights, readQueryMetrics, readRequestLog, recordAuthEvent, recordFunctionMetric, recordMetricHistory, recordQueryMetric, redactArgs, resolveTraceAnchor, upsertIssueState };
|
|
2194
|
+
type RecordAuthEventInput, type RecordFunctionMetricInput, type RequestLogEntry, type RequestLogResult, type RequestLogWriteOptions, type RequestOutcome, type SecurityAuditResult, type SecurityFinding, type SecurityFindingKind, type SecurityFindingLevel, SpanBuffer, type SpanCollection, type SpanCollector, type SpanEvent, type SpanEventPoint, type SpanHandle, type OtlpSpanKind as SpanKind, type SpanLink, type SpanOptions, type TraceAnchor, type TraceSpan, type TraceSummary, type TracedFetchDeps, type TracerDeps, appendRequestLogEntry, buildSecurityAudit, createDatabaseTally, createMetrics, createSpanCollector, createTracedFetch, createTracer, dispatchRootSpan, emitLogEvent, emitRequestLogEvent, ensureAuthMetricsTables, ensureFunctionMetricsTables, ensureRequestLogTable, explainIssue, findDanglingReferences, foldTraces, formatTally, instrumentDatabase, mergeScanAttribution, parseExplainIssueArgs, parseLogArgs, readAuthMetrics, readErrorIssues, readFunctionMetricBuckets, readFunctionMetricIndexHits, readFunctionMetricScans, readFunctionMetrics, readFunctionMetricsTotals, readMetricHistory, readQueryInsights, readQueryMetrics, readRequestLog, recordAuthEvent, recordFunctionMetric, recordMetricHistory, recordQueryMetric, redactArgs, resolveTraceAnchor, setHostSpanAttributes, upsertIssueState };
|
package/dist/index.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{AUTH_METRICS_BUCKETS_TABLE as t,AUTH_METRICS_BUCKET_MS as T,AUTH_METRICS_BUCKET_RETENTION as o,AUTH_METRICS_TABLE as a,ensureAuthMetricsTables as s,readAuthMetrics as E,recordAuthEvent as _}from"./packem_shared/AUTH_METRICS_BUCKETS_TABLE-C-qbQA-w.mjs";import{createMetrics as S,createSpanCollector as I,createTracedFetch as i,createTracer as n,dispatchRootSpan as M}from"./packem_shared/createMetrics-
|
|
1
|
+
import{AUTH_METRICS_BUCKETS_TABLE as t,AUTH_METRICS_BUCKET_MS as T,AUTH_METRICS_BUCKET_RETENTION as o,AUTH_METRICS_TABLE as a,ensureAuthMetricsTables as s,readAuthMetrics as E,recordAuthEvent as _}from"./packem_shared/AUTH_METRICS_BUCKETS_TABLE-C-qbQA-w.mjs";import{createMetrics as S,createSpanCollector as I,createTracedFetch as i,createTracer as n,dispatchRootSpan as M}from"./packem_shared/createMetrics-pQCAOmxn.mjs";import{createDatabaseTally as A,formatTally as p,instrumentDatabase as C}from"./packem_shared/createDatabaseTally-BVH6hi5W.mjs";import{FUNCTION_METRICS_BUCKETS_TABLE as f,FUNCTION_METRICS_BUCKET_MS as U,FUNCTION_METRICS_BUCKET_RETENTION as d,FUNCTION_METRICS_INDEX_TABLE as R,FUNCTION_METRICS_MAX_PATHS as L,FUNCTION_METRICS_READ_LIMIT as m,FUNCTION_METRICS_SCANS_TABLE as x,FUNCTION_METRICS_TABLE as B,ensureFunctionMetricsTables as F,mergeScanAttribution as l,readFunctionMetricBuckets as g,readFunctionMetricIndexHits as O,readFunctionMetricScans as H,readFunctionMetrics as b,readFunctionMetricsTotals as y,recordFunctionMetric as D}from"./packem_shared/FUNCTION_METRICS_BUCKETS_TABLE-ChlIe0vF.mjs";import{setHostSpanAttributes as K}from"./packem_shared/setHostSpanAttributes-DfxUKy_K.mjs";import{DEFAULT_EXPLAIN_ISSUE_MODEL as v,explainIssue as Q,parseExplainIssueArgs as G}from"./packem_shared/DEFAULT_EXPLAIN_ISSUE_MODEL-BkFTgdkd.mjs";import{ISSUE_SEVERITIES as P,ISSUE_STATE_TABLE as k,ISSUE_STATUSES as V,upsertIssueState as j}from"./packem_shared/ISSUE_SEVERITIES-0SJ0glV4.mjs";import{LogBuffer as z}from"./packem_shared/LogBuffer-BmD4CfV0.mjs";import{M as W}from"./packem_shared/metric-buffer-Bx0XbypU.mjs";import{readMetricHistory as Z,recordMetricHistory as $}from"./packem_shared/readMetricHistory-TKfnwFNv.mjs";import{readQueryInsights as re,readQueryMetrics as te,recordQueryMetric as Te}from"./packem_shared/readQueryInsights-DkQfxGfP.mjs";import{R as ae,a as se,e as Ee,b as _e,c as ce,p as Se,r as Ie,d as ie,f as ne}from"./packem_shared/request-log-ClXupUgG.mjs";import{MIN_ADMIN_TOKEN_LENGTH as ue,MIN_AUTH_SECRET_LENGTH as Ae,buildSecurityAudit as pe}from"./packem_shared/MIN_ADMIN_TOKEN_LENGTH-DSOQ6rno.mjs";import{SpanBuffer as Ne,foldTraces as fe}from"./packem_shared/SpanBuffer-DnYOc8uk.mjs";import{findDanglingReferences as de}from"./packem_shared/findDanglingReferences-BaOyIdxz.mjs";import{resolveTraceAnchor as Le}from"./packem_shared/resolveTraceAnchor-CTZfm9KX.mjs";export{t as AUTH_METRICS_BUCKETS_TABLE,T as AUTH_METRICS_BUCKET_MS,o as AUTH_METRICS_BUCKET_RETENTION,a as AUTH_METRICS_TABLE,v as DEFAULT_EXPLAIN_ISSUE_MODEL,f as FUNCTION_METRICS_BUCKETS_TABLE,U as FUNCTION_METRICS_BUCKET_MS,d as FUNCTION_METRICS_BUCKET_RETENTION,R as FUNCTION_METRICS_INDEX_TABLE,L as FUNCTION_METRICS_MAX_PATHS,m as FUNCTION_METRICS_READ_LIMIT,x as FUNCTION_METRICS_SCANS_TABLE,B as FUNCTION_METRICS_TABLE,P as ISSUE_SEVERITIES,k as ISSUE_STATE_TABLE,V as ISSUE_STATUSES,z as LogBuffer,ue as MIN_ADMIN_TOKEN_LENGTH,Ae as MIN_AUTH_SECRET_LENGTH,W as MetricBuffer,ae as REQUEST_LOG_TABLE,Ne as SpanBuffer,se as appendRequestLogEntry,pe as buildSecurityAudit,A as createDatabaseTally,S as createMetrics,I as createSpanCollector,i as createTracedFetch,n as createTracer,M as dispatchRootSpan,Ee as emitLogEvent,_e as emitRequestLogEvent,s as ensureAuthMetricsTables,F as ensureFunctionMetricsTables,ce as ensureRequestLogTable,Q as explainIssue,de as findDanglingReferences,fe as foldTraces,p as formatTally,C as instrumentDatabase,l as mergeScanAttribution,G as parseExplainIssueArgs,Se as parseLogArgs,E as readAuthMetrics,Ie as readErrorIssues,g as readFunctionMetricBuckets,O as readFunctionMetricIndexHits,H as readFunctionMetricScans,b as readFunctionMetrics,y as readFunctionMetricsTotals,Z as readMetricHistory,re as readQueryInsights,te as readQueryMetrics,ie as readRequestLog,_ as recordAuthEvent,D as recordFunctionMetric,$ as recordMetricHistory,Te as recordQueryMetric,ne as redactArgs,Le as resolveTraceAnchor,K as setHostSpanAttributes,j as upsertIssueState};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{o as m}from"./otlp-B-WBkikT.mjs";import{f as b}from"./request-log-ClXupUgG.mjs";import{toErrorType as M}from"./resolveTraceAnchor-CTZfm9KX.mjs";const y=100,T=new Set(["aggregate","count","delete","deleteMany","deleteWhere","findFirst","findFirstOrThrow","findMany","get","groupBy","insert","insertMany","insertManyUnsafe","lookupById","patch","patchMany","patchWhere","rank","rankBefore","rankPage","rankPageRows","related","replace","restore"]),w=new Set(["aggregate","count","deleteWhere","findFirst","findFirstOrThrow","findMany","groupBy","insert","insertMany","insertManyUnsafe","patchWhere","rank","rankBefore","rankPage","rankPageRows"]),S=(e,t)=>{if(!w.has(e))return;const n=t[0];return typeof n=="string"&&n.length>0?n:void 0},k=e=>e instanceof Error?e.message:typeof e=="string"?e:JSON.stringify(e)??String(e),E=e=>{const{deps:t,durationMs:n,failure:a,operation:s,startTs:r,table:o}=e;return{attributes:{"db.operation.name":s,...o===void 0?{}:{"db.collection.name":o},"db.system.name":"sqlite"},durationMs:n,...a===void 0?{}:{error:{message:b(k(a),t.captureRaw),type:M(a)}},functionPath:t.functionPath,kind:"client",name:o===void 0?`db.${s}`:`db.${s} ${o}`,ok:a===void 0,parentSpanId:t.anchor.rootSpanId,shardKey:t.shardKey,spanId:m(8),startTs:r,traceId:t.anchor.traceId,userId:t.userId()}},D=(e,t)=>{if(t.mode==="off")return e;const{tally:n}=t,a=new Map;return new Proxy(e,{get(s,r,o){const c=Reflect.get(s,r,o);if(typeof r!="string"||typeof c!="function"||!T.has(r))return c;const f=a.get(r);if(f!==void 0)return f;const g=c,u=async(...p)=>{const l=Date.now(),h=S(r,p);let d;try{return await g.apply(s,p)}catch(i){throw d=i,i}finally{const i=Date.now()-l;n.calls+=1,n.durationMs+=i,n.perOperation[r]=(n.perOperation[r]??0)+1,d!==void 0&&(n.errors+=1);try{t.mode==="spans"&&(n.spansEmitted>=y?n.spansTruncated=!0:(n.spansEmitted+=1,t.record(E({deps:t,durationMs:i,failure:d,operation:r,startTs:l,table:h}))))}catch{}}};return a.set(r,u),u}})},P=()=>({calls:0,durationMs:0,errors:0,perOperation:{},spansEmitted:0,spansTruncated:!1}),R=e=>{const t={"db.calls":e.calls,"db.duration_ms":e.durationMs};e.errors>0&&(t["db.errors"]=e.errors),e.spansTruncated&&(t["db.spans_truncated"]=!0);for(const[n,a]of Object.entries(e.perOperation))t[`db.op.${n}`]=a;return t};export{P as createDatabaseTally,R as formatTally,D as instrumentDatabase};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{f as _,g as k,n as b}from"./request-log-ClXupUgG.mjs";import{o as j,b as L,O as F}from"./otlp-B-WBkikT.mjs";import{applyHostSpanAttributes as K}from"./setHostSpanAttributes-DfxUKy_K.mjs";import{toErrorType as O}from"./resolveTraceAnchor-CTZfm9KX.mjs";const U=/[\w.-]/u,q=t=>{let e="";for(const r of t)e+=U.test(r)?r:"_";return e},C=t=>{if(typeof t.name!="string"||t.name.length===0)throw new TypeError("recordEvaluation requires a non-empty `name`");if(typeof t.score!="number"||!Number.isFinite(t.score))throw new TypeError("recordEvaluation `score` must be a finite number");const e=q(t.name),r={[`gen_ai.evaluation.${e}.score`]:t.score};return t.label!==void 0&&(r[`gen_ai.evaluation.${e}.label`]=t.label),r},X=t=>{const e=Object.keys(t);if(e.length===0||!e.every(a=>a==="attributes"||a==="kind"||a==="links"))return!1;const{kind:r}=t;return r===void 0||Object.hasOwn(F,r)},B=128,V=128,x=128,y=(t,e)=>{if(e===void 0)return;let r=Object.keys(t).length;for(const[a,n]of Object.entries(e)){const s=!Object.hasOwn(t,a);s&&r>=x||(s&&(r+=1),t[a]=n)}},$=t=>{const e=b(t);if(e===void 0||Object.keys(e).length<=x)return e;const r={};return y(r,e),r},G=t=>{try{const e=new URL(t);return`${e.protocol}//${e.host}${e.pathname}`}catch{return t}},J=t=>{try{return new URL(t).host}catch{return t}},Q=(t,e)=>{try{return t(new URL(e))}catch{return!1}},W=t=>t===void 0?{}:X(t)?t:{attributes:t},Y=(t,e=!1)=>{const r={attributes:{},events:[],links:[]},a={spanContext:()=>t,addEvent:(n,s)=>{if(r.events.length>=B)return;const o=k($(s),e);r.events.push({...o===void 0?{}:{attributes:o},name:n,ts:Date.now()})},addLink:n=>{if(r.links.length>=V)return;const s=k($(n.attributes),e);r.links.push({...s===void 0?{}:{attributes:s},spanId:n.spanId,traceId:n.traceId})},recordEvaluation:n=>{y(r.attributes,b(C(n)))},recordException:n=>{const s=n instanceof Error?n.message:String(n);a.addEvent("exception",{"exception.message":_(s,e),...e&&n instanceof Error&&typeof n.stack=="string"?{"exception.stacktrace":n.stack}:{},"exception.type":O(n)})},setAttribute:(n,s)=>{y(r.attributes,b({[n]:s}))},setAttributes:n=>{y(r.attributes,b(n))}};return{collected:r,handle:a}},nt=t=>{const{anchor:e,captureRaw:r=!1,fuseHostSpans:a,functionPath:n,record:s,resolveHostTracing:o,shardKey:c,userId:f}=t,d=m=>async(I,E,u,P)=>{const l=P?.spanId??j(8),w=P?.parentSpanId??m,i=Date.now(),g=W(u),z=b(g.attributes),{collected:T,handle:D}=Y({...e.sampled===void 0?{}:{sampled:e.sampled},spanId:l,traceId:e.traceId},r),H=async S=>{let p=!0,v;try{return await E(d(l),D)}catch(h){p=!1;const A=h instanceof Error?h.message:String(h);throw v={message:_(A,r),type:O(h)},h}finally{const h=Date.now()-i,A=f(),N={};y(N,z),y(N,T.attributes);const M=k(N,r),R=[...g.links??[],...T.links];try{s({...Object.keys(M).length===0?{}:{attributes:M},durationMs:h,...T.events.length===0?{}:{events:T.events},...v===void 0?{}:{error:v},functionPath:n,...g.kind===void 0||g.kind==="internal"?{}:{kind:g.kind},...R.length===0?{}:{links:R},name:I,ok:p,parentSpanId:w,shardKey:c,spanId:l,startTs:i,traceId:e.traceId,userId:A})}catch{}if(S!==void 0)try{K(S,{attributes:M,durationMs:h,error:v,functionPath:n,ok:p,shardKey:c,userId:A})}catch{}}};if(a===!0&&o!==void 0){let S=!1;try{const p=await o();if(p!==void 0&&typeof p.enterSpan=="function")return await p.enterSpan(I,v=>(S=!0,H(v)))}catch(p){if(S)throw p}}return await H()};return d(e.rootSpanId)},st=(t,e)=>{const{anchor:r,captureRaw:a=!1,functionPath:n,propagate:s=!0,record:o,shardKey:c,userId:f}=t;return async(d,m)=>{const I=j(8),E=Date.now(),u=new Request(d,m);(typeof s=="function"?Q(s,u.url):s)&&u.headers.set("traceparent",L(r.traceId,I,r.sampled??!0));let l,w;try{const i=await e(u);return w=i.status,i.ok||(l={message:`HTTP ${String(i.status)}`,type:`HTTP_${String(i.status)}`}),i}catch(i){const g=i instanceof Error?i.message:String(i);throw l={message:_(g,a),type:O(i)},i}finally{try{o({attributes:{"http.request.method":u.method,...w===void 0?{}:{"http.response.status_code":w},"url.full":G(u.url)},durationMs:Date.now()-E,...l===void 0?{}:{error:l},functionPath:n,kind:"client",name:`${u.method} ${J(u.url)}`,ok:l===void 0,parentSpanId:r.rootSpanId,shardKey:c,spanId:I,startTs:E,traceId:r.traceId,userId:f()})}catch{}}}},at=t=>{const{functionPath:e,record:r,shardKey:a}=t,n=(s,o,c,f)=>{if(!Number.isFinite(c))return;const d=k(b(f));try{r({...d===void 0?{}:{attributes:d},functionPath:e,kind:s,name:o,shardKey:a,ts:Date.now(),value:c})}catch{}};return{count:(s,o=1,c)=>{n("counter",s,o,c)},gauge:(s,o,c)=>{n("gauge",s,o,c)},record:(s,o,c)=>{n("histogram",s,o,c)}}},ot=t=>{const{anchor:e,captureRaw:r=!1,collected:a,durationMs:n,failure:s,functionPath:o,shardKey:c,startTs:f,userId:d}=t,m=k(a?.attributes??{},r);return{...Object.keys(m).length===0?{}:{attributes:m},dispatch:!0,durationMs:n,...a===void 0||a.events.length===0?{}:{events:a.events},...s===void 0?{}:{error:{message:_(s.thrown instanceof Error?s.thrown.message:String(s.thrown),r),type:O(s.thrown)}},functionPath:o,...a===void 0||a.links.length===0?{}:{links:a.links},name:o,ok:s===void 0,parentSpanId:"",shardKey:c,spanId:e.rootSpanId,startTs:f,traceId:e.traceId,userId:d}};export{at as createMetrics,Y as createSpanCollector,st as createTracedFetch,nt as createTracer,ot as dispatchRootSpan};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
const d=Array.from({length:256},(r,e)=>e.toString(16).padStart(2,"0")),u=512,c=new Uint8Array(u);let s=u;const i=(r,e,t)=>{let o="";for(let n=0;n<t;n+=1)o+=d[r[e+n]];return o},p=r=>{if(r>u){const t=new Uint8Array(r);return crypto.getRandomValues(t),i(t,0,r)}s+r>u&&(crypto.getRandomValues(c),s=0);const e=i(c,s,r);return s+=r,e},l=/^[0-9a-f]+$/,f=(r,e,t=!0)=>`00-${r}-${e}-${t?"01":"00"}`,g=r=>{if(r==null)return;const e=r.split("-"),[t,o,n,a]=e;if(!(e.length<4||t===void 0||t.length!==2||!l.test(t)||t==="ff"||t==="00"&&e.length!==4||o===void 0||n===void 0||a===void 0||a.length!==2||!l.test(a)||o.length!==32||n.length!==16||!l.test(o)||!l.test(n)||o==="00000000000000000000000000000000"||n==="0000000000000000"))return{parentSpanId:n,sampled:(Number.parseInt(a,16)&1)===1,traceId:o}},h={client:3,consumer:5,internal:1,producer:4,server:2},_=Object.freeze({durationMs:"lunora.duration_ms",errorMessage:"error.message",errorType:"error.type",functionPath:"lunora.function_path",ok:"lunora.ok",shardKey:"lunora.shard_key",userId:"lunora.user_id"});export{_ as L,h as O,f as b,p as o,g as p};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{isLunoraError as n}from"@lunora/errors";import{p as e,o as t}from"./otlp-B-WBkikT.mjs";const c=r=>{const o=e(r);return{rootSpanId:o?.parentSpanId??t(8),sampled:o?.sampled??!0,traceId:o?.traceId??t(16)}},s=r=>n(r)?r.code:r instanceof Error?r.constructor.name:"Error";export{c as resolveTraceAnchor,s as toErrorType};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{L as o}from"./otlp-B-WBkikT.mjs";const n=(e,r)=>{if(!e.isTraced)return;const s={};for(const[i,t]of Object.entries(r))(typeof t=="boolean"||typeof t=="number"||typeof t=="string")&&(s[i]=t);if(typeof e.setAttributes=="function"){e.setAttributes(s);return}for(const[i,t]of Object.entries(s))e.setAttribute(i,t)},f=(e,r)=>{if(!e.isTraced)return;const s={[o.functionPath]:r.functionPath,[o.ok]:r.ok,[o.durationMs]:r.durationMs,...r.shardKey===void 0?{}:{[o.shardKey]:r.shardKey},...r.userId===void 0?{}:{[o.userId]:r.userId},...r.error===void 0?{}:{[o.errorType]:r.error.type,[o.errorMessage]:r.error.message}};for(const[i,t]of Object.entries(r.attributes))s[`lunora.attr.${i}`]=t;n(e,s),r.error!==void 0&&typeof e.recordException=="function"&&e.recordException({message:r.error.message,name:r.error.type})};export{f as applyHostSpanAttributes,n as setHostSpanAttributes};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lunora/observability",
|
|
3
|
-
"version": "1.0.0-alpha.
|
|
3
|
+
"version": "1.0.0-alpha.112",
|
|
4
4
|
"description": "Host-neutral telemetry storage and read models for Lunora, backing the Studio's Logs, Traces, Metrics and Issues views",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"lunora",
|
|
@@ -43,9 +43,9 @@
|
|
|
43
43
|
"access": "public"
|
|
44
44
|
},
|
|
45
45
|
"dependencies": {
|
|
46
|
-
"@lunora/errors": "1.0.0-alpha.
|
|
46
|
+
"@lunora/errors": "1.0.0-alpha.48",
|
|
47
47
|
"@lunora/fingerprint": "1.0.0-alpha.9",
|
|
48
|
-
"@lunora/shard-engine": "1.0.0-alpha.
|
|
48
|
+
"@lunora/shard-engine": "1.0.0-alpha.103",
|
|
49
49
|
"@visulima/redact": "5.0.0"
|
|
50
50
|
},
|
|
51
51
|
"engines": {
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{o as m,t as b}from"./trace-context-d_EfGPSZ.mjs";import{f as M}from"./request-log-ClXupUgG.mjs";const y=100,T=new Set(["aggregate","count","delete","deleteMany","deleteWhere","findFirst","findFirstOrThrow","findMany","get","groupBy","insert","insertMany","insertManyUnsafe","lookupById","patch","patchMany","patchWhere","rank","rankBefore","rankPage","rankPageRows","related","replace","restore"]),w=new Set(["aggregate","count","deleteWhere","findFirst","findFirstOrThrow","findMany","groupBy","insert","insertMany","insertManyUnsafe","patchWhere","rank","rankBefore","rankPage","rankPageRows"]),S=(e,t)=>{if(!w.has(e))return;const n=t[0];return typeof n=="string"&&n.length>0?n:void 0},k=e=>e instanceof Error?e.message:typeof e=="string"?e:JSON.stringify(e)??String(e),E=e=>{const{deps:t,durationMs:n,failure:a,operation:s,startTs:r,table:o}=e;return{attributes:{"db.operation.name":s,...o===void 0?{}:{"db.collection.name":o},"db.system.name":"sqlite"},durationMs:n,...a===void 0?{}:{error:{message:M(k(a),t.captureRaw),type:b(a)}},functionPath:t.functionPath,kind:"client",name:o===void 0?`db.${s}`:`db.${s} ${o}`,ok:a===void 0,parentSpanId:t.anchor.rootSpanId,shardKey:t.shardKey,spanId:m(8),startTs:r,traceId:t.anchor.traceId,userId:t.userId()}},v=(e,t)=>{if(t.mode==="off")return e;const{tally:n}=t,a=new Map;return new Proxy(e,{get(s,r,o){const c=Reflect.get(s,r,o);if(typeof r!="string"||typeof c!="function"||!T.has(r))return c;const f=a.get(r);if(f!==void 0)return f;const g=c,u=async(...p)=>{const l=Date.now(),h=S(r,p);let d;try{return await g.apply(s,p)}catch(i){throw d=i,i}finally{const i=Date.now()-l;n.calls+=1,n.durationMs+=i,n.perOperation[r]=(n.perOperation[r]??0)+1,d!==void 0&&(n.errors+=1);try{t.mode==="spans"&&(n.spansEmitted>=y?n.spansTruncated=!0:(n.spansEmitted+=1,t.record(E({deps:t,durationMs:i,failure:d,operation:r,startTs:l,table:h}))))}catch{}}};return a.set(r,u),u}})},D=()=>({calls:0,durationMs:0,errors:0,perOperation:{},spansEmitted:0,spansTruncated:!1}),P=e=>{const t={"db.calls":e.calls,"db.duration_ms":e.durationMs};e.errors>0&&(t["db.errors"]=e.errors),e.spansTruncated&&(t["db.spans_truncated"]=!0);for(const[n,a]of Object.entries(e.perOperation))t[`db.op.${n}`]=a;return t};export{D as createDatabaseTally,P as formatTally,v as instrumentDatabase};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{f as O,g as A,n as I}from"./request-log-ClXupUgG.mjs";import{L as g,o as K,b as D,t as P,O as U}from"./trace-context-d_EfGPSZ.mjs";const F=/[\w.-]/u,q=t=>{let e="";for(const r of t)e+=F.test(r)?r:"_";return e},C=t=>{if(typeof t.name!="string"||t.name.length===0)throw new TypeError("recordEvaluation requires a non-empty `name`");if(typeof t.score!="number"||!Number.isFinite(t.score))throw new TypeError("recordEvaluation `score` must be a finite number");const e=q(t.name),r={[`gen_ai.evaluation.${e}.score`]:t.score};return t.label!==void 0&&(r[`gen_ai.evaluation.${e}.label`]=t.label),r},X=t=>{const e=Object.keys(t);if(e.length===0||!e.every(o=>o==="attributes"||o==="kind"||o==="links"))return!1;const{kind:r}=t;return r===void 0||Object.hasOwn(U,r)},B=128,V=128,L=128,m=(t,e)=>{if(e===void 0)return;let r=Object.keys(t).length;for(const[o,s]of Object.entries(e)){const n=!Object.hasOwn(t,o);n&&r>=L||(n&&(r+=1),t[o]=s)}},H=t=>{const e=I(t);if(e===void 0||Object.keys(e).length<=L)return e;const r={};return m(r,e),r},G=t=>{try{const e=new URL(t);return`${e.protocol}//${e.host}${e.pathname}`}catch{return t}},J=t=>{try{return new URL(t).host}catch{return t}},Q=(t,e)=>{try{return t(new URL(e))}catch{return!1}},W=t=>t===void 0?{}:X(t)?t:{attributes:t},Y=(t,e)=>{if(t.isTraced){t.setAttribute(g.functionPath,e.functionPath),t.setAttribute(g.ok,e.ok),t.setAttribute(g.durationMs,e.durationMs),e.shardKey!==void 0&&t.setAttribute(g.shardKey,e.shardKey),e.userId!==void 0&&t.setAttribute(g.userId,e.userId),e.error!==void 0&&(t.setAttribute(g.errorType,e.error.type),t.setAttribute(g.errorMessage,e.error.message));for(const[r,o]of Object.entries(e.attributes))(typeof o=="boolean"||typeof o=="number"||typeof o=="string")&&t.setAttribute(`lunora.attr.${r}`,o)}},Z=(t,e=!1)=>{const r={attributes:{},events:[],links:[]},o={spanContext:()=>t,addEvent:(s,n)=>{if(r.events.length>=B)return;const a=A(H(n),e);r.events.push({...a===void 0?{}:{attributes:a},name:s,ts:Date.now()})},addLink:s=>{if(r.links.length>=V)return;const n=A(H(s.attributes),e);r.links.push({...n===void 0?{}:{attributes:n},spanId:s.spanId,traceId:s.traceId})},recordEvaluation:s=>{m(r.attributes,I(C(s)))},recordException:s=>{const n=s instanceof Error?s.message:String(s);o.addEvent("exception",{"exception.message":O(n,e),...e&&s instanceof Error&&typeof s.stack=="string"?{"exception.stacktrace":s.stack}:{},"exception.type":P(s)})},setAttribute:(s,n)=>{m(r.attributes,I({[s]:n}))},setAttributes:s=>{m(r.attributes,I(s))}};return{collected:r,handle:o}},rt=t=>{const{anchor:e,captureRaw:r=!1,fuseHostSpans:o,functionPath:s,record:n,resolveHostTracing:a,shardKey:c,userId:p}=t,d=y=>async(k,T,u,M)=>{const l=M?.spanId??K(8),w=M?.parentSpanId??y,i=Date.now(),b=W(u),x=I(b.attributes),{collected:E,handle:z}=Z({...e.sampled===void 0?{}:{sampled:e.sampled},spanId:l,traceId:e.traceId},r),$=async S=>{let f=!0,v;try{return await T(d(l),z)}catch(h){f=!1;const _=h instanceof Error?h.message:String(h);throw v={message:O(_,r),type:P(h)},h}finally{const h=Date.now()-i,_=p(),N={};m(N,x),m(N,E.attributes);const R=A(N,r),j=[...b.links??[],...E.links];try{n({...Object.keys(R).length===0?{}:{attributes:R},durationMs:h,...E.events.length===0?{}:{events:E.events},...v===void 0?{}:{error:v},functionPath:s,...b.kind===void 0||b.kind==="internal"?{}:{kind:b.kind},...j.length===0?{}:{links:j},name:k,ok:f,parentSpanId:w,shardKey:c,spanId:l,startTs:i,traceId:e.traceId,userId:_})}catch{}if(S!==void 0)try{Y(S,{attributes:R,durationMs:h,error:v,functionPath:s,ok:f,shardKey:c,userId:_})}catch{}}};if(o===!0&&a!==void 0){let S=!1;try{const f=await a();if(f!==void 0&&typeof f.enterSpan=="function")return await f.enterSpan(k,v=>(S=!0,$(v)))}catch(f){if(S)throw f}}return await $()};return d(e.rootSpanId)},st=(t,e)=>{const{anchor:r,captureRaw:o=!1,functionPath:s,propagate:n=!0,record:a,shardKey:c,userId:p}=t;return async(d,y)=>{const k=K(8),T=Date.now(),u=new Request(d,y);(typeof n=="function"?Q(n,u.url):n)&&u.headers.set("traceparent",D(r.traceId,k,r.sampled??!0));let l,w;try{const i=await e(u);return w=i.status,i.ok||(l={message:`HTTP ${String(i.status)}`,type:`HTTP_${String(i.status)}`}),i}catch(i){const b=i instanceof Error?i.message:String(i);throw l={message:O(b,o),type:P(i)},i}finally{try{a({attributes:{"http.request.method":u.method,...w===void 0?{}:{"http.response.status_code":w},"url.full":G(u.url)},durationMs:Date.now()-T,...l===void 0?{}:{error:l},functionPath:s,kind:"client",name:`${u.method} ${J(u.url)}`,ok:l===void 0,parentSpanId:r.rootSpanId,shardKey:c,spanId:k,startTs:T,traceId:r.traceId,userId:p()})}catch{}}}},nt=t=>{const{functionPath:e,record:r,shardKey:o}=t,s=(n,a,c,p)=>{if(!Number.isFinite(c))return;const d=A(I(p));try{r({...d===void 0?{}:{attributes:d},functionPath:e,kind:n,name:a,shardKey:o,ts:Date.now(),value:c})}catch{}};return{count:(n,a=1,c)=>{s("counter",n,a,c)},gauge:(n,a,c)=>{s("gauge",n,a,c)},record:(n,a,c)=>{s("histogram",n,a,c)}}},ot=t=>{const{anchor:e,captureRaw:r=!1,collected:o,durationMs:s,failure:n,functionPath:a,shardKey:c,startTs:p,userId:d}=t,y=A(o?.attributes??{},r);return{...Object.keys(y).length===0?{}:{attributes:y},dispatch:!0,durationMs:s,...o===void 0||o.events.length===0?{}:{events:o.events},...n===void 0?{}:{error:{message:O(n.thrown instanceof Error?n.thrown.message:String(n.thrown),r),type:P(n.thrown)}},functionPath:a,...o===void 0||o.links.length===0?{}:{links:o.links},name:a,ok:n===void 0,parentSpanId:"",shardKey:c,spanId:e.rootSpanId,startTs:p,traceId:e.traceId,userId:d}};export{Y as applyHostSpanAttributes,nt as createMetrics,Z as createSpanCollector,st as createTracedFetch,rt as createTracer,ot as dispatchRootSpan};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{r as e,t as a}from"./trace-context-d_EfGPSZ.mjs";export{e as resolveTraceAnchor,a as toErrorType};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{isLunoraError as p}from"@lunora/errors";const f=Array.from({length:256},(r,t)=>t.toString(16).padStart(2,"0")),u=512,l=new Uint8Array(u);let s=u;const i=(r,t,e)=>{let o="";for(let n=0;n<e;n+=1)o+=f[r[t+n]];return o},d=r=>{if(r>u){const e=new Uint8Array(r);return crypto.getRandomValues(e),i(e,0,r)}s+r>u&&(crypto.getRandomValues(l),s=0);const t=i(l,s,r);return s+=r,t},c=/^[0-9a-f]+$/,h=(r,t,e=!0)=>`00-${r}-${t}-${e?"01":"00"}`,m=r=>{if(r==null)return;const t=r.split("-"),[e,o,n,a]=t;if(!(t.length<4||e===void 0||e.length!==2||!c.test(e)||e==="ff"||e==="00"&&t.length!==4||o===void 0||n===void 0||a===void 0||a.length!==2||!c.test(a)||o.length!==32||n.length!==16||!c.test(o)||!c.test(n)||o==="00000000000000000000000000000000"||n==="0000000000000000"))return{parentSpanId:n,sampled:(Number.parseInt(a,16)&1)===1,traceId:o}},v={client:3,consumer:5,internal:1,producer:4,server:2},_=Object.freeze({durationMs:"lunora.duration_ms",errorMessage:"error.message",errorType:"error.type",functionPath:"lunora.function_path",ok:"lunora.ok",shardKey:"lunora.shard_key",userId:"lunora.user_id"}),T=r=>{const t=m(r);return{rootSpanId:t?.parentSpanId??d(8),sampled:t?.sampled??!0,traceId:t?.traceId??d(16)}},I=r=>p(r)?r.code:r instanceof Error?r.constructor.name:"Error";export{_ as L,v as O,h as b,d as o,T as r,I as t};
|