@pydantic/logfire-cf-workers 0.5.0 → 0.7.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/README.md CHANGED
@@ -1,6 +1,5 @@
1
1
  # Pydantic Logfire — Uncomplicated Observability — JavaScript SDK
2
2
 
3
- From the team behind [Pydantic](https://pydantic.dev/), **Logfire** is an observability platform built on the same belief as our
4
- open source library — that the most powerful tools can be easy to use.
3
+ From the team behind [Pydantic Validation](https://pydantic.dev/), **Pydantic Logfire** is an observability platform built on the same belief as our open source library — that the most powerful tools can be easy to use.
5
4
 
6
5
  Check the [Github Repository README](https://github.com/pydantic/logfire-js) for more information on how to use the SDK.
package/dist/index.cjs CHANGED
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const a=require("@pydantic/logfire-api"),u=require("@pydantic/otel-cf-workers"),d=require("@opentelemetry/core"),g=require("@opentelemetry/otlp-transformer");class m{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){c(r.resource);for(const n of r.scopeSpans){n.scope&&c(n.scope);for(const o of n.spans??[])c(o)}}return e}_sendSpans(e,r){const n=g.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:d.ExportResultCode.SUCCESS})}}function c(t){t!=null&&t.attributes&&(t.attributes=t.attributes.filter(v))}function v(t){return Object.keys(t.value).length>0}async function S(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(p){console.error(p)}}}function y(t){return e=>{const{LOGFIRE_ENVIRONMENT:r,LOGFIRE_TOKEN:n=""}=e,o=a.resolveBaseUrl(e,t.baseUrl,n),s=t.environment??r;return Object.assign({},t,{environment:s,exporter:{headers:{Authorization:n},url:`${o}/v1/traces`},idGenerator:new a.ULIDGenerator,postProcessor:i=>E(i)})}}function l(t){return e=>Object.assign({},t,{exporter:new m,idGenerator:new a.ULIDGenerator})}function f(t,e){return u.instrument(t,y(e))}function T(t,e){return u.instrument(t,l(e))}const b=f;function E(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=S;exports.getTailConfig=l;exports.instrument=b;exports.instrumentInProcess=f;exports.instrumentTail=T;
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;
package/dist/index.d.cts CHANGED
@@ -1,10 +1,6 @@
1
+ import * as logfireApi from '@pydantic/logfire-api';
1
2
  import { TraceConfig } from '@pydantic/otel-cf-workers';
2
3
 
3
- export declare interface CloudflareConfigOptions {
4
- baseUrl?: string;
5
- token: string;
6
- }
7
-
8
4
  declare type ConfigOptionsBase = Pick<TraceConfig, 'environment' | 'fetch' | 'handlers' | 'instrumentation' | 'propagator' | 'sampling' | 'scope' | 'service'>;
9
5
 
10
6
  declare type Env = Record<string, string | undefined>;
@@ -15,6 +11,14 @@ export declare function getTailConfig(config: TailConfigOptions): (env: Env) =>
15
11
 
16
12
  export declare interface InProcessConfigOptions extends ConfigOptionsBase {
17
13
  baseUrl?: string;
14
+ /**
15
+ * Whether to log the spans to the console in addition to sending them to the Logfire API.
16
+ */
17
+ console?: boolean;
18
+ /**
19
+ * Options for scrubbing sensitive data. Set to False to disable.
20
+ */
21
+ scrubbing?: false | logfireApi.ScrubbingOptions;
18
22
  }
19
23
 
20
24
  /**
package/dist/index.d.ts CHANGED
@@ -1,10 +1,6 @@
1
+ import * as logfireApi from '@pydantic/logfire-api';
1
2
  import { TraceConfig } from '@pydantic/otel-cf-workers';
2
3
 
3
- export declare interface CloudflareConfigOptions {
4
- baseUrl?: string;
5
- token: string;
6
- }
7
-
8
4
  declare type ConfigOptionsBase = Pick<TraceConfig, 'environment' | 'fetch' | 'handlers' | 'instrumentation' | 'propagator' | 'sampling' | 'scope' | 'service'>;
9
5
 
10
6
  declare type Env = Record<string, string | undefined>;
@@ -15,6 +11,14 @@ export declare function getTailConfig(config: TailConfigOptions): (env: Env) =>
15
11
 
16
12
  export declare interface InProcessConfigOptions extends ConfigOptionsBase {
17
13
  baseUrl?: string;
14
+ /**
15
+ * Whether to log the spans to the console in addition to sending them to the Logfire API.
16
+ */
17
+ console?: boolean;
18
+ /**
19
+ * Options for scrubbing sensitive data. Set to False to disable.
20
+ */
21
+ scrubbing?: false | logfireApi.ScrubbingOptions;
18
22
  }
