@lunora/observability 1.0.0-alpha.8 → 1.0.0-alpha.81

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.
Files changed (43) hide show
  1. package/README.md +2 -4
  2. package/dist/index.d.mts +239 -49
  3. package/dist/index.d.ts +239 -49
  4. package/dist/index.mjs +1 -1
  5. package/dist/packem_shared/AUTH_METRICS_BUCKETS_TABLE-CeplWoRm.mjs +22 -0
  6. package/dist/packem_shared/DEFAULT_EXPLAIN_ISSUE_MODEL-BGGX6k5D.mjs +3 -0
  7. package/dist/packem_shared/FUNCTION_METRICS_BUCKETS_TABLE-ChlIe0vF.mjs +56 -0
  8. package/dist/packem_shared/ISSUE_SEVERITIES-gLC4VEPQ.mjs +15 -0
  9. package/dist/packem_shared/LogBuffer-BmD4CfV0.mjs +1 -0
  10. package/dist/packem_shared/MIN_ADMIN_TOKEN_LENGTH-DSOQ6rno.mjs +1 -0
  11. package/dist/packem_shared/MetricBuffer-DnOJJVHH.mjs +1 -0
  12. package/dist/packem_shared/REQUEST_LOG_TABLE--5PBTOVZ.mjs +1 -0
  13. package/dist/packem_shared/SpanBuffer-DnYOc8uk.mjs +1 -0
  14. package/dist/packem_shared/createDatabaseTally-n3nCJ5OW.mjs +1 -0
  15. package/dist/packem_shared/createMetrics-C1-k5PCU.mjs +1 -0
  16. package/dist/packem_shared/findDanglingReferences-BNgg0jD_.mjs +1 -0
  17. package/dist/packem_shared/metric-buffer-Bx0XbypU.mjs +1 -0
  18. package/dist/packem_shared/prune-marker-B4An9Nuj.mjs +1 -0
  19. package/dist/packem_shared/readMetricHistory-TKfnwFNv.mjs +31 -0
  20. package/dist/packem_shared/readQueryInsights-B98JliCi.mjs +32 -0
  21. package/dist/packem_shared/request-log-C2scoFaB.mjs +24 -0
  22. package/dist/packem_shared/resolveTraceAnchor-COLuCGmj.mjs +1 -0
  23. package/dist/packem_shared/run-sql-0aPgJkIw.mjs +1 -0
  24. package/dist/packem_shared/trace-context-DgWo6N3y.mjs +1 -0
  25. package/package.json +5 -5
  26. package/dist/packem_shared/AUTH_METRICS_BUCKETS_TABLE-C2V-DiGu.mjs +0 -22
  27. package/dist/packem_shared/DEFAULT_EXPLAIN_ISSUE_MODEL-xF11R4vX.mjs +0 -3
  28. package/dist/packem_shared/FUNCTION_METRICS_BUCKETS_TABLE-BB8kcFBe.mjs +0 -56
  29. package/dist/packem_shared/ISSUE_SEVERITIES-Js6lGUG5.mjs +0 -15
  30. package/dist/packem_shared/LogBuffer-bIvCelI-.mjs +0 -1
  31. package/dist/packem_shared/MIN_ADMIN_TOKEN_LENGTH-T-zuwRVR.mjs +0 -1
  32. package/dist/packem_shared/MetricBuffer-CYrLuEsz.mjs +0 -1
  33. package/dist/packem_shared/REQUEST_LOG_TABLE-BvpprPd_.mjs +0 -1
  34. package/dist/packem_shared/SpanBuffer-BR6Ff0M-.mjs +0 -1
  35. package/dist/packem_shared/createDatabaseTally-DBs7wDeF.mjs +0 -1
  36. package/dist/packem_shared/createMetrics-BXNmqy0o.mjs +0 -1
  37. package/dist/packem_shared/findDanglingReferences-D-x9LvY0.mjs +0 -1
  38. package/dist/packem_shared/metric-buffer-CdgXal7w.mjs +0 -1
  39. package/dist/packem_shared/readMetricHistory-CVcUgQEL.mjs +0 -31
  40. package/dist/packem_shared/readQueryInsights-DN07YcQy.mjs +0 -32
  41. package/dist/packem_shared/request-log-BwFic6VV.mjs +0 -21
  42. package/dist/packem_shared/resolveTraceAnchor-IAN8riI0.mjs +0 -1
  43. package/dist/packem_shared/trace-context-DrdF960P.mjs +0 -1
