@pydantic/logfire-cf-workers 0.4.3 → 0.5.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 +1 -1
- package/dist/index.d.cts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +33 -49
- package/package.json +2 -2
package/dist/index.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";
|
|
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;
|
package/dist/index.d.cts
CHANGED
|
@@ -5,7 +5,7 @@ export declare interface CloudflareConfigOptions {
|
|
|
5
5
|
token: string;
|
|
6
6
|
}
|
|
7
7
|
|
|
8
|
-
declare type ConfigOptionsBase = Pick<TraceConfig, 'fetch' | 'handlers' | 'instrumentation' | 'propagator' | 'sampling' | 'scope' | 'service'>;
|
|
8
|
+
declare type ConfigOptionsBase = Pick<TraceConfig, 'environment' | 'fetch' | 'handlers' | 'instrumentation' | 'propagator' | 'sampling' | 'scope' | 'service'>;
|
|
9
9
|
|
|
10
10
|
declare type Env = Record<string, string | undefined>;
|
|
11
11
|
|
package/dist/index.d.ts
CHANGED
|
@@ -5,7 +5,7 @@ export declare interface CloudflareConfigOptions {
|
|
|
5
5
|
token: string;
|
|
6
6
|
}
|
|
7
7
|
|
|
8
|
-
declare type ConfigOptionsBase = Pick<TraceConfig, 'fetch' | 'handlers' | 'instrumentation' | 'propagator' | 'sampling' | 'scope' | 'service'>;
|
|
8
|
+
declare type ConfigOptionsBase = Pick<TraceConfig, 'environment' | 'fetch' | 'handlers' | 'instrumentation' | 'propagator' | 'sampling' | 'scope' | 'service'>;
|
|
9
9
|
|
|
10
10
|
declare type Env = Record<string, string | undefined>;
|
|
11
11
|
|
package/dist/index.js
CHANGED
|
@@ -1,12 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
import {
|
|
5
|
-
|
|
6
|
-
import { ExportResultCode as S } from "@opentelemetry/core";
|
|
7
|
-
import { JsonTraceSerializer as y } from "@opentelemetry/otlp-transformer";
|
|
8
|
-
import { RandomIdGenerator as b } from "@opentelemetry/sdk-trace-base";
|
|
9
|
-
class h {
|
|
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 {
|
|
10
6
|
export(t, r) {
|
|
11
7
|
this._sendSpans(t, r);
|
|
12
8
|
}
|
|
@@ -27,36 +23,23 @@ class h {
|
|
|
27
23
|
return t;
|
|
28
24
|
}
|
|
29
25
|
_sendSpans(t, r) {
|
|
30
|
-
const n =
|
|
31
|
-
return console.log(i), r == null ? void 0 : r({ code:
|
|
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 });
|
|
32
28
|
}
|
|
33
29
|
}
|
|
34
30
|
function a(e) {
|
|
35
|
-
e != null && e.attributes && (e.attributes = e.attributes.filter(
|
|
31
|
+
e != null && e.attributes && (e.attributes = e.attributes.filter(v));
|
|
36
32
|
}
|
|
37
|
-
function
|
|
33
|
+
function v(e) {
|
|
38
34
|
return Object.keys(e.value).length > 0;
|
|
39
35
|
}
|
|
40
|
-
|
|
41
|
-
constructor() {
|
|
42
|
-
super(...arguments);
|
|
43
|
-
c(this, "generateTraceId", () => T().toString(16).padStart(32, "0"));
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
function T() {
|
|
47
|
-
let e = BigInt(Date.now());
|
|
48
|
-
const t = crypto.getRandomValues(new Uint8Array(10));
|
|
49
|
-
for (const r of t)
|
|
50
|
-
e <<= BigInt(8), e |= BigInt(r);
|
|
51
|
-
return e;
|
|
52
|
-
}
|
|
53
|
-
async function G(e, t) {
|
|
36
|
+
async function x(e, t) {
|
|
54
37
|
const r = t.LOGFIRE_TOKEN;
|
|
55
38
|
if (!r) {
|
|
56
39
|
console.warn("No token provided, not sending payload to Logfire");
|
|
57
40
|
return;
|
|
58
41
|
}
|
|
59
|
-
const n =
|
|
42
|
+
const n = c(t, void 0, r);
|
|
60
43
|
for (const o of e)
|
|
61
44
|
for (const s of o.logs)
|
|
62
45
|
if (Array.isArray(s.message)) {
|
|
@@ -71,51 +54,52 @@ async function G(e, t) {
|
|
|
71
54
|
},
|
|
72
55
|
method: "POST"
|
|
73
56
|
});
|
|
74
|
-
} catch (
|
|
75
|
-
console.error(
|
|
57
|
+
} catch (f) {
|
|
58
|
+
console.error(f);
|
|
76
59
|
}
|
|
77
60
|
}
|
|
78
61
|
}
|
|
79
|
-
function
|
|
62
|
+
function y(e) {
|
|
80
63
|
return (t) => {
|
|
81
|
-
const {
|
|
64
|
+
const { LOGFIRE_ENVIRONMENT: r, LOGFIRE_TOKEN: n = "" } = t, o = c(t, e.baseUrl, n), s = e.environment ?? r;
|
|
82
65
|
return Object.assign({}, e, {
|
|
66
|
+
environment: s,
|
|
83
67
|
exporter: {
|
|
84
|
-
headers: { Authorization:
|
|
85
|
-
url: `${
|
|
68
|
+
headers: { Authorization: n },
|
|
69
|
+
url: `${o}/v1/traces`
|
|
86
70
|
},
|
|
87
|
-
idGenerator: new
|
|
88
|
-
postProcessor: (
|
|
71
|
+
idGenerator: new u(),
|
|
72
|
+
postProcessor: (i) => g(i)
|
|
89
73
|
});
|
|
90
74
|
};
|
|
91
75
|
}
|
|
92
|
-
function
|
|
76
|
+
function b(e) {
|
|
93
77
|
return (t) => Object.assign({}, e, {
|
|
94
|
-
exporter: new
|
|
95
|
-
idGenerator: new
|
|
78
|
+
exporter: new S(),
|
|
79
|
+
idGenerator: new u()
|
|
96
80
|
});
|
|
97
81
|
}
|
|
98
82
|
function E(e, t) {
|
|
99
|
-
return
|
|
83
|
+
return l(e, y(t));
|
|
100
84
|
}
|
|
101
|
-
function
|
|
102
|
-
return
|
|
85
|
+
function _(e, t) {
|
|
86
|
+
return l(e, b(t));
|
|
103
87
|
}
|
|
104
|
-
const
|
|
105
|
-
function
|
|
88
|
+
const A = E;
|
|
89
|
+
function g(e) {
|
|
106
90
|
for (const t of e) {
|
|
107
91
|
for (const r of Object.keys(t.attributes)) {
|
|
108
92
|
const n = t.attributes[r];
|
|
109
93
|
n == null && delete t.attributes[r];
|
|
110
94
|
}
|
|
111
|
-
Object.assign(t.attributes,
|
|
95
|
+
Object.assign(t.attributes, p(t.attributes));
|
|
112
96
|
}
|
|
113
97
|
return e;
|
|
114
98
|
}
|
|
115
99
|
export {
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
100
|
+
x as exportTailEventsToLogfire,
|
|
101
|
+
b as getTailConfig,
|
|
102
|
+
A as instrument,
|
|
119
103
|
E as instrumentInProcess,
|
|
120
|
-
|
|
104
|
+
_ as instrumentTail
|
|
121
105
|
};
|
package/package.json
CHANGED
|
@@ -22,7 +22,7 @@
|
|
|
22
22
|
"stats",
|
|
23
23
|
"monitoring"
|
|
24
24
|
],
|
|
25
|
-
"version": "0.
|
|
25
|
+
"version": "0.5.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
|
+
"@pydantic/otel-cf-workers": "^1.0.0-rc.53"
|
|
54
54
|
},
|
|
55
55
|
"devDependencies": {
|
|
56
56
|
"@cloudflare/workers-types": "4.20250311.0",
|