19
23
 
20
24
  /**
package/dist/index.js CHANGED
@@ -1,52 +1,106 @@
1
- import { resolveBaseUrl as c, ULIDGenerator as u, serializeAttributes as p } from "@pydantic/logfire-api";
2
- import { instrument as l } from "@pydantic/otel-cf-workers";
3
- import { ExportResultCode as m } from "@opentelemetry/core";
4
- import { JsonTraceSerializer as d } from "@opentelemetry/otlp-transformer";
5
- class S {
6
- export(t, r) {
7
- this._sendSpans(t, r);
1
+ import { SimpleSpanProcessor as m } from "@opentelemetry/sdk-trace-base";
2
+ import * as S from "@pydantic/logfire-api";
3
+ import { resolveBaseUrl as l, ULIDGenerator as f, serializeAttributes as g } from "@pydantic/logfire-api";
4
+ import { instrument as p } from "@pydantic/otel-cf-workers";
5
+ import { hrTimeToMicroseconds as u, ExportResultCode as d } from "@opentelemetry/core";
6
+ import { JsonTraceSerializer as b } from "@opentelemetry/otlp-transformer";
7
+ const v = {
8
+ 1: "trace",
9
+ 5: "debug",
10
+ 9: "info",
11
+ 10: "notice",
12
+ 13: "warning",
13
+ 17: "error",
14
+ 21: "fatal"
15
+ };
16
+ class h {
17
+ export(e, r) {
18
+ this.sendSpans(e, r);
19
+ }
20
+ forceFlush() {
21
+ return Promise.resolve();
22
+ }
23
+ shutdown() {
24
+ return this.sendSpans([]), this.forceFlush();
25
+ }
26
+ /**
27
+ * converts span info into more readable format
28
+ * @param span
29
+ */
30
+ exportInfo(e) {
31
+ var r;
32
+ return {
33
+ attributes: e.attributes,
34
+ duration: u(e.duration),
35
+ events: e.events,
36
+ id: e.spanContext().spanId,
37
+ instrumentationScope: e.instrumentationScope,
38
+ kind: e.kind,
39
+ links: e.links,
40
+ name: e.name,
41
+ parentSpanContext: e.parentSpanContext,
42
+ resource: {
43
+ attributes: e.resource.attributes
44
+ },
45
+ status: e.status,
46
+ timestamp: u(e.startTime),
47
+ traceId: e.spanContext().traceId,
48
+ traceState: (r = e.spanContext().traceState) == null ? void 0 : r.serialize()
49
+ };
50
+ }
51
+ sendSpans(e, r) {
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("---");
55
+ }
56
+ r && r({ code: d.SUCCESS });
57
+ }
58
+ }
59
+ class y {
60
+ export(e, r) {
61
+ this._sendSpans(e, r);
8
62
  }
9
63
  shutdown() {
10
64
  return this._sendSpans([]), Promise.resolve();
11
65
  }
12
- _cleanNullValues(t) {
13
- if (!t.resourceSpans)
14
- return t;
15
- for (const r of t.resourceSpans) {
16
- a(r.resource);
17
- for (const n of r.scopeSpans) {
18
- n.scope && a(n.scope);
19
- for (const o of n.spans ?? [])
20
- a(o);
66
+ _cleanNullValues(e) {
67
+ if (!e.resourceSpans)
68
+ return e;
69
+ for (const r of e.resourceSpans) {
70
+ c(r.resource);
71
+ for (const o of r.scopeSpans) {
72
+ o.scope && c(o.scope);
73
+ for (const n of o.spans ?? [])
74
+ c(n);
21
75
  }
22
76
  }
23
- return t;
77
+ return e;
24
78
  }
25
- _sendSpans(t, r) {
26
- const n = d.serializeRequest(t), o = new TextDecoder().decode(n), s = JSON.parse(o), i = this._cleanNullValues(s);
27
- return console.log(i), r == null ? void 0 : r({ code: m.SUCCESS });
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 });
28
82
  }
29
83
  }
30
- function a(e) {
31
- e != null && e.attributes && (e.attributes = e.attributes.filter(v));
84
+ function c(t) {
85
+ t != null && t.attributes && (t.attributes = t.attributes.filter(x));
32
86
  }
33
- function v(e) {
34
- return Object.keys(e.value).length > 0;
87
+ function x(t) {
88
+ return Object.keys(t.value).length > 0;
35
89
  }
36
- async function x(e, t) {
37
- const r = t.LOGFIRE_TOKEN;
90
+ async function k(t, e) {
91
+ const r = e.LOGFIRE_TOKEN;
38
92
  if (!r) {
39
93
  console.warn("No token provided, not sending payload to Logfire");
40
94
  return;
41
95
  }
42
- const n = c(t, void 0, r);
43
- for (const o of e)
44
- for (const s of o.logs)
96
+ const o = l(e, void 0, r);
97
+ for (const n of t)
98
+ for (const s of n.logs)
45
99
  if (Array.isArray(s.message)) {
46
100
  for (const i of s.message)
47
101
  if ("resourceSpans" in i)
48
102
  try {
49
- return await fetch(`${n}/v1/traces`, {
103
+ return await fetch(`${o}/v1/traces`, {
50
104
  body: JSON.stringify(i),
51
105
  headers: {
52
106
  Authorization: r,
@@ -54,52 +108,53 @@ async function x(e, t) {
54
108
  },
55
109
  method: "POST"
56
110
  });
57
- } catch (f) {
58
- console.error(f);
111
+ } catch (a) {
112
+ console.error(a);
59
113
  }
60
114
  }
61
115
  }
62
- function y(e) {
63
- return (t) => {
64
- const { LOGFIRE_ENVIRONMENT: r, LOGFIRE_TOKEN: n = "" } = t, o = c(t, e.baseUrl, n), s = e.environment ?? r;
65
- return Object.assign({}, e, {
116
+ function E(t) {
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,
66
121
  environment: s,
67
122
  exporter: {
68
- headers: { Authorization: n },
69
- url: `${o}/v1/traces`
123
+ headers: { Authorization: o },
124
+ url: `${n}/v1/traces`
70
125
  },
71
- idGenerator: new u(),
72
- postProcessor: (i) => g(i)
126
+ idGenerator: new f(),
127
+ postProcessor: (a) => T(a)
73
128
  });
74
129
  };
75
130
  }
76
- function b(e) {
77
- return (t) => Object.assign({}, e, {
78
- exporter: new S(),
79
- idGenerator: new u()
131
+ function O(t) {
132
+ return (e) => Object.assign({}, t, {
133
+ exporter: new y(),
134
+ idGenerator: new f()
80
135
  });
81
136
  }
82
- function E(e, t) {
83
- return l(e, y(t));
137
+ function C(t, e) {
138
+ return e.scrubbing !== void 0 && S.configureLogfireApi({ scrubbing: e.scrubbing }), p(t, E(e));
84
139
  }
85
- function _(e, t) {
86
- return l(e, b(t));
140
+ function _(t, e) {
141
+ return p(t, O(e));
87
142
  }
88
- const A = E;
89
- function g(e) {
90
- for (const t of e) {
91
- for (const r of Object.keys(t.attributes)) {
92
- const n = t.attributes[r];
93
- n == null && delete t.attributes[r];
143
+ const P = C;
144
+ function T(t) {
145
+ for (const e of t) {
146
+ for (const r of Object.keys(e.attributes)) {
147
+ const o = e.attributes[r];
148
+ o == null && delete e.attributes[r];
94
149
  }
95
- Object.assign(t.attributes, p(t.attributes));
150
+ Object.assign(e.attributes, g(e.attributes));
96
151
  }
97
- return e;
152
+ return t;
98
153
  }
99
154
  export {
100
- x as exportTailEventsToLogfire,
101
- b as getTailConfig,
102
- A as instrument,
103
- E as instrumentInProcess,
155
+ k as exportTailEventsToLogfire,
156
+ O as getTailConfig,
157
+ P as instrument,
158
+ C as instrumentInProcess,
104
159
  _ as instrumentTail
105
160
  };
package/package.json CHANGED
@@ -22,7 +22,7 @@
22
22
  "stats",
23
23
  "monitoring"
24
24
  ],
25
- "version": "0.5.0",
25
+ "version": "0.7.0",
26
26
  "type": "module",
27
27
  "main": "./dist/index.cjs",
28
28
  "module": "./dist/index.js",
@@ -50,7 +50,7 @@
50
50
  },
51
51
  "dependencies": {
52
52
  "@pydantic/logfire-api": "*",
53
- "@pydantic/otel-cf-workers": "^1.0.0-rc.53"
53
+ "@pydantic/otel-cf-workers": "^1.0.0-rc.54"
54
54
  },
55
55
  "devDependencies": {
56
56
  "@cloudflare/workers-types": "4.20250311.0",