@pydantic/logfire-cf-workers 0.4.4 → 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.js +31 -48
- package/package.json +1 -1
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.js
CHANGED
|
@@ -1,12 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
var m = (e, t, r) => t in e ? d(e, t, { enumerable: !0, configurable: !0, writable: !0, value: r }) : e[t] = r;
|
|
3
|
-
var c = (e, t, r) => m(e, typeof t != "symbol" ? t + "" : t, r);
|
|
4
|
-
import { resolveBaseUrl as u, serializeAttributes as g } from "@pydantic/logfire-api";
|
|
1
|
+
import { resolveBaseUrl as c, ULIDGenerator as u, serializeAttributes as p } from "@pydantic/logfire-api";
|
|
5
2
|
import { instrument as l } from "@pydantic/otel-cf-workers";
|
|
6
|
-
import { ExportResultCode as
|
|
7
|
-
import { JsonTraceSerializer as
|
|
8
|
-
|
|
9
|
-
class b {
|
|
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 b {
|
|
|
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", () => O().toString(16).padStart(32, "0"));
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
function O() {
|
|
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 k(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,52 +54,52 @@ async function k(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 { LOGFIRE_ENVIRONMENT: r, LOGFIRE_TOKEN: n = "" } = t, o =
|
|
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, {
|
|
83
66
|
environment: s,
|
|
84
67
|
exporter: {
|
|
85
68
|
headers: { Authorization: n },
|
|
86
69
|
url: `${o}/v1/traces`
|
|
87
70
|
},
|
|
88
|
-
idGenerator: new
|
|
89
|
-
postProcessor: (i) =>
|
|
71
|
+
idGenerator: new u(),
|
|
72
|
+
postProcessor: (i) => g(i)
|
|
90
73
|
});
|
|
91
74
|
};
|
|
92
75
|
}
|
|
93
|
-
function
|
|
76
|
+
function b(e) {
|
|
94
77
|
return (t) => Object.assign({}, e, {
|
|
95
|
-
exporter: new
|
|
96
|
-
idGenerator: new
|
|
78
|
+
exporter: new S(),
|
|
79
|
+
idGenerator: new u()
|
|
97
80
|
});
|
|
98
81
|
}
|
|
99
|
-
function
|
|
100
|
-
return l(e,
|
|
82
|
+
function E(e, t) {
|
|
83
|
+
return l(e, y(t));
|
|
101
84
|
}
|
|
102
|
-
function
|
|
103
|
-
return l(e,
|
|
85
|
+
function _(e, t) {
|
|
86
|
+
return l(e, b(t));
|
|
104
87
|
}
|
|
105
|
-
const
|
|
106
|
-
function
|
|
88
|
+
const A = E;
|
|
89
|
+
function g(e) {
|
|
107
90
|
for (const t of e) {
|
|
108
91
|
for (const r of Object.keys(t.attributes)) {
|
|
109
92
|
const n = t.attributes[r];
|
|
110
93
|
n == null && delete t.attributes[r];
|
|
111
94
|
}
|
|
112
|
-
Object.assign(t.attributes,
|
|
95
|
+
Object.assign(t.attributes, p(t.attributes));
|
|
113
96
|
}
|
|
114
97
|
return e;
|
|
115
98
|
}
|
|
116
99
|
export {
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
100
|
+
x as exportTailEventsToLogfire,
|
|
101
|
+
b as getTailConfig,
|
|
102
|
+
A as instrument,
|
|
103
|
+
E as instrumentInProcess,
|
|
104
|
+
_ as instrumentTail
|
|
122
105
|
};
|