@lunora/observability 1.0.0-alpha.48 → 1.0.0-alpha.49
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
|
@@ -625,6 +625,14 @@ declare const createTracer: (deps: TracerDeps) => ContextTracer;
|
|
|
625
625
|
interface TracedFetchDeps {
|
|
626
626
|
/** The trace the CLIENT spans belong to. */
|
|
627
627
|
anchor: TraceAnchor;
|
|
628
|
+
/**
|
|
629
|
+
* Whether to record a failed fetch's error message verbatim rather than
|
|
630
|
+
* redacted. Same dev-only escape hatch as {@link TracerDeps.captureRaw}, and
|
|
631
|
+
* the same reason: a `fetch` TypeError embeds the request URL, so a key in a
|
|
632
|
+
* query string would otherwise reach the collector in the clear on the very
|
|
633
|
+
* span whose `url.full` is scrubbed by `redactUrl`.
|
|
634
|
+
*/
|
|
635
|
+
captureRaw?: boolean;
|
|
628
636
|
/** Function path the spans are attributed to. */
|
|
629
637
|
functionPath: string;
|
|
630
638
|
/**
|
package/dist/index.d.ts
CHANGED
|
@@ -625,6 +625,14 @@ declare const createTracer: (deps: TracerDeps) => ContextTracer;
|
|
|
625
625
|
interface TracedFetchDeps {
|
|
626
626
|
/** The trace the CLIENT spans belong to. */
|
|
627
627
|
anchor: TraceAnchor;
|
|
628
|
+
/**
|
|
629
|
+
* Whether to record a failed fetch's error message verbatim rather than
|
|
630
|
+
* redacted. Same dev-only escape hatch as {@link TracerDeps.captureRaw}, and
|
|
631
|
+
* the same reason: a `fetch` TypeError embeds the request URL, so a key in a
|
|
632
|
+
* query string would otherwise reach the collector in the clear on the very
|
|
633
|
+
* span whose `url.full` is scrubbed by `redactUrl`.
|
|
634
|
+
*/
|
|
635
|
+
captureRaw?: boolean;
|
|
628
636
|
/** Function path the spans are attributed to. */
|
|
629
637
|
functionPath: string;
|
|
630
638
|
/**
|
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-B366_-Qf.mjs";import{createDatabaseTally as A,formatTally as C,instrumentDatabase as N}from"./packem_shared/createDatabaseTally-DCMuBKoP.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-bIvCelI-.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-D37H7MII.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-COB2xhns.mjs";import{MIN_ADMIN_TOKEN_LENGTH as ne,MIN_AUTH_SECRET_LENGTH as Me,buildSecurityAudit as ue}from"./packem_shared/MIN_ADMIN_TOKEN_LENGTH-CidkqOQ1.mjs";import{SpanBuffer as Ce,foldTraces as Ne}from"./packem_shared/SpanBuffer-zjqCAuGp.mjs";import{findDanglingReferences as fe}from"./packem_shared/findDanglingReferences-Dxl42LBT.mjs";import{r as de}from"./packem_shared/trace-context-DfJZi_g2.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};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{f as E,n as y}from"./request-log-COB2xhns.mjs";import{L as b,o as O,b as H,t as _}from"./trace-context-DfJZi_g2.mjs";const x=/[\w.-]/u,K=t=>{let e="";for(const r of t)e+=x.test(r)?r:"_";return e},L=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=K(t.name),r={[`gen_ai.evaluation.${e}.score`]:t.score};return t.label!==void 0&&(r[`gen_ai.evaluation.${e}.label`]=t.label),r},j=t=>{const e=Object.keys(t);return e.length>0&&e.every(r=>r==="attributes"||r==="kind"||r==="links")},z=128,U=128,D=128,P=(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>=D||(n&&(r+=1),t[o]=s)}},F=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}},C=(t,e)=>{try{return t(new URL(e))}catch{return!1}},X=t=>t===void 0?{}:j(t)?t:{attributes:t},B=(t,e)=>{if(t.isTraced){t.setAttribute(b.functionPath,e.functionPath),t.setAttribute(b.ok,e.ok),t.setAttribute(b.durationMs,e.durationMs),e.shardKey!==void 0&&t.setAttribute(b.shardKey,e.shardKey),e.userId!==void 0&&t.setAttribute(b.userId,e.userId),e.error!==void 0&&(t.setAttribute(b.errorType,e.error.type),t.setAttribute(b.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)}},V=(t,e=!1)=>{const r={attributes:{},events:[],links:[]},o={spanContext:()=>t,addEvent:(s,n)=>{if(r.events.length>=z)return;const a=y(n);r.events.push({...a===void 0?{}:{attributes:a},name:s,ts:Date.now()})},addLink:s=>{if(r.links.length>=U)return;const n=y(s.attributes);r.links.push({...n===void 0?{}:{attributes:n},spanId:s.spanId,traceId:s.traceId})},recordEvaluation:s=>{P(r.attributes,y(L(s)))},recordException:s=>{const n=s instanceof Error?s.message:String(s);o.addEvent("exception",{"exception.message":E(n,e),...e&&s instanceof Error&&typeof s.stack=="string"?{"exception.stacktrace":s.stack}:{},"exception.type":_(s)})},setAttribute:(s,n)=>{P(r.attributes,y({[s]:n}))},setAttributes:s=>{P(r.attributes,y(s))}};return{collected:r,handle:o}},Q=t=>{const{anchor:e,captureRaw:r=!1,fuseHostSpans:o,functionPath:s,record:n,resolveHostTracing:a,shardKey:c,userId:g}=t,u=v=>async(m,A,d)=>{const S=O(8),h=Date.now(),l=X(d),i=y(l.attributes),{collected:I,handle:$}=V({spanId:S,traceId:e.traceId},r),R=async k=>{let f=!0,w;try{return await A(u(S),$)}catch(p){f=!1;const T=p instanceof Error?p.message:String(p);throw w={message:E(T,r),type:_(p)},p}finally{const p=Date.now()-h,T=g(),M={...i,...I.attributes},N=[...l.links??[],...I.links];try{n({...Object.keys(M).length===0?{}:{attributes:M},durationMs:p,...I.events.length===0?{}:{events:I.events},...w===void 0?{}:{error:w},functionPath:s,...l.kind===void 0||l.kind==="internal"?{}:{kind:l.kind},...N.length===0?{}:{links:N},name:m,ok:f,parentSpanId:v,shardKey:c,spanId:S,startTs:h,traceId:e.traceId,userId:T})}catch{}if(k!==void 0)try{B(k,{attributes:M,durationMs:p,error:w,functionPath:s,ok:f,shardKey:c,userId:T})}catch{}}};if(o===!0&&a!==void 0){let k=!1;try{const f=await a();if(f!==void 0&&typeof f.enterSpan=="function")return await f.enterSpan(m,w=>(k=!0,R(w)))}catch(f){if(k)throw f}}return await R()};return u(e.rootSpanId)},W=(t,e)=>{const{anchor:r,captureRaw:o=!1,functionPath:s,propagate:n=!0,record:a,shardKey:c,userId:g}=t;return async(u,v)=>{const m=O(8),A=Date.now(),d=new Request(u,v);(typeof n=="function"?C(n,d.url):n)&&d.headers.set("traceparent",H(r.traceId,m,r.sampled??!0));let h,l;try{const i=await e(d);return l=i.status,i.ok||(h={message:`HTTP ${String(i.status)}`,type:`HTTP_${String(i.status)}`}),i}catch(i){const I=i instanceof Error?i.message:String(i);throw h={message:E(I,o),type:_(i)},i}finally{try{a({attributes:{"http.request.method":d.method,...l===void 0?{}:{"http.response.status_code":l},"url.full":F(d.url)},durationMs:Date.now()-A,...h===void 0?{}:{error:h},functionPath:s,kind:"client",name:`${d.method} ${q(d.url)}`,ok:h===void 0,parentSpanId:r.rootSpanId,shardKey:c,spanId:m,startTs:A,traceId:r.traceId,userId:g()})}catch{}}}},Y=t=>{const{functionPath:e,record:r,shardKey:o}=t,s=(n,a,c,g)=>{if(!Number.isFinite(c))return;const u=y(g);try{r({...u===void 0?{}:{attributes:u},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)}}},Z=t=>{const{anchor:e,captureRaw:r=!1,collected:o,durationMs:s,failure:n,functionPath:a,shardKey:c,startTs:g,userId:u}=t,v=o?.attributes??{};return{...Object.keys(v).length===0?{}:{attributes:v},dispatch:!0,durationMs:s,...o===void 0||o.events.length===0?{}:{events:o.events},...n===void 0?{}:{error:{message:E(n.thrown instanceof Error?n.thrown.message:String(n.thrown),r),type:_(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:g,traceId:e.traceId,userId:u}};export{B as applyHostSpanAttributes,Y as createMetrics,V as createSpanCollector,W as createTracedFetch,Q as createTracer,Z as dispatchRootSpan};
|
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.49",
|
|
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.26",
|
|
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.48",
|
|
49
49
|
"@visulima/redact": "4.0.0"
|
|
50
50
|
},
|
|
51
51
|
"engines": {
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{f as E,n as b}from"./request-log-COB2xhns.mjs";import{L as g,o as R,b as H,t as A}from"./trace-context-DfJZi_g2.mjs";const N=/[\w.-]/u,x=t=>{let e="";for(const r of t)e+=N.test(r)?r:"_";return e},K=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=x(t.name),r={[`gen_ai.evaluation.${e}.score`]:t.score};return t.label!==void 0&&(r[`gen_ai.evaluation.${e}.label`]=t.label),r},L=t=>{const e=Object.keys(t);return e.length>0&&e.every(r=>r==="attributes"||r==="kind"||r==="links")},j=128,z=128,D=t=>{try{const e=new URL(t);return`${e.protocol}//${e.host}${e.pathname}`}catch{return t}},F=t=>{try{return new URL(t).host}catch{return t}},U=(t,e)=>{try{return t(new URL(e))}catch{return!1}},q=t=>t===void 0?{}:L(t)?t:{attributes:t},C=(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)}},X=(t,e=!1)=>{const r={attributes:{},events:[],links:[]},o={spanContext:()=>t,addEvent:(s,n)=>{if(r.events.length>=j)return;const a=b(n);r.events.push({...a===void 0?{}:{attributes:a},name:s,ts:Date.now()})},addLink:s=>{if(r.links.length>=z)return;const n=b(s.attributes);r.links.push({...n===void 0?{}:{attributes:n},spanId:s.spanId,traceId:s.traceId})},recordEvaluation:s=>{Object.assign(r.attributes,b(K(s)))},recordException:s=>{const n=s instanceof Error?s.message:String(s);o.addEvent("exception",{"exception.message":E(n,e),...e&&s instanceof Error&&typeof s.stack=="string"?{"exception.stacktrace":s.stack}:{},"exception.type":A(s)})},setAttribute:(s,n)=>{Object.assign(r.attributes,b({[s]:n}))},setAttributes:s=>{Object.assign(r.attributes,b(s))}};return{collected:r,handle:o}},G=t=>{const{anchor:e,captureRaw:r=!1,fuseHostSpans:o,functionPath:s,record:n,resolveHostTracing:a,shardKey:i,userId:f}=t,u=p=>async(I,d,_)=>{const l=R(8),y=Date.now(),c=q(_),O=b(c.attributes),{collected:k,handle:$}=X({spanId:l,traceId:e.traceId},r),P=async v=>{let m=!0,w;try{return await d(u(l),$)}catch(h){m=!1;const S=h instanceof Error?h.message:String(h);throw w={message:E(S,r),type:A(h)},h}finally{const h=Date.now()-y,S=f(),T={...O,...k.attributes},M=[...c.links??[],...k.links];try{n({...Object.keys(T).length===0?{}:{attributes:T},durationMs:h,...k.events.length===0?{}:{events:k.events},...w===void 0?{}:{error:w},functionPath:s,...c.kind===void 0||c.kind==="internal"?{}:{kind:c.kind},...M.length===0?{}:{links:M},name:I,ok:m,parentSpanId:p,shardKey:i,spanId:l,startTs:y,traceId:e.traceId,userId:S})}catch{}if(v!==void 0)try{C(v,{attributes:T,durationMs:h,error:w,functionPath:s,ok:m,shardKey:i,userId:S})}catch{}}};if(o===!0&&a!==void 0){const v=await a();if(v!==void 0&&typeof v.enterSpan=="function")return await v.enterSpan(I,m=>P(m))}return await P()};return u(e.rootSpanId)},J=(t,e)=>{const{anchor:r,functionPath:o,propagate:s=!0,record:n,shardKey:a,userId:i}=t;return async(f,u)=>{const p=R(8),I=Date.now(),d=new Request(f,u);(typeof s=="function"?U(s,d.url):s)&&d.headers.set("traceparent",H(r.traceId,p,r.sampled??!0));let l,y;try{const c=await e(d);return y=c.status,c.ok||(l={message:`HTTP ${String(c.status)}`,type:`HTTP_${String(c.status)}`}),c}catch(c){throw l={message:c instanceof Error?c.message:String(c),type:A(c)},c}finally{try{n({attributes:{"http.request.method":d.method,...y===void 0?{}:{"http.response.status_code":y},"url.full":D(d.url)},durationMs:Date.now()-I,...l===void 0?{}:{error:l},functionPath:o,kind:"client",name:`${d.method} ${F(d.url)}`,ok:l===void 0,parentSpanId:r.rootSpanId,shardKey:a,spanId:p,startTs:I,traceId:r.traceId,userId:i()})}catch{}}}},Q=t=>{const{functionPath:e,record:r,shardKey:o}=t,s=(n,a,i,f)=>{if(!Number.isFinite(i))return;const u=b(f);try{r({...u===void 0?{}:{attributes:u},functionPath:e,kind:n,name:a,shardKey:o,ts:Date.now(),value:i})}catch{}};return{count:(n,a=1,i)=>{s("counter",n,a,i)},gauge:(n,a,i)=>{s("gauge",n,a,i)},record:(n,a,i)=>{s("histogram",n,a,i)}}},W=t=>{const{anchor:e,captureRaw:r=!1,collected:o,durationMs:s,failure:n,functionPath:a,shardKey:i,startTs:f,userId:u}=t,p=o?.attributes??{};return{...Object.keys(p).length===0?{}:{attributes:p},dispatch:!0,durationMs:s,...o===void 0||o.events.length===0?{}:{events:o.events},...n===void 0?{}:{error:{message:E(n.thrown instanceof Error?n.thrown.message:String(n.thrown),r),type:A(n.thrown)}},functionPath:a,...o===void 0||o.links.length===0?{}:{links:o.links},name:a,ok:n===void 0,parentSpanId:"",shardKey:i,spanId:e.rootSpanId,startTs:f,traceId:e.traceId,userId:u}};export{C as applyHostSpanAttributes,Q as createMetrics,X as createSpanCollector,J as createTracedFetch,G as createTracer,W as dispatchRootSpan};
|