@pydantic/logfire-cf-workers 0.7.0 → 0.8.1
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 +27 -2
- package/dist/index.cjs +1 -1
- package/dist/index.d.cts +5 -0
- package/dist/index.d.ts +5 -0
- package/dist/index.js +20 -20
- package/package.json +5 -1
package/README.md
CHANGED
|
@@ -1,5 +1,30 @@
|
|
|
1
|
-
# Pydantic Logfire —
|
|
1
|
+
# Pydantic Logfire — JavaScript SDK
|
|
2
2
|
|
|
3
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.
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
What sets Logfire apart:
|
|
6
|
+
|
|
7
|
+
- **Simple and Powerful:** Logfire's dashboard is simple relative to the power it provides, ensuring your entire engineering team will actually use it.
|
|
8
|
+
- **SQL:** Query your data using standard SQL — all the control and (for many) nothing new to learn. Using SQL also means you can query your data with existing BI tools and database querying libraries.
|
|
9
|
+
- **OpenTelemetry:** Logfire is an opinionated wrapper around OpenTelemetry, allowing you to leverage existing tooling, infrastructure, and instrumentation for many common packages, and enabling support for virtually any language.
|
|
10
|
+
|
|
11
|
+
See the [documentation](https://logfire.pydantic.dev/docs/) for more information.
|
|
12
|
+
|
|
13
|
+
**Feel free to report issues and ask any questions about Logfire in this repository!**
|
|
14
|
+
|
|
15
|
+
This repo contains the JavaScript Cloudflare SDK; the server application for recording and displaying data is closed source.
|
|
16
|
+
|
|
17
|
+
If you need to instrument your Node.js application, see the [`logfire` package](https://www.npmjs.com/package/logfire).
|
|
18
|
+
If you need to instrument your browser application, see the [Logfire Browser package](https://www.npmjs.com/package/@pydantic/logfire-browser).
|
|
19
|
+
|
|
20
|
+
## Basic usage
|
|
21
|
+
|
|
22
|
+
See the [cf-worker example](https://github.com/pydantic/logfire-js/tree/main/examples/cf-worker) for a primer.
|
|
23
|
+
|
|
24
|
+
## Contributing
|
|
25
|
+
|
|
26
|
+
See [CONTRIBUTING.md](https://github.com/pydantic/logfire-js/blob/main/CONTRIBUTING.md) for development instructions.
|
|
27
|
+
|
|
28
|
+
## License
|
|
29
|
+
|
|
30
|
+
MIT
|
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
|
|
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
|
|
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
|
|
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:
|
|
54
|
-
console.log(`Logfire: ${n} >> ${
|
|
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 =
|
|
81
|
-
return console.log(
|
|
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
|
|
99
|
-
if (Array.isArray(
|
|
100
|
-
for (const
|
|
101
|
-
if ("resourceSpans" in
|
|
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(
|
|
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),
|
|
119
|
-
return Object.assign({}, t, {
|
|
120
|
-
additionalSpanProcessors:
|
|
121
|
-
environment:
|
|
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
|
|
140
|
+
function P(t, e) {
|
|
141
141
|
return p(t, O(e));
|
|
142
142
|
}
|
|
143
|
-
const
|
|
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,
|
|
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
|
-
|
|
157
|
+
_ as instrument,
|
|
158
158
|
C as instrumentInProcess,
|
|
159
|
-
|
|
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.
|
|
29
|
+
"version": "0.8.1",
|
|
26
30
|
"type": "module",
|
|
27
31
|
"main": "./dist/index.cjs",
|
|
28
32
|
"module": "./dist/index.js",
|