@pydantic/logfire-cf-workers 2.0.21 → 2.0.23
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.d.ts +18 -19
- package/dist/index.js +1 -1
- package/package.json +3 -3
package/dist/index.d.ts
CHANGED
|
@@ -1,43 +1,42 @@
|
|
|
1
1
|
import { SpanProcessor } from "@opentelemetry/sdk-trace-base";
|
|
2
2
|
import { TraceConfig } from "@pydantic/otel-cf-workers";
|
|
3
3
|
import { Level, LogfireAttributeScrubber, NoopAttributeScrubber, ScrubbingOptions, ULIDGenerator, configureLogfireApi, debug, error, fatal, info, log, logfireApiConfig, notice, reportError, resolveBaseUrl, resolveSendToLogfire, serializeAttributes, span, startPendingSpan, startSpan, trace, warning, withSettings, withTags } from "logfire";
|
|
4
|
-
|
|
5
4
|
//#region src/exportTailEventsToLogfire.d.ts
|
|
6
|
-
interface TraceItem {
|
|
5
|
+
export interface TraceItem {
|
|
7
6
|
logs: {
|
|
8
7
|
message: unknown[];
|
|
9
8
|
}[];
|
|
10
9
|
}
|
|
11
|
-
declare function exportTailEventsToLogfire(events: TraceItem[], env: Record<string, string | undefined>): Promise<Response | undefined>;
|
|
10
|
+
export declare function exportTailEventsToLogfire(events: TraceItem[], env: Record<string, string | undefined>): Promise<Response | undefined>;
|
|
12
11
|
//#endregion
|
|
13
12
|
//#region src/index.d.ts
|
|
14
13
|
type Env = unknown;
|
|
15
14
|
type DOClass<Env = unknown> = new (state: DurableObjectState, env: Env) => DurableObject;
|
|
16
15
|
type ConfigOptionsBase = Pick<TraceConfig, "environment" | "fetch" | "handlers" | "instrumentation" | "propagator" | "sampling" | "scope" | "service">;
|
|
17
|
-
interface InProcessConfigOptions extends ConfigOptionsBase {
|
|
16
|
+
export interface InProcessConfigOptions extends ConfigOptionsBase {
|
|
18
17
|
/**
|
|
19
|
-
|
|
20
|
-
|
|
18
|
+
* Additional span processors to add to the tracer provider.
|
|
19
|
+
*/
|
|
21
20
|
additionalSpanProcessors?: SpanProcessor[];
|
|
22
21
|
baseUrl?: string;
|
|
23
22
|
/**
|
|
24
|
-
|
|
25
|
-
|
|
23
|
+
* Whether to log the spans to the console in addition to sending them to the Logfire API.
|
|
24
|
+
*/
|
|
26
25
|
console?: boolean;
|
|
27
26
|
/**
|
|
28
|
-
|
|
29
|
-
|
|
27
|
+
* Options for scrubbing sensitive data. Set to False to disable.
|
|
28
|
+
*/
|
|
30
29
|
scrubbing?: false | ScrubbingOptions;
|
|
31
30
|
}
|
|
32
|
-
interface TailConfigOptions extends ConfigOptionsBase {}
|
|
33
|
-
declare function getTailConfig(config: TailConfigOptions): (env: Env) => TraceConfig;
|
|
34
|
-
declare function instrumentInProcess<T>(handler: T, config: InProcessConfigOptions): T;
|
|
35
|
-
declare function instrumentDO<Env = unknown, T extends DOClass<Env> = DOClass<Env>>(doClass: T, config: InProcessConfigOptions): T;
|
|
36
|
-
declare function instrumentTail<T>(handler: T, config: TailConfigOptions): T;
|
|
31
|
+
export interface TailConfigOptions extends ConfigOptionsBase {}
|
|
32
|
+
export declare function getTailConfig(config: TailConfigOptions): (env: Env) => TraceConfig;
|
|
33
|
+
export declare function instrumentInProcess<T>(handler: T, config: InProcessConfigOptions): T;
|
|
34
|
+
export declare function instrumentDO<Env = unknown, T extends DOClass<Env> = DOClass<Env>>(doClass: T, config: InProcessConfigOptions): T;
|
|
35
|
+
export declare function instrumentTail<T>(handler: T, config: TailConfigOptions): T;
|
|
37
36
|
/**
|
|
38
|
-
* Alias for `instrumentInProcess` to maintain compatibility with previous versions.
|
|
39
|
-
*/
|
|
40
|
-
declare const instrument: typeof instrumentInProcess;
|
|
37
|
+
* Alias for `instrumentInProcess` to maintain compatibility with previous versions.
|
|
38
|
+
*/
|
|
39
|
+
export declare const instrument: typeof instrumentInProcess;
|
|
41
40
|
declare const defaultExport: {
|
|
42
41
|
exportTailEventsToLogfire: typeof exportTailEventsToLogfire;
|
|
43
42
|
Level: typeof Level;
|
|
@@ -70,4 +69,4 @@ declare const defaultExport: {
|
|
|
70
69
|
withTags: typeof withTags;
|
|
71
70
|
};
|
|
72
71
|
//#endregion
|
|
73
|
-
export {
|
|
72
|
+
export { defaultExport as default };
|
package/dist/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{SimpleSpanProcessor as e}from"@opentelemetry/sdk-trace-base";import{OTLP_EXPORTER_USER_AGENT as t,instrument as n,instrumentDO as r}from"@pydantic/otel-cf-workers";import{Level as i,LogfireAttributeScrubber as a,NoopAttributeScrubber as o,ULIDGenerator as s,configureLogfireApi as c,debug as l,error as u,fatal as d,info as f,log as p,logfireApiConfig as m,notice as h,reportError as g,resolveBaseUrl as _,resolveSendToLogfire as v,serializeAttributes as y,span as b,startPendingSpan as x,startSpan as S,trace as C,warning as w,withSettings as T,withTags as E}from"logfire";import{ExportResultCode as D,hrTimeToMicroseconds as O}from"@opentelemetry/core";import{JsonTraceSerializer as k}from"@opentelemetry/otlp-transformer";const A=`logfire-js/2.0.
|
|
1
|
+
import{SimpleSpanProcessor as e}from"@opentelemetry/sdk-trace-base";import{OTLP_EXPORTER_USER_AGENT as t,instrument as n,instrumentDO as r}from"@pydantic/otel-cf-workers";import{Level as i,LogfireAttributeScrubber as a,NoopAttributeScrubber as o,ULIDGenerator as s,configureLogfireApi as c,debug as l,error as u,fatal as d,info as f,log as p,logfireApiConfig as m,notice as h,reportError as g,resolveBaseUrl as _,resolveSendToLogfire as v,serializeAttributes as y,span as b,startPendingSpan as x,startSpan as S,trace as C,warning as w,withSettings as T,withTags as E}from"logfire";import{ExportResultCode as D,hrTimeToMicroseconds as O}from"@opentelemetry/core";import{JsonTraceSerializer as k}from"@opentelemetry/otlp-transformer";const A=`logfire-js/2.0.23`;async function j(e,n){let r=n.LOGFIRE_TOKEN;if(r===void 0||r===``){console.warn(`No token provided, not sending payload to Logfire`);return}let i=_(n,void 0,r),a=M(e);if(a!==null)try{return await fetch(`${i}/v1/traces`,{body:JSON.stringify(a),headers:{Authorization:r,"Content-Type":`application/json`,"User-Agent":`${A} ${t}`},method:`POST`})}catch(e){console.error(e);return}}function M(e){for(let t of e)for(let e of t.logs)if(Array.isArray(e.message)){for(let t of e.message)if(N(t))return t}return null}function N(e){return typeof e==`object`&&!!e&&`resourceSpans`in e}const P={1:`trace`,5:`debug`,9:`info`,10:`notice`,13:`warning`,17:`error`,21:`fatal`};var F=class{export(e,t){this.sendSpans(e,t)}async forceFlush(){return Promise.resolve()}async shutdown(){return this.sendSpans([]),this.forceFlush()}exportInfo(e){return{attributes:e.attributes,duration:O(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:O(e.startTime),traceId:e.spanContext().traceId,traceState:e.spanContext().traceState?.serialize()}}sendSpans(e,t){for(let t of e){let e=P[t.attributes[`logfire.level_num`]]??`info`,{attributes:n,name:r,...i}=this.exportInfo(t);console.log(`Logfire: ${e} >> ${r}`),console.log(`Attributes:`),console.log(JSON.stringify(n,null,2)),console.log(`---`),console.log(`Span details:`),console.log(JSON.stringify(i,null,2)),console.log(`---`)}t&&t({code:D.SUCCESS})}},I=class{export(e,t){this.sendSpans(e,t)}async shutdown(){return this.sendSpans([]),Promise.resolve()}cleanNullValues(e){if(!e.resourceSpans)return e;for(let t of e.resourceSpans){L(t.resource);for(let e of t.scopeSpans){e.scope&&L(e.scope);for(let t of e.spans??[])L(t)}}return e}sendSpans(e,t){let n=k.serializeRequest(e),r=new TextDecoder().decode(n),i=JSON.parse(r),a=this.cleanNullValues(i);return console.log(a),t?.({code:D.SUCCESS})}};function L(e){e?.attributes&&(e.attributes=e.attributes.filter(R))}function R(e){return Object.keys(e.value).length>0}function z(e,t){if(typeof e!=`object`||!e)return;let n=e[t];return typeof n==`string`?n:void 0}function B(e){e.scrubbing!==void 0&&c({scrubbing:e.scrubbing})}function V(t){return n=>{let r=z(n,`LOGFIRE_TOKEN`)??``,i=z(n,`LOGFIRE_ENVIRONMENT`),a=_(n,t.baseUrl,r),o=t.environment??i,c=[...t.additionalSpanProcessors??[]];return t.console===!0&&c.push(new e(new F)),{...t,additionalSpanProcessors:c,exporter:{headers:{Authorization:r},url:`${a}/v1/traces`,userAgent:A},idGenerator:new s,postProcessor:e=>q(e),...o===void 0?{}:{environment:o}}}}function H(e){return t=>({...e,exporter:new I,idGenerator:new s})}function U(e,t){return B(t),n(e,V(t))}function W(e,t){return B(t),r(e,V(t))}function G(e,t){return n(e,H(t))}const K=U;function q(e){for(let t of e){for(let e of Object.keys(t.attributes))t.attributes[e]??delete t.attributes[e];let e=y(t.attributes);for(let[n,r]of Object.entries(e))Object.defineProperty(t.attributes,n,{configurable:!0,enumerable:!0,value:r,writable:!0})}return e}const J={exportTailEventsToLogfire:j,configureLogfireApi:c,debug:l,error:u,fatal:d,getTailConfig:H,info:f,instrument:K,instrumentDO:W,instrumentInProcess:U,instrumentTail:G,Level:i,log:p,logfireApiConfig:m,LogfireAttributeScrubber:a,NoopAttributeScrubber:o,notice:h,reportError:g,resolveBaseUrl:_,resolveSendToLogfire:v,serializeAttributes:y,span:b,startPendingSpan:x,startSpan:S,trace:C,ULIDGenerator:s,warning:w,withSettings:T,withTags:E};export{J as default,j as exportTailEventsToLogfire,H as getTailConfig,K as instrument,W as instrumentDO,U as instrumentInProcess,G as instrumentTail};
|
package/package.json
CHANGED
|
@@ -26,7 +26,7 @@
|
|
|
26
26
|
"stats",
|
|
27
27
|
"monitoring"
|
|
28
28
|
],
|
|
29
|
-
"version": "2.0.
|
|
29
|
+
"version": "2.0.23",
|
|
30
30
|
"type": "module",
|
|
31
31
|
"main": "./dist/index.js",
|
|
32
32
|
"module": "./dist/index.js",
|
|
@@ -38,8 +38,8 @@
|
|
|
38
38
|
}
|
|
39
39
|
},
|
|
40
40
|
"dependencies": {
|
|
41
|
-
"
|
|
42
|
-
"
|
|
41
|
+
"@pydantic/otel-cf-workers": "2.1.4",
|
|
42
|
+
"logfire": "0.22.10"
|
|
43
43
|
},
|
|
44
44
|
"devDependencies": {
|
|
45
45
|
"@cloudflare/workers-types": "4.20260528.1",
|