@pydantic/logfire-cf-workers 0.7.0 → 0.8.0

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 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 n=Object.getOwnPropertyDescriptor(t,r);Object.defineProperty(e,r,n.get?n:{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 n of e){const o=v[n.attributes["logfire.level_num"]]??"info",{attributes:s,name:i,...c}=this.exportInfo(n);console.log(`Logfire: ${o} >> ${i}`),console.log("Attributes:"),console.log(JSON.stringify(s,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 n of r.scopeSpans){n.scope&&l(n.scope);for(const o of n.spans??[])l(o)}}return e}_sendSpans(e,r){const n=S.JsonTraceSerializer.serializeRequest(e),o=new TextDecoder().decode(n),s=JSON.parse(o),i=this._cleanNullValues(s);return console.log(i),r==null?void 0:r({code:u.ExportResultCode.SUCCESS})}}function l(t){t!=null&&t.attributes&&(t.attributes=t.attributes.filter(O))}function O(t){return Object.keys(t.value).length>0}async function h(t,e){const r=e.LOGFIRE_TOKEN;if(!r){console.warn("No token provided, not sending payload to Logfire");return}const n=a.resolveBaseUrl(e,void 0,r);for(const o of t)for(const s of o.logs)if(Array.isArray(s.message)){for(const i of s.message)if("resourceSpans"in i)try{return await fetch(`${n}/v1/traces`,{body:JSON.stringify(i),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:n=""}=e,o=a.resolveBaseUrl(e,t.baseUrl,n),s=t.environment??r,i=t.console?[new g.SimpleSpanProcessor(new T)]:[];return Object.assign({},t,{additionalSpanProcessors:i,environment:s,exporter:{headers:{Authorization:n},url:`${o}/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 n=e.attributes[r];n==null&&delete e.attributes[r]}Object.assign(e.attributes,a.serializeAttributes(e.attributes))}return t}exports.exportTailEventsToLogfire=h;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)),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.d.cts CHANGED
@@ -1,4 +1,5 @@
1
1
  import * as logfireApi from '@pydantic/logfire-api';
2
+ import { SpanProcessor } from '@opentelemetry/sdk-trace-base';
2
3
  import { TraceConfig } from '@pydantic/otel-cf-workers';
3
4
 
4
5
  declare type ConfigOptionsBase = Pick<TraceConfig, 'environment' | 'fetch' | 'handlers' | 'instrumentation' | 'propagator' | 'sampling' | 'scope' | 'service'>;
@@ -10,6 +11,10 @@ export declare function exportTailEventsToLogfire(events: TraceItem[], env: Reco
10
11
  export declare function getTailConfig(config: TailConfigOptions): (env: Env) => TraceConfig;
11
12
 
12
13
  export declare interface InProcessConfigOptions extends ConfigOptionsBase {
14
+ /**
15
+ * Additional span processors to add to the tracer provider.
16
+ */
17
+ additionalSpanProcessors?: SpanProcessor[];
13
18
  baseUrl?: string;
14
19
  /**
15
20
  * Whether to log the spans to the console in addition to sending them to the Logfire API.
package/dist/index.d.ts CHANGED
@@ -1,4 +1,5 @@
1
1
  import * as logfireApi from '@pydantic/logfire-api';
2
+ import { SpanProcessor } from '@opentelemetry/sdk-trace-base';
2
3
  import { TraceConfig } from '@pydantic/otel-cf-workers';
3
4
 
4
5
  declare type ConfigOptionsBase = Pick<TraceConfig, 'environment' | 'fetch' | 'handlers' | 'instrumentation' | 'propagator' | 'sampling' | 'scope' | 'service'>;
@@ -10,6 +11,10 @@ export declare function exportTailEventsToLogfire(events: TraceItem[], env: Reco
10
11
  export declare function getTailConfig(config: TailConfigOptions): (env: Env) => TraceConfig;
11
12
 
12
13
  export declare interface InProcessConfigOptions extends ConfigOptionsBase {
14
+ /**
15
+ * Additional span processors to add to the tracer provider.
16
+ */
17
+ additionalSpanProcessors?: SpanProcessor[];
13
18
  baseUrl?: string;
14
19
  /**
15
20
  * Whether to log the spans to the console in addition to sending them to the Logfire API.
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 g } from "@pydantic/logfire-api";
3
+ import { resolveBaseUrl as l, ULIDGenerator as f, serializeAttributes as b } 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 b } from "@opentelemetry/otlp-transformer";
6
+ import { JsonTraceSerializer as g } from "@opentelemetry/otlp-transformer";
7
7
  const v = {
8
8
  1: "trace",
9
9
  5: "debug",
@@ -50,8 +50,8 @@ class h {
50
50
  }
51
51
  sendSpans(e, r) {
52
52
  for (const o of e) {
53
- const n = v[o.attributes["logfire.level_num"]] ?? "info", { attributes: s, name: i, ...a } = this.exportInfo(o);
54
- console.log(`Logfire: ${n} >> ${i}`), console.log("Attributes:"), console.log(JSON.stringify(s, null, 2)), console.log("---"), console.log("Span details:"), console.log(JSON.stringify(a, null, 2)), console.log("---");
53
+ const n = v[o.attributes["logfire.level_num"]] ?? "info", { attributes: i, name: s, ...a } = this.exportInfo(o);
54
+ 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(a, null, 2)), console.log("---");
55
55
  }
56
56
  r && r({ code: d.SUCCESS });
57
57
  }
@@ -77,8 +77,8 @@ class y {
77
77
  return e;
78
78
  }
79
79
  _sendSpans(e, r) {
80
- const o = b.serializeRequest(e), n = new TextDecoder().decode(o), s = JSON.parse(n), i = this._cleanNullValues(s);
81
- return console.log(i), r == null ? void 0 : r({ code: d.SUCCESS });
80
+ const o = g.serializeRequest(e), n = new TextDecoder().decode(o), i = JSON.parse(n), s = this._cleanNullValues(i);
81
+ return console.log(s), r == null ? void 0 : r({ code: d.SUCCESS });
82
82
  }
83
83
  }
84
84
  function c(t) {
@@ -95,13 +95,13 @@ async function k(t, e) {
95
95
  }
96
96
  const o = l(e, void 0, r);
97
97
  for (const n of t)
98
- for (const s of n.logs)
99
- if (Array.isArray(s.message)) {
100
- for (const i of s.message)
101
- if ("resourceSpans" in i)
98
+ for (const i of n.logs)
99
+ if (Array.isArray(i.message)) {
100
+ for (const s of i.message)
101
+ if ("resourceSpans" in s)
102
102
  try {
103
103
  return await fetch(`${o}/v1/traces`, {
104
- body: JSON.stringify(i),
104
+ body: JSON.stringify(s),
105
105
  headers: {
106
106
  Authorization: r,
107
107
  "Content-Type": "application/json"
@@ -115,10 +115,10 @@ async function k(t, e) {
115
115
  }
116
116
  function E(t) {
117
117
  return (e) => {
118
- const { LOGFIRE_ENVIRONMENT: r, LOGFIRE_TOKEN: o = "" } = e, n = l(e, t.baseUrl, o), s = t.environment ?? r, i = t.console ? [new m(new h())] : [];
119
- return Object.assign({}, t, {
120
- additionalSpanProcessors: i,
121
- environment: s,
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, {
120
+ additionalSpanProcessors: s,
121
+ environment: i,
122
122
  exporter: {
123
123
  headers: { Authorization: o },
124
124
  url: `${n}/v1/traces`
@@ -137,24 +137,24 @@ function O(t) {
137
137
  function C(t, e) {
138
138
  return e.scrubbing !== void 0 && S.configureLogfireApi({ scrubbing: e.scrubbing }), p(t, E(e));
139
139
  }
140
- function _(t, e) {
140
+ function P(t, e) {
141
141
  return p(t, O(e));
142
142
  }
143
- const P = C;
143
+ const _ = C;
144
144
  function T(t) {
145
145
  for (const e of t) {
146
146
  for (const r of Object.keys(e.attributes)) {
147
147
  const o = e.attributes[r];
148
148
  o == null && delete e.attributes[r];
149
149
  }
150
- Object.assign(e.attributes, g(e.attributes));
150
+ Object.assign(e.attributes, b(e.attributes));
151
151
  }
152
152
  return t;
153
153
  }
154
154
  export {
155
155
  k as exportTailEventsToLogfire,
156
156
  O as getTailConfig,
157
- P as instrument,
157
+ _ as instrument,
158
158
  C as instrumentInProcess,
159
- _ as instrumentTail
159
+ P as instrumentTail
160
160
  };
package/package.json CHANGED
@@ -7,6 +7,10 @@
7
7
  "email": "engineering@pydantic.dev",
8
8
  "url": "https://pydantic.dev"
9
9
  },
10
+ "repository": {
11
+ "url": "https://github.com/pydantic/logfire-js",
12
+ "directory": "packages/logfire-cf-workers"
13
+ },
10
14
  "sideEffects": false,
11
15
  "homepage": "https://pydantic.dev/logfire",
12
16
  "license": "MIT",
@@ -22,7 +26,7 @@
22
26
  "stats",
23
27
  "monitoring"
24
28
  ],
25
- "version": "0.7.0",
29
+ "version": "0.8.0",
26
30
  "type": "module",
27
31
  "main": "./dist/index.cjs",
28
32
  "module": "./dist/index.js",