@pydantic/logfire-cf-workers 0.11.7 → 0.11.9

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
@@ -21,6 +21,13 @@ If you need to instrument your browser application, see the [Logfire Browser pac
21
21
 
22
22
  See the [cf-worker example](https://github.com/pydantic/logfire-js/tree/main/examples/cf-worker) for a primer.
23
23
 
24
+ ## Managed Variables
25
+
26
+ Cloudflare Workers can use local managed variables from `logfire/vars` when the
27
+ worker already depends on the core `logfire` package. Remote managed variables
28
+ need a Logfire API key, so only configure them when the key is stored as a
29
+ Worker secret and never sent to a browser client.
30
+
24
31
  ## Contributing
25
32
 
26
33
  See [CONTRIBUTING.md](https://github.com/pydantic/logfire-js/blob/main/CONTRIBUTING.md) for development instructions.
package/dist/index.cjs CHANGED
@@ -1 +1 @@
1
- "use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const v=require("@opentelemetry/sdk-trace-base"),g=require("@pydantic/otel-cf-workers"),r=require("logfire"),c=require("@opentelemetry/core"),m=require("@opentelemetry/otlp-transformer");async function d(t,e){const o=e.LOGFIRE_TOKEN;if(!o){console.warn("No token provided, not sending payload to Logfire");return}const n=r.resolveBaseUrl(e,void 0,o);for(const s of t)for(const a of s.logs)if(Array.isArray(a.message)){for(const i of a.message)if("resourceSpans"in i)try{return await fetch(`${n}/v1/traces`,{body:JSON.stringify(i),headers:{Authorization:o,"Content-Type":"application/json"},method:"POST"})}catch(u){console.error(u)}}}const T=Object.freeze(Object.defineProperty({__proto__:null,exportTailEventsToLogfire:d},Symbol.toStringTag,{value:"Module"})),E={1:"trace",5:"debug",9:"info",10:"notice",13:"warning",17:"error",21:"fatal"};class L{export(e,o){this.sendSpans(e,o)}forceFlush(){return Promise.resolve()}shutdown(){return this.sendSpans([]),this.forceFlush()}exportInfo(e){var o;return{attributes:e.attributes,duration:c.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:c.hrTimeToMicroseconds(e.startTime),traceId:e.spanContext().traceId,traceState:(o=e.spanContext().traceState)==null?void 0:o.serialize()}}sendSpans(e,o){for(const n of e){const s=E[n.attributes["logfire.level_num"]]??"info",{attributes:a,name:i,...u}=this.exportInfo(n);console.log(`Logfire: ${s} >> ${i}`),console.log("Attributes:"),console.log(JSON.stringify(a,null,2)),console.log("---"),console.log("Span details:"),console.log(JSON.stringify(u,null,2)),console.log("---")}o&&o({code:c.ExportResultCode.SUCCESS})}}class h{export(e,o){this._sendSpans(e,o)}shutdown(){return this._sendSpans([]),Promise.resolve()}_cleanNullValues(e){if(!e.resourceSpans)return e;for(const o of e.resourceSpans){l(o.resource);for(const n of o.scopeSpans){n.scope&&l(n.scope);for(const s of n.spans??[])l(s)}}return e}_sendSpans(e,o){const n=m.JsonTraceSerializer.serializeRequest(e),s=new TextDecoder().decode(n),a=JSON.parse(s),i=this._cleanNullValues(a);return console.log(i),o==null?void 0:o({code:c.ExportResultCode.SUCCESS})}}function l(t){t!=null&&t.attributes&&(t.attributes=t.attributes.filter(x))}function x(t){return Object.keys(t.value).length>0}function y(t){return e=>{const{LOGFIRE_ENVIRONMENT:o,LOGFIRE_TOKEN:n=""}=e,s=r.resolveBaseUrl(e,t.baseUrl,n),a=t.environment??o,i=t.additionalSpanProcessors??[];return t.console&&i.push(new v.SimpleSpanProcessor(new L)),Object.assign({},t,{additionalSpanProcessors:i,environment:a,exporter:{headers:{Authorization:n},url:`${s}/v1/traces`},idGenerator:new r.ULIDGenerator,postProcessor:u=>A(u)})}}function f(t){return e=>Object.assign({},t,{exporter:new h,idGenerator:new r.ULIDGenerator})}function p(t,e){return e.scrubbing!==void 0&&r.configureLogfireApi({scrubbing:e.scrubbing}),g.instrument(t,y(e))}function b(t,e){return g.instrument(t,f(e))}const S=p;function A(t){for(const e of t){for(const o of Object.keys(e.attributes)){const n=e.attributes[o];n==null&&delete e.attributes[o]}Object.assign(e.attributes,r.serializeAttributes(e.attributes))}return t}const C={...T,configureLogfireApi:r.configureLogfireApi,debug:r.debug,error:r.error,fatal:r.fatal,getTailConfig:f,info:r.info,instrument:S,instrumentInProcess:p,instrumentTail:b,Level:r.Level,log:r.log,logfireApiConfig:r.logfireApiConfig,LogfireAttributeScrubber:r.LogfireAttributeScrubber,NoopAttributeScrubber:r.NoopAttributeScrubber,notice:r.notice,reportError:r.reportError,resolveBaseUrl:r.resolveBaseUrl,resolveSendToLogfire:r.resolveSendToLogfire,serializeAttributes:r.serializeAttributes,span:r.span,startSpan:r.startSpan,trace:r.trace,ULIDGenerator:r.ULIDGenerator,warning:r.warning};exports.default=C;exports.exportTailEventsToLogfire=d;exports.getTailConfig=f;exports.instrument=S;exports.instrumentInProcess=p;exports.instrumentTail=b;
1
+ Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:`Module`}});let e=require(`@opentelemetry/sdk-trace-base`),t=require(`@pydantic/otel-cf-workers`),n=require(`logfire`),r=require(`@opentelemetry/core`),i=require(`@opentelemetry/otlp-transformer`);async function a(e,t){let r=t.LOGFIRE_TOKEN;if(r===void 0||r===``){console.warn(`No token provided, not sending payload to Logfire`);return}let i=(0,n.resolveBaseUrl)(t,void 0,r),a=o(e);if(a!==null)try{return await fetch(`${i}/v1/traces`,{body:JSON.stringify(a),headers:{Authorization:r,"Content-Type":`application/json`},method:`POST`})}catch(e){console.error(e);return}}function o(e){for(let t of e)for(let e of t.logs)if(Array.isArray(e.message)){for(let t of e.message)if(s(t))return t}return null}function s(e){return typeof e==`object`&&!!e&&`resourceSpans`in e}const c={1:`trace`,5:`debug`,9:`info`,10:`notice`,13:`warning`,17:`error`,21:`fatal`};var l=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:(0,r.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:(0,r.hrTimeToMicroseconds)(e.startTime),traceId:e.spanContext().traceId,traceState:e.spanContext().traceState?.serialize()}}sendSpans(e,t){for(let t of e){let e=c[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:r.ExportResultCode.SUCCESS})}},u=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){d(t.resource);for(let e of t.scopeSpans){e.scope&&d(e.scope);for(let t of e.spans??[])d(t)}}return e}_sendSpans(e,t){let n=i.JsonTraceSerializer.serializeRequest(e),a=new TextDecoder().decode(n),o=JSON.parse(a),s=this._cleanNullValues(o);return console.log(s),t?.({code:r.ExportResultCode.SUCCESS})}};function d(e){e?.attributes&&(e.attributes=e.attributes.filter(f))}function f(e){return Object.keys(e.value).length>0}function p(t){return r=>{let{LOGFIRE_ENVIRONMENT:i,LOGFIRE_TOKEN:a=``}=r,o=(0,n.resolveBaseUrl)(r,t.baseUrl,a),s=t.environment??i,c=t.additionalSpanProcessors??[];return t.console===!0&&c.push(new e.SimpleSpanProcessor(new l)),{...t,additionalSpanProcessors:c,exporter:{headers:{Authorization:a},url:`${o}/v1/traces`},idGenerator:new n.ULIDGenerator,postProcessor:e=>v(e),...s===void 0?{}:{environment:s}}}}function m(e){return t=>({...e,exporter:new u,idGenerator:new n.ULIDGenerator})}function h(e,r){return r.scrubbing!==void 0&&(0,n.configureLogfireApi)({scrubbing:r.scrubbing}),(0,t.instrument)(e,p(r))}function g(e,n){return(0,t.instrument)(e,m(n))}const _=h;function v(e){for(let t of e){for(let e of Object.keys(t.attributes))t.attributes[e]??delete t.attributes[e];Object.assign(t.attributes,(0,n.serializeAttributes)(t.attributes))}return e}const y={exportTailEventsToLogfire:a,configureLogfireApi:n.configureLogfireApi,debug:n.debug,error:n.error,fatal:n.fatal,getTailConfig:m,info:n.info,instrument:_,instrumentInProcess:h,instrumentTail:g,Level:n.Level,log:n.log,logfireApiConfig:n.logfireApiConfig,LogfireAttributeScrubber:n.LogfireAttributeScrubber,NoopAttributeScrubber:n.NoopAttributeScrubber,notice:n.notice,reportError:n.reportError,resolveBaseUrl:n.resolveBaseUrl,resolveSendToLogfire:n.resolveSendToLogfire,serializeAttributes:n.serializeAttributes,span:n.span,startSpan:n.startSpan,trace:n.trace,ULIDGenerator:n.ULIDGenerator,warning:n.warning};exports.default=y,exports.exportTailEventsToLogfire=a,exports.getTailConfig=m,exports.instrument=_,exports.instrumentInProcess=h,exports.instrumentTail=g;
package/dist/index.d.cts CHANGED
@@ -1,111 +1,67 @@
1
- import { configureLogfireApi } from 'logfire';
2
- import { debug } from 'logfire';
3
- import { error } from 'logfire';
4
- import { fatal } from 'logfire';
5
- import { info } from 'logfire';
6
- import { log } from 'logfire';
7
- import { LogfireApiConfig } from 'logfire';
8
- import { LogfireAttributeScrubber } from 'logfire';
9
- import { NoopAttributeScrubber } from 'logfire';
10
- import { notice } from 'logfire';
11
- import { reportError as reportError_2 } from 'logfire';
12
- import { resolveBaseUrl } from 'logfire';
13
- import { resolveSendToLogfire } from 'logfire';
14
- import { ScrubbingOptions } from 'logfire';
15
- import { serializeAttributes } from 'logfire';
16
- import { span } from 'logfire';
17
- import { SpanProcessor } from '@opentelemetry/sdk-trace-base';
18
- import { startSpan } from 'logfire';
19
- import { trace } from 'logfire';
20
- import { TraceConfig } from '@pydantic/otel-cf-workers';
21
- import { ULIDGenerator } from 'logfire';
22
- import { warning } from 'logfire';
23
-
24
- declare type ConfigOptionsBase = Pick<TraceConfig, 'environment' | 'fetch' | 'handlers' | 'instrumentation' | 'propagator' | 'sampling' | 'scope' | 'service'>;
25
-
26
- declare const _default: {
27
- configureLogfireApi: typeof configureLogfireApi;
28
- debug: typeof debug;
29
- error: typeof error;
30
- fatal: typeof fatal;
31
- getTailConfig: typeof getTailConfig;
32
- info: typeof info;
33
- instrument: typeof instrumentInProcess;
34
- instrumentInProcess: typeof instrumentInProcess;
35
- instrumentTail: typeof instrumentTail;
36
- Level: {
37
- Trace: 1;
38
- Debug: 5;
39
- Info: 9;
40
- Notice: 10;
41
- Warning: 13;
42
- Error: 17;
43
- Fatal: 21;
44
- };
45
- log: typeof log;
46
- logfireApiConfig: LogfireApiConfig;
47
- LogfireAttributeScrubber: typeof LogfireAttributeScrubber;
48
- NoopAttributeScrubber: typeof NoopAttributeScrubber;
49
- notice: typeof notice;
50
- reportError: typeof reportError_2;
51
- resolveBaseUrl: typeof resolveBaseUrl;
52
- resolveSendToLogfire: typeof resolveSendToLogfire;
53
- serializeAttributes: typeof serializeAttributes;
54
- span: typeof span;
55
- startSpan: typeof startSpan;
56
- trace: typeof trace;
57
- ULIDGenerator: typeof ULIDGenerator;
58
- warning: typeof warning;
59
- exportTailEventsToLogfire(events: exportTailEventsExports.TraceItem[], env: Record<string, string | undefined>): Promise<Response | undefined>;
60
- };
61
- export default _default;
62
-
63
- declare type Env_2 = Record<string, string | undefined>;
64
-
65
- declare namespace exportTailEventsExports {
66
- export {
67
- exportTailEventsToLogfire,
68
- TraceItem_2 as TraceItem
69
- }
70
- }
71
-
72
- export declare function exportTailEventsToLogfire(events: TraceItem_2[], env: Record<string, string | undefined>): Promise<Response | undefined>;
73
-
74
- export declare function getTailConfig(config: TailConfigOptions): (env: Env_2) => TraceConfig;
75
-
76
- export declare interface InProcessConfigOptions extends ConfigOptionsBase {
77
- /**
78
- * Additional span processors to add to the tracer provider.
79
- */
80
- additionalSpanProcessors?: SpanProcessor[];
81
- baseUrl?: string;
82
- /**
83
- * Whether to log the spans to the console in addition to sending them to the Logfire API.
84
- */
85
- console?: boolean;
86
- /**
87
- * Options for scrubbing sensitive data. Set to False to disable.
88
- */
89
- scrubbing?: false | ScrubbingOptions;
90
- }
91
-
92
- /**
93
- * Alias for `instrumentInProcess` to maintain compatibility with previous versions.
94
- */
95
- export declare const instrument: typeof instrumentInProcess;
96
-
97
- export declare function instrumentInProcess<T>(handler: T, config: InProcessConfigOptions): T;
98
-
99
- export declare function instrumentTail<T>(handler: T, config: TailConfigOptions): T;
100
-
101
- export declare interface TailConfigOptions extends ConfigOptionsBase {
102
- }
103
-
104
- declare interface TraceItem_2 {
105
- logs: {
106
- message: any[];
107
- }[];
108
- }
109
- export { TraceItem_2 as TraceItem }
110
-
111
- export { }
1
+ import { SpanProcessor } from "@opentelemetry/sdk-trace-base";
2
+ import { TraceConfig } from "@pydantic/otel-cf-workers";
3
+ import { Level, LogfireAttributeScrubber, NoopAttributeScrubber, ScrubbingOptions, ULIDGenerator, configureLogfireApi, debug, error, fatal, info, log, logfireApiConfig, notice, reportError, resolveBaseUrl, resolveSendToLogfire, serializeAttributes, span, startSpan, trace, warning } from "logfire";
4
+
5
+ //#region src/exportTailEventsToLogfire.d.ts
6
+ interface TraceItem {
7
+ logs: {
8
+ message: unknown[];
9
+ }[];
10
+ }
11
+ declare function exportTailEventsToLogfire(events: TraceItem[], env: Record<string, string | undefined>): Promise<Response | undefined>;
12
+ //#endregion
13
+ //#region src/index.d.ts
14
+ type Env = Record<string, string | undefined>;
15
+ type ConfigOptionsBase = Pick<TraceConfig, "environment" | "fetch" | "handlers" | "instrumentation" | "propagator" | "sampling" | "scope" | "service">;
16
+ interface InProcessConfigOptions extends ConfigOptionsBase {
17
+ /**
18
+ * Additional span processors to add to the tracer provider.
19
+ */
20
+ additionalSpanProcessors?: SpanProcessor[];
21
+ baseUrl?: string;
22
+ /**
23
+ * Whether to log the spans to the console in addition to sending them to the Logfire API.
24
+ */
25
+ console?: boolean;
26
+ /**
27
+ * Options for scrubbing sensitive data. Set to False to disable.
28
+ */
29
+ scrubbing?: false | ScrubbingOptions;
30
+ }
31
+ interface TailConfigOptions extends ConfigOptionsBase {}
32
+ declare function getTailConfig(config: TailConfigOptions): (env: Env) => TraceConfig;
33
+ declare function instrumentInProcess<T>(handler: T, config: InProcessConfigOptions): T;
34
+ declare function instrumentTail<T>(handler: T, config: TailConfigOptions): T;
35
+ /**
36
+ * Alias for `instrumentInProcess` to maintain compatibility with previous versions.
37
+ */
38
+ declare const instrument: typeof instrumentInProcess;
39
+ declare const defaultExport: {
40
+ exportTailEventsToLogfire: typeof exportTailEventsToLogfire;
41
+ Level: typeof Level;
42
+ LogfireAttributeScrubber: typeof LogfireAttributeScrubber;
43
+ NoopAttributeScrubber: typeof NoopAttributeScrubber;
44
+ ULIDGenerator: typeof ULIDGenerator;
45
+ configureLogfireApi: typeof configureLogfireApi;
46
+ debug: typeof debug;
47
+ error: typeof error;
48
+ fatal: typeof fatal;
49
+ getTailConfig: typeof getTailConfig;
50
+ info: typeof info;
51
+ instrument: typeof instrument;
52
+ instrumentInProcess: typeof instrumentInProcess;
53
+ instrumentTail: typeof instrumentTail;
54
+ log: typeof log;
55
+ logfireApiConfig: typeof logfireApiConfig;
56
+ notice: typeof notice;
57
+ reportError: typeof reportError;
58
+ resolveBaseUrl: typeof resolveBaseUrl;
59
+ resolveSendToLogfire: typeof resolveSendToLogfire;
60
+ serializeAttributes: typeof serializeAttributes;
61
+ span: typeof span;
62
+ startSpan: typeof startSpan;
63
+ trace: typeof trace;
64
+ warning: typeof warning;
65
+ };
66
+ //#endregion
67
+ export { InProcessConfigOptions, TailConfigOptions, TraceItem, defaultExport as default, exportTailEventsToLogfire, getTailConfig, instrument, instrumentInProcess, instrumentTail };
package/dist/index.d.ts CHANGED
@@ -1,111 +1,67 @@
1
- import { configureLogfireApi } from 'logfire';
2
- import { debug } from 'logfire';
3
- import { error } from 'logfire';
4
- import { fatal } from 'logfire';
5
- import { info } from 'logfire';
6
- import { log } from 'logfire';
7
- import { LogfireApiConfig } from 'logfire';
8
- import { LogfireAttributeScrubber } from 'logfire';
9
- import { NoopAttributeScrubber } from 'logfire';
10
- import { notice } from 'logfire';
11
- import { reportError as reportError_2 } from 'logfire';
12
- import { resolveBaseUrl } from 'logfire';
13
- import { resolveSendToLogfire } from 'logfire';
14
- import { ScrubbingOptions } from 'logfire';
15
- import { serializeAttributes } from 'logfire';
16
- import { span } from 'logfire';
17
- import { SpanProcessor } from '@opentelemetry/sdk-trace-base';
18
- import { startSpan } from 'logfire';
19
- import { trace } from 'logfire';
20
- import { TraceConfig } from '@pydantic/otel-cf-workers';
21
- import { ULIDGenerator } from 'logfire';
22
- import { warning } from 'logfire';
23
-
24
- declare type ConfigOptionsBase = Pick<TraceConfig, 'environment' | 'fetch' | 'handlers' | 'instrumentation' | 'propagator' | 'sampling' | 'scope' | 'service'>;
25
-
26
- declare const _default: {
27
- configureLogfireApi: typeof configureLogfireApi;
28
- debug: typeof debug;
29
- error: typeof error;
30
- fatal: typeof fatal;
31
- getTailConfig: typeof getTailConfig;
32
- info: typeof info;
33
- instrument: typeof instrumentInProcess;
34
- instrumentInProcess: typeof instrumentInProcess;
35
- instrumentTail: typeof instrumentTail;
36
- Level: {
37
- Trace: 1;
38
- Debug: 5;
39
- Info: 9;
40
- Notice: 10;
41
- Warning: 13;
42
- Error: 17;
43
- Fatal: 21;
44
- };
45
- log: typeof log;
46
- logfireApiConfig: LogfireApiConfig;
47
- LogfireAttributeScrubber: typeof LogfireAttributeScrubber;
48
- NoopAttributeScrubber: typeof NoopAttributeScrubber;
49
- notice: typeof notice;
50
- reportError: typeof reportError_2;
51
- resolveBaseUrl: typeof resolveBaseUrl;
52
- resolveSendToLogfire: typeof resolveSendToLogfire;
53
- serializeAttributes: typeof serializeAttributes;
54
- span: typeof span;
55
- startSpan: typeof startSpan;
56
- trace: typeof trace;
57
- ULIDGenerator: typeof ULIDGenerator;
58
- warning: typeof warning;
59
- exportTailEventsToLogfire(events: exportTailEventsExports.TraceItem[], env: Record<string, string | undefined>): Promise<Response | undefined>;
60
- };
61
- export default _default;
62
-
63
- declare type Env_2 = Record<string, string | undefined>;
64
-
65
- declare namespace exportTailEventsExports {
66
- export {
67
- exportTailEventsToLogfire,
68
- TraceItem_2 as TraceItem
69
- }
70
- }
71
-
72
- export declare function exportTailEventsToLogfire(events: TraceItem_2[], env: Record<string, string | undefined>): Promise<Response | undefined>;
73
-
74
- export declare function getTailConfig(config: TailConfigOptions): (env: Env_2) => TraceConfig;
75
-
76
- export declare interface InProcessConfigOptions extends ConfigOptionsBase {
77
- /**
78
- * Additional span processors to add to the tracer provider.
79
- */
80
- additionalSpanProcessors?: SpanProcessor[];
81
- baseUrl?: string;
82
- /**
83
- * Whether to log the spans to the console in addition to sending them to the Logfire API.
84
- */
85
- console?: boolean;
86
- /**
87
- * Options for scrubbing sensitive data. Set to False to disable.
88
- */
89
- scrubbing?: false | ScrubbingOptions;
90
- }
91
-
92
- /**
93
- * Alias for `instrumentInProcess` to maintain compatibility with previous versions.
94
- */
95
- export declare const instrument: typeof instrumentInProcess;
96
-
97
- export declare function instrumentInProcess<T>(handler: T, config: InProcessConfigOptions): T;
98
-
99
- export declare function instrumentTail<T>(handler: T, config: TailConfigOptions): T;
100
-
101
- export declare interface TailConfigOptions extends ConfigOptionsBase {
102
- }
103
-
104
- declare interface TraceItem_2 {
105
- logs: {
106
- message: any[];
107
- }[];
108
- }
109
- export { TraceItem_2 as TraceItem }
110
-
111
- export { }
1
+ import { SpanProcessor } from "@opentelemetry/sdk-trace-base";
2
+ import { TraceConfig } from "@pydantic/otel-cf-workers";
3
+ import { Level, LogfireAttributeScrubber, NoopAttributeScrubber, ScrubbingOptions, ULIDGenerator, configureLogfireApi, debug, error, fatal, info, log, logfireApiConfig, notice, reportError, resolveBaseUrl, resolveSendToLogfire, serializeAttributes, span, startSpan, trace, warning } from "logfire";
4
+
5
+ //#region src/exportTailEventsToLogfire.d.ts
6
+ interface TraceItem {
7
+ logs: {
8
+ message: unknown[];
9
+ }[];
10
+ }
11
+ declare function exportTailEventsToLogfire(events: TraceItem[], env: Record<string, string | undefined>): Promise<Response | undefined>;
12
+ //#endregion
13
+ //#region src/index.d.ts
14
+ type Env = Record<string, string | undefined>;
15
+ type ConfigOptionsBase = Pick<TraceConfig, "environment" | "fetch" | "handlers" | "instrumentation" | "propagator" | "sampling" | "scope" | "service">;
16
+ interface InProcessConfigOptions extends ConfigOptionsBase {
17
+ /**
18
+ * Additional span processors to add to the tracer provider.
19
+ */
20
+ additionalSpanProcessors?: SpanProcessor[];
21
+ baseUrl?: string;
22
+ /**
23
+ * Whether to log the spans to the console in addition to sending them to the Logfire API.
24
+ */
25
+ console?: boolean;
26
+ /**
27
+ * Options for scrubbing sensitive data. Set to False to disable.
28
+ */
29
+ scrubbing?: false | ScrubbingOptions;
30
+ }
31
+ interface TailConfigOptions extends ConfigOptionsBase {}
32
+ declare function getTailConfig(config: TailConfigOptions): (env: Env) => TraceConfig;
33
+ declare function instrumentInProcess<T>(handler: T, config: InProcessConfigOptions): T;
34
+ declare function instrumentTail<T>(handler: T, config: TailConfigOptions): T;
35
+ /**
36
+ * Alias for `instrumentInProcess` to maintain compatibility with previous versions.
37
+ */
38
+ declare const instrument: typeof instrumentInProcess;
39
+ declare const defaultExport: {
40
+ exportTailEventsToLogfire: typeof exportTailEventsToLogfire;
41
+ Level: typeof Level;
42
+ LogfireAttributeScrubber: typeof LogfireAttributeScrubber;
43
+ NoopAttributeScrubber: typeof NoopAttributeScrubber;
44
+ ULIDGenerator: typeof ULIDGenerator;
45
+ configureLogfireApi: typeof configureLogfireApi;
46
+ debug: typeof debug;
47
+ error: typeof error;
48
+ fatal: typeof fatal;
49
+ getTailConfig: typeof getTailConfig;
50
+ info: typeof info;
51
+ instrument: typeof instrument;
52
+ instrumentInProcess: typeof instrumentInProcess;
53
+ instrumentTail: typeof instrumentTail;
54
+ log: typeof log;
55
+ logfireApiConfig: typeof logfireApiConfig;
56
+ notice: typeof notice;
57
+ reportError: typeof reportError;
58
+ resolveBaseUrl: typeof resolveBaseUrl;
59
+ resolveSendToLogfire: typeof resolveSendToLogfire;
60
+ serializeAttributes: typeof serializeAttributes;
61
+ span: typeof span;
62
+ startSpan: typeof startSpan;
63
+ trace: typeof trace;
64
+ warning: typeof warning;
65
+ };
66
+ //#endregion
67
+ export { InProcessConfigOptions, TailConfigOptions, TraceItem, defaultExport as default, exportTailEventsToLogfire, getTailConfig, instrument, instrumentInProcess, instrumentTail };
package/dist/index.js CHANGED
@@ -1,191 +1 @@
1
- import { SimpleSpanProcessor as v } from "@opentelemetry/sdk-trace-base";
2
- import { instrument as p } from "@pydantic/otel-cf-workers";
3
- import { resolveBaseUrl as u, warning as h, ULIDGenerator as l, trace as x, startSpan as y, span as E, serializeAttributes as d, resolveSendToLogfire as O, reportError as T, notice as C, NoopAttributeScrubber as L, LogfireAttributeScrubber as _, logfireApiConfig as A, log as N, Level as w, info as I, fatal as P, error as k, debug as z, configureLogfireApi as S } from "logfire";
4
- import { hrTimeToMicroseconds as f, ExportResultCode as b } from "@opentelemetry/core";
5
- import { JsonTraceSerializer as G } from "@opentelemetry/otlp-transformer";
6
- async function R(t, e) {
7
- const r = e.LOGFIRE_TOKEN;
8
- if (!r) {
9
- console.warn("No token provided, not sending payload to Logfire");
10
- return;
11
- }
12
- const o = u(e, void 0, r);
13
- for (const n of t)
14
- for (const i of n.logs)
15
- if (Array.isArray(i.message)) {
16
- for (const s of i.message)
17
- if ("resourceSpans" in s)
18
- try {
19
- return await fetch(`${o}/v1/traces`, {
20
- body: JSON.stringify(s),
21
- headers: {
22
- Authorization: r,
23
- "Content-Type": "application/json"
24
- },
25
- method: "POST"
26
- });
27
- } catch (a) {
28
- console.error(a);
29
- }
30
- }
31
- }
32
- const U = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
33
- __proto__: null,
34
- exportTailEventsToLogfire: R
35
- }, Symbol.toStringTag, { value: "Module" })), F = {
36
- 1: "trace",
37
- 5: "debug",
38
- 9: "info",
39
- 10: "notice",
40
- 13: "warning",
41
- 17: "error",
42
- 21: "fatal"
43
- };
44
- class J {
45
- export(e, r) {
46
- this.sendSpans(e, r);
47
- }
48
- forceFlush() {
49
- return Promise.resolve();
50
- }
51
- shutdown() {
52
- return this.sendSpans([]), this.forceFlush();
53
- }
54
- /**
55
- * converts span info into more readable format
56
- * @param span
57
- */
58
- exportInfo(e) {
59
- var r;
60
- return {
61
- attributes: e.attributes,
62
- duration: f(e.duration),
63
- events: e.events,
64
- id: e.spanContext().spanId,
65
- instrumentationScope: e.instrumentationScope,
66
- kind: e.kind,
67
- links: e.links,
68
- name: e.name,
69
- parentSpanContext: e.parentSpanContext,
70
- resource: {
71
- attributes: e.resource.attributes
72
- },
73
- status: e.status,
74
- timestamp: f(e.startTime),
75
- traceId: e.spanContext().traceId,
76
- traceState: (r = e.spanContext().traceState) == null ? void 0 : r.serialize()
77
- };
78
- }
79
- sendSpans(e, r) {
80
- for (const o of e) {
81
- const n = F[o.attributes["logfire.level_num"]] ?? "info", { attributes: i, name: s, ...a } = this.exportInfo(o);
82
- 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("---");
83
- }
84
- r && r({ code: b.SUCCESS });
85
- }
86
- }
87
- class $ {
88
- export(e, r) {
89
- this._sendSpans(e, r);
90
- }
91
- shutdown() {
92
- return this._sendSpans([]), Promise.resolve();
93
- }
94
- _cleanNullValues(e) {
95
- if (!e.resourceSpans)
96
- return e;
97
- for (const r of e.resourceSpans) {
98
- c(r.resource);
99
- for (const o of r.scopeSpans) {
100
- o.scope && c(o.scope);
101
- for (const n of o.spans ?? [])
102
- c(n);
103
- }
104
- }
105
- return e;
106
- }
107
- _sendSpans(e, r) {
108
- const o = G.serializeRequest(e), n = new TextDecoder().decode(o), i = JSON.parse(n), s = this._cleanNullValues(i);
109
- return console.log(s), r == null ? void 0 : r({ code: b.SUCCESS });
110
- }
111
- }
112
- function c(t) {
113
- t != null && t.attributes && (t.attributes = t.attributes.filter(M));
114
- }
115
- function M(t) {
116
- return Object.keys(t.value).length > 0;
117
- }
118
- function V(t) {
119
- return (e) => {
120
- const { LOGFIRE_ENVIRONMENT: r, LOGFIRE_TOKEN: o = "" } = e, n = u(e, t.baseUrl, o), i = t.environment ?? r, s = t.additionalSpanProcessors ?? [];
121
- return t.console && s.push(new v(new J())), Object.assign({}, t, {
122
- additionalSpanProcessors: s,
123
- environment: i,
124
- exporter: {
125
- headers: { Authorization: o },
126
- url: `${n}/v1/traces`
127
- },
128
- idGenerator: new l(),
129
- postProcessor: (a) => K(a)
130
- });
131
- };
132
- }
133
- function g(t) {
134
- return (e) => Object.assign({}, t, {
135
- exporter: new $(),
136
- idGenerator: new l()
137
- });
138
- }
139
- function m(t, e) {
140
- return e.scrubbing !== void 0 && S({ scrubbing: e.scrubbing }), p(t, V(e));
141
- }
142
- function j(t, e) {
143
- return p(t, g(e));
144
- }
145
- const D = m;
146
- function K(t) {
147
- for (const e of t) {
148
- for (const r of Object.keys(e.attributes)) {
149
- const o = e.attributes[r];
150
- o == null && delete e.attributes[r];
151
- }
152
- Object.assign(e.attributes, d(e.attributes));
153
- }
154
- return t;
155
- }
156
- const X = {
157
- ...U,
158
- configureLogfireApi: S,
159
- debug: z,
160
- error: k,
161
- fatal: P,
162
- getTailConfig: g,
163
- info: I,
164
- instrument: D,
165
- instrumentInProcess: m,
166
- instrumentTail: j,
167
- // Re-export all from logfire
168
- Level: w,
169
- log: N,
170
- logfireApiConfig: A,
171
- LogfireAttributeScrubber: _,
172
- NoopAttributeScrubber: L,
173
- notice: C,
174
- reportError: T,
175
- resolveBaseUrl: u,
176
- resolveSendToLogfire: O,
177
- serializeAttributes: d,
178
- span: E,
179
- startSpan: y,
180
- trace: x,
181
- ULIDGenerator: l,
182
- warning: h
183
- };
184
- export {
185
- X as default,
186
- R as exportTailEventsToLogfire,
187
- g as getTailConfig,
188
- D as instrument,
189
- m as instrumentInProcess,
190
- j as instrumentTail
191
- };
1
+ import{SimpleSpanProcessor as e}from"@opentelemetry/sdk-trace-base";import{instrument as t}from"@pydantic/otel-cf-workers";import{Level as n,LogfireAttributeScrubber as r,NoopAttributeScrubber as i,ULIDGenerator as a,configureLogfireApi as o,debug as s,error as c,fatal as l,info as u,log as d,logfireApiConfig as f,notice as p,reportError as m,resolveBaseUrl as h,resolveSendToLogfire as g,serializeAttributes as _,span as v,startSpan as y,trace as b,warning as x}from"logfire";import{ExportResultCode as S,hrTimeToMicroseconds as C}from"@opentelemetry/core";import{JsonTraceSerializer as w}from"@opentelemetry/otlp-transformer";async function T(e,t){let n=t.LOGFIRE_TOKEN;if(n===void 0||n===``){console.warn(`No token provided, not sending payload to Logfire`);return}let r=h(t,void 0,n),i=E(e);if(i!==null)try{return await fetch(`${r}/v1/traces`,{body:JSON.stringify(i),headers:{Authorization:n,"Content-Type":`application/json`},method:`POST`})}catch(e){console.error(e);return}}function E(e){for(let t of e)for(let e of t.logs)if(Array.isArray(e.message)){for(let t of e.message)if(D(t))return t}return null}function D(e){return typeof e==`object`&&!!e&&`resourceSpans`in e}const O={1:`trace`,5:`debug`,9:`info`,10:`notice`,13:`warning`,17:`error`,21:`fatal`};var k=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:C(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:C(e.startTime),traceId:e.spanContext().traceId,traceState:e.spanContext().traceState?.serialize()}}sendSpans(e,t){for(let t of e){let e=O[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:S.SUCCESS})}},A=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){j(t.resource);for(let e of t.scopeSpans){e.scope&&j(e.scope);for(let t of e.spans??[])j(t)}}return e}_sendSpans(e,t){let n=w.serializeRequest(e),r=new TextDecoder().decode(n),i=JSON.parse(r),a=this._cleanNullValues(i);return console.log(a),t?.({code:S.SUCCESS})}};function j(e){e?.attributes&&(e.attributes=e.attributes.filter(M))}function M(e){return Object.keys(e.value).length>0}function N(t){return n=>{let{LOGFIRE_ENVIRONMENT:r,LOGFIRE_TOKEN:i=``}=n,o=h(n,t.baseUrl,i),s=t.environment??r,c=t.additionalSpanProcessors??[];return t.console===!0&&c.push(new e(new k)),{...t,additionalSpanProcessors:c,exporter:{headers:{Authorization:i},url:`${o}/v1/traces`},idGenerator:new a,postProcessor:e=>R(e),...s===void 0?{}:{environment:s}}}}function P(e){return t=>({...e,exporter:new A,idGenerator:new a})}function F(e,n){return n.scrubbing!==void 0&&o({scrubbing:n.scrubbing}),t(e,N(n))}function I(e,n){return t(e,P(n))}const L=F;function R(e){for(let t of e){for(let e of Object.keys(t.attributes))t.attributes[e]??delete t.attributes[e];Object.assign(t.attributes,_(t.attributes))}return e}const z={exportTailEventsToLogfire:T,configureLogfireApi:o,debug:s,error:c,fatal:l,getTailConfig:P,info:u,instrument:L,instrumentInProcess:F,instrumentTail:I,Level:n,log:d,logfireApiConfig:f,LogfireAttributeScrubber:r,NoopAttributeScrubber:i,notice:p,reportError:m,resolveBaseUrl:h,resolveSendToLogfire:g,serializeAttributes:_,span:v,startSpan:y,trace:b,ULIDGenerator:a,warning:x};export{z as default,T as exportTailEventsToLogfire,P as getTailConfig,L as instrument,F as instrumentInProcess,I as instrumentTail};
package/package.json CHANGED
@@ -26,7 +26,7 @@
26
26
  "stats",
