@pydantic/logfire-browser 0.14.2 → 0.15.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/README.md CHANGED
@@ -21,6 +21,34 @@ If you're instrumenting Cloudflare, see the [Logfire CF workers package](https:/
21
21
 
22
22
  See the [Logfire Browser docs for a primer](https://logfire.pydantic.dev/docs/integrations/javascript/browser/). Ready to run examples are available in the repository [in vanilla browser](https://github.com/pydantic/logfire-js/tree/main/examples/browser) and [Next.js variants](https://github.com/pydantic/logfire-js/tree/main/examples/nextjs-client-side-instrumentation).
23
23
 
24
+ ## Managed Variables
25
+
26
+ Browser applications can use local managed variables from `logfire/vars` when
27
+ the app already depends on the core `logfire` package. Do not configure the
28
+ remote provider in browser bundles because it requires a Logfire API key.
29
+
30
+ ## Resource attributes
31
+
32
+ Use `resourceAttributes` for stable browser application or session metadata that
33
+ should be attached to all telemetry from the configured provider:
34
+
35
+ ```js
36
+ import * as logfire from '@pydantic/logfire-browser'
37
+
38
+ logfire.configure({
39
+ traceUrl: '/client-traces',
40
+ serviceName: 'browser-app',
41
+ resourceAttributes: {
42
+ 'service.namespace': 'my-company',
43
+ 'app.installation.id': installationId,
44
+ },
45
+ })
46
+ ```
47
+
48
+ Do not use resource attributes for per-request values or sensitive user data.
49
+ First-class options such as `serviceName`, `serviceVersion`, and `environment`
50
+ take precedence over conflicting `resourceAttributes` keys.
51
+
24
52
  ## Contributing
25
53
 
26
54
  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";var R=Object.defineProperty;var p=(r,e,t)=>e in r?R(r,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):r[e]=t;var E=(r,e,t)=>p(r,typeof e!="symbol"?e+"":e,t);Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const s=require("@opentelemetry/api"),_=require("@opentelemetry/exporter-trace-otlp-http"),w=require("@opentelemetry/instrumentation"),m=require("@opentelemetry/resources"),l=require("@opentelemetry/sdk-trace-web"),i=require("@opentelemetry/semantic-conventions"),c=require("@opentelemetry/semantic-conventions/incubating"),o=require("logfire"),T=require("@opentelemetry/core"),A="target_xpath",v="event_type",h={1:"trace",5:"debug",9:"info",10:"notice",13:"warning",17:"error",21:"fatal"},S={debug:"#E3E3E3",error:"#EA4335",fatal:"#EA4335",info:"#9EC1FB",notice:"#A5D490","on-debug":"#636262","on-error":"#FFEDE9","on-fatal":"#FFEDE9","on-info":"#063175","on-notice":"#222222","on-trace":"#636262","on-warning":"#613A0D",trace:"#E3E3E3",warning:"#EFB77A"};class C{export(e,t){this.sendSpans(e,t)}forceFlush(){return Promise.resolve()}shutdown(){return this.sendSpans([]),this.forceFlush()}exportInfo(e){var t;return{attributes:e.attributes,duration:T.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:T.hrTimeToMicroseconds(e.startTime),traceId:e.spanContext().traceId,traceState:(t=e.spanContext().traceState)==null?void 0:t.serialize()}}sendSpans(e,t){for(const a of e){const n=h[a.attributes["logfire.level_num"]]??"info",{attributes:u,name:d,...f}=this.exportInfo(a);console.log(`%cLogfire %c${n}`,"background-color: #E520E9; color: #FFFFFF",`background-color: ${S[`on-${n}`]}; color: ${S[n]}`,d,u,f)}t&&t({code:T.ExportResultCode.SUCCESS})}}class D{constructor(e,t){E(this,"console");E(this,"wrapped");t&&(this.console=new l.SimpleSpanProcessor(new C)),this.wrapped=e}async forceFlush(){var e;return await((e=this.console)==null?void 0:e.forceFlush()),this.wrapped.forceFlush()}onEnd(e){var t;(t=this.console)==null||t.onEnd(e),this.wrapped.onEnd(e)}onStart(e,t){var a;if(c.ATTR_HTTP_URL in e.attributes){const n=new URL(e.attributes[c.ATTR_HTTP_URL]);Reflect.set(e,"name",`${e.name} ${n.pathname}`)}A in e.attributes&&Reflect.set(e,"name",`${e.attributes[v]??"unknown"} ${e.attributes[A]??""}`),(a=this.console)==null||a.onStart(e,t),this.wrapped.onStart(e,t)}async shutdown(){var e;return await((e=this.console)==null?void 0:e.shutdown()),this.wrapped.shutdown()}}function F(){return{}}async function P(r,e){return{...typeof r=="function"?await r():r??{},...e()}}function L(r){var f,b;r.diagLogLevel!==void 0&&s.diag.setLogger(new s.DiagConsoleLogger,r.diagLogLevel),o.configureLogfireApi({errorFingerprinting:r.errorFingerprinting??!1,scrubbing:r.scrubbing});const e=m.resourceFromAttributes({[c.ATTR_BROWSER_LANGUAGE]:navigator.language,[i.ATTR_SERVICE_NAME]:r.serviceName??"logfire-browser",[i.ATTR_SERVICE_VERSION]:r.serviceVersion??"0.0.1",[i.ATTR_TELEMETRY_SDK_LANGUAGE]:i.TELEMETRY_SDK_LANGUAGE_VALUE_WEBJS,[i.ATTR_TELEMETRY_SDK_NAME]:"logfire-browser",...r.environment?{[c.ATTR_DEPLOYMENT_ENVIRONMENT_NAME]:r.environment}:{},[i.ATTR_TELEMETRY_SDK_VERSION]:"0.14.2",...navigator.userAgentData?{[c.ATTR_BROWSER_BRANDS]:navigator.userAgentData.brands.map(g=>`${g.brand} ${g.version}`),[c.ATTR_BROWSER_MOBILE]:navigator.userAgentData.mobile,[c.ATTR_BROWSER_PLATFORM]:navigator.userAgentData.platform}:{[i.ATTR_USER_AGENT_ORIGINAL]:navigator.userAgent}});s.diag.info("logfire-browser: starting");const t=(f=r.sampling)==null?void 0:f.head,a=t!==void 0&&t<1?new l.ParentBasedSampler({root:new l.TraceIdRatioBasedSampler(t)}):void 0;let n=new D(new l.BatchSpanProcessor(new _.OTLPTraceExporter({...r.traceExporterConfig,headers:async()=>{var g;return P((g=r.traceExporterConfig)==null?void 0:g.headers,r.traceExporterHeaders??F)},url:r.traceUrl}),r.batchSpanProcessorConfig),!!r.console);(b=r.sampling)!=null&&b.tail&&(n=new o.TailSamplingProcessor(n,r.sampling.tail));const u=new l.WebTracerProvider({idGenerator:new o.ULIDGenerator,resource:e,...a?{sampler:a}:{},spanProcessors:[n]});u.register({contextManager:r.contextManager??new l.StackContextManager});const d=w.registerInstrumentations({instrumentations:r.instrumentations??[],tracerProvider:u});return async()=>{s.diag.info("logfire-browser: shutting down"),d(),await u.forceFlush(),await u.shutdown(),s.diag.info("logfire-browser: shut down complete")}}const x={configure:L,configureLogfireApi:o.configureLogfireApi,debug:o.debug,DiagLogLevel:s.DiagLogLevel,error:o.error,fatal:o.fatal,info:o.info,Level:o.Level,log:o.log,logfireApiConfig:o.logfireApiConfig,LogfireAttributeScrubber:o.LogfireAttributeScrubber,NoopAttributeScrubber:o.NoopAttributeScrubber,notice:o.notice,reportError:o.reportError,resolveBaseUrl:o.resolveBaseUrl,resolveSendToLogfire:o.resolveSendToLogfire,serializeAttributes:o.serializeAttributes,span:o.span,startSpan:o.startSpan,trace:o.trace,ULIDGenerator:o.ULIDGenerator,warning:o.warning};Object.defineProperty(exports,"DiagLogLevel",{enumerable:!0,get:()=>s.DiagLogLevel});exports.configure=L;exports.default=x;Object.keys(o).forEach(r=>{r!=="default"&&!Object.prototype.hasOwnProperty.call(exports,r)&&Object.defineProperty(exports,r,{enumerable:!0,get:()=>o[r]})});
1
+ Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:`Module`}});let e=require(`@opentelemetry/api`),t=require(`@opentelemetry/exporter-trace-otlp-http`),n=require(`@opentelemetry/instrumentation`),r=require(`@opentelemetry/resources`),i=require(`@opentelemetry/sdk-trace-web`),a=require(`@opentelemetry/semantic-conventions`),o=require(`@opentelemetry/semantic-conventions/incubating`),s=require(`logfire`),c=require(`@opentelemetry/core`);const l=`target_xpath`,u={1:`trace`,5:`debug`,9:`info`,10:`notice`,13:`warning`,17:`error`,21:`fatal`},d={debug:`#E3E3E3`,error:`#EA4335`,fatal:`#EA4335`,info:`#9EC1FB`,notice:`#A5D490`,"on-debug":`#636262`,"on-error":`#FFEDE9`,"on-fatal":`#FFEDE9`,"on-info":`#063175`,"on-notice":`#222222`,"on-trace":`#636262`,"on-warning":`#613A0D`,trace:`#E3E3E3`,warning:`#EFB77A`};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:(0,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:(0,c.hrTimeToMicroseconds)(e.startTime),traceId:e.spanContext().traceId,traceState:e.spanContext().traceState?.serialize()}}sendSpans(e,t){for(let t of e){let e=u[t.attributes[`logfire.level_num`]]??`info`,{attributes:n,name:r,...i}=this.exportInfo(t);console.log(`%cLogfire %c${e}`,`background-color: #E520E9; color: #FFFFFF`,`background-color: ${d[`on-${e}`]}; color: ${d[e]}`,r,n,i)}t&&t({code:c.ExportResultCode.SUCCESS})}},p=class{console;wrapped;constructor(e,t){t&&(this.console=new i.SimpleSpanProcessor(new f)),this.wrapped=e}async forceFlush(){return await this.console?.forceFlush(),this.wrapped.forceFlush()}onEnd(e){this.console?.onEnd(e),this.wrapped.onEnd(e)}onStart(e,t){if(o.ATTR_HTTP_URL in e.attributes){let t=new URL(e.attributes[o.ATTR_HTTP_URL]);Reflect.set(e,`name`,`${e.name} ${t.pathname}`)}if(l in e.attributes){let t=String(e.attributes.event_type??`unknown`),n=String(e.attributes[l]??``);Reflect.set(e,`name`,`${t} ${n}`)}this.console?.onStart(e,t),this.wrapped.onStart(e,t)}async shutdown(){return await this.console?.shutdown(),this.wrapped.shutdown()}};function m(){return{}}async function h(e,t){return{...typeof e==`function`?await e():e??{},...t()}}function g(c){c.diagLogLevel!==void 0&&e.diag.setLogger(new e.DiagConsoleLogger,c.diagLogLevel);let l={errorFingerprinting:c.errorFingerprinting??!1};c.scrubbing!==void 0&&(l.scrubbing=c.scrubbing),(0,s.configureLogfireApi)(l);let u=(0,r.resourceFromAttributes)(c.resourceAttributes??{}).merge((0,r.resourceFromAttributes)({[o.ATTR_BROWSER_LANGUAGE]:navigator.language,[a.ATTR_SERVICE_NAME]:c.serviceName??`logfire-browser`,[a.ATTR_SERVICE_VERSION]:c.serviceVersion??`0.0.1`,[a.ATTR_TELEMETRY_SDK_LANGUAGE]:a.TELEMETRY_SDK_LANGUAGE_VALUE_WEBJS,[a.ATTR_TELEMETRY_SDK_NAME]:`logfire-browser`,...c.environment!==void 0&&c.environment!==``?{[o.ATTR_DEPLOYMENT_ENVIRONMENT_NAME]:c.environment}:{},[a.ATTR_TELEMETRY_SDK_VERSION]:`1.0.0`,...navigator.userAgentData?{[o.ATTR_BROWSER_BRANDS]:navigator.userAgentData.brands.map(e=>`${e.brand} ${e.version}`),[o.ATTR_BROWSER_MOBILE]:navigator.userAgentData.mobile,[o.ATTR_BROWSER_PLATFORM]:navigator.userAgentData.platform}:{[a.ATTR_USER_AGENT_ORIGINAL]:navigator.userAgent}}));e.diag.info(`logfire-browser: starting`);let d=c.sampling?.head,f=d!==void 0&&d<1?new i.ParentBasedSampler({root:new i.TraceIdRatioBasedSampler(d)}):void 0,g=new p(new i.BatchSpanProcessor(new t.OTLPTraceExporter({...c.traceExporterConfig,headers:async()=>h(c.traceExporterConfig?.headers,c.traceExporterHeaders??m),url:c.traceUrl}),c.batchSpanProcessorConfig),!!c.console);c.sampling?.tail&&(g=new s.TailSamplingProcessor(g,c.sampling.tail));let _=new i.WebTracerProvider({idGenerator:new s.ULIDGenerator,resource:u,...f?{sampler:f}:{},spanProcessors:[g]});_.register({contextManager:c.contextManager??new i.StackContextManager});let v=(0,n.registerInstrumentations)({instrumentations:c.instrumentations??[],tracerProvider:_});return async()=>{e.diag.info(`logfire-browser: shutting down`),v(),await _.forceFlush(),await _.shutdown(),e.diag.info(`logfire-browser: shut down complete`)}}const _={configure:g,configureLogfireApi:s.configureLogfireApi,debug:s.debug,DiagLogLevel:e.DiagLogLevel,error:s.error,fatal:s.fatal,info:s.info,Level:s.Level,log:s.log,logfireApiConfig:s.logfireApiConfig,LogfireAttributeScrubber:s.LogfireAttributeScrubber,NoopAttributeScrubber:s.NoopAttributeScrubber,notice:s.notice,reportError:s.reportError,resolveBaseUrl:s.resolveBaseUrl,resolveSendToLogfire:s.resolveSendToLogfire,serializeAttributes:s.serializeAttributes,span:s.span,startSpan:s.startSpan,trace:s.trace,ULIDGenerator:s.ULIDGenerator,warning:s.warning};Object.defineProperty(exports,`DiagLogLevel`,{enumerable:!0,get:function(){return e.DiagLogLevel}}),exports.configure=g,exports.default=_,Object.keys(s).forEach(function(e){e!==`default`&&!Object.prototype.hasOwnProperty.call(exports,e)&&Object.defineProperty(exports,e,{enumerable:!0,get:function(){return s[e]}})});
package/dist/index.d.cts CHANGED
@@ -1,140 +1,110 @@
1
- import { BufferConfig } from '@opentelemetry/sdk-trace-web';
2
- import { configureLogfireApi } from 'logfire';
3
- import { ContextManager } from '@opentelemetry/api';
4
- import { debug } from 'logfire';
5
- import { DiagLogLevel } from '@opentelemetry/api';
6
- import { error } from 'logfire';
7
- import { fatal } from 'logfire';
8
- import { info } from 'logfire';
9
- import { Instrumentation } from '@opentelemetry/instrumentation';
10
- import { log } from 'logfire';
11
- import { LogfireApiConfig } from 'logfire';
12
- import { LogfireAttributeScrubber } from 'logfire';
13
- import { NoopAttributeScrubber } from 'logfire';
14
- import { notice } from 'logfire';
15
- import { OTLPTraceExporter } from '@opentelemetry/exporter-trace-otlp-http';
16
- import { reportError as reportError_2 } from 'logfire';
17
- import { resolveBaseUrl } from 'logfire';
18
- import { resolveSendToLogfire } from 'logfire';
19
- import { SamplingOptions } from 'logfire';
20
- import { ScrubbingOptions } from 'logfire';
21
- import { serializeAttributes } from 'logfire';
22
- import { span } from 'logfire';
23
- import { startSpan } from 'logfire';
24
- import { trace } from 'logfire';
25
- import { ULIDGenerator } from 'logfire';
26
- import { warning } from 'logfire';
27
-
28
- export declare function configure(options: LogfireConfigOptions): () => Promise<void>;
29
-
30
- declare const _default: {
31
- configure: typeof configure;
32
- configureLogfireApi: typeof configureLogfireApi;
33
- debug: typeof debug;
34
- DiagLogLevel: typeof DiagLogLevel;
35
- error: typeof error;
36
- fatal: typeof fatal;
37
- info: typeof info;
38
- Level: {
39
- Trace: 1;
40
- Debug: 5;
41
- Info: 9;
42
- Notice: 10;
43
- Warning: 13;
44
- Error: 17;
45
- Fatal: 21;
46
- };
47
- log: typeof log;
48
- logfireApiConfig: LogfireApiConfig;
49
- LogfireAttributeScrubber: typeof LogfireAttributeScrubber;
50
- NoopAttributeScrubber: typeof NoopAttributeScrubber;
51
- notice: typeof notice;
52
- reportError: typeof reportError_2;
53
- resolveBaseUrl: typeof resolveBaseUrl;
54
- resolveSendToLogfire: typeof resolveSendToLogfire;
55
- serializeAttributes: typeof serializeAttributes;
56
- span: typeof span;
57
- startSpan: typeof startSpan;
58
- trace: typeof trace;
59
- ULIDGenerator: typeof ULIDGenerator;
60
- warning: typeof warning;
61
- };
62
- export default _default;
63
-
64
- export { DiagLogLevel }
65
-
66
- export declare interface LogfireConfigOptions {
67
- /**
68
- * The configuration of the batch span processor.
69
- */
70
- batchSpanProcessorConfig?: BufferConfig;
71
- /**
72
- * Whether to log the spans to the console in addition to sending them to the Logfire API.
73
- */
74
- console?: boolean;
75
- /**
76
- * Pass a context manager (e.g. ZoneContextManager) to use.
77
- */
78
- contextManager?: ContextManager;
79
- /**
80
- * Defines the available internal logging levels for the diagnostic logger.
81
- */
82
- diagLogLevel?: DiagLogLevel;
83
- /**
84
- * The environment this service is running in, e.g. `staging` or `prod`. Sets the deployment.environment.name resource attribute. Useful for filtering within projects in the Logfire UI.
85
- * Defaults to the `LOGFIRE_ENVIRONMENT` environment variable.
86
- */
87
- environment?: string;
88
- /**
89
- * Whether to compute fingerprints for errors reported via reportError().
90
- * Defaults to false for browser since minified code produces unstable fingerprints.
91
- */
92
- errorFingerprinting?: boolean;
93
- /**
94
- * The instrumentations to register - a common one [is the fetch instrumentation](https://www.npmjs.com/package/@opentelemetry/instrumentation-fetch).
95
- */
96
- instrumentations?: (Instrumentation | Instrumentation[])[];
97
- /**
98
- * Sampling options for controlling which traces are exported.
99
- * `head` sets a probabilistic sample rate (0.0-1.0) at trace creation time.
100
- * `tail` provides a callback evaluated on every span to decide whether to keep the trace.
101
- *
102
- * Note: Tail sampling buffers all spans in a trace in memory until either a span meets the
103
- * sampling criteria or the root span ends. In long-lived browser sessions, this can lead to
104
- * significant memory usage. Consider using head sampling alone for long-running traces, or
105
- * ensure tail callbacks accept traces quickly (e.g., on the first error-level span).
106
- */
107
- sampling?: SamplingOptions;
108
- /**
109
- * Options for scrubbing sensitive data. Set to False to disable.
110
- */
111
- scrubbing?: false | ScrubbingOptions;
112
- /**
113
- * Name of this service.
114
- */
115
- serviceName?: string;
116
- /**
117
- * Version of this service.
118
- */
119
- serviceVersion?: string;
120
- /**
121
- * configures the trace exporter.
122
- */
123
- traceExporterConfig?: TraceExporterConfig;
124
- /**
125
- * Any additional HTTP headers to be sent with the trace exporter requests.
126
- * This is useful for authentication or other custom headers.
127
- */
128
- traceExporterHeaders?: () => Record<string, string>;
129
- /**
130
- * The URL of your trace exporter proxy endpoint.
131
- */
132
- traceUrl: string;
133
- }
134
-
135
- declare type TraceExporterConfig = NonNullable<typeof OTLPTraceExporter extends new (config: infer T) => unknown ? T : never>;
136
-
137
-
138
- export * from "logfire";
139
-
140
- export { }
1
+ import { Attributes, ContextManager, DiagLogLevel, DiagLogLevel as DiagLogLevel$1 } from "@opentelemetry/api";
2
+ import { OTLPTraceExporter } from "@opentelemetry/exporter-trace-otlp-http";
3
+ import { Instrumentation } from "@opentelemetry/instrumentation";
4
+ import { BufferConfig } from "@opentelemetry/sdk-trace-web";
5
+ import { Level, LogfireAttributeScrubber, NoopAttributeScrubber, SamplingOptions, ScrubbingOptions, ULIDGenerator, configureLogfireApi, debug, error, fatal, info, log, logfireApiConfig, notice, reportError, resolveBaseUrl, resolveSendToLogfire, serializeAttributes, span, startSpan, trace, warning } from "logfire";
6
+ export * from "logfire";
7
+
8
+ //#region src/index.d.ts
9
+ type TraceExporterConfig = NonNullable<typeof OTLPTraceExporter extends (new (config: infer T) => unknown) ? T : never>;
10
+ interface LogfireConfigOptions {
11
+ /**
12
+ * The configuration of the batch span processor.
13
+ */
14
+ batchSpanProcessorConfig?: BufferConfig;
15
+ /**
16
+ * Whether to log the spans to the console in addition to sending them to the Logfire API.
17
+ */
18
+ console?: boolean;
19
+ /**
20
+ * Pass a context manager (e.g. ZoneContextManager) to use.
21
+ */
22
+ contextManager?: ContextManager;
23
+ /**
24
+ * Defines the available internal logging levels for the diagnostic logger.
25
+ */
26
+ diagLogLevel?: DiagLogLevel$1;
27
+ /**
28
+ * The environment this service is running in, e.g. `staging` or `prod`. Sets the deployment.environment.name resource attribute. Useful for filtering within projects in the Logfire UI.
29
+ * Defaults to the `LOGFIRE_ENVIRONMENT` environment variable.
30
+ */
31
+ environment?: string;
32
+ /**
33
+ * Whether to compute fingerprints for errors reported via reportError().
34
+ * Defaults to false for browser since minified code produces unstable fingerprints.
35
+ */
36
+ errorFingerprinting?: boolean;
37
+ /**
38
+ * The instrumentations to register - a common one [is the fetch instrumentation](https://www.npmjs.com/package/@opentelemetry/instrumentation-fetch).
39
+ */
40
+ instrumentations?: (Instrumentation | Instrumentation[])[];
41
+ /**
42
+ * Sampling options for controlling which traces are exported.
43
+ * `head` sets a probabilistic sample rate (0.0-1.0) at trace creation time.
44
+ * `tail` provides a callback evaluated on every span to decide whether to keep the trace.
45
+ *
46
+ * Note: Tail sampling buffers all spans in a trace in memory until either a span meets the
47
+ * sampling criteria or the root span ends. In long-lived browser sessions, this can lead to
48
+ * significant memory usage. Consider using head sampling alone for long-running traces, or
49
+ * ensure tail callbacks accept traces quickly (e.g., on the first error-level span).
50
+ */
51
+ sampling?: SamplingOptions;
52
+ /**
53
+ * Options for scrubbing sensitive data. Set to False to disable.
54
+ */
55
+ scrubbing?: false | ScrubbingOptions;
56
+ /**
57
+ * Additional OpenTelemetry resource attributes for the entity producing telemetry.
58
+ *
59
+ * Use this for stable application or browser-session metadata, not per-request or sensitive user data.
60
+ */
61
+ resourceAttributes?: Attributes;
62
+ /**
63
+ * Name of this service.
64
+ */
65
+ serviceName?: string;
66
+ /**
67
+ * Version of this service.
68
+ */
69
+ serviceVersion?: string;
70
+ /**
71
+ * configures the trace exporter.
72
+ */
73
+ traceExporterConfig?: TraceExporterConfig;
74
+ /**
75
+ * Any additional HTTP headers to be sent with the trace exporter requests.
76
+ * This is useful for authentication or other custom headers.
77
+ */
78
+ traceExporterHeaders?: () => Record<string, string>;
79
+ /**
80
+ * The URL of your trace exporter proxy endpoint.
81
+ */
82
+ traceUrl: string;
83
+ }
84
+ declare function configure(options: LogfireConfigOptions): () => Promise<void>;
85
+ declare const defaultExport: {
86
+ DiagLogLevel: typeof DiagLogLevel$1;
87
+ Level: typeof Level;
88
+ LogfireAttributeScrubber: typeof LogfireAttributeScrubber;
89
+ NoopAttributeScrubber: typeof NoopAttributeScrubber;
90
+ ULIDGenerator: typeof ULIDGenerator;
91
+ configure: typeof configure;
92
+ configureLogfireApi: typeof configureLogfireApi;
93
+ debug: typeof debug;
94
+ error: typeof error;
95
+ fatal: typeof fatal;
96
+ info: typeof info;
97
+ log: typeof log;
98
+ logfireApiConfig: typeof logfireApiConfig;
99
+ notice: typeof notice;
100
+ reportError: typeof reportError;
101
+ resolveBaseUrl: typeof resolveBaseUrl;
102
+ resolveSendToLogfire: typeof resolveSendToLogfire;
103
+ serializeAttributes: typeof serializeAttributes;
104
+ span: typeof span;
105
+ startSpan: typeof startSpan;
106
+ trace: typeof trace;
107
+ warning: typeof warning;
108
+ };
109
+ //#endregion
110
+ export { DiagLogLevel, LogfireConfigOptions, configure, defaultExport as default };
package/dist/index.d.ts CHANGED
@@ -1,140 +1,110 @@
1
- import { BufferConfig } from '@opentelemetry/sdk-trace-web';
2
- import { configureLogfireApi } from 'logfire';
3
- import { ContextManager } from '@opentelemetry/api';
4
- import { debug } from 'logfire';
5
- import { DiagLogLevel } from '@opentelemetry/api';
6
- import { error } from 'logfire';
7
- import { fatal } from 'logfire';
8
- import { info } from 'logfire';
9
- import { Instrumentation } from '@opentelemetry/instrumentation';
10
- import { log } from 'logfire';
11
- import { LogfireApiConfig } from 'logfire';
12
- import { LogfireAttributeScrubber } from 'logfire';
13
- import { NoopAttributeScrubber } from 'logfire';
14
- import { notice } from 'logfire';
15
- import { OTLPTraceExporter } from '@opentelemetry/exporter-trace-otlp-http';
16
- import { reportError as reportError_2 } from 'logfire';
17
- import { resolveBaseUrl } from 'logfire';
18
- import { resolveSendToLogfire } from 'logfire';
19
- import { SamplingOptions } from 'logfire';
20
- import { ScrubbingOptions } from 'logfire';
21
- import { serializeAttributes } from 'logfire';
22
- import { span } from 'logfire';
23
- import { startSpan } from 'logfire';
24
- import { trace } from 'logfire';
25
- import { ULIDGenerator } from 'logfire';
26
- import { warning } from 'logfire';
27
-
28
- export declare function configure(options: LogfireConfigOptions): () => Promise<void>;
29
-
30
- declare const _default: {
31
- configure: typeof configure;
32
- configureLogfireApi: typeof configureLogfireApi;
33
- debug: typeof debug;
34
- DiagLogLevel: typeof DiagLogLevel;
35
- error: typeof error;
36
- fatal: typeof fatal;
37
- info: typeof info;
38
- Level: {
39
- Trace: 1;
40
- Debug: 5;
41
- Info: 9;
42
- Notice: 10;
43
- Warning: 13;
44
- Error: 17;
45
- Fatal: 21;
46
- };
47
- log: typeof log;
48
- logfireApiConfig: LogfireApiConfig;
49
- LogfireAttributeScrubber: typeof LogfireAttributeScrubber;
50
- NoopAttributeScrubber: typeof NoopAttributeScrubber;
51
- notice: typeof notice;
52
- reportError: typeof reportError_2;
53
- resolveBaseUrl: typeof resolveBaseUrl;
54
- resolveSendToLogfire: typeof resolveSendToLogfire;
55
- serializeAttributes: typeof serializeAttributes;
56
- span: typeof span;
57
- startSpan: typeof startSpan;
58
- trace: typeof trace;
59
- ULIDGenerator: typeof ULIDGenerator;
60
- warning: typeof warning;
61
- };
62
- export default _default;
63
-
64
- export { DiagLogLevel }
65
-
66
- export declare interface LogfireConfigOptions {
67
- /**
68
- * The configuration of the batch span processor.
69
- */
70
- batchSpanProcessorConfig?: BufferConfig;
71
- /**
72
- * Whether to log the spans to the console in addition to sending them to the Logfire API.
73
- */
74
- console?: boolean;
75
- /**
76
- * Pass a context manager (e.g. ZoneContextManager) to use.
77
- */
78
- contextManager?: ContextManager;
79
- /**
80
- * Defines the available internal logging levels for the diagnostic logger.
81
- */
82
- diagLogLevel?: DiagLogLevel;
83
- /**
84
- * The environment this service is running in, e.g. `staging` or `prod`. Sets the deployment.environment.name resource attribute. Useful for filtering within projects in the Logfire UI.
85
- * Defaults to the `LOGFIRE_ENVIRONMENT` environment variable.
86
- */
87
- environment?: string;
88
- /**
89
- * Whether to compute fingerprints for errors reported via reportError().
90
- * Defaults to false for browser since minified code produces unstable fingerprints.
91
- */
92
- errorFingerprinting?: boolean;
93
- /**
94
- * The instrumentations to register - a common one [is the fetch instrumentation](https://www.npmjs.com/package/@opentelemetry/instrumentation-fetch).
95
- */
96
- instrumentations?: (Instrumentation | Instrumentation[])[];
97
- /**
98
- * Sampling options for controlling which traces are exported.
99
- * `head` sets a probabilistic sample rate (0.0-1.0) at trace creation time.
100
- * `tail` provides a callback evaluated on every span to decide whether to keep the trace.
101
- *
102
- * Note: Tail sampling buffers all spans in a trace in memory until either a span meets the
103
- * sampling criteria or the root span ends. In long-lived browser sessions, this can lead to
104
- * significant memory usage. Consider using head sampling alone for long-running traces, or
105
- * ensure tail callbacks accept traces quickly (e.g., on the first error-level span).
106
- */
107
- sampling?: SamplingOptions;
108
- /**
109
- * Options for scrubbing sensitive data. Set to False to disable.
110
- */
111
- scrubbing?: false | ScrubbingOptions;
112
- /**
113
- * Name of this service.
114
- */
115
- serviceName?: string;
116
- /**
117
- * Version of this service.
118
- */
119
- serviceVersion?: string;
120
- /**
121
- * configures the trace exporter.
122
- */
123
- traceExporterConfig?: TraceExporterConfig;
124
- /**
125
- * Any additional HTTP headers to be sent with the trace exporter requests.
126
- * This is useful for authentication or other custom headers.
127
- */
128
- traceExporterHeaders?: () => Record<string, string>;
129
- /**
130
- * The URL of your trace exporter proxy endpoint.
131
- */
132
- traceUrl: string;
133
- }
134
-
135
- declare type TraceExporterConfig = NonNullable<typeof OTLPTraceExporter extends new (config: infer T) => unknown ? T : never>;
136
-
137
-
138
- export * from "logfire";
139
-
140
- export { }
1
+ import { Attributes, ContextManager, DiagLogLevel, DiagLogLevel as DiagLogLevel$1 } from "@opentelemetry/api";
2
+ import { OTLPTraceExporter } from "@opentelemetry/exporter-trace-otlp-http";
3
+ import { Instrumentation } from "@opentelemetry/instrumentation";
4
+ import { BufferConfig } from "@opentelemetry/sdk-trace-web";
5
+ import { Level, LogfireAttributeScrubber, NoopAttributeScrubber, SamplingOptions, ScrubbingOptions, ULIDGenerator, configureLogfireApi, debug, error, fatal, info, log, logfireApiConfig, notice, reportError, resolveBaseUrl, resolveSendToLogfire, serializeAttributes, span, startSpan, trace, warning } from "logfire";
6
+ export * from "logfire";
7
+
8
+ //#region src/index.d.ts
9
+ type TraceExporterConfig = NonNullable<typeof OTLPTraceExporter extends (new (config: infer T) => unknown) ? T : never>;
10
+ interface LogfireConfigOptions {
11
+ /**
12
+ * The configuration of the batch span processor.
13
+ */
14
+ batchSpanProcessorConfig?: BufferConfig;
15
+ /**
16
+ * Whether to log the spans to the console in addition to sending them to the Logfire API.
17
+ */
18
+ console?: boolean;
19
+ /**
20
+ * Pass a context manager (e.g. ZoneContextManager) to use.
21
+ */
22
+ contextManager?: ContextManager;
23
+ /**
24
+ * Defines the available internal logging levels for the diagnostic logger.
25
+ */
26
+ diagLogLevel?: DiagLogLevel$1;
27
+ /**
28
+ * The environment this service is running in, e.g. `staging` or `prod`. Sets the deployment.environment.name resource attribute. Useful for filtering within projects in the Logfire UI.
29
+ * Defaults to the `LOGFIRE_ENVIRONMENT` environment variable.
30
+ */
31
+ environment?: string;
32
+ /**
33
+ * Whether to compute fingerprints for errors reported via reportError().
34
+ * Defaults to false for browser since minified code produces unstable fingerprints.
35
+ */
36
+ errorFingerprinting?: boolean;
37
+ /**
38
+ * The instrumentations to register - a common one [is the fetch instrumentation](https://www.npmjs.com/package/@opentelemetry/instrumentation-fetch).
39
+ */
40
+ instrumentations?: (Instrumentation | Instrumentation[])[];
41
+ /**
42
+ * Sampling options for controlling which traces are exported.
43
+ * `head` sets a probabilistic sample rate (0.0-1.0) at trace creation time.
44
+ * `tail` provides a callback evaluated on every span to decide whether to keep the trace.
45
+ *
46
+ * Note: Tail sampling buffers all spans in a trace in memory until either a span meets the
47
+ * sampling criteria or the root span ends. In long-lived browser sessions, this can lead to
48
+ * significant memory usage. Consider using head sampling alone for long-running traces, or
49
+ * ensure tail callbacks accept traces quickly (e.g., on the first error-level span).
50
+ */
51
+ sampling?: SamplingOptions;
52
+ /**
53
+ * Options for scrubbing sensitive data. Set to False to disable.
54
+ */
55
+ scrubbing?: false | ScrubbingOptions;
56
+ /**
57
+ * Additional OpenTelemetry resource attributes for the entity producing telemetry.
58
+ *
59
+ * Use this for stable application or browser-session metadata, not per-request or sensitive user data.
60
+ */
61
+ resourceAttributes?: Attributes;
62
+ /**
63
+ * Name of this service.
64
+ */
65
+ serviceName?: string;
66
+ /**
67
+ * Version of this service.
68
+ */
69
+ serviceVersion?: string;
70
+ /**
71
+ * configures the trace exporter.
72
+ */
73
+ traceExporterConfig?: TraceExporterConfig;
74
+ /**
75
+ * Any additional HTTP headers to be sent with the trace exporter requests.
76
+ * This is useful for authentication or other custom headers.
77
+ */
78
+ traceExporterHeaders?: () => Record<string, string>;
79
+ /**
80
+ * The URL of your trace exporter proxy endpoint.
81
+ */
82
+ traceUrl: string;
83
+ }
84
+ declare function configure(options: LogfireConfigOptions): () => Promise<void>;
85
+ declare const defaultExport: {
86
+ DiagLogLevel: typeof DiagLogLevel$1;
87
+ Level: typeof Level;
88
+ LogfireAttributeScrubber: typeof LogfireAttributeScrubber;
89
+ NoopAttributeScrubber: typeof NoopAttributeScrubber;
90
+ ULIDGenerator: typeof ULIDGenerator;
91
+ configure: typeof configure;
92
+ configureLogfireApi: typeof configureLogfireApi;
93
+ debug: typeof debug;
94
+ error: typeof error;
95
+ fatal: typeof fatal;
96
+ info: typeof info;
97
+ log: typeof log;
98
+ logfireApiConfig: typeof logfireApiConfig;
99
+ notice: typeof notice;
100
+ reportError: typeof reportError;
101
+ resolveBaseUrl: typeof resolveBaseUrl;
102
+ resolveSendToLogfire: typeof resolveSendToLogfire;
103
+ serializeAttributes: typeof serializeAttributes;
104
+ span: typeof span;
105
+ startSpan: typeof startSpan;
106
+ trace: typeof trace;
107
+ warning: typeof warning;
108
+ };
109
+ //#endregion
110
+ export { DiagLogLevel, LogfireConfigOptions, configure, defaultExport as default };
package/dist/index.js CHANGED
@@ -1,214 +1 @@
1
- var S = Object.defineProperty;
2
- var R = (r, e, t) => e in r ? S(r, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : r[e] = t;
3
- var u = (r, e, t) => R(r, typeof e != "symbol" ? e + "" : e, t);
4
- import { DiagLogLevel as w, diag as c, DiagConsoleLogger as _ } from "@opentelemetry/api";
5
- import { DiagLogLevel as Ce } from "@opentelemetry/api";
6
- import { OTLPTraceExporter as b } from "@opentelemetry/exporter-trace-otlp-http";
7
- import { registerInstrumentations as p } from "@opentelemetry/instrumentation";
8
- import { resourceFromAttributes as h } from "@opentelemetry/resources";
9
- import { SimpleSpanProcessor as L, ParentBasedSampler as v, TraceIdRatioBasedSampler as x, BatchSpanProcessor as F, WebTracerProvider as C, StackContextManager as D } from "@opentelemetry/sdk-trace-web";
10
- import { TELEMETRY_SDK_LANGUAGE_VALUE_WEBJS as N, ATTR_USER_AGENT_ORIGINAL as P, ATTR_TELEMETRY_SDK_VERSION as I, ATTR_TELEMETRY_SDK_NAME as M, ATTR_TELEMETRY_SDK_LANGUAGE as B, ATTR_SERVICE_VERSION as O, ATTR_SERVICE_NAME as G } from "@opentelemetry/semantic-conventions";
11
- import { ATTR_HTTP_URL as E, ATTR_BROWSER_PLATFORM as U, ATTR_BROWSER_MOBILE as $, ATTR_BROWSER_BRANDS as k, ATTR_DEPLOYMENT_ENVIRONMENT_NAME as y, ATTR_BROWSER_LANGUAGE as V } from "@opentelemetry/semantic-conventions/incubating";
12
- import { warning as W, ULIDGenerator as m, trace as Y, startSpan as H, span as K, serializeAttributes as z, resolveSendToLogfire as J, resolveBaseUrl as X, reportError as j, notice as q, NoopAttributeScrubber as Q, LogfireAttributeScrubber as Z, logfireApiConfig as ee, log as re, Level as te, info as oe, fatal as ne, error as ae, debug as ie, configureLogfireApi as A, TailSamplingProcessor as se } from "logfire";
13
- export * from "logfire";
14
- import { hrTimeToMicroseconds as f, ExportResultCode as ce } from "@opentelemetry/core";
15
- const d = "target_xpath", le = "event_type", ue = {
16
- 1: "trace",
17
- 5: "debug",
18
- 9: "info",
19
- 10: "notice",
20
- 13: "warning",
21
- 17: "error",
22
- 21: "fatal"
23
- }, T = {
24
- debug: "#E3E3E3",
25
- error: "#EA4335",
26
- fatal: "#EA4335",
27
- info: "#9EC1FB",
28
- notice: "#A5D490",
29
- "on-debug": "#636262",
30
- "on-error": "#FFEDE9",
31
- "on-fatal": "#FFEDE9",
32
- "on-info": "#063175",
33
- "on-notice": "#222222",
34
- "on-trace": "#636262",
35
- "on-warning": "#613A0D",
36
- trace: "#E3E3E3",
37
- warning: "#EFB77A"
38
- };
39
- class ge {
40
- export(e, t) {
41
- this.sendSpans(e, t);
42
- }
43
- forceFlush() {
44
- return Promise.resolve();
45
- }
46
- shutdown() {
47
- return this.sendSpans([]), this.forceFlush();
48
- }
49
- /**
50
- * converts span info into more readable format
51
- * @param span
52
- */
53
- exportInfo(e) {
54
- var t;
55
- return {
56
- attributes: e.attributes,
57
- duration: f(e.duration),
58
- events: e.events,
59
- id: e.spanContext().spanId,
60
- instrumentationScope: e.instrumentationScope,
61
- kind: e.kind,
62
- links: e.links,
63
- name: e.name,
64
- parentSpanContext: e.parentSpanContext,
65
- resource: {
66
- attributes: e.resource.attributes
67
- },
68
- status: e.status,
69
- timestamp: f(e.startTime),
70
- traceId: e.spanContext().traceId,
71
- traceState: (t = e.spanContext().traceState) == null ? void 0 : t.serialize()
72
- };
73
- }
74
- sendSpans(e, t) {
75
- for (const n of e) {
76
- const o = ue[n.attributes["logfire.level_num"]] ?? "info", { attributes: a, name: l, ...s } = this.exportInfo(n);
77
- console.log(
78
- `%cLogfire %c${o}`,
79
- "background-color: #E520E9; color: #FFFFFF",
80
- `background-color: ${T[`on-${o}`]}; color: ${T[o]}`,
81
- l,
82
- a,
83
- s
84
- );
85
- }
86
- t && t({ code: ce.SUCCESS });
87
- }
88
- }
89
- class Ee {
90
- constructor(e, t) {
91
- u(this, "console");
92
- u(this, "wrapped");
93
- t && (this.console = new L(new ge())), this.wrapped = e;
94
- }
95
- async forceFlush() {
96
- var e;
97
- return await ((e = this.console) == null ? void 0 : e.forceFlush()), this.wrapped.forceFlush();
98
- }
99
- onEnd(e) {
100
- var t;
101
- (t = this.console) == null || t.onEnd(e), this.wrapped.onEnd(e);
102
- }
103
- onStart(e, t) {
104
- var n;
105
- if (E in e.attributes) {
106
- const o = new URL(e.attributes[E]);
107
- Reflect.set(e, "name", `${e.name} ${o.pathname}`);
108
- }
109
- d in e.attributes && Reflect.set(e, "name", `${e.attributes[le] ?? "unknown"} ${e.attributes[d] ?? ""}`), (n = this.console) == null || n.onStart(e, t), this.wrapped.onStart(e, t);
110
- }
111
- async shutdown() {
112
- var e;
113
- return await ((e = this.console) == null ? void 0 : e.shutdown()), this.wrapped.shutdown();
114
- }
115
- }
116
- function fe() {
117
- return {};
118
- }
119
- async function de(r, e) {
120
- return {
121
- ...typeof r == "function" ? await r() : r ?? {},
122
- ...e()
123
- };
124
- }
125
- function Te(r) {
126
- var s, g;
127
- r.diagLogLevel !== void 0 && c.setLogger(new _(), r.diagLogLevel), A({
128
- errorFingerprinting: r.errorFingerprinting ?? !1,
129
- scrubbing: r.scrubbing
130
- });
131
- const e = h({
132
- [V]: navigator.language,
133
- [G]: r.serviceName ?? "logfire-browser",
134
- [O]: r.serviceVersion ?? "0.0.1",
135
- [B]: N,
136
- [M]: "logfire-browser",
137
- ...r.environment ? { [y]: r.environment } : {},
138
- // eslint-disable-next-line no-undef
139
- [I]: "0.14.2",
140
- ...navigator.userAgentData ? {
141
- [k]: navigator.userAgentData.brands.map((i) => `${i.brand} ${i.version}`),
142
- [$]: navigator.userAgentData.mobile,
143
- [U]: navigator.userAgentData.platform
144
- } : {
145
- [P]: navigator.userAgent
146
- }
147
- });
148
- c.info("logfire-browser: starting");
149
- const t = (s = r.sampling) == null ? void 0 : s.head, n = t !== void 0 && t < 1 ? new v({ root: new x(t) }) : void 0;
150
- let o = new Ee(
151
- new F(
152
- new b({
153
- ...r.traceExporterConfig,
154
- headers: async () => {
155
- var i;
156
- return de((i = r.traceExporterConfig) == null ? void 0 : i.headers, r.traceExporterHeaders ?? fe);
157
- },
158
- url: r.traceUrl
159
- }),
160
- r.batchSpanProcessorConfig
161
- ),
162
- !!r.console
163
- );
164
- (g = r.sampling) != null && g.tail && (o = new se(
165
- o,
166
- r.sampling.tail
167
- ));
168
- const a = new C({
169
- idGenerator: new m(),
170
- resource: e,
171
- ...n ? { sampler: n } : {},
172
- spanProcessors: [o]
173
- });
174
- a.register({
175
- contextManager: r.contextManager ?? new D()
176
- });
177
- const l = p({
178
- instrumentations: r.instrumentations ?? [],
179
- tracerProvider: a
180
- });
181
- return async () => {
182
- c.info("logfire-browser: shutting down"), l(), await a.forceFlush(), await a.shutdown(), c.info("logfire-browser: shut down complete");
183
- };
184
- }
185
- const ve = {
186
- configure: Te,
187
- configureLogfireApi: A,
188
- debug: ie,
189
- DiagLogLevel: w,
190
- error: ae,
191
- fatal: ne,
192
- info: oe,
193
- // Re-export all from logfire
194
- Level: te,
195
- log: re,
196
- logfireApiConfig: ee,
197
- LogfireAttributeScrubber: Z,
198
- NoopAttributeScrubber: Q,
199
- notice: q,
200
- reportError: j,
201
- resolveBaseUrl: X,
202
- resolveSendToLogfire: J,
203
- serializeAttributes: z,
204
- span: K,
205
- startSpan: H,
206
- trace: Y,
207
- ULIDGenerator: m,
208
- warning: W
209
- };
210
- export {
211
- Ce as DiagLogLevel,
212
- Te as configure,
213
- ve as default
214
- };
1
+ import{DiagConsoleLogger as e,DiagLogLevel as t,DiagLogLevel as n,diag as r}from"@opentelemetry/api";import{OTLPTraceExporter as i}from"@opentelemetry/exporter-trace-otlp-http";import{registerInstrumentations as a}from"@opentelemetry/instrumentation";import{resourceFromAttributes as o}from"@opentelemetry/resources";import{BatchSpanProcessor as s,ParentBasedSampler as c,SimpleSpanProcessor as l,StackContextManager as u,TraceIdRatioBasedSampler as d,WebTracerProvider as f}from"@opentelemetry/sdk-trace-web";import{ATTR_SERVICE_NAME as p,ATTR_SERVICE_VERSION as m,ATTR_TELEMETRY_SDK_LANGUAGE as h,ATTR_TELEMETRY_SDK_NAME as g,ATTR_TELEMETRY_SDK_VERSION as _,ATTR_USER_AGENT_ORIGINAL as v,TELEMETRY_SDK_LANGUAGE_VALUE_WEBJS as ee}from"@opentelemetry/semantic-conventions";import{ATTR_BROWSER_BRANDS as y,ATTR_BROWSER_LANGUAGE as b,ATTR_BROWSER_MOBILE as x,ATTR_BROWSER_PLATFORM as S,ATTR_DEPLOYMENT_ENVIRONMENT_NAME as C,ATTR_HTTP_URL as w}from"@opentelemetry/semantic-conventions/incubating";import{Level as T,LogfireAttributeScrubber as E,NoopAttributeScrubber as D,TailSamplingProcessor as O,ULIDGenerator as k,configureLogfireApi as A,debug as j,error as M,fatal as N,info as te,log as P,logfireApiConfig as F,notice as I,reportError as L,resolveBaseUrl as R,resolveSendToLogfire as z,serializeAttributes as B,span as V,startSpan as H,trace as U,warning as W}from"logfire";import{ExportResultCode as G,hrTimeToMicroseconds as K}from"@opentelemetry/core";export*from"logfire";const q=`target_xpath`,J={1:`trace`,5:`debug`,9:`info`,10:`notice`,13:`warning`,17:`error`,21:`fatal`},Y={debug:`#E3E3E3`,error:`#EA4335`,fatal:`#EA4335`,info:`#9EC1FB`,notice:`#A5D490`,"on-debug":`#636262`,"on-error":`#FFEDE9`,"on-fatal":`#FFEDE9`,"on-info":`#063175`,"on-notice":`#222222`,"on-trace":`#636262`,"on-warning":`#613A0D`,trace:`#E3E3E3`,warning:`#EFB77A`};var X=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:K(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:K(e.startTime),traceId:e.spanContext().traceId,traceState:e.spanContext().traceState?.serialize()}}sendSpans(e,t){for(let t of e){let e=J[t.attributes[`logfire.level_num`]]??`info`,{attributes:n,name:r,...i}=this.exportInfo(t);console.log(`%cLogfire %c${e}`,`background-color: #E520E9; color: #FFFFFF`,`background-color: ${Y[`on-${e}`]}; color: ${Y[e]}`,r,n,i)}t&&t({code:G.SUCCESS})}},Z=class{console;wrapped;constructor(e,t){t&&(this.console=new l(new X)),this.wrapped=e}async forceFlush(){return await this.console?.forceFlush(),this.wrapped.forceFlush()}onEnd(e){this.console?.onEnd(e),this.wrapped.onEnd(e)}onStart(e,t){if(w in e.attributes){let t=new URL(e.attributes[w]);Reflect.set(e,`name`,`${e.name} ${t.pathname}`)}if(q in e.attributes){let t=String(e.attributes.event_type??`unknown`),n=String(e.attributes[q]??``);Reflect.set(e,`name`,`${t} ${n}`)}this.console?.onStart(e,t),this.wrapped.onStart(e,t)}async shutdown(){return await this.console?.shutdown(),this.wrapped.shutdown()}};function Q(){return{}}async function ne(e,t){return{...typeof e==`function`?await e():e??{},...t()}}function $(t){t.diagLogLevel!==void 0&&r.setLogger(new e,t.diagLogLevel);let n={errorFingerprinting:t.errorFingerprinting??!1};t.scrubbing!==void 0&&(n.scrubbing=t.scrubbing),A(n);let l=o(t.resourceAttributes??{}).merge(o({[b]:navigator.language,[p]:t.serviceName??`logfire-browser`,[m]:t.serviceVersion??`0.0.1`,[h]:ee,[g]:`logfire-browser`,...t.environment!==void 0&&t.environment!==``?{[C]:t.environment}:{},[_]:`1.0.0`,...navigator.userAgentData?{[y]:navigator.userAgentData.brands.map(e=>`${e.brand} ${e.version}`),[x]:navigator.userAgentData.mobile,[S]:navigator.userAgentData.platform}:{[v]:navigator.userAgent}}));r.info(`logfire-browser: starting`);let w=t.sampling?.head,T=w!==void 0&&w<1?new c({root:new d(w)}):void 0,E=new Z(new s(new i({...t.traceExporterConfig,headers:async()=>ne(t.traceExporterConfig?.headers,t.traceExporterHeaders??Q),url:t.traceUrl}),t.batchSpanProcessorConfig),!!t.console);t.sampling?.tail&&(E=new O(E,t.sampling.tail));let D=new f({idGenerator:new k,resource:l,...T?{sampler:T}:{},spanProcessors:[E]});D.register({contextManager:t.contextManager??new u});let j=a({instrumentations:t.instrumentations??[],tracerProvider:D});return async()=>{r.info(`logfire-browser: shutting down`),j(),await D.forceFlush(),await D.shutdown(),r.info(`logfire-browser: shut down complete`)}}const re={configure:$,configureLogfireApi:A,debug:j,DiagLogLevel:n,error:M,fatal:N,info:te,Level:T,log:P,logfireApiConfig:F,LogfireAttributeScrubber:E,NoopAttributeScrubber:D,notice:I,reportError:L,resolveBaseUrl:R,resolveSendToLogfire:z,serializeAttributes:B,span:V,startSpan:H,trace:U,ULIDGenerator:k,warning:W};export{t as DiagLogLevel,$ as configure,re as default};
package/package.json CHANGED
@@ -25,7 +25,7 @@
25
25
  "stats",
26
26
  "monitoring"
27
27
  ],
28
- "version": "0.14.2",
28
+ "version": "0.15.0",
29
29
  "type": "module",
30
30
  "main": "./dist/index.cjs",
31
31
  "module": "./dist/index.js",
@@ -48,7 +48,7 @@
48
48
  "@opentelemetry/exporter-trace-otlp-http": "^0.215.0",
49
49
  "@opentelemetry/instrumentation": "^0.215.0",
50
50
  "@opentelemetry/resources": "^2.7.0",
51
- "logfire": "0.13.2"
51
+ "logfire": "0.15.0"
52
52
  },
53
53
  "peerDependencies": {
54
54
  "@opentelemetry/sdk-trace-web": "^2.7.0",
@@ -64,11 +64,11 @@
64
64
  "LICENSE"
65
65
  ],
66
66
  "scripts": {
67
- "dev": "vite build",
68
- "build": "vite build",
69
- "lint": "eslint",
70
- "preview": "vite preview",
67
+ "dev": "vp pack --watch",
68
+ "build": "vp pack",
69
+ "lint": "vp lint",
70
+ "preview": "vp preview",
71
71
  "typecheck": "tsc",
72
- "test": "vitest run --passWithNoTests"
72
+ "test": "vp test --passWithNoTests"
73
73
  }
74
74
  }