@lunora/observability 1.0.0-alpha.118 → 1.0.0-alpha.119
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
|
@@ -563,8 +563,8 @@ interface TraceAnchor {
|
|
|
563
563
|
/**
|
|
564
564
|
* Cloudflare Ray ID of the request this dispatch serves, forwarded by the
|
|
565
565
|
* runtime alongside `traceparent`. Carried on the anchor so every span and
|
|
566
|
-
* log line of the dispatch stamps the same value.
|
|
567
|
-
*
|
|
566
|
+
* log line of the dispatch stamps the same value. Absent off the edge.
|
|
567
|
+
* Informational only, as `parseRayId` in `shared/ray-id.ts` defines it.
|
|
568
568
|
*/
|
|
569
569
|
rayId?: string;
|
|
570
570
|
rootSpanId: string;
|
|
@@ -2192,13 +2192,11 @@ declare const findDanglingReferences: (sql: SqlExec, storageColumns: Record<stri
|
|
|
2192
2192
|
* `rayHeader` is the Cloudflare Ray ID the runtime forwarded alongside the
|
|
2193
2193
|
* `traceparent` (`x-lunora-ray-id`). It is re-validated here and carried on the
|
|
2194
2194
|
* anchor so every span and log line of the dispatch stamps it; absent or
|
|
2195
|
-
* malformed, the anchor simply has none. Informational only
|
|
2195
|
+
* malformed, the anchor simply has none. Informational only — see
|
|
2196
|
+
* {@link parseRayId}.
|
|
2196
2197
|
*/
|
|
2197
|
-
declare const resolveTraceAnchor: (traceparent: string | undefined, rayHeader?: null | string) => {
|
|
2198
|
-
rayId?: string;
|
|
2199
|
-
rootSpanId: string;
|
|
2198
|
+
declare const resolveTraceAnchor: (traceparent: string | undefined, rayHeader?: null | string) => TraceAnchor & {
|
|
2200
2199
|
sampled: boolean;
|
|
2201
|
-
traceId: string;
|
|
2202
2200
|
};
|
|
2203
2201
|
export { AUTH_METRICS_BUCKETS_TABLE, AUTH_METRICS_BUCKET_MS, AUTH_METRICS_BUCKET_RETENTION, AUTH_METRICS_TABLE, type AiRunBinding, type AppendRequestLogEntry,
|
|
2204
2202
|
/**
|
package/dist/index.d.ts
CHANGED
|
@@ -563,8 +563,8 @@ interface TraceAnchor {
|
|
|
563
563
|
/**
|
|
564
564
|
* Cloudflare Ray ID of the request this dispatch serves, forwarded by the
|
|
565
565
|
* runtime alongside `traceparent`. Carried on the anchor so every span and
|
|
566
|
-
* log line of the dispatch stamps the same value.
|
|
567
|
-
*
|
|
566
|
+
* log line of the dispatch stamps the same value. Absent off the edge.
|
|
567
|
+
* Informational only, as `parseRayId` in `shared/ray-id.ts` defines it.
|
|
568
568
|
*/
|
|
569
569
|
rayId?: string;
|
|
570
570
|
rootSpanId: string;
|
|
@@ -2192,13 +2192,11 @@ declare const findDanglingReferences: (sql: SqlExec, storageColumns: Record<stri
|
|
|
2192
2192
|
* `rayHeader` is the Cloudflare Ray ID the runtime forwarded alongside the
|
|
2193
2193
|
* `traceparent` (`x-lunora-ray-id`). It is re-validated here and carried on the
|
|
2194
2194
|
* anchor so every span and log line of the dispatch stamps it; absent or
|
|
2195
|
-
* malformed, the anchor simply has none. Informational only
|
|
2195
|
+
* malformed, the anchor simply has none. Informational only — see
|
|
2196
|
+
* {@link parseRayId}.
|
|
2196
2197
|
*/
|
|
2197
|
-
declare const resolveTraceAnchor: (traceparent: string | undefined, rayHeader?: null | string) => {
|
|
2198
|
-
rayId?: string;
|
|
2199
|
-
rootSpanId: string;
|
|
2198
|
+
declare const resolveTraceAnchor: (traceparent: string | undefined, rayHeader?: null | string) => TraceAnchor & {
|
|
2200
2199
|
sampled: boolean;
|
|
2201
|
-
traceId: string;
|
|
2202
2200
|
};
|
|
2203
2201
|
export { AUTH_METRICS_BUCKETS_TABLE, AUTH_METRICS_BUCKET_MS, AUTH_METRICS_BUCKET_RETENTION, AUTH_METRICS_TABLE, type AiRunBinding, type AppendRequestLogEntry,
|
|
2204
2202
|
/**
|
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-
|
|
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};
|
|
@@ -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"./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};
|
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.119",
|
|
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.
|
|
48
|
+
"@lunora/shard-engine": "1.0.0-alpha.110",
|
|
49
49
|
"@visulima/redact": "5.0.0"
|
|
50
50
|
},
|
|
51
51
|
"engines": {
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{f as _,g as k,n as v}from"./request-log-BmtC_cDV.mjs";import{o as j,b as L,O as F}from"./otlp-DR7601NL.mjs";import{applyHostSpanAttributes as K}from"./setHostSpanAttributes-tUccMpGP.mjs";import{toErrorType as O}from"./resolveTraceAnchor-DDAPZRBB.mjs";const U=/[\w.-]/u,q=e=>{let t="";for(const r of e)t+=U.test(r)?r:"_";return t},C=e=>{if(typeof e.name!="string"||e.name.length===0)throw new TypeError("recordEvaluation requires a non-empty `name`");if(typeof e.score!="number"||!Number.isFinite(e.score))throw new TypeError("recordEvaluation `score` must be a finite number");const t=q(e.name),r={[`gen_ai.evaluation.${t}.score`]:e.score};return e.label!==void 0&&(r[`gen_ai.evaluation.${t}.label`]=e.label),r},X=e=>{const t=Object.keys(e);if(t.length===0||!t.every(a=>a==="attributes"||a==="kind"||a==="links"))return!1;const{kind:r}=e;return r===void 0||Object.hasOwn(F,r)},B=128,V=128,x=128,I=(e,t)=>{if(t===void 0)return;let r=Object.keys(e).length;for(const[a,n]of Object.entries(t)){const s=!Object.hasOwn(e,a);s&&r>=x||(s&&(r+=1),e[a]=n)}},$=e=>{const t=v(e);if(t===void 0||Object.keys(t).length<=x)return t;const r={};return I(r,t),r},G=e=>{try{const t=new URL(e);return`${t.protocol}//${t.host}${t.pathname}`}catch{return e}},J=e=>{try{return new URL(e).host}catch{return e}},Q=(e,t)=>{try{return e(new URL(t))}catch{return!1}},W=e=>e===void 0?{}:X(e)?e:{attributes:e},Y=(e,t=!1)=>{const r={attributes:{},events:[],links:[]},a={spanContext:()=>e,addEvent:(n,s)=>{if(r.events.length>=B)return;const o=k($(s),t);r.events.push({...o===void 0?{}:{attributes:o},name:n,ts:Date.now()})},addLink:n=>{if(r.links.length>=V)return;const s=k($(n.attributes),t);r.links.push({...s===void 0?{}:{attributes:s},spanId:n.spanId,traceId:n.traceId})},recordEvaluation:n=>{I(r.attributes,v(C(n)))},recordException:n=>{const s=n instanceof Error?n.message:String(n);a.addEvent("exception",{"exception.message":_(s,t),...t&&n instanceof Error&&typeof n.stack=="string"?{"exception.stacktrace":n.stack}:{},"exception.type":O(n)})},setAttribute:(n,s)=>{I(r.attributes,v({[n]:s}))},setAttributes:n=>{I(r.attributes,v(n))}};return{collected:r,handle:a}},nt=e=>{const{anchor:t,captureRaw:r=!1,fuseHostSpans:a,functionPath:n,record:s,resolveHostTracing:o,shardKey:c,userId:f}=e,d=y=>async(b,E,u,P)=>{const l=P?.spanId??j(8),w=P?.parentSpanId??y,i=Date.now(),g=W(u),z=v(g.attributes),{collected:T,handle:D}=Y({...t.sampled===void 0?{}:{sampled:t.sampled},spanId:l,traceId:t.traceId},r),H=async S=>{let p=!0,m;try{return await E(d(l),D)}catch(h){p=!1;const A=h instanceof Error?h.message:String(h);throw m={message:_(A,r),type:O(h)},h}finally{const h=Date.now()-i,A=f(),N={};I(N,z),I(N,T.attributes);const M=k(N,r),R=[...g.links??[],...T.links];try{s({...Object.keys(M).length===0?{}:{attributes:M},durationMs:h,...T.events.length===0?{}:{events:T.events},...m===void 0?{}:{error:m},functionPath:n,...g.kind===void 0||g.kind==="internal"?{}:{kind:g.kind},...R.length===0?{}:{links:R},name:b,ok:p,parentSpanId:w,...t.rayId===void 0?{}:{rayId:t.rayId},shardKey:c,spanId:l,startTs:i,traceId:t.traceId,userId:A})}catch{}if(S!==void 0)try{K(S,{attributes:M,durationMs:h,error:m,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(b,m=>(S=!0,H(m)))}catch(p){if(S)throw p}}return await H()};return d(t.rootSpanId)},st=(e,t)=>{const{anchor:r,captureRaw:a=!1,functionPath:n,propagate:s=!0,record:o,shardKey:c,userId:f}=e;return async(d,y)=>{const b=j(8),E=Date.now(),u=new Request(d,y);(typeof s=="function"?Q(s,u.url):s)&&u.headers.set("traceparent",L(r.traceId,b,r.sampled??!0));let l,w;try{const i=await t(u);return w=i.status,i.ok||(l={message:`HTTP ${String(i.status)}`,type:`HTTP_${String(i.status)}`}),i}catch(i){const g=i instanceof Error?i.message:String(i);throw l={message:_(g,a),type:O(i)},i}finally{try{o({attributes:{"http.request.method":u.method,...w===void 0?{}:{"http.response.status_code":w},"url.full":G(u.url)},durationMs:Date.now()-E,...l===void 0?{}:{error:l},functionPath:n,kind:"client",name:`${u.method} ${J(u.url)}`,ok:l===void 0,parentSpanId:r.rootSpanId,...r.rayId===void 0?{}:{rayId:r.rayId},shardKey:c,spanId:b,startTs:E,traceId:r.traceId,userId:f()})}catch{}}}},at=e=>{const{functionPath:t,record:r,shardKey:a}=e,n=(s,o,c,f)=>{if(!Number.isFinite(c))return;const d=k(v(f));try{r({...d===void 0?{}:{attributes:d},functionPath:t,kind:s,name:o,shardKey:a,ts:Date.now(),value:c})}catch{}};return{count:(s,o=1,c)=>{n("counter",s,o,c)},gauge:(s,o,c)=>{n("gauge",s,o,c)},record:(s,o,c)=>{n("histogram",s,o,c)}}},ot=e=>{const{anchor:t,captureRaw:r=!1,collected:a,durationMs:n,failure:s,functionPath:o,shardKey:c,startTs:f,userId:d}=e,y=k(a?.attributes??{},r);return{...Object.keys(y).length===0?{}:{attributes:y},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:"",...t.rayId===void 0?{}:{rayId:t.rayId},shardKey:c,spanId:t.rootSpanId,startTs:f,traceId:t.traceId,userId:d}};export{at as createMetrics,Y as createSpanCollector,st as createTracedFetch,nt as createTracer,ot as dispatchRootSpan};
|