27
27
  "monitoring"
28
28
  ],
29
- "version": "0.11.7",
29
+ "version": "0.11.9",
30
30
  "type": "module",
31
31
  "main": "./dist/index.cjs",
32
32
  "module": "./dist/index.js",
@@ -44,29 +44,30 @@
44
44
  }
45
45
  },
46
46
  "dependencies": {
47
- "@pydantic/otel-cf-workers": "^1.0.0-rc.55",
48
- "logfire": "0.14.0"
47
+ "@pydantic/otel-cf-workers": "^1.0.0-rc.56",
48
+ "logfire": "0.15.1"
49
49
  },
50
50
  "devDependencies": {
51
51
  "@cloudflare/workers-types": "4.20250311.0",
52
- "@opentelemetry/core": "^2.7.0",
53
- "@opentelemetry/otlp-transformer": "^0.215.0",
54
- "@opentelemetry/sdk-trace-base": "^2.7.0"
52
+ "@opentelemetry/core": "^2.7.1",
53
+ "@opentelemetry/otlp-transformer": "^0.217.0",
54
+ "@opentelemetry/sdk-trace-base": "^2.7.1"
55
55
  },
56
56
  "peerDependencies": {
57
- "@opentelemetry/core": "^2.7.0",
58
- "@opentelemetry/otlp-transformer": "^0.215.0",
59
- "@opentelemetry/sdk-trace-base": "^2.7.0"
57
+ "@opentelemetry/core": "^2.7.1",
58
+ "@opentelemetry/otlp-transformer": "^0.217.0",
59
+ "@opentelemetry/sdk-trace-base": "^2.7.1"
60
60
  },
61
61
  "files": [
62
62
  "dist",
63
63
  "LICENSE"
64
64
  ],
65
65
  "scripts": {
66
- "dev": "vite build",
67
- "build": "vite build",
68
- "lint": "eslint",
69
- "preview": "vite preview",
70
- "typecheck": "tsc"
66
+ "dev": "vp pack --watch",
67
+ "build": "vp pack",
68
+ "lint": "vp lint",
69
+ "preview": "vp preview",
70
+ "typecheck": "tsc",
71
+ "test": "vp test --passWithNoTests"
71
72
  }
72
73
  }