@lunora/observability 1.0.0-alpha.69 → 1.0.0-alpha.70
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 +8 -2
- package/dist/index.d.ts +8 -2
- package/dist/index.mjs +1 -1
- package/dist/packem_shared/{REQUEST_LOG_TABLE-C50rAMgd.mjs → REQUEST_LOG_TABLE--5PBTOVZ.mjs} +1 -1
- package/dist/packem_shared/{createDatabaseTally-DlEwx6BE.mjs → createDatabaseTally-hp-LQRAz.mjs} +1 -1
- package/dist/packem_shared/{createMetrics-DCUKQowk.mjs → createMetrics-C1-k5PCU.mjs} +1 -1
- package/dist/packem_shared/request-log-C2scoFaB.mjs +24 -0
- package/package.json +2 -2
- package/dist/packem_shared/request-log-l0ZqMbzd.mjs +0 -22
package/dist/index.d.mts
CHANGED
|
@@ -1467,9 +1467,9 @@ interface QueryStatEntry {
|
|
|
1467
1467
|
execCount: number;
|
|
1468
1468
|
/** Normalised SQL text (literals stripped, truncated). */
|
|
1469
1469
|
normalizedSql: string;
|
|
1470
|
-
/** Total rows
|
|
1470
|
+
/** Total rows SCANNED across all executions (the billed number, not the result-set size). */
|
|
1471
1471
|
rowsRead: number;
|
|
1472
|
-
/** Total rows
|
|
1472
|
+
/** Total rows WRITTEN across all executions. */
|
|
1473
1473
|
rowsWritten: number;
|
|
1474
1474
|
/** Total wall-clock milliseconds across all executions. */
|
|
1475
1475
|
totalDurationMs: number;
|
|
@@ -1550,6 +1550,8 @@ type RequestOutcome = "error" | "ok";
|
|
|
1550
1550
|
interface RequestLogEntry {
|
|
1551
1551
|
/** Whether the result was served from the reactive cache; `undefined` when the cache is disabled or the path isn't cached (a write/action). */
|
|
1552
1552
|
cacheHit?: boolean;
|
|
1553
|
+
/** Worker deployment id from the `CF_VERSION_METADATA` binding; `undefined` when the binding isn't declared. Group on this to answer "did this start with a deploy?". */
|
|
1554
|
+
deploymentId?: string;
|
|
1553
1555
|
/** Handler wall-clock duration in milliseconds (before the subscription write-flush, matching the per-function metrics). */
|
|
1554
1556
|
durationMs: number;
|
|
1555
1557
|
/** Error message when `outcome === "error"`, redacted like args/identity; absent on success. */
|
|
@@ -1578,10 +1580,13 @@ interface RequestLogEntry {
|
|
|
1578
1580
|
ts: number;
|
|
1579
1581
|
/** Acting userId forwarded by the runtime, or `undefined` when anonymous. */
|
|
1580
1582
|
userId?: string;
|
|
1583
|
+
/** Worker version tag from the `CF_VERSION_METADATA` binding; `undefined` when the binding isn't declared or the deploy carried no tag. */
|
|
1584
|
+
versionTag?: string;
|
|
1581
1585
|
}
|
|
1582
1586
|
/** Fields accepted when appending one request-log entry; `seq` is assigned by the table. */
|
|
1583
1587
|
interface AppendRequestLogEntry {
|
|
1584
1588
|
cacheHit?: boolean;
|
|
1589
|
+
deploymentId?: string;
|
|
1585
1590
|
durationMs: number;
|
|
1586
1591
|
errorMessage?: string;
|
|
1587
1592
|
functionPath: string;
|
|
@@ -1595,6 +1600,7 @@ interface AppendRequestLogEntry {
|
|
|
1595
1600
|
traceId?: string;
|
|
1596
1601
|
ts: number;
|
|
1597
1602
|
userId?: string;
|
|
1603
|
+
versionTag?: string;
|
|
1598
1604
|
}
|
|
1599
1605
|
/** Knobs the dispatch site threads into a request-log write. */
|
|
1600
1606
|
interface RequestLogWriteOptions {
|
package/dist/index.d.ts
CHANGED
|
@@ -1467,9 +1467,9 @@ interface QueryStatEntry {
|
|
|
1467
1467
|
execCount: number;
|
|
1468
1468
|
/** Normalised SQL text (literals stripped, truncated). */
|
|
1469
1469
|
normalizedSql: string;
|
|
1470
|
-
/** Total rows
|
|
1470
|
+
/** Total rows SCANNED across all executions (the billed number, not the result-set size). */
|
|
1471
1471
|
rowsRead: number;
|
|
1472
|
-
/** Total rows
|
|
1472
|
+
/** Total rows WRITTEN across all executions. */
|
|
1473
1473
|
rowsWritten: number;
|
|
1474
1474
|
/** Total wall-clock milliseconds across all executions. */
|
|
1475
1475
|
totalDurationMs: number;
|
|
@@ -1550,6 +1550,8 @@ type RequestOutcome = "error" | "ok";
|
|
|
1550
1550
|
interface RequestLogEntry {
|
|
1551
1551
|
/** Whether the result was served from the reactive cache; `undefined` when the cache is disabled or the path isn't cached (a write/action). */
|
|
1552
1552
|
cacheHit?: boolean;
|
|
1553
|
+
/** Worker deployment id from the `CF_VERSION_METADATA` binding; `undefined` when the binding isn't declared. Group on this to answer "did this start with a deploy?". */
|
|
1554
|
+
deploymentId?: string;
|
|
1553
1555
|
/** Handler wall-clock duration in milliseconds (before the subscription write-flush, matching the per-function metrics). */
|
|
1554
1556
|
durationMs: number;
|
|
1555
1557
|
/** Error message when `outcome === "error"`, redacted like args/identity; absent on success. */
|
|
@@ -1578,10 +1580,13 @@ interface RequestLogEntry {
|
|
|
1578
1580
|
ts: number;
|
|
1579
1581
|
/** Acting userId forwarded by the runtime, or `undefined` when anonymous. */
|
|
1580
1582
|
userId?: string;
|
|
1583
|
+
/** Worker version tag from the `CF_VERSION_METADATA` binding; `undefined` when the binding isn't declared or the deploy carried no tag. */
|
|
1584
|
+
versionTag?: string;
|
|
1581
1585
|
}
|
|
1582
1586
|
/** Fields accepted when appending one request-log entry; `seq` is assigned by the table. */
|
|
1583
1587
|
interface AppendRequestLogEntry {
|
|
1584
1588
|
cacheHit?: boolean;
|
|
1589
|
+
deploymentId?: string;
|
|
1585
1590
|
durationMs: number;
|
|
1586
1591
|
errorMessage?: string;
|
|
1587
1592
|
functionPath: string;
|
|
@@ -1595,6 +1600,7 @@ interface AppendRequestLogEntry {
|
|
|
1595
1600
|
traceId?: string;
|
|
1596
1601
|
ts: number;
|
|
1597
1602
|
userId?: string;
|
|
1603
|
+
versionTag?: string;
|
|
1598
1604
|
}
|
|
1599
1605
|
/** Knobs the dispatch site threads into a request-log write. */
|
|
1600
1606
|
interface RequestLogWriteOptions {
|
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-CeplWoRm.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-CeplWoRm.mjs";import{createMetrics as S,createSpanCollector as I,createTracedFetch as i,createTracer as n,dispatchRootSpan as M}from"./packem_shared/createMetrics-C1-k5PCU.mjs";import{createDatabaseTally as A,formatTally as C,instrumentDatabase as N}from"./packem_shared/createDatabaseTally-hp-LQRAz.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 y,readFunctionMetricsTotals as b,recordFunctionMetric as D}from"./packem_shared/FUNCTION_METRICS_BUCKETS_TABLE-ChlIe0vF.mjs";import{DEFAULT_EXPLAIN_ISSUE_MODEL as K,explainIssue as q,parseExplainIssueArgs as v}from"./packem_shared/DEFAULT_EXPLAIN_ISSUE_MODEL-BGGX6k5D.mjs";import{ISSUE_SEVERITIES as G,ISSUE_STATE_TABLE as X,ISSUE_STATUSES as P,upsertIssueState as k}from"./packem_shared/ISSUE_SEVERITIES-gLC4VEPQ.mjs";import{LogBuffer as j}from"./packem_shared/LogBuffer-BmD4CfV0.mjs";import{M as z}from"./packem_shared/metric-buffer-Bx0XbypU.mjs";import{readMetricHistory as W,recordMetricHistory as Y}from"./packem_shared/readMetricHistory-TKfnwFNv.mjs";import{readQueryInsights as $,readQueryMetrics as ee,recordQueryMetric as re}from"./packem_shared/readQueryInsights-B98JliCi.mjs";import{R as Te,a as oe,e as ae,b as se,c as Ee,p as _e,r as ce,d as Se,f as Ie}from"./packem_shared/request-log-C2scoFaB.mjs";import{MIN_ADMIN_TOKEN_LENGTH as ne,MIN_AUTH_SECRET_LENGTH as Me,buildSecurityAudit as ue}from"./packem_shared/MIN_ADMIN_TOKEN_LENGTH-DSOQ6rno.mjs";import{SpanBuffer as Ce,foldTraces as Ne}from"./packem_shared/SpanBuffer-DnYOc8uk.mjs";import{findDanglingReferences as fe}from"./packem_shared/findDanglingReferences-BNgg0jD_.mjs";import{r as de}from"./packem_shared/trace-context-DgWo6N3y.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,K 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,G as ISSUE_SEVERITIES,X as ISSUE_STATE_TABLE,P as ISSUE_STATUSES,j as LogBuffer,ne as MIN_ADMIN_TOKEN_LENGTH,Me as MIN_AUTH_SECRET_LENGTH,z as MetricBuffer,Te as REQUEST_LOG_TABLE,Ce as SpanBuffer,oe as appendRequestLogEntry,ue as buildSecurityAudit,A as createDatabaseTally,S as createMetrics,I as createSpanCollector,i as createTracedFetch,n as createTracer,M as dispatchRootSpan,ae as emitLogEvent,se as emitRequestLogEvent,s as ensureAuthMetricsTables,F as ensureFunctionMetricsTables,Ee as ensureRequestLogTable,q as explainIssue,fe as findDanglingReferences,Ne as foldTraces,C as formatTally,N as instrumentDatabase,l as mergeScanAttribution,v as parseExplainIssueArgs,_e as parseLogArgs,E as readAuthMetrics,ce as readErrorIssues,g as readFunctionMetricBuckets,O as readFunctionMetricIndexHits,H as readFunctionMetricScans,y as readFunctionMetrics,b as readFunctionMetricsTotals,W as readMetricHistory,$ as readQueryInsights,ee as readQueryMetrics,Se as readRequestLog,_ as recordAuthEvent,D as recordFunctionMetric,Y as recordMetricHistory,re as recordQueryMetric,Ie as redactArgs,de as resolveTraceAnchor,k as upsertIssueState};
|
package/dist/packem_shared/{REQUEST_LOG_TABLE-C50rAMgd.mjs → REQUEST_LOG_TABLE--5PBTOVZ.mjs}
RENAMED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{g as t,R as o,a as g,e as E,b as L,c as R,p,r as d,d as n,f as u,h as T}from"./request-log-
|
|
1
|
+
import{g as t,R as o,a as g,e as E,b as L,c as R,p,r as d,d as n,f as u,h as T}from"./request-log-C2scoFaB.mjs";import"./ISSUE_SEVERITIES-gLC4VEPQ.mjs";import"./run-sql-0aPgJkIw.mjs";export{t as REQUEST_LOG_RETENTION,o as REQUEST_LOG_TABLE,g as appendRequestLogEntry,E as emitLogEvent,L as emitRequestLogEvent,R as ensureRequestLogTable,p as parseLogArgs,d as readErrorIssues,n as readRequestLog,u as redactArgs,T as renderLogMessage};
|
package/dist/packem_shared/{createDatabaseTally-DlEwx6BE.mjs → createDatabaseTally-hp-LQRAz.mjs}
RENAMED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{o as m,t as b}from"./trace-context-DgWo6N3y.mjs";import{f as M}from"./request-log-
|
|
1
|
+
import{o as m,t as b}from"./trace-context-DgWo6N3y.mjs";import{f as M}from"./request-log-C2scoFaB.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","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 +1 @@
|
|
|
1
|
-
import{f as O,n as I}from"./request-log-
|
|
1
|
+
import{f as O,n as I}from"./request-log-C2scoFaB.mjs";import{L as g,o as j,b as x,t as P,O as z}from"./trace-context-DgWo6N3y.mjs";const D=/[\w.-]/u,U=t=>{let e="";for(const r of t)e+=D.test(r)?r:"_";return e},F=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=U(t.name),r={[`gen_ai.evaluation.${e}.score`]:t.score};return t.label!==void 0&&(r[`gen_ai.evaluation.${e}.label`]=t.label),r},q=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(z,r)},C=128,X=128,H=128,m=(t,e)=>{if(e===void 0)return;let r=Object.keys(t).length;for(const[o,n]of Object.entries(e)){const s=!Object.hasOwn(t,o);s&&r>=H||(s&&(r+=1),t[o]=n)}},$=t=>{const e=I(t);if(e===void 0||Object.keys(e).length<=H)return e;const r={};return m(r,e),r},B=t=>{try{const e=new URL(t);return`${e.protocol}//${e.host}${e.pathname}`}catch{return t}},V=t=>{try{return new URL(t).host}catch{return t}},G=(t,e)=>{try{return t(new URL(e))}catch{return!1}},J=t=>t===void 0?{}:q(t)?t:{attributes:t},Q=(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)}},W=(t,e=!1)=>{const r={attributes:{},events:[],links:[]},o={spanContext:()=>t,addEvent:(n,s)=>{if(r.events.length>=C)return;const a=$(s);r.events.push({...a===void 0?{}:{attributes:a},name:n,ts:Date.now()})},addLink:n=>{if(r.links.length>=X)return;const s=$(n.attributes);r.links.push({...s===void 0?{}:{attributes:s},spanId:n.spanId,traceId:n.traceId})},recordEvaluation:n=>{m(r.attributes,I(F(n)))},recordException:n=>{const s=n instanceof Error?n.message:String(n);o.addEvent("exception",{"exception.message":O(s,e),...e&&n instanceof Error&&typeof n.stack=="string"?{"exception.stacktrace":n.stack}:{},"exception.type":P(n)})},setAttribute:(n,s)=>{m(r.attributes,I({[n]:s}))},setAttributes:n=>{m(r.attributes,I(n))}};return{collected:r,handle:o}},tt=t=>{const{anchor:e,captureRaw:r=!1,fuseHostSpans:o,functionPath:n,record:s,resolveHostTracing:a,shardKey:c,userId:p}=t,d=y=>async(w,T,u,M)=>{const l=M?.spanId??j(8),k=M?.parentSpanId??y,i=Date.now(),b=J(u),K=I(b.attributes),{collected:E,handle:L}=W({...e.sampled===void 0?{}:{sampled:e.sampled},spanId:l,traceId:e.traceId},r),N=async S=>{let f=!0,v;try{return await T(d(l),L)}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(),A={};m(A,K),m(A,E.attributes);const R=[...b.links??[],...E.links];try{s({...Object.keys(A).length===0?{}:{attributes:A},durationMs:h,...E.events.length===0?{}:{events:E.events},...v===void 0?{}:{error:v},functionPath:n,...b.kind===void 0||b.kind==="internal"?{}:{kind:b.kind},...R.length===0?{}:{links:R},name:w,ok:f,parentSpanId:k,shardKey:c,spanId:l,startTs:i,traceId:e.traceId,userId:_})}catch{}if(S!==void 0)try{Q(S,{attributes:A,durationMs:h,error:v,functionPath:n,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(w,v=>(S=!0,N(v)))}catch(f){if(S)throw f}}return await N()};return d(e.rootSpanId)},et=(t,e)=>{const{anchor:r,captureRaw:o=!1,functionPath:n,propagate:s=!0,record:a,shardKey:c,userId:p}=t;return async(d,y)=>{const w=j(8),T=Date.now(),u=new Request(d,y);(typeof s=="function"?G(s,u.url):s)&&u.headers.set("traceparent",x(r.traceId,w,r.sampled??!0));let l,k;try{const i=await e(u);return k=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,...k===void 0?{}:{"http.response.status_code":k},"url.full":B(u.url)},durationMs:Date.now()-T,...l===void 0?{}:{error:l},functionPath:n,kind:"client",name:`${u.method} ${V(u.url)}`,ok:l===void 0,parentSpanId:r.rootSpanId,shardKey:c,spanId:w,startTs:T,traceId:r.traceId,userId:p()})}catch{}}}},rt=t=>{const{functionPath:e,record:r,shardKey:o}=t,n=(s,a,c,p)=>{if(!Number.isFinite(c))return;const d=I(p);try{r({...d===void 0?{}:{attributes:d},functionPath:e,kind:s,name:a,shardKey:o,ts:Date.now(),value:c})}catch{}};return{count:(s,a=1,c)=>{n("counter",s,a,c)},gauge:(s,a,c)=>{n("gauge",s,a,c)},record:(s,a,c)=>{n("histogram",s,a,c)}}},nt=t=>{const{anchor:e,captureRaw:r=!1,collected:o,durationMs:n,failure:s,functionPath:a,shardKey:c,startTs:p,userId:d}=t,y=o?.attributes??{};return{...Object.keys(y).length===0?{}:{attributes:y},dispatch:!0,durationMs:n,...o===void 0||o.events.length===0?{}:{events:o.events},...s===void 0?{}:{error:{message:O(s.thrown instanceof Error?s.thrown.message:String(s.thrown),r),type:P(s.thrown)}},functionPath:a,...o===void 0||o.links.length===0?{}:{links:o.links},name:a,ok:s===void 0,parentSpanId:"",shardKey:c,spanId:e.rootSpanId,startTs:p,traceId:e.traceId,userId:d}};export{Q as applyHostSpanAttributes,rt as createMetrics,W as createSpanCollector,et as createTracedFetch,tt as createTracer,nt as dispatchRootSpan};
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import{fingerprintError as I}from"@lunora/fingerprint";import{redact as M,standardRules as U}from"@visulima/redact";import{readIssueStates as X}from"./ISSUE_SEVERITIES-gLC4VEPQ.mjs";import{r as g}from"./run-sql-0aPgJkIw.mjs";const P=e=>{if(typeof e=="string")return e;try{return JSON.stringify(e)??String(e)}catch{return String(e)}},S=e=>typeof e=="boolean"||typeof e=="number"||typeof e=="string"?e:P(e),v=(e,t)=>{if(e===void 0&&t===void 0)return;const s={};if(t!==void 0)for(const[o,r]of Object.entries(t))s[o]=S(r);if(e!==void 0)for(const[o,r]of Object.entries(e))s[o]=S(r);return Object.keys(s).length===0?void 0:s},d="__lunora_reqlog__",E=1e3,O="lunora",D=["error_fingerprint TEXT","trace_id TEXT","deployment_id TEXT","version_tag TEXT"],u=(e,t=!1)=>t||e===null||e===void 0?e:M(e,U),R=new WeakSet,m=e=>{if(!R.has(e)){g(e,`CREATE TABLE IF NOT EXISTS "${d}" (
|
|
2
|
+
seq INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
3
|
+
ts REAL NOT NULL,
|
|
4
|
+
function_path TEXT NOT NULL,
|
|
5
|
+
shard_key TEXT,
|
|
6
|
+
user_id TEXT,
|
|
7
|
+
identity TEXT,
|
|
8
|
+
args TEXT,
|
|
9
|
+
outcome TEXT NOT NULL,
|
|
10
|
+
error_message TEXT,
|
|
11
|
+
error_fingerprint TEXT,
|
|
12
|
+
trace_id TEXT,
|
|
13
|
+
deployment_id TEXT,
|
|
14
|
+
version_tag TEXT,
|
|
15
|
+
duration_ms REAL NOT NULL,
|
|
16
|
+
tables_read TEXT NOT NULL DEFAULT '[]',
|
|
17
|
+
tables_written TEXT NOT NULL DEFAULT '[]',
|
|
18
|
+
cache_hit INTEGER,
|
|
19
|
+
subscriptions_rerun INTEGER NOT NULL DEFAULT 0
|
|
20
|
+
)`);for(const t of D)try{g(e,`ALTER TABLE "${d}" ADD COLUMN ${t}`)}catch{}R.add(e)}},N=e=>JSON.stringify([...new Set(e)].toSorted((t,s)=>t.localeCompare(s))),F=e=>e===void 0?null:e?1:0,V=(e,t,s={})=>{m(e);const o=s.captureRaw??!1,r=s.retention??E,h=t.outcome==="error"&&t.errorMessage!==void 0?I({functionPath:t.functionPath,message:t.errorMessage}).hash:void 0;g(e,`INSERT INTO "${d}"
|
|
21
|
+
(ts, function_path, shard_key, user_id, identity, args, outcome, error_message, error_fingerprint, trace_id, deployment_id, version_tag, duration_ms, tables_read, tables_written, cache_hit, subscriptions_rerun)
|
|
22
|
+
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`,t.ts,t.functionPath,t.shardKey??null,t.userId??null,t.identity===void 0?null:JSON.stringify(u(t.identity,o)),t.redactedArgs===void 0?null:JSON.stringify(u(t.redactedArgs,o)),t.outcome,t.errorMessage===void 0?null:u(t.errorMessage,o),h??null,t.traceId??null,t.deploymentId??null,t.versionTag??null,t.durationMs,N(t.tablesRead),N(t.tablesWritten),F(t.cacheHit),t.subscriptionsReRun??0),g(e,`DELETE FROM "${d}" WHERE seq <= (SELECT MAX(seq) - ? FROM "${d}")`,r)},Y=(e,t={})=>{const s=t.captureRaw??!1,o={args:e.redactedArgs===void 0?void 0:u(e.redactedArgs,s),cacheHit:e.cacheHit,deploymentId:e.deploymentId,durationMs:e.durationMs,error:e.errorMessage===void 0?void 0:u(e.errorMessage,s),function:e.functionPath,identity:e.identity===void 0?void 0:u(e.identity,s),outcome:e.outcome,shard:e.shardKey,source:O,tablesRead:e.tablesRead??[],tablesWritten:e.tablesWritten??[],traceId:e.traceId,ts:e.ts,type:"request",userId:e.userId,versionTag:e.versionTag},r=JSON.stringify(o);e.outcome==="error"?console.error(r):console.log(r)},$="log",j=e=>e.map(t=>{if(typeof t=="string")return t;try{return JSON.stringify(t)??String(t)}catch{return String(t)}}).join(" "),k=e=>{if(typeof e!="object"||e===null||Array.isArray(e))return!1;const t=Object.getPrototypeOf(e);return t===Object.prototype||t===null},B=(e,t)=>e.length===2&&typeof e[0]=="string"&&k(e[1])?{fields:v(e[1],t),message:e[0]}:{fields:v(void 0,t),message:j(e)},Q=(e,t={})=>{const s=t.captureRaw??!1,o={fields:e.fields===void 0?void 0:u(e.fields,s),function:e.functionPath,level:e.level,message:e.message,shard:e.shardKey,source:O,spanId:e.spanId,traceId:e.traceId,ts:e.ts,type:$,userId:e.userId};let r;try{r=JSON.stringify(o)}catch{r=JSON.stringify({...o,fields:void 0})}e.level==="error"||e.level==="fatal"?console.error(r):e.level==="warn"?console.warn(r):console.log(r)},J=(e,t)=>`lower(substr(${e}, 1, ${String([...t].length)})) = lower(?)`,y=(e,t,s)=>{s.functionPathPrefix!==void 0&&s.functionPathPrefix!==""&&(e.push(J("function_path",s.functionPathPrefix)),t.push(s.functionPathPrefix)),s.userId!==void 0&&s.userId!==""&&(e.push("user_id = ?"),t.push(s.userId)),s.shardKey!==void 0&&s.shardKey!==""&&(e.push("shard_key = ?"),t.push(s.shardKey))},L=e=>{try{const t=JSON.parse(e);return Array.isArray(t)?t.filter(s=>typeof s=="string"):[]}catch{return[]}},C=e=>{try{const t=JSON.parse(e);return t!==null&&typeof t=="object"?t:void 0}catch{return}},q=e=>{try{return JSON.parse(e)}catch{return}},w=(e,t={})=>{m(e);const s=Math.max(1,Math.min(t.limit??E,1e4)),o=["seq > ?"],r=[t.sinceSeq??0];if(y(o,r,t),t.outcome!==void 0&&(o.push("outcome = ?"),r.push(t.outcome)),t.tableTouched!==void 0&&t.tableTouched!==""){const i=JSON.stringify(t.tableTouched);o.push("(instr(lower(tables_read), lower(?)) > 0 OR instr(lower(tables_written), lower(?)) > 0)"),r.push(i,i)}r.push(s);const h=t.sinceSeq===void 0?"DESC":"ASC";return g(e,`SELECT seq, ts, function_path, shard_key, user_id, identity, args, outcome, error_message, trace_id, deployment_id, version_tag, duration_ms, tables_read, tables_written, cache_hit, subscriptions_rerun
|
|
23
|
+
FROM "${d}" WHERE ${o.join(" AND ")} ORDER BY seq ${h} LIMIT ?`,...r).toArray().map(i=>{const a={durationMs:i.duration_ms,functionPath:i.function_path,outcome:i.outcome==="error"?"error":"ok",seq:i.seq,subscriptionsReRun:i.subscriptions_rerun,tablesRead:L(i.tables_read),tablesWritten:L(i.tables_written),ts:i.ts};if(i.shard_key!==null&&(a.shardKey=i.shard_key),i.user_id!==null&&(a.userId=i.user_id),i.identity!==null){const l=C(i.identity);l!==void 0&&(a.identity=l)}if(i.args!==null){const l=q(i.args);l!==void 0&&(a.redactedArgs=l)}return i.error_message!==null&&(a.errorMessage=i.error_message),i.cache_hit!==null&&(a.cacheHit=i.cache_hit===1),i.trace_id!==null&&(a.traceId=i.trace_id),i.deployment_id!==null&&(a.deploymentId=i.deployment_id),i.version_tag!==null&&(a.versionTag=i.version_tag),a})},x=(e,t)=>{const s=X(e,[...t.keys()]);for(const o of t.values()){const r=s.get(o.hash);r!==void 0&&(o.stateUpdatedAt=r.updatedAt,r.assignee!==void 0&&(o.assignee=r.assignee),r.severity!==void 0&&(o.severity=r.severity),o.status=r.status==="resolved"&&o.lastSeen>r.updatedAt?"open":r.status)}},z=(e,t={})=>{m(e);const s=Math.max(1,Math.min(t.limit??E,1e4)),o=["outcome = 'error'"],r=[];y(o,r,t),r.push(s);const h=g(e,`SELECT function_path, error_message, error_fingerprint, ts
|
|
24
|
+
FROM "${d}" WHERE ${o.join(" AND ")} ORDER BY seq DESC LIMIT ?`,...r).toArray(),_=new Map,i=new Map;for(const n of h){const T=n.error_message??"",{culprit:b,hash:A,title:p}=I({functionPath:n.function_path,message:T}),f=n.error_fingerprint??A,c=_.get(f);if(c===void 0){_.set(f,{count:1,culprit:b,firstSeen:n.ts,hash:f,lastSeen:n.ts,sampleMessage:T,status:"open",title:p}),i.set(f,n.ts);continue}c.count+=1,c.firstSeen=Math.min(c.firstSeen,n.ts),c.lastSeen=Math.max(c.lastSeen,n.ts),n.ts>(i.get(f)??Number.NEGATIVE_INFINITY)&&(i.set(f,n.ts),c.sampleMessage=T,c.title=p)}x(e,_);const a=[..._.values()];return(t.status===void 0?a:a.filter(n=>n.status===t.status)).toSorted((n,T)=>T.lastSeen-n.lastSeen)};export{d as R,V as a,Y as b,m as c,w as d,Q as e,u as f,E as g,j as h,v as n,B as p,z as r};
|
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.70",
|
|
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.35",
|
|
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.63",
|
|
49
49
|
"@visulima/redact": "5.0.0"
|
|
50
50
|
},
|
|
51
51
|
"engines": {
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
import{fingerprintError as b}from"@lunora/fingerprint";import{redact as M,standardRules as U}from"@visulima/redact";import{readIssueStates as P}from"./ISSUE_SEVERITIES-gLC4VEPQ.mjs";import{r as h}from"./run-sql-0aPgJkIw.mjs";const D=e=>{if(typeof e=="string")return e;try{return JSON.stringify(e)??String(e)}catch{return String(e)}},S=e=>typeof e=="boolean"||typeof e=="number"||typeof e=="string"?e:D(e),R=(e,t)=>{if(e===void 0&&t===void 0)return;const s={};if(t!==void 0)for(const[o,r]of Object.entries(t))s[o]=S(r);if(e!==void 0)for(const[o,r]of Object.entries(e))s[o]=S(r);return Object.keys(s).length===0?void 0:s},d="__lunora_reqlog__",T=1e3,v="lunora",X=["error_fingerprint TEXT","trace_id TEXT"],u=(e,t=!1)=>t||e===null||e===void 0?e:M(e,U),N=new WeakSet,m=e=>{if(!N.has(e)){h(e,`CREATE TABLE IF NOT EXISTS "${d}" (
|
|
2
|
-
seq INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
3
|
-
ts REAL NOT NULL,
|
|
4
|
-
function_path TEXT NOT NULL,
|
|
5
|
-
shard_key TEXT,
|
|
6
|
-
user_id TEXT,
|
|
7
|
-
identity TEXT,
|
|
8
|
-
args TEXT,
|
|
9
|
-
outcome TEXT NOT NULL,
|
|
10
|
-
error_message TEXT,
|
|
11
|
-
error_fingerprint TEXT,
|
|
12
|
-
trace_id TEXT,
|
|
13
|
-
duration_ms REAL NOT NULL,
|
|
14
|
-
tables_read TEXT NOT NULL DEFAULT '[]',
|
|
15
|
-
tables_written TEXT NOT NULL DEFAULT '[]',
|
|
16
|
-
cache_hit INTEGER,
|
|
17
|
-
subscriptions_rerun INTEGER NOT NULL DEFAULT 0
|
|
18
|
-
)`);for(const t of X)try{h(e,`ALTER TABLE "${d}" ADD COLUMN ${t}`)}catch{}N.add(e)}},L=e=>JSON.stringify([...new Set(e)].toSorted((t,s)=>t.localeCompare(s))),F=e=>e===void 0?null:e?1:0,w=(e,t,s={})=>{m(e);const o=s.captureRaw??!1,r=s.retention??T,g=t.outcome==="error"&&t.errorMessage!==void 0?b({functionPath:t.functionPath,message:t.errorMessage}).hash:void 0;h(e,`INSERT INTO "${d}"
|
|
19
|
-
(ts, function_path, shard_key, user_id, identity, args, outcome, error_message, error_fingerprint, trace_id, duration_ms, tables_read, tables_written, cache_hit, subscriptions_rerun)
|
|
20
|
-
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`,t.ts,t.functionPath,t.shardKey??null,t.userId??null,t.identity===void 0?null:JSON.stringify(u(t.identity,o)),t.redactedArgs===void 0?null:JSON.stringify(u(t.redactedArgs,o)),t.outcome,t.errorMessage===void 0?null:u(t.errorMessage,o),g??null,t.traceId??null,t.durationMs,L(t.tablesRead),L(t.tablesWritten),F(t.cacheHit),t.subscriptionsReRun??0),h(e,`DELETE FROM "${d}" WHERE seq <= (SELECT MAX(seq) - ? FROM "${d}")`,r)},V=(e,t={})=>{const s=t.captureRaw??!1,o={args:e.redactedArgs===void 0?void 0:u(e.redactedArgs,s),cacheHit:e.cacheHit,durationMs:e.durationMs,error:e.errorMessage===void 0?void 0:u(e.errorMessage,s),function:e.functionPath,identity:e.identity===void 0?void 0:u(e.identity,s),outcome:e.outcome,shard:e.shardKey,source:v,tablesRead:e.tablesRead??[],tablesWritten:e.tablesWritten??[],traceId:e.traceId,ts:e.ts,type:"request",userId:e.userId},r=JSON.stringify(o);e.outcome==="error"?console.error(r):console.log(r)},$="log",j=e=>e.map(t=>{if(typeof t=="string")return t;try{return JSON.stringify(t)??String(t)}catch{return String(t)}}).join(" "),k=e=>{if(typeof e!="object"||e===null||Array.isArray(e))return!1;const t=Object.getPrototypeOf(e);return t===Object.prototype||t===null},Y=(e,t)=>e.length===2&&typeof e[0]=="string"&&k(e[1])?{fields:R(e[1],t),message:e[0]}:{fields:R(void 0,t),message:j(e)},B=(e,t={})=>{const s=t.captureRaw??!1,o={fields:e.fields===void 0?void 0:u(e.fields,s),function:e.functionPath,level:e.level,message:e.message,shard:e.shardKey,source:v,spanId:e.spanId,traceId:e.traceId,ts:e.ts,type:$,userId:e.userId};let r;try{r=JSON.stringify(o)}catch{r=JSON.stringify({...o,fields:void 0})}e.level==="error"||e.level==="fatal"?console.error(r):e.level==="warn"?console.warn(r):console.log(r)},J=(e,t)=>`lower(substr(${e}, 1, ${String([...t].length)})) = lower(?)`,I=(e,t,s)=>{s.functionPathPrefix!==void 0&&s.functionPathPrefix!==""&&(e.push(J("function_path",s.functionPathPrefix)),t.push(s.functionPathPrefix)),s.userId!==void 0&&s.userId!==""&&(e.push("user_id = ?"),t.push(s.userId)),s.shardKey!==void 0&&s.shardKey!==""&&(e.push("shard_key = ?"),t.push(s.shardKey))},O=e=>{try{const t=JSON.parse(e);return Array.isArray(t)?t.filter(s=>typeof s=="string"):[]}catch{return[]}},C=e=>{try{const t=JSON.parse(e);return t!==null&&typeof t=="object"?t:void 0}catch{return}},q=e=>{try{return JSON.parse(e)}catch{return}},Q=(e,t={})=>{m(e);const s=Math.max(1,Math.min(t.limit??T,1e4)),o=["seq > ?"],r=[t.sinceSeq??0];if(I(o,r,t),t.outcome!==void 0&&(o.push("outcome = ?"),r.push(t.outcome)),t.tableTouched!==void 0&&t.tableTouched!==""){const i=JSON.stringify(t.tableTouched);o.push("(instr(lower(tables_read), lower(?)) > 0 OR instr(lower(tables_written), lower(?)) > 0)"),r.push(i,i)}r.push(s);const g=t.sinceSeq===void 0?"DESC":"ASC";return h(e,`SELECT seq, ts, function_path, shard_key, user_id, identity, args, outcome, error_message, trace_id, duration_ms, tables_read, tables_written, cache_hit, subscriptions_rerun
|
|
21
|
-
FROM "${d}" WHERE ${o.join(" AND ")} ORDER BY seq ${g} LIMIT ?`,...r).toArray().map(i=>{const a={durationMs:i.duration_ms,functionPath:i.function_path,outcome:i.outcome==="error"?"error":"ok",seq:i.seq,subscriptionsReRun:i.subscriptions_rerun,tablesRead:O(i.tables_read),tablesWritten:O(i.tables_written),ts:i.ts};if(i.shard_key!==null&&(a.shardKey=i.shard_key),i.user_id!==null&&(a.userId=i.user_id),i.identity!==null){const l=C(i.identity);l!==void 0&&(a.identity=l)}if(i.args!==null){const l=q(i.args);l!==void 0&&(a.redactedArgs=l)}return i.error_message!==null&&(a.errorMessage=i.error_message),i.cache_hit!==null&&(a.cacheHit=i.cache_hit===1),i.trace_id!==null&&(a.traceId=i.trace_id),a})},x=(e,t)=>{const s=P(e,[...t.keys()]);for(const o of t.values()){const r=s.get(o.hash);r!==void 0&&(o.stateUpdatedAt=r.updatedAt,r.assignee!==void 0&&(o.assignee=r.assignee),r.severity!==void 0&&(o.severity=r.severity),o.status=r.status==="resolved"&&o.lastSeen>r.updatedAt?"open":r.status)}},z=(e,t={})=>{m(e);const s=Math.max(1,Math.min(t.limit??T,1e4)),o=["outcome = 'error'"],r=[];I(o,r,t),r.push(s);const g=h(e,`SELECT function_path, error_message, error_fingerprint, ts
|
|
22
|
-
FROM "${d}" WHERE ${o.join(" AND ")} ORDER BY seq DESC LIMIT ?`,...r).toArray(),E=new Map,i=new Map;for(const n of g){const _=n.error_message??"",{culprit:A,hash:y,title:p}=b({functionPath:n.function_path,message:_}),f=n.error_fingerprint??y,c=E.get(f);if(c===void 0){E.set(f,{count:1,culprit:A,firstSeen:n.ts,hash:f,lastSeen:n.ts,sampleMessage:_,status:"open",title:p}),i.set(f,n.ts);continue}c.count+=1,c.firstSeen=Math.min(c.firstSeen,n.ts),c.lastSeen=Math.max(c.lastSeen,n.ts),n.ts>(i.get(f)??Number.NEGATIVE_INFINITY)&&(i.set(f,n.ts),c.sampleMessage=_,c.title=p)}x(e,E);const a=[...E.values()];return(t.status===void 0?a:a.filter(n=>n.status===t.status)).toSorted((n,_)=>_.lastSeen-n.lastSeen)};export{d as R,w as a,V as b,m as c,Q as d,B as e,u as f,T as g,j as h,R as n,Y as p,z as r};
|