@pydantic/logfire-cf-workers 2.0.7 → 2.0.8
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.js +1 -1
- package/package.json +3 -3
package/dist/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{SimpleSpanProcessor as e}from"@opentelemetry/sdk-trace-base";import{OTLP_EXPORTER_USER_AGENT as t,instrument as n,instrumentDO as r}from"@pydantic/otel-cf-workers";import{Level as i,LogfireAttributeScrubber as a,NoopAttributeScrubber as o,ULIDGenerator as s,configureLogfireApi as c,debug as l,error as u,fatal as d,info as f,log as p,logfireApiConfig as m,notice as h,reportError as g,resolveBaseUrl as _,resolveSendToLogfire as v,serializeAttributes as y,span as b,startPendingSpan as x,startSpan as S,trace as C,warning as w,withSettings as T,withTags as E}from"logfire";import{ExportResultCode as D,hrTimeToMicroseconds as O}from"@opentelemetry/core";import{JsonTraceSerializer as k}from"@opentelemetry/otlp-transformer";const A=`logfire-js/2.0.
|
|
1
|
+
import{SimpleSpanProcessor as e}from"@opentelemetry/sdk-trace-base";import{OTLP_EXPORTER_USER_AGENT as t,instrument as n,instrumentDO as r}from"@pydantic/otel-cf-workers";import{Level as i,LogfireAttributeScrubber as a,NoopAttributeScrubber as o,ULIDGenerator as s,configureLogfireApi as c,debug as l,error as u,fatal as d,info as f,log as p,logfireApiConfig as m,notice as h,reportError as g,resolveBaseUrl as _,resolveSendToLogfire as v,serializeAttributes as y,span as b,startPendingSpan as x,startSpan as S,trace as C,warning as w,withSettings as T,withTags as E}from"logfire";import{ExportResultCode as D,hrTimeToMicroseconds as O}from"@opentelemetry/core";import{JsonTraceSerializer as k}from"@opentelemetry/otlp-transformer";const A=`logfire-js/2.0.8`;async function j(e,n){let r=n.LOGFIRE_TOKEN;if(r===void 0||r===``){console.warn(`No token provided, not sending payload to Logfire`);return}let i=_(n,void 0,r),a=M(e);if(a!==null)try{return await fetch(`${i}/v1/traces`,{body:JSON.stringify(a),headers:{Authorization:r,"Content-Type":`application/json`,"User-Agent":`${A} ${t}`},method:`POST`})}catch(e){console.error(e);return}}function M(e){for(let t of e)for(let e of t.logs)if(Array.isArray(e.message)){for(let t of e.message)if(N(t))return t}return null}function N(e){return typeof e==`object`&&!!e&&`resourceSpans`in e}const P={1:`trace`,5:`debug`,9:`info`,10:`notice`,13:`warning`,17:`error`,21:`fatal`};var F=class{export(e,t){this.sendSpans(e,t)}async forceFlush(){return Promise.resolve()}async shutdown(){return this.sendSpans([]),this.forceFlush()}exportInfo(e){return{attributes:e.attributes,duration:O(e.duration),events:e.events,id:e.spanContext().spanId,instrumentationScope:e.instrumentationScope,kind:e.kind,links:e.links,name:e.name,parentSpanContext:e.parentSpanContext,resource:{attributes:e.resource.attributes},status:e.status,timestamp:O(e.startTime),traceId:e.spanContext().traceId,traceState:e.spanContext().traceState?.serialize()}}sendSpans(e,t){for(let t of e){let e=P[t.attributes[`logfire.level_num`]]??`info`,{attributes:n,name:r,...i}=this.exportInfo(t);console.log(`Logfire: ${e} >> ${r}`),console.log(`Attributes:`),console.log(JSON.stringify(n,null,2)),console.log(`---`),console.log(`Span details:`),console.log(JSON.stringify(i,null,2)),console.log(`---`)}t&&t({code:D.SUCCESS})}},I=class{export(e,t){this.sendSpans(e,t)}async shutdown(){return this.sendSpans([]),Promise.resolve()}cleanNullValues(e){if(!e.resourceSpans)return e;for(let t of e.resourceSpans){L(t.resource);for(let e of t.scopeSpans){e.scope&&L(e.scope);for(let t of e.spans??[])L(t)}}return e}sendSpans(e,t){let n=k.serializeRequest(e),r=new TextDecoder().decode(n),i=JSON.parse(r),a=this.cleanNullValues(i);return console.log(a),t?.({code:D.SUCCESS})}};function L(e){e?.attributes&&(e.attributes=e.attributes.filter(R))}function R(e){return Object.keys(e.value).length>0}function z(e,t){if(typeof e!=`object`||!e)return;let n=e[t];return typeof n==`string`?n:void 0}function B(e){e.scrubbing!==void 0&&c({scrubbing:e.scrubbing})}function V(t){return n=>{let r=z(n,`LOGFIRE_TOKEN`)??``,i=z(n,`LOGFIRE_ENVIRONMENT`),a=_(n,t.baseUrl,r),o=t.environment??i,c=t.additionalSpanProcessors??[];return t.console===!0&&c.push(new e(new F)),{...t,additionalSpanProcessors:c,exporter:{headers:{Authorization:r},url:`${a}/v1/traces`,userAgent:A},idGenerator:new s,postProcessor:e=>q(e),...o===void 0?{}:{environment:o}}}}function H(e){return t=>({...e,exporter:new I,idGenerator:new s})}function U(e,t){return B(t),n(e,V(t))}function W(e,t){return B(t),r(e,V(t))}function G(e,t){return n(e,H(t))}const K=U;function q(e){for(let t of e){for(let e of Object.keys(t.attributes))t.attributes[e]??delete t.attributes[e];Object.assign(t.attributes,y(t.attributes))}return e}const J={exportTailEventsToLogfire:j,configureLogfireApi:c,debug:l,error:u,fatal:d,getTailConfig:H,info:f,instrument:K,instrumentDO:W,instrumentInProcess:U,instrumentTail:G,Level:i,log:p,logfireApiConfig:m,LogfireAttributeScrubber:a,NoopAttributeScrubber:o,notice:h,reportError:g,resolveBaseUrl:_,resolveSendToLogfire:v,serializeAttributes:y,span:b,startPendingSpan:x,startSpan:S,trace:C,ULIDGenerator:s,warning:w,withSettings:T,withTags:E};export{J as default,j as exportTailEventsToLogfire,H as getTailConfig,K as instrument,W as instrumentDO,U as instrumentInProcess,G as instrumentTail};
|
package/package.json
CHANGED
|
@@ -26,7 +26,7 @@
|
|
|
26
26
|
"stats",
|
|
27
27
|
"monitoring"
|
|
28
28
|
],
|
|
29
|
-
"version": "2.0.
|
|
29
|
+
"version": "2.0.8",
|
|
30
30
|
"type": "module",
|
|
31
31
|
"main": "./dist/index.js",
|
|
32
32
|
"module": "./dist/index.js",
|
|
@@ -38,8 +38,8 @@
|
|
|
38
38
|
}
|
|
39
39
|
},
|
|
40
40
|
"dependencies": {
|
|
41
|
-
"
|
|
42
|
-
"
|
|
41
|
+
"logfire": "0.21.7",
|
|
42
|
+
"@pydantic/otel-cf-workers": "2.1.2"
|
|
43
43
|
},
|
|
44
44
|
"devDependencies": {
|
|
45
45
|
"@cloudflare/workers-types": "4.20260528.1",
|