@pydantic/logfire-cf-workers 0.11.7 → 0.11.8
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 +7 -0
- package/dist/index.cjs +1 -1
- package/dist/index.d.cts +67 -111
- package/dist/index.d.ts +67 -111
- package/dist/index.js +1 -191
- package/package.json +8 -7
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
|
-
|
|
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 {
|
|
2
|
-
import {
|
|
3
|
-
import { error } from
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
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 {
|
|
2
|
-
import {
|
|
3
|
-
import { error } from
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
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 {
|
|
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.
|
|
29
|
+
"version": "0.11.8",
|
|
30
30
|
"type": "module",
|
|
31
31
|
"main": "./dist/index.cjs",
|
|
32
32
|
"module": "./dist/index.js",
|
|
@@ -45,7 +45,7 @@
|
|
|
45
45
|
},
|
|
46
46
|
"dependencies": {
|
|
47
47
|
"@pydantic/otel-cf-workers": "^1.0.0-rc.55",
|
|
48
|
-
"logfire": "0.
|
|
48
|
+
"logfire": "0.15.0"
|
|
49
49
|
},
|
|
50
50
|
"devDependencies": {
|
|
51
51
|
"@cloudflare/workers-types": "4.20250311.0",
|
|
@@ -63,10 +63,11 @@
|
|
|
63
63
|
"LICENSE"
|
|
64
64
|
],
|
|
65
65
|
"scripts": {
|
|
66
|
-
"dev": "
|
|
67
|
-
"build": "
|
|
68
|
-
"lint": "
|
|
69
|
-
"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
|
}
|