@pydantic/logfire-cf-workers 0.8.1 → 0.8.2
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.cjs +1 -1
- package/dist/index.js +5 -5
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const g=require("@opentelemetry/sdk-trace-base"),a=require("@pydantic/logfire-api"),f=require("@pydantic/otel-cf-workers"),u=require("@opentelemetry/core"),S=require("@opentelemetry/otlp-transformer");function b(t){const e=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(t){for(const r in t)if(r!=="default"){const o=Object.getOwnPropertyDescriptor(t,r);Object.defineProperty(e,r,o.get?o:{enumerable:!0,get:()=>t[r]})}}return e.default=t,Object.freeze(e)}const m=b(a),v={1:"trace",5:"debug",9:"info",10:"notice",13:"warning",17:"error",21:"fatal"};class T{export(e,r){this.sendSpans(e,r)}forceFlush(){return Promise.resolve()}shutdown(){return this.sendSpans([]),this.forceFlush()}exportInfo(e){var r;return{attributes:e.attributes,duration:u.hrTimeToMicroseconds(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:u.hrTimeToMicroseconds(e.startTime),traceId:e.spanContext().traceId,traceState:(r=e.spanContext().traceState)==null?void 0:r.serialize()}}sendSpans(e,r){for(const o of e){const n=v[o.attributes["logfire.level_num"]]??"info",{attributes:i,name:s,...c}=this.exportInfo(o);console.log(`Logfire: ${n} >> ${s}`),console.log("Attributes:"),console.log(JSON.stringify(i,null,2)),console.log("---"),console.log("Span details:"),console.log(JSON.stringify(c,null,2)),console.log("---")}r&&r({code:u.ExportResultCode.SUCCESS})}}class y{export(e,r){this._sendSpans(e,r)}shutdown(){return this._sendSpans([]),Promise.resolve()}_cleanNullValues(e){if(!e.resourceSpans)return e;for(const r of e.resourceSpans){l(r.resource);for(const o of r.scopeSpans){o.scope&&l(o.scope);for(const n of o.spans??[])l(n)}}return e}_sendSpans(e,r){const o=S.JsonTraceSerializer.serializeRequest(e),n=new TextDecoder().decode(o),i=JSON.parse(n),s=this._cleanNullValues(i);return console.log(s),r==null?void 0:r({code:u.ExportResultCode.SUCCESS})}}function l(t){t!=null&&t.attributes&&(t.attributes=t.attributes.filter(h))}function h(t){return Object.keys(t.value).length>0}async function O(t,e){const r=e.LOGFIRE_TOKEN;if(!r){console.warn("No token provided, not sending payload to Logfire");return}const o=a.resolveBaseUrl(e,void 0,r);for(const n of t)for(const i of n.logs)if(Array.isArray(i.message)){for(const s of i.message)if("resourceSpans"in s)try{return await fetch(`${o}/v1/traces`,{body:JSON.stringify(s),headers:{Authorization:r,"Content-Type":"application/json"},method:"POST"})}catch(c){console.error(c)}}}function x(t){return e=>{const{LOGFIRE_ENVIRONMENT:r,LOGFIRE_TOKEN:o=""}=e,n=a.resolveBaseUrl(e,t.baseUrl,o),i=t.environment??r,s=t.additionalSpanProcessors??[];return t.console&&s.push(new g.SimpleSpanProcessor(new T)),Object.assign({},t,{additionalSpanProcessors:s,environment:i,exporter:{headers:{Authorization:o},url:`${n}/v1/traces`},idGenerator:new a.ULIDGenerator,postProcessor:c=>I(c)})}}function p(t){return e=>Object.assign({},t,{exporter:new y,idGenerator:new a.ULIDGenerator})}function d(t,e){return e.scrubbing!==void 0&&m.configureLogfireApi({scrubbing:e.scrubbing}),f.instrument(t,x(e))}function E(t,e){return f.instrument(t,p(e))}const C=d;function I(t){for(const e of t){for(const r of Object.keys(e.attributes)){const o=e.attributes[r];o==null&&delete e.attributes[r]}Object.assign(e.attributes,a.serializeAttributes(e.attributes))}return t}exports.exportTailEventsToLogfire=O;exports.getTailConfig=p;exports.instrument=C;exports.instrumentInProcess=d;exports.instrumentTail=E;
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const g=require("@opentelemetry/sdk-trace-base"),a=require("@pydantic/logfire-api"),f=require("@pydantic/otel-cf-workers"),u=require("@opentelemetry/core"),S=require("@opentelemetry/otlp-transformer");function b(t){const e=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(t){for(const r in t)if(r!=="default"){const o=Object.getOwnPropertyDescriptor(t,r);Object.defineProperty(e,r,o.get?o:{enumerable:!0,get:()=>t[r]})}}return e.default=t,Object.freeze(e)}const m=b(a),v={1:"trace",5:"debug",9:"info",10:"notice",13:"warning",17:"error",21:"fatal"};class T{export(e,r){this.sendSpans(e,r)}forceFlush(){return Promise.resolve()}shutdown(){return this.sendSpans([]),this.forceFlush()}exportInfo(e){var r;return{attributes:e.attributes,duration:u.hrTimeToMicroseconds(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:u.hrTimeToMicroseconds(e.startTime),traceId:e.spanContext().traceId,traceState:(r=e.spanContext().traceState)==null?void 0:r.serialize()}}sendSpans(e,r){for(const o of e){const n=v[o.attributes["logfire.level_num"]]??"info",{attributes:i,name:s,...c}=this.exportInfo(o);console.log(`Logfire: ${n} >> ${s}`),console.log("Attributes:"),console.log(JSON.stringify(i,null,2)),console.log("---"),console.log("Span details:"),console.log(JSON.stringify(c,null,2)),console.log("---")}r&&r({code:u.ExportResultCode.SUCCESS})}}class y{export(e,r){this._sendSpans(e,r)}shutdown(){return this._sendSpans([]),Promise.resolve()}_cleanNullValues(e){if(!e.resourceSpans)return e;for(const r of e.resourceSpans){l(r.resource);for(const o of r.scopeSpans){o.scope&&l(o.scope);for(const n of o.spans??[])l(n)}}return e}_sendSpans(e,r){const o=S.JsonTraceSerializer.serializeRequest(e),n=new TextDecoder().decode(o),i=JSON.parse(n),s=this._cleanNullValues(i);return console.log(s),r==null?void 0:r({code:u.ExportResultCode.SUCCESS})}}function l(t){t!=null&&t.attributes&&(t.attributes=t.attributes.filter(h))}function h(t){return Object.keys(t.value).length>0}async function O(t,e){const r=e.LOGFIRE_TOKEN;if(!r){console.warn("No token provided, not sending payload to Logfire");return}const o=a.resolveBaseUrl(e,void 0,r);for(const n of t)for(const i of n.logs)if(Array.isArray(i.message)){for(const s of i.message)if("resourceSpans"in s)try{return await fetch(`${o}/v1/traces`,{body:JSON.stringify(s),headers:{Authorization:r,"Content-Type":"application/json"},method:"POST"})}catch(c){console.error(c)}}}function x(t){return e=>{const{LOGFIRE_ENVIRONMENT:r,LOGFIRE_TOKEN:o=""}=e,n=a.resolveBaseUrl(e,t.baseUrl,o),i=t.environment??r,s=t.additionalSpanProcessors??[];return t.console&&s.push(new g.SimpleSpanProcessor(new T)),console.log({baseUrl:n}),Object.assign({},t,{additionalSpanProcessors:s,environment:i,exporter:{headers:{Authorization:o},url:`${n}/v1/traces`},idGenerator:new a.ULIDGenerator,postProcessor:c=>I(c)})}}function p(t){return e=>Object.assign({},t,{exporter:new y,idGenerator:new a.ULIDGenerator})}function d(t,e){return e.scrubbing!==void 0&&m.configureLogfireApi({scrubbing:e.scrubbing}),f.instrument(t,x(e))}function E(t,e){return f.instrument(t,p(e))}const C=d;function I(t){for(const e of t){for(const r of Object.keys(e.attributes)){const o=e.attributes[r];o==null&&delete e.attributes[r]}Object.assign(e.attributes,a.serializeAttributes(e.attributes))}return t}exports.exportTailEventsToLogfire=O;exports.getTailConfig=p;exports.instrument=C;exports.instrumentInProcess=d;exports.instrumentTail=E;
|
package/dist/index.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { SimpleSpanProcessor as m } from "@opentelemetry/sdk-trace-base";
|
|
2
2
|
import * as S from "@pydantic/logfire-api";
|
|
3
|
-
import { resolveBaseUrl as l, ULIDGenerator as f, serializeAttributes as
|
|
3
|
+
import { resolveBaseUrl as l, ULIDGenerator as f, serializeAttributes as g } from "@pydantic/logfire-api";
|
|
4
4
|
import { instrument as p } from "@pydantic/otel-cf-workers";
|
|
5
5
|
import { hrTimeToMicroseconds as u, ExportResultCode as d } from "@opentelemetry/core";
|
|
6
|
-
import { JsonTraceSerializer as
|
|
6
|
+
import { JsonTraceSerializer as b } from "@opentelemetry/otlp-transformer";
|
|
7
7
|
const v = {
|
|
8
8
|
1: "trace",
|
|
9
9
|
5: "debug",
|
|
@@ -77,7 +77,7 @@ class y {
|
|
|
77
77
|
return e;
|
|
78
78
|
}
|
|
79
79
|
_sendSpans(e, r) {
|
|
80
|
-
const o =
|
|
80
|
+
const o = b.serializeRequest(e), n = new TextDecoder().decode(o), i = JSON.parse(n), s = this._cleanNullValues(i);
|
|
81
81
|
return console.log(s), r == null ? void 0 : r({ code: d.SUCCESS });
|
|
82
82
|
}
|
|
83
83
|
}
|
|
@@ -116,7 +116,7 @@ async function k(t, e) {
|
|
|
116
116
|
function E(t) {
|
|
117
117
|
return (e) => {
|
|
118
118
|
const { LOGFIRE_ENVIRONMENT: r, LOGFIRE_TOKEN: o = "" } = e, n = l(e, t.baseUrl, o), i = t.environment ?? r, s = t.additionalSpanProcessors ?? [];
|
|
119
|
-
return t.console && s.push(new m(new h())), Object.assign({}, t, {
|
|
119
|
+
return t.console && s.push(new m(new h())), console.log({ baseUrl: n }), Object.assign({}, t, {
|
|
120
120
|
additionalSpanProcessors: s,
|
|
121
121
|
environment: i,
|
|
122
122
|
exporter: {
|
|
@@ -147,7 +147,7 @@ function T(t) {
|
|
|
147
147
|
const o = e.attributes[r];
|
|
148
148
|
o == null && delete e.attributes[r];
|
|
149
149
|
}
|
|
150
|
-
Object.assign(e.attributes,
|
|
150
|
+
Object.assign(e.attributes, g(e.attributes));
|
|
151
151
|
}
|
|
152
152
|
return t;
|
|
153
153
|
}
|