@lunora/observability 1.0.0-alpha.119 → 1.0.0-alpha.120

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 CHANGED
@@ -512,6 +512,16 @@ interface HostSpanLike {
512
512
  setAttribute: (key: string, value: boolean | number | string | undefined) => unknown;
513
513
  /** Attach several attributes in one call (CF 2026-09-25). Optional, like `recordException`. */
514
514
  setAttributes?: (attributes: Record<string, boolean | number | string>) => unknown;
515
+ /**
516
+ * Set the span's OTel status (workers-types 5.20260929). Optional and
517
+ * feature-detected, like `recordException`: older runtimes lack it. The
518
+ * bridge only ever sets `"error"` — OTel instrumentation leaves a successful
519
+ * span `"unset"` rather than marking it `"ok"`.
520
+ */
521
+ setStatus?: (status: {
522
+ code: "error" | "ok" | "unset";
523
+ message?: string;
524
+ }) => unknown;
515
525
  }
516
526
  /**
517
527
  * Minimal structural shape of the `tracing` namespace exported by
@@ -541,6 +551,30 @@ type HostTracingResolver = () => HostTracingLike | Promise<HostTracingLike | und
541
551
  * since CF's setters take `string | number | boolean` only.
542
552
  */
543
553
  declare const setHostSpanAttributes: (span: HostSpanLike, attributes: Record<string, LogFields[string]>) => void;
554
+ /**
555
+ * Mirror a finished dispatch onto the host's invocation span — the one
556
+ * `tracing.getActiveSpan()` returns once every `ctx.trace` custom span has
557
+ * ended. Pure and fully best-effort: a missing `getActiveSpan`, an untraced span
558
+ * or a throwing setter is a silent no-op, never an error for the dispatch.
559
+ *
560
+ * `attributes` is the dispatch root span's already-redacted wide event, when it
561
+ * recorded one. `error` is set when the dispatch failed; its `serverFault` is the
562
+ * CALLER's verdict on whether that failure is the server's: the status of the
563
+ * response it actually sent (>= 500) for an RPC, always `true` for a trigger
564
+ * that threw. Only a server fault marks the span failed; a 4xx is an expected
565
+ * client outcome that OTel's server-span convention leaves `"unset"`. `message`
566
+ * must already be redacted.
567
+ *
568
+ * The status is written before the attributes so a throwing attribute setter
569
+ * cannot drop it.
570
+ */
571
+ declare const applyHostRootSpan: (tracing: HostTracingLike | undefined, root: {
572
+ attributes?: Record<string, LogFields[string]>;
573
+ error?: {
574
+ message: string;
575
+ serverFault: boolean;
576
+ };
577
+ }) => void;
544
578
  /**
545
579
  * Structural shape of the `ctx.trace` span factory (see the server
546
580
  * `LunoraTracer`). Declared here rather than imported so `@lunora/do` takes no
@@ -2255,4 +2289,4 @@ type AuthMetricsBucket, type ContextFetch, type ContextLogLevel, type ContextMet
2255
2289
  * mistake `@lunora/do`'s own barrel documents having made once with the search
2256
2290
  * core. What is exported here is what a consumer actually needs.
2257
2291
  */
2258
- 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 SqlClientLike, type TallySurface, 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, instrumentSqlClient, mergeScanAttribution, parseExplainIssueArgs, parseLogArgs, readAuthMetrics, readErrorIssues, readFunctionMetricBuckets, readFunctionMetricIndexHits, readFunctionMetricScans, readFunctionMetrics, readFunctionMetricsTotals, readMetricHistory, readQueryInsights, readQueryMetrics, readRequestLog, recordAuthEvent, recordFunctionMetric, recordMetricHistory, recordQueryMetric, redactArgs, resolveTraceAnchor, setHostSpanAttributes, upsertIssueState };
2292
+ 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 SqlClientLike, type TallySurface, type TraceAnchor, type TraceSpan, type TraceSummary, type TracedFetchDeps, type TracerDeps, appendRequestLogEntry, applyHostRootSpan, buildSecurityAudit, createDatabaseTally, createMetrics, createSpanCollector, createTracedFetch, createTracer, dispatchRootSpan, emitLogEvent, emitRequestLogEvent, ensureAuthMetricsTables, ensureFunctionMetricsTables, ensureRequestLogTable, explainIssue, findDanglingReferences, foldTraces, formatTally, instrumentDatabase, instrumentSqlClient, 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
@@ -512,6 +512,16 @@ interface HostSpanLike {
512
512
  setAttribute: (key: string, value: boolean | number | string | undefined) => unknown;
513
513
  /** Attach several attributes in one call (CF 2026-09-25). Optional, like `recordException`. */
514
514
  setAttributes?: (attributes: Record<string, boolean | number | string>) => unknown;
515
+ /**
516
+ * Set the span's OTel status (workers-types 5.20260929). Optional and
517
+ * feature-detected, like `recordException`: older runtimes lack it. The
518
+ * bridge only ever sets `"error"` — OTel instrumentation leaves a successful
519
+ * span `"unset"` rather than marking it `"ok"`.
520
+ */
521
+ setStatus?: (status: {
522
+ code: "error" | "ok" | "unset";
523
+ message?: string;
524
+ }) => unknown;
515
525
  }
516
526
  /**
517
527
  * Minimal structural shape of the `tracing` namespace exported by
@@ -541,6 +551,30 @@ type HostTracingResolver = () => HostTracingLike | Promise<HostTracingLike | und
541
551
  * since CF's setters take `string | number | boolean` only.
542
552
  */
543
553
  declare const setHostSpanAttributes: (span: HostSpanLike, attributes: Record<string, LogFields[string]>) => void;
554
+ /**
555
+ * Mirror a finished dispatch onto the host's invocation span — the one
556
+ * `tracing.getActiveSpan()` returns once every `ctx.trace` custom span has
557
+ * ended. Pure and fully best-effort: a missing `getActiveSpan`, an untraced span
558
+ * or a throwing setter is a silent no-op, never an error for the dispatch.
559
+ *
560
+ * `attributes` is the dispatch root span's already-redacted wide event, when it
561
+ * recorded one. `error` is set when the dispatch failed; its `serverFault` is the
562
+ * CALLER's verdict on whether that failure is the server's: the status of the
563
+ * response it actually sent (>= 500) for an RPC, always `true` for a trigger
564
+ * that threw. Only a server fault marks the span failed; a 4xx is an expected
565
+ * client outcome that OTel's server-span convention leaves `"unset"`. `message`
566
+ * must already be redacted.
567
+ *
568
+ * The status is written before the attributes so a throwing attribute setter
569
+ * cannot drop it.
570
+ */
571
+ declare const applyHostRootSpan: (tracing: HostTracingLike | undefined, root: {
572
+ attributes?: Record<string, LogFields[string]>;
573
+ error?: {
574
+ message: string;
575
+ serverFault: boolean;
576
+ };
577
+ }) => void;
544
578
  /**
545
579
  * Structural shape of the `ctx.trace` span factory (see the server
546
580
  * `LunoraTracer`). Declared here rather than imported so `@lunora/do` takes no
@@ -2255,4 +2289,4 @@ type AuthMetricsBucket, type ContextFetch, type ContextLogLevel, type ContextMet
2255
2289
  * mistake `@lunora/do`'s own barrel documents having made once with the search
2256
2290
  * core. What is exported here is what a consumer actually needs.
2257
2291
  */
2258
- 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 SqlClientLike, type TallySurface, 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, instrumentSqlClient, mergeScanAttribution, parseExplainIssueArgs, parseLogArgs, readAuthMetrics, readErrorIssues, readFunctionMetricBuckets, readFunctionMetricIndexHits, readFunctionMetricScans, readFunctionMetrics, readFunctionMetricsTotals, readMetricHistory, readQueryInsights, readQueryMetrics, readRequestLog, recordAuthEvent, recordFunctionMetric, recordMetricHistory, recordQueryMetric, redactArgs, resolveTraceAnchor, setHostSpanAttributes, upsertIssueState };
2292
+ 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 SqlClientLike, type TallySurface, type TraceAnchor, type TraceSpan, type TraceSummary, type TracedFetchDeps, type TracerDeps, appendRequestLogEntry, applyHostRootSpan, buildSecurityAudit, createDatabaseTally, createMetrics, createSpanCollector, createTracedFetch, createTracer, dispatchRootSpan, emitLogEvent, emitRequestLogEvent, ensureAuthMetricsTables, ensureFunctionMetricsTables, ensureRequestLogTable, explainIssue, findDanglingReferences, foldTraces, formatTally, instrumentDatabase, instrumentSqlClient, 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 s,ensureAuthMetricsTables as a,readAuthMetrics as E,recordAuthEvent as _}from"./packem_shared/AUTH_METRICS_BUCKETS_TABLE-C-qbQA-w.mjs";import{createMetrics as S,createSpanCollector as n,createTracedFetch as i,createTracer as I,dispatchRootSpan as u}from"./packem_shared/createMetrics-D3QG9wMf.mjs";import{createDatabaseTally as A,formatTally as C,instrumentDatabase as p,instrumentSqlClient as N}from"./packem_shared/createDatabaseTally-BGQNFq78.mjs";import{FUNCTION_METRICS_BUCKETS_TABLE as U,FUNCTION_METRICS_BUCKET_MS as d,FUNCTION_METRICS_BUCKET_RETENTION as R,FUNCTION_METRICS_INDEX_TABLE as m,FUNCTION_METRICS_MAX_PATHS as L,FUNCTION_METRICS_READ_LIMIT as x,FUNCTION_METRICS_SCANS_TABLE as l,FUNCTION_METRICS_TABLE as B,ensureFunctionMetricsTables as F,mergeScanAttribution as g,readFunctionMetricBuckets as O,readFunctionMetricIndexHits as H,readFunctionMetricScans as b,readFunctionMetrics as y,readFunctionMetricsTotals as D,recordFunctionMetric as h}from"./packem_shared/FUNCTION_METRICS_BUCKETS_TABLE-ChlIe0vF.mjs";import{setHostSpanAttributes as q}from"./packem_shared/setHostSpanAttributes-tUccMpGP.mjs";import{DEFAULT_EXPLAIN_ISSUE_MODEL as Q,explainIssue as G,parseExplainIssueArgs as X}from"./packem_shared/DEFAULT_EXPLAIN_ISSUE_MODEL-BkFTgdkd.mjs";import{ISSUE_SEVERITIES as k,ISSUE_STATE_TABLE as V,ISSUE_STATUSES as j,upsertIssueState as w}from"./packem_shared/ISSUE_SEVERITIES-0SJ0glV4.mjs";import{LogBuffer as J}from"./packem_shared/LogBuffer-BmD4CfV0.mjs";import{M as Y}from"./packem_shared/metric-buffer-Bx0XbypU.mjs";import{readMetricHistory as $,recordMetricHistory as ee}from"./packem_shared/readMetricHistory-TKfnwFNv.mjs";import{readQueryInsights as te,readQueryMetrics as Te,recordQueryMetric as oe}from"./packem_shared/readQueryInsights-DkQfxGfP.mjs";import{R as ae,a as Ee,e as _e,b as ce,c as Se,p as ne,r as ie,d as Ie,f as ue}from"./packem_shared/request-log-BmtC_cDV.mjs";import{MIN_ADMIN_TOKEN_LENGTH as Ae,MIN_AUTH_SECRET_LENGTH as Ce,buildSecurityAudit as pe}from"./packem_shared/MIN_ADMIN_TOKEN_LENGTH-DSOQ6rno.mjs";import{SpanBuffer as fe,foldTraces as Ue}from"./packem_shared/SpanBuffer-DnYOc8uk.mjs";import{findDanglingReferences as Re}from"./packem_shared/findDanglingReferences-BaOyIdxz.mjs";import{resolveTraceAnchor as Le}from"./packem_shared/resolveTraceAnchor-DDAPZRBB.mjs";export{t as AUTH_METRICS_BUCKETS_TABLE,T as AUTH_METRICS_BUCKET_MS,o as AUTH_METRICS_BUCKET_RETENTION,s as AUTH_METRICS_TABLE,Q as DEFAULT_EXPLAIN_ISSUE_MODEL,U as FUNCTION_METRICS_BUCKETS_TABLE,d as FUNCTION_METRICS_BUCKET_MS,R as FUNCTION_METRICS_BUCKET_RETENTION,m as FUNCTION_METRICS_INDEX_TABLE,L as FUNCTION_METRICS_MAX_PATHS,x as FUNCTION_METRICS_READ_LIMIT,l as FUNCTION_METRICS_SCANS_TABLE,B as FUNCTION_METRICS_TABLE,k as ISSUE_SEVERITIES,V as ISSUE_STATE_TABLE,j as ISSUE_STATUSES,J as LogBuffer,Ae as MIN_ADMIN_TOKEN_LENGTH,Ce as MIN_AUTH_SECRET_LENGTH,Y as MetricBuffer,ae as REQUEST_LOG_TABLE,fe as SpanBuffer,Ee as appendRequestLogEntry,pe as buildSecurityAudit,A as createDatabaseTally,S as createMetrics,n as createSpanCollector,i as createTracedFetch,I as createTracer,u as dispatchRootSpan,_e as emitLogEvent,ce as emitRequestLogEvent,a as ensureAuthMetricsTables,F as ensureFunctionMetricsTables,Se as ensureRequestLogTable,G as explainIssue,Re as findDanglingReferences,Ue as foldTraces,C as formatTally,p as instrumentDatabase,N as instrumentSqlClient,g as mergeScanAttribution,X as parseExplainIssueArgs,ne as parseLogArgs,E as readAuthMetrics,ie as readErrorIssues,O as readFunctionMetricBuckets,H as readFunctionMetricIndexHits,b as readFunctionMetricScans,y as readFunctionMetrics,D as readFunctionMetricsTotals,$ as readMetricHistory,te as readQueryInsights,Te as readQueryMetrics,Ie as readRequestLog,_ as recordAuthEvent,h as recordFunctionMetric,ee as recordMetricHistory,oe as recordQueryMetric,ue as redactArgs,Le as resolveTraceAnchor,q as setHostSpanAttributes,w as upsertIssueState};
1
+ import{AUTH_METRICS_BUCKETS_TABLE as t,AUTH_METRICS_BUCKET_MS as o,AUTH_METRICS_BUCKET_RETENTION as T,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 n,createTracedFetch as i,createTracer as I,dispatchRootSpan as u}from"./packem_shared/createMetrics-Byt8y5Kw.mjs";import{createDatabaseTally as p,formatTally as A,instrumentDatabase as C,instrumentSqlClient as N}from"./packem_shared/createDatabaseTally-BGQNFq78.mjs";import{FUNCTION_METRICS_BUCKETS_TABLE as R,FUNCTION_METRICS_BUCKET_MS as U,FUNCTION_METRICS_BUCKET_RETENTION as d,FUNCTION_METRICS_INDEX_TABLE as m,FUNCTION_METRICS_MAX_PATHS as L,FUNCTION_METRICS_READ_LIMIT as l,FUNCTION_METRICS_SCANS_TABLE as x,FUNCTION_METRICS_TABLE as B,ensureFunctionMetricsTables as F,mergeScanAttribution as g,readFunctionMetricBuckets as H,readFunctionMetricIndexHits as O,readFunctionMetricScans as y,readFunctionMetrics as b,readFunctionMetricsTotals as D,recordFunctionMetric as h}from"./packem_shared/FUNCTION_METRICS_BUCKETS_TABLE-ChlIe0vF.mjs";import{applyHostRootSpan as q,setHostSpanAttributes as v}from"./packem_shared/applyHostRootSpan-DToRfMn8.mjs";import{DEFAULT_EXPLAIN_ISSUE_MODEL as G,explainIssue as X,parseExplainIssueArgs as P}from"./packem_shared/DEFAULT_EXPLAIN_ISSUE_MODEL-BkFTgdkd.mjs";import{ISSUE_SEVERITIES as V,ISSUE_STATE_TABLE as j,ISSUE_STATUSES as w,upsertIssueState as z}from"./packem_shared/ISSUE_SEVERITIES-0SJ0glV4.mjs";import{LogBuffer as W}from"./packem_shared/LogBuffer-BmD4CfV0.mjs";import{M as Z}from"./packem_shared/metric-buffer-Bx0XbypU.mjs";import{readMetricHistory as ee,recordMetricHistory as re}from"./packem_shared/readMetricHistory-TKfnwFNv.mjs";import{readQueryInsights as oe,readQueryMetrics as Te,recordQueryMetric as ae}from"./packem_shared/readQueryInsights-DkQfxGfP.mjs";import{R as Ee,a as _e,e as ce,b as Se,c as ne,p as ie,r as Ie,d as ue,f as Me}from"./packem_shared/request-log-BmtC_cDV.mjs";import{MIN_ADMIN_TOKEN_LENGTH as Ae,MIN_AUTH_SECRET_LENGTH as Ce,buildSecurityAudit as Ne}from"./packem_shared/MIN_ADMIN_TOKEN_LENGTH-DSOQ6rno.mjs";import{SpanBuffer as Re,foldTraces as Ue}from"./packem_shared/SpanBuffer-DnYOc8uk.mjs";import{findDanglingReferences as me}from"./packem_shared/findDanglingReferences-BaOyIdxz.mjs";import{resolveTraceAnchor as le}from"./packem_shared/resolveTraceAnchor-DDAPZRBB.mjs";export{t as AUTH_METRICS_BUCKETS_TABLE,o as AUTH_METRICS_BUCKET_MS,T as AUTH_METRICS_BUCKET_RETENTION,a as AUTH_METRICS_TABLE,G as DEFAULT_EXPLAIN_ISSUE_MODEL,R as FUNCTION_METRICS_BUCKETS_TABLE,U as FUNCTION_METRICS_BUCKET_MS,d as FUNCTION_METRICS_BUCKET_RETENTION,m as FUNCTION_METRICS_INDEX_TABLE,L as FUNCTION_METRICS_MAX_PATHS,l as FUNCTION_METRICS_READ_LIMIT,x as FUNCTION_METRICS_SCANS_TABLE,B as FUNCTION_METRICS_TABLE,V as ISSUE_SEVERITIES,j as ISSUE_STATE_TABLE,w as ISSUE_STATUSES,W as LogBuffer,Ae as MIN_ADMIN_TOKEN_LENGTH,Ce as MIN_AUTH_SECRET_LENGTH,Z as MetricBuffer,Ee as REQUEST_LOG_TABLE,Re as SpanBuffer,_e as appendRequestLogEntry,q as applyHostRootSpan,Ne as buildSecurityAudit,p as createDatabaseTally,S as createMetrics,n as createSpanCollector,i as createTracedFetch,I as createTracer,u as dispatchRootSpan,ce as emitLogEvent,Se as emitRequestLogEvent,s as ensureAuthMetricsTables,F as ensureFunctionMetricsTables,ne as ensureRequestLogTable,X as explainIssue,me as findDanglingReferences,Ue as foldTraces,A as formatTally,C as instrumentDatabase,N as instrumentSqlClient,g as mergeScanAttribution,P as parseExplainIssueArgs,ie as parseLogArgs,E as readAuthMetrics,Ie as readErrorIssues,H as readFunctionMetricBuckets,O as readFunctionMetricIndexHits,y as readFunctionMetricScans,b as readFunctionMetrics,D as readFunctionMetricsTotals,ee as readMetricHistory,oe as readQueryInsights,Te as readQueryMetrics,ue as readRequestLog,_ as recordAuthEvent,h as recordFunctionMetric,re as recordMetricHistory,ae as recordQueryMetric,Me as redactArgs,le as resolveTraceAnchor,v as setHostSpanAttributes,z as upsertIssueState};
@@ -0,0 +1 @@
1
+ import{L as s}from"./otlp-DR7601NL.mjs";const u=(t,r)=>{if(!t.isTraced)return;const e={};for(const[i,o]of Object.entries(r))(typeof o=="boolean"||typeof o=="number"||typeof o=="string")&&(e[i]=o);if(typeof t.setAttributes=="function"){t.setAttributes(e);return}for(const[i,o]of Object.entries(e))t.setAttribute(i,o)},n=(t,r)=>{if(!(!t.isTraced||typeof t.setStatus!="function"))try{t.setStatus({code:"error",message:r})}catch{}},f=(t,r)=>{if(!t.isTraced)return;r.error!==void 0&&n(t,r.error.message);const e={[s.functionPath]:r.functionPath,[s.ok]:r.ok,[s.durationMs]:r.durationMs,...r.shardKey===void 0?{}:{[s.shardKey]:r.shardKey},...r.userId===void 0?{}:{[s.userId]:r.userId},...r.error===void 0?{}:{[s.errorType]:r.error.type,[s.errorMessage]:r.error.message}};for(const[i,o]of Object.entries(r.attributes))e[`lunora.attr.${i}`]=o;u(t,e),r.error!==void 0&&typeof t.recordException=="function"&&t.recordException({message:r.error.message,name:r.error.type})},d=(t,r)=>{let e;try{e=t?.getActiveSpan?.()}catch{return}if(e!==void 0&&(r.error?.serverFault===!0&&n(e,r.error.message),r.attributes!==void 0))try{u(e,r.attributes)}catch{}};export{d as applyHostRootSpan,f as applyHostSpanAttributes,u as setHostSpanAttributes};
@@ -0,0 +1 @@
1
+ import{f as _,g as k,n as y}from"./request-log-BmtC_cDV.mjs";import{o as x,b as L,O as K}from"./otlp-DR7601NL.mjs";import{applyHostSpanAttributes as U}from"./applyHostRootSpan-DToRfMn8.mjs";import{toErrorType as O}from"./resolveTraceAnchor-DDAPZRBB.mjs";const q=/[\w.-]/u,C=t=>{let e="";for(const r of t)e+=q.test(r)?r:"_";return e},X=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=C(t.name),r={[`gen_ai.evaluation.${e}.score`]:t.score};return t.label!==void 0&&(r[`gen_ai.evaluation.${e}.label`]=t.label),r},B=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(K,r)},V=128,G=128,z=128,b=(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>=z||(s&&(r+=1),t[a]=n)}},j=t=>{const e=y(t);if(e===void 0||Object.keys(e).length<=z)return e;const r={};return b(r,e),r},J=t=>{try{const e=new URL(t);return`${e.protocol}//${e.host}${e.pathname}`}catch{return t}},Q=t=>{try{return new URL(t).host}catch{return t}},W=(t,e)=>{try{return t(new URL(e))}catch{return!1}},Y=t=>t===void 0?{}:B(t)?t:{attributes:t},H=t=>t.rayId===void 0?{traceId:t.traceId}:{rayId:t.rayId,traceId:t.traceId},Z=(t,e=!1)=>{const r={attributes:{},events:[],links:[]},a={spanContext:()=>t,addEvent:(n,s)=>{if(r.events.length>=V)return;const o=k(j(s),e);r.events.push({...o===void 0?{}:{attributes:o},name:n,ts:Date.now()})},addLink:n=>{if(r.links.length>=G)return;const s=k(j(n.attributes),e);r.links.push({...s===void 0?{}:{attributes:s},spanId:n.spanId,traceId:n.traceId})},recordEvaluation:n=>{b(r.attributes,y(X(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)=>{b(r.attributes,y({[n]:s}))},setAttributes:n=>{b(r.attributes,y(n))}};return{collected:r,handle:a}},st=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??x(8),w=P?.parentSpanId??m,i=Date.now(),g=Y(u),D=y(g.attributes),{collected:T,handle:F}=Z({...e.sampled===void 0?{}:{sampled:e.sampled},spanId:l,traceId:e.traceId},r),R=async S=>{let p=!0,v;try{return await E(d(l),F)}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={};b(N,D),b(N,T.attributes);const M=k(N,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},...$.length===0?{}:{links:$},name:I,ok:p,parentSpanId:w,...H(e),shardKey:c,spanId:l,startTs:i,userId:A})}catch{}if(S!==void 0)try{U(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,R(v)))}catch(p){if(S)throw p}}return await R()};return d(e.rootSpanId)},at=(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=x(8),E=Date.now(),u=new Request(d,m);(typeof s=="function"?W(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":J(u.url)},durationMs:Date.now()-E,...l===void 0?{}:{error:l},functionPath:n,kind:"client",name:`${u.method} ${Q(u.url)}`,ok:l===void 0,parentSpanId:r.rootSpanId,...H(r),shardKey:c,spanId:I,startTs:E,userId:f()})}catch{}}}},ot=t=>{const{functionPath:e,record:r,shardKey:a}=t,n=(s,o,c,f)=>{if(!Number.isFinite(c))return;const d=k(y(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)}}},ct=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:"",...H(e),shardKey:c,spanId:e.rootSpanId,startTs:f,userId:d}};export{ot as createMetrics,Z as createSpanCollector,at as createTracedFetch,st as createTracer,ct as dispatchRootSpan,H as spanAnchorFields};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lunora/observability",
3
- "version": "1.0.0-alpha.119",
3
+ "version": "1.0.0-alpha.120",
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",
@@ -45,7 +45,7 @@
45
45
  "dependencies": {
46
46
  "@lunora/errors": "1.0.0-alpha.50",
47
47
  "@lunora/fingerprint": "1.0.0-alpha.9",
48
- "@lunora/shard-engine": "1.0.0-alpha.110",
48
+ "@lunora/shard-engine": "1.0.0-alpha.111",
49
49
  "@visulima/redact": "5.0.0"
50
50
  },
51
51
  "engines": {
@@ -1 +0,0 @@
1
- import{f as _,g as k,n as y}from"./request-log-BmtC_cDV.mjs";import{o as x,b as L,O as K}from"./otlp-DR7601NL.mjs";import{applyHostSpanAttributes as U}from"./setHostSpanAttributes-tUccMpGP.mjs";import{toErrorType as O}from"./resolveTraceAnchor-DDAPZRBB.mjs";const q=/[\w.-]/u,C=t=>{let e="";for(const r of t)e+=q.test(r)?r:"_";return e},X=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=C(t.name),r={[`gen_ai.evaluation.${e}.score`]:t.score};return t.label!==void 0&&(r[`gen_ai.evaluation.${e}.label`]=t.label),r},B=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(K,r)},V=128,G=128,z=128,b=(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>=z||(s&&(r+=1),t[a]=n)}},j=t=>{const e=y(t);if(e===void 0||Object.keys(e).length<=z)return e;const r={};return b(r,e),r},J=t=>{try{const e=new URL(t);return`${e.protocol}//${e.host}${e.pathname}`}catch{return t}},Q=t=>{try{return new URL(t).host}catch{return t}},W=(t,e)=>{try{return t(new URL(e))}catch{return!1}},Y=t=>t===void 0?{}:B(t)?t:{attributes:t},H=t=>t.rayId===void 0?{traceId:t.traceId}:{rayId:t.rayId,traceId:t.traceId},Z=(t,e=!1)=>{const r={attributes:{},events:[],links:[]},a={spanContext:()=>t,addEvent:(n,s)=>{if(r.events.length>=V)return;const o=k(j(s),e);r.events.push({...o===void 0?{}:{attributes:o},name:n,ts:Date.now()})},addLink:n=>{if(r.links.length>=G)return;const s=k(j(n.attributes),e);r.links.push({...s===void 0?{}:{attributes:s},spanId:n.spanId,traceId:n.traceId})},recordEvaluation:n=>{b(r.attributes,y(X(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)=>{b(r.attributes,y({[n]:s}))},setAttributes:n=>{b(r.attributes,y(n))}};return{collected:r,handle:a}},st=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??x(8),w=P?.parentSpanId??m,i=Date.now(),g=Y(u),D=y(g.attributes),{collected:T,handle:F}=Z({...e.sampled===void 0?{}:{sampled:e.sampled},spanId:l,traceId:e.traceId},r),R=async S=>{let p=!0,v;try{return await E(d(l),F)}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={};b(N,D),b(N,T.attributes);const M=k(N,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},...$.length===0?{}:{links:$},name:I,ok:p,parentSpanId:w,...H(e),shardKey:c,spanId:l,startTs:i,userId:A})}catch{}if(S!==void 0)try{U(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,R(v)))}catch(p){if(S)throw p}}return await R()};return d(e.rootSpanId)},at=(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=x(8),E=Date.now(),u=new Request(d,m);(typeof s=="function"?W(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":J(u.url)},durationMs:Date.now()-E,...l===void 0?{}:{error:l},functionPath:n,kind:"client",name:`${u.method} ${Q(u.url)}`,ok:l===void 0,parentSpanId:r.rootSpanId,...H(r),shardKey:c,spanId:I,startTs:E,userId:f()})}catch{}}}},ot=t=>{const{functionPath:e,record:r,shardKey:a}=t,n=(s,o,c,f)=>{if(!Number.isFinite(c))return;const d=k(y(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)}}},ct=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:"",...H(e),shardKey:c,spanId:e.rootSpanId,startTs:f,userId:d}};export{ot as createMetrics,Z as createSpanCollector,at as createTracedFetch,st as createTracer,ct as dispatchRootSpan,H as spanAnchorFields};
@@ -1 +0,0 @@
1
- import{L as o}from"./otlp-DR7601NL.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};