@@ -1,21 +0,0 @@
1
- import{fingerprintError as I}from"@lunora/fingerprint";import{redact as L,standardRules as R}from"@visulima/redact";import{readIssueStates as M}from"./ISSUE_SEVERITIES-Js6lGUG5.mjs";const P=e=>{if(typeof e=="string")return e;try{return JSON.stringify(e)??String(e)}catch{return String(e)}},m=e=>typeof e=="boolean"||typeof e=="number"||typeof e=="string"?e:P(e),v=(e,r)=>{if(e===void 0&&r===void 0)return;const o={};if(r!==void 0)for(const[t,s]of Object.entries(r))o[t]=m(s);if(e!==void 0)for(const[t,s]of Object.entries(e))o[t]=m(s);return Object.keys(o).length===0?void 0:o},d="__lunora_reqlog__",E=1e3,b="lunora",h=(e,r,...o)=>e.exec.call(e,r,...o),c=(e,r=!1)=>r||e===null||e===void 0?e:L(e,R),y=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
- duration_ms REAL NOT NULL,
13
- tables_read TEXT NOT NULL DEFAULT '[]',
14
- tables_written TEXT NOT NULL DEFAULT '[]',
15
- cache_hit INTEGER,
16
- subscriptions_rerun INTEGER NOT NULL DEFAULT 0
17
- )`);try{h(e,`ALTER TABLE "${d}" ADD COLUMN error_fingerprint TEXT`)}catch{}},S=e=>JSON.stringify([...new Set(e)].toSorted((r,o)=>r.localeCompare(o))),w=e=>e===void 0?null:e?1:0,x=(e,r,o={})=>{y(e);const t=o.captureRaw??!1,s=o.retention??E,i=r.outcome==="error"&&r.errorMessage!==void 0?I({functionPath:r.functionPath,message:r.errorMessage}).hash:void 0;h(e,`INSERT INTO "${d}"
18
- (ts, function_path, shard_key, user_id, identity, args, outcome, error_message, error_fingerprint, duration_ms, tables_read, tables_written, cache_hit, subscriptions_rerun)
19
- VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`,r.ts,r.functionPath,r.shardKey??null,r.userId??null,r.identity===void 0?null:JSON.stringify(c(r.identity,t)),r.redactedArgs===void 0?null:JSON.stringify(c(r.redactedArgs,t)),r.outcome,r.errorMessage===void 0?null:c(r.errorMessage,t),i??null,r.durationMs,S(r.tablesRead),S(r.tablesWritten),w(r.cacheHit),r.subscriptionsReRun??0),h(e,`DELETE FROM "${d}" WHERE seq <= (SELECT MAX(seq) - ? FROM "${d}")`,s)},D=(e,r={})=>{const o=r.captureRaw??!1,t={args:e.redactedArgs===void 0?void 0:c(e.redactedArgs,o),cacheHit:e.cacheHit,durationMs:e.durationMs,error:e.errorMessage===void 0?void 0:c(e.errorMessage,o),function:e.functionPath,identity:e.identity===void 0?void 0:c(e.identity,o),outcome:e.outcome,shard:e.shardKey,source:b,tablesRead:e.tablesRead??[],tablesWritten:e.tablesWritten??[],ts:e.ts,type:"request",userId:e.userId},s=JSON.stringify(t);e.outcome==="error"?console.error(s):console.log(s)},K="log",U=e=>e.map(r=>{if(typeof r=="string")return r;try{return JSON.stringify(r)??String(r)}catch{return String(r)}}).join(" "),C=e=>{if(typeof e!="object"||e===null||Array.isArray(e))return!1;const r=Object.getPrototypeOf(e);return r===Object.prototype||r===null},J=(e,r)=>e.length===2&&typeof e[0]=="string"&&C(e[1])?{fields:v(e[1],r),message:e[0]}:{fields:v(void 0,r),message:U(e)},k=(e,r={})=>{const o=r.captureRaw??!1,t={fields:e.fields===void 0?void 0:c(e.fields,o),function:e.functionPath,level:e.level,message:e.message,shard:e.shardKey,source:b,spanId:e.spanId,traceId:e.traceId,ts:e.ts,type:K,userId:e.userId};let s;try{s=JSON.stringify(t)}catch{s=JSON.stringify({...t,fields:void 0})}e.level==="error"||e.level==="fatal"?console.error(s):e.level==="warn"?console.warn(s):console.log(s)},g=e=>e.replaceAll(/[\\%_]/g,r=>`\\${r}`),N=e=>{try{const r=JSON.parse(e);return Array.isArray(r)?r.filter(o=>typeof o=="string"):[]}catch{return[]}},j=(e,r={})=>{y(e);const o=Math.max(1,Math.min(r.limit??E,1e4)),t=["seq > ?"],s=[r.sinceSeq??0];if(r.functionPathPrefix!==void 0&&r.functionPathPrefix!==""&&(t.push(String.raw`function_path LIKE ? ESCAPE '\'`),s.push(`${g(r.functionPathPrefix)}%`)),r.userId!==void 0&&r.userId!==""&&(t.push("user_id = ?"),s.push(r.userId)),r.shardKey!==void 0&&r.shardKey!==""&&(t.push("shard_key = ?"),s.push(r.shardKey)),r.outcome!==void 0&&(t.push("outcome = ?"),s.push(r.outcome)),r.tableTouched!==void 0&&r.tableTouched!==""){const i=`%${g(JSON.stringify(r.tableTouched))}%`;t.push(String.raw`(tables_read LIKE ? ESCAPE '\' OR tables_written LIKE ? ESCAPE '\')`),s.push(i,i)}return s.push(o),h(e,`SELECT seq, ts, function_path, shard_key, user_id, identity, args, outcome, error_message, duration_ms, tables_read, tables_written, cache_hit, subscriptions_rerun
20
- FROM "${d}" WHERE ${t.join(" AND ")} ORDER BY seq DESC LIMIT ?`,...s).toArray().map(i=>{const n={durationMs:i.duration_ms,functionPath:i.function_path,outcome:i.outcome==="error"?"error":"ok",seq:i.seq,subscriptionsReRun:i.subscriptions_rerun,tablesRead:N(i.tables_read),tablesWritten:N(i.tables_written),ts:i.ts};return i.shard_key!==null&&(n.shardKey=i.shard_key),i.user_id!==null&&(n.userId=i.user_id),i.identity!==null&&(n.identity=JSON.parse(i.identity)),i.args!==null&&(n.redactedArgs=JSON.parse(i.args)),i.error_message!==null&&(n.errorMessage=i.error_message),i.cache_hit!==null&&(n.cacheHit=i.cache_hit===1),n})},q=(e,r)=>{const o=M(e,[...r.keys()]);for(const t of r.values()){const s=o.get(t.hash);s!==void 0&&(t.stateUpdatedAt=s.updatedAt,s.assignee!==void 0&&(t.assignee=s.assignee),s.severity!==void 0&&(t.severity=s.severity),t.status=s.status==="resolved"&&t.lastSeen>s.updatedAt?"open":s.status)}},W=(e,r={})=>{y(e);const o=Math.max(1,Math.min(r.limit??E,1e4)),t=["outcome = 'error'"],s=[];r.functionPathPrefix!==void 0&&r.functionPathPrefix!==""&&(t.push(String.raw`function_path LIKE ? ESCAPE '\'`),s.push(`${g(r.functionPathPrefix)}%`)),r.userId!==void 0&&r.userId!==""&&(t.push("user_id = ?"),s.push(r.userId)),r.shardKey!==void 0&&r.shardKey!==""&&(t.push("shard_key = ?"),s.push(r.shardKey)),s.push(o);const i=h(e,`SELECT function_path, error_message, error_fingerprint, ts
21
- FROM "${d}" WHERE ${t.join(" AND ")} ORDER BY seq DESC LIMIT ?`,...s).toArray(),n=new Map,p=new Map;for(const a of i){const f=a.error_message??"",{culprit:O,hash:A,title:T}=I({functionPath:a.function_path,message:f}),l=a.error_fingerprint??A,u=n.get(l);if(u===void 0){n.set(l,{count:1,culprit:O,firstSeen:a.ts,hash:l,lastSeen:a.ts,sampleMessage:f,status:"open",title:T}),p.set(l,a.ts);continue}u.count+=1,u.firstSeen=Math.min(u.firstSeen,a.ts),u.lastSeen=Math.max(u.lastSeen,a.ts),a.ts>(p.get(l)??Number.NEGATIVE_INFINITY)&&(p.set(l,a.ts),u.sampleMessage=f,u.title=T)}q(e,n);const _=[...n.values()];return(r.status===void 0?_:_.filter(a=>a.status===r.status)).toSorted((a,f)=>f.lastSeen-a.lastSeen)};export{J as C,E,k as K,j as U,W,c,d,x as k,y as m,v as n,D as w,U as y};
@@ -1 +0,0 @@
1
- import"@lunora/errors";import{r as t,t as a}from"./trace-context-DrdF960P.mjs";export{t as resolveTraceAnchor,a as toErrorType};
@@ -1 +0,0 @@
1
- import{isLunoraError as u}from"@lunora/errors";const d=r=>{const t=new Uint8Array(r);crypto.getRandomValues(t);let e="";for(const o of t)e+=o.toString(16).padStart(2,"0");return e},s=/^[0-9a-f]+$/,i=(r,t,e=!0)=>`00-${r}-${t}-${e?"01":"00"}`,l=r=>{if(r==null)return;const t=r.trim().toLowerCase().split("-"),[e,o,n,a]=t;if(!(t.length<4||e===void 0||e.length!==2||!s.test(e)||e==="ff"||e==="00"&&t.length!==4||o===void 0||n===void 0||a===void 0||a.length!==2||!s.test(a)||o.length!==32||n.length!==16||!s.test(o)||!s.test(n)||o==="00000000000000000000000000000000"||n==="0000000000000000"))return{parentSpanId:n,sampled:(Number.parseInt(a,16)&1)===1,traceId:o}},p=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"}),f=r=>{const t=l(r);return{rootSpanId:t?.parentSpanId??d(8),sampled:t?.sampled??!0,traceId:t?.traceId??d(16)}},m=r=>u(r)?r.code:r instanceof Error?r.constructor.name:"Error";export{d as O,i as m,f as r,m as t,p as w};