@pydantic/logfire-browser 0.9.0 → 0.10.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 ADDED
@@ -0,0 +1,30 @@
1
+ # Pydantic Logfire — JavaScript SDK
2
+
3
+ From the team behind [Pydantic Validation](https://pydantic.dev/), **Pydantic Logfire** is an observability platform built on the same belief as our open source library — that the most powerful tools can be easy to use.
4
+
5
+ What sets Logfire apart:
6
+
7
+ - **Simple and Powerful:** Logfire's dashboard is simple relative to the power it provides, ensuring your entire engineering team will actually use it.
8
+ - **SQL:** Query your data using standard SQL — all the control and (for many) nothing new to learn. Using SQL also means you can query your data with existing BI tools and database querying libraries.
9
+ - **OpenTelemetry:** Logfire is an opinionated wrapper around OpenTelemetry, allowing you to leverage existing tooling, infrastructure, and instrumentation for many common packages, and enabling support for virtually any language.
10
+
11
+ See the [documentation](https://logfire.pydantic.dev/docs/) for more information.
12
+
13
+ **Feel free to report issues and ask any questions about Logfire in this repository!**
14
+
15
+ This repo contains the JavaScript Browser SDK; the server application for recording and displaying data is closed source.
16
+
17
+ If you need to instrument your Node.js application, see the [`logfire` package](https://www.npmjs.com/package/logfire).
18
+ If you're instrumenting Cloudflare, see the [Logfire CF workers package](https://www.npmjs.com/package/@pydantic/logfire-cf-workers).
19
+
20
+ ## Basic usage
21
+
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
+
24
+ ## Contributing
25
+
26
+ See [CONTRIBUTING.md](https://github.com/pydantic/logfire-js/blob/main/CONTRIBUTING.md) for development instructions.
27
+
28
+ ## License
29
+
30
+ MIT
package/dist/index.cjs CHANGED
@@ -1 +1 @@
1
- "use strict";var m=Object.defineProperty;var p=(r,e,t)=>e in r?m(r,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):r[e]=t;var l=(r,e,t)=>p(r,typeof e!="symbol"?e+"":e,t);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const s=require("@opentelemetry/api"),A=require("@opentelemetry/instrumentation"),_=require("@opentelemetry/resources"),c=require("@opentelemetry/sdk-trace-web"),a=require("@opentelemetry/semantic-conventions"),i=require("@opentelemetry/semantic-conventions/incubating"),u=require("@pydantic/logfire-api"),g=require("@opentelemetry/core"),E=require("@opentelemetry/otlp-exporter-base"),S=require("@opentelemetry/otlp-exporter-base/browser-http"),R=require("@opentelemetry/otlp-transformer");function w(r){const e=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(r){for(const t in r)if(t!=="default"){const o=Object.getOwnPropertyDescriptor(r,t);Object.defineProperty(e,t,o.get?o:{enumerable:!0,get:()=>r[t]})}}return e.default=r,Object.freeze(e)}const L=w(u),d="target_xpath",v="event_type",O={1:"trace",5:"debug",9:"info",10:"notice",13:"warning",17:"error",21:"fatal"},f={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 D{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:g.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:g.hrTimeToMicroseconds(e.startTime),traceId:e.spanContext().traceId,traceState:(t=e.spanContext().traceState)==null?void 0:t.serialize()}}sendSpans(e,t){for(const o of e){const n=O[o.attributes["logfire.level_num"]]??"info",{attributes:T,name:b,...h}=this.exportInfo(o);console.log(`%cLogfire %c${n}`,"background-color: #E520E9; color: #FFFFFF",`background-color: ${f[`on-${n}`]}; color: ${f[n]}`,b,T,h)}t&&t({code:g.ExportResultCode.SUCCESS})}}class x{constructor(e,t){l(this,"console");l(this,"wrapped");t&&(this.console=new c.SimpleSpanProcessor(new D)),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 o;if(i.ATTR_HTTP_URL in e.attributes){const n=new URL(e.attributes[i.ATTR_HTTP_URL]);Reflect.set(e,"name",`${e.name} ${n.pathname}`)}d in e.attributes&&Reflect.set(e,"name",`${e.attributes[v]??"unknown"} ${e.attributes[d]??""}`),(o=this.console)==null||o.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()}}class C extends E.OTLPExporterBase{constructor(e,t){const n={...E.mergeOtlpSharedConfigurationWithDefaults({compression:e.compression,concurrencyLimit:e.concurrencyLimit,timeoutMillis:e.timeoutMillis},{},E.getSharedConfigurationDefaults()),agentOptions:{keepAlive:!0},headers:()=>({"Content-Type":"application/json",...e.headers??{},...t?t():{}}),url:e.url??"http://localhost:4318/v1/traces"};super(S.createOtlpXhrExportDelegate(n,R.JsonTraceSerializer))}}function P(){return{}}function F(r){r.diagLogLevel!==void 0&&s.diag.setLogger(new s.DiagConsoleLogger,r.diagLogLevel),r.scrubbing!==void 0&&L.configureLogfireApi({scrubbing:r.scrubbing});const e=_.resourceFromAttributes({[i.ATTR_BROWSER_LANGUAGE]:navigator.language,[a.ATTR_SERVICE_NAME]:r.serviceName??"logfire-browser",[a.ATTR_SERVICE_VERSION]:r.serviceVersion??"0.0.1",[a.ATTR_TELEMETRY_SDK_LANGUAGE]:a.TELEMETRY_SDK_LANGUAGE_VALUE_WEBJS,[a.ATTR_TELEMETRY_SDK_NAME]:"logfire-browser",...r.environment?{[i.ATTR_DEPLOYMENT_ENVIRONMENT_NAME]:r.environment}:{},[a.ATTR_TELEMETRY_SDK_VERSION]:"0.9.0",...navigator.userAgentData?{[i.ATTR_BROWSER_BRANDS]:navigator.userAgentData.brands.map(n=>`${n.brand} ${n.version}`),[i.ATTR_BROWSER_MOBILE]:navigator.userAgentData.mobile,[i.ATTR_BROWSER_PLATFORM]:navigator.userAgentData.platform}:{[a.ATTR_USER_AGENT_ORIGINAL]:navigator.userAgent}});s.diag.info("logfire-browser: starting");const t=new c.WebTracerProvider({idGenerator:new u.ULIDGenerator,resource:e,spanProcessors:[new x(new c.BatchSpanProcessor(new C({...r.traceExporterConfig,url:r.traceUrl},r.traceExporterHeaders??P),r.batchSpanProcessorConfig),!!r.console)]});t.register({contextManager:r.contextManager??new c.StackContextManager});const o=A.registerInstrumentations({instrumentations:r.instrumentations??[],tracerProvider:t});return async()=>{s.diag.info("logfire-browser: shutting down"),o(),await t.forceFlush(),await t.shutdown(),s.diag.info("logfire-browser: shut down complete")}}Object.defineProperty(exports,"DiagLogLevel",{enumerable:!0,get:()=>s.DiagLogLevel});exports.configure=F;Object.keys(u).forEach(r=>{r!=="default"&&!Object.prototype.hasOwnProperty.call(exports,r)&&Object.defineProperty(exports,r,{enumerable:!0,get:()=>u[r]})});
1
+ "use strict";var L=Object.defineProperty;var S=(r,e,t)=>e in r?L(r,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):r[e]=t;var l=(r,e,t)=>S(r,typeof e!="symbol"?e+"":e,t);Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const s=require("@opentelemetry/api"),h=require("@opentelemetry/instrumentation"),_=require("@opentelemetry/resources"),u=require("@opentelemetry/sdk-trace-web"),a=require("@opentelemetry/semantic-conventions"),c=require("@opentelemetry/semantic-conventions/incubating"),o=require("@pydantic/logfire-api"),g=require("@opentelemetry/core"),f=require("@opentelemetry/otlp-exporter-base"),R=require("@opentelemetry/otlp-exporter-base/browser-http"),m=require("@opentelemetry/otlp-transformer"),E="target_xpath",w="event_type",v={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"};class D{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:g.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:g.hrTimeToMicroseconds(e.startTime),traceId:e.spanContext().traceId,traceState:(t=e.spanContext().traceState)==null?void 0:t.serialize()}}sendSpans(e,t){for(const i of e){const n=v[i.attributes["logfire.level_num"]]??"info",{attributes:b,name:A,...p}=this.exportInfo(i);console.log(`%cLogfire %c${n}`,"background-color: #E520E9; color: #FFFFFF",`background-color: ${d[`on-${n}`]}; color: ${d[n]}`,A,b,p)}t&&t({code:g.ExportResultCode.SUCCESS})}}class C{constructor(e,t){l(this,"console");l(this,"wrapped");t&&(this.console=new u.SimpleSpanProcessor(new D)),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 i;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}`)}E in e.attributes&&Reflect.set(e,"name",`${e.attributes[w]??"unknown"} ${e.attributes[E]??""}`),(i=this.console)==null||i.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()}}class x extends f.OTLPExporterBase{constructor(e,t){const n={...f.mergeOtlpSharedConfigurationWithDefaults({compression:e.compression,concurrencyLimit:e.concurrencyLimit,timeoutMillis:e.timeoutMillis},{},f.getSharedConfigurationDefaults()),agentOptions:{keepAlive:!0},headers:()=>({"Content-Type":"application/json",...e.headers??{},...t?t():{}}),url:e.url??"http://localhost:4318/v1/traces"};super(R.createOtlpXhrExportDelegate(n,m.JsonTraceSerializer))}}function O(){return{}}function T(r){r.diagLogLevel!==void 0&&s.diag.setLogger(new s.DiagConsoleLogger,r.diagLogLevel),r.scrubbing!==void 0&&o.configureLogfireApi({scrubbing:r.scrubbing});const e=_.resourceFromAttributes({[c.ATTR_BROWSER_LANGUAGE]:navigator.language,[a.ATTR_SERVICE_NAME]:r.serviceName??"logfire-browser",[a.ATTR_SERVICE_VERSION]:r.serviceVersion??"0.0.1",[a.ATTR_TELEMETRY_SDK_LANGUAGE]:a.TELEMETRY_SDK_LANGUAGE_VALUE_WEBJS,[a.ATTR_TELEMETRY_SDK_NAME]:"logfire-browser",...r.environment?{[c.ATTR_DEPLOYMENT_ENVIRONMENT_NAME]:r.environment}:{},[a.ATTR_TELEMETRY_SDK_VERSION]:"0.10.0",...navigator.userAgentData?{[c.ATTR_BROWSER_BRANDS]:navigator.userAgentData.brands.map(n=>`${n.brand} ${n.version}`),[c.ATTR_BROWSER_MOBILE]:navigator.userAgentData.mobile,[c.ATTR_BROWSER_PLATFORM]:navigator.userAgentData.platform}:{[a.ATTR_USER_AGENT_ORIGINAL]:navigator.userAgent}});s.diag.info("logfire-browser: starting");const t=new u.WebTracerProvider({idGenerator:new o.ULIDGenerator,resource:e,spanProcessors:[new C(new u.BatchSpanProcessor(new x({...r.traceExporterConfig,url:r.traceUrl},r.traceExporterHeaders??O),r.batchSpanProcessorConfig),!!r.console)]});t.register({contextManager:r.contextManager??new u.StackContextManager});const i=h.registerInstrumentations({instrumentations:r.instrumentations??[],tracerProvider:t});return async()=>{s.diag.info("logfire-browser: shutting down"),i(),await t.forceFlush(),await t.shutdown(),s.diag.info("logfire-browser: shut down complete")}}const F={configure:T,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=T;exports.default=F;Object.keys(o).forEach(r=>{r!=="default"&&!Object.prototype.hasOwnProperty.call(exports,r)&&Object.defineProperty(exports,r,{enumerable:!0,get:()=>o[r]})});
package/dist/index.d.cts CHANGED
@@ -1,12 +1,65 @@
1
1
  import { BufferConfig } from '@opentelemetry/sdk-trace-web';
2
+ import { configureLogfireApi } from '@pydantic/logfire-api';
2
3
  import { ContextManager } from '@opentelemetry/api';
4
+ import { debug } from '@pydantic/logfire-api';
3
5
  import { DiagLogLevel } from '@opentelemetry/api';
6
+ import { error } from '@pydantic/logfire-api';
7
+ import { fatal } from '@pydantic/logfire-api';
8
+ import { info } from '@pydantic/logfire-api';
4
9
  import { Instrumentation } from '@opentelemetry/instrumentation';
5
- import * as logfireApi from '@pydantic/logfire-api';
10
+ import { log } from '@pydantic/logfire-api';
11
+ import { LogfireApiConfig } from '@pydantic/logfire-api';
12
+ import { LogfireAttributeScrubber } from '@pydantic/logfire-api';
13
+ import { NoopAttributeScrubber } from '@pydantic/logfire-api';
14
+ import { notice } from '@pydantic/logfire-api';
6
15
  import { OTLPTraceExporter } from '@opentelemetry/exporter-trace-otlp-http';
16
+ import { reportError as reportError_2 } from '@pydantic/logfire-api';
17
+ import { resolveBaseUrl } from '@pydantic/logfire-api';
18
+ import { resolveSendToLogfire } from '@pydantic/logfire-api';
19
+ import { ScrubbingOptions } from '@pydantic/logfire-api';
20
+ import { serializeAttributes } from '@pydantic/logfire-api';
21
+ import { span } from '@pydantic/logfire-api';
22
+ import { startSpan } from '@pydantic/logfire-api';
23
+ import { trace } from '@pydantic/logfire-api';
24
+ import { ULIDGenerator } from '@pydantic/logfire-api';
25
+ import { warning } from '@pydantic/logfire-api';
7
26
 
8
27
  export declare function configure(options: LogfireConfigOptions): () => Promise<void>;
9
28
 
29
+ declare const _default: {
30
+ configure: typeof configure;
31
+ configureLogfireApi: typeof configureLogfireApi;
32
+ debug: typeof debug;
33
+ DiagLogLevel: typeof DiagLogLevel;
34
+ error: typeof error;
35
+ fatal: typeof fatal;
36
+ info: typeof info;
37
+ Level: {
38
+ Trace: 1;
39
+ Debug: 5;
40
+ Info: 9;
41
+ Notice: 10;
42
+ Warning: 13;
43
+ Error: 17;
44
+ Fatal: 21;
45
+ };
46
+ log: typeof log;
47
+ logfireApiConfig: LogfireApiConfig;
48
+ LogfireAttributeScrubber: typeof LogfireAttributeScrubber;
49
+ NoopAttributeScrubber: typeof NoopAttributeScrubber;
50
+ notice: typeof notice;
51
+ reportError: typeof reportError_2;
52
+ resolveBaseUrl: typeof resolveBaseUrl;
53
+ resolveSendToLogfire: typeof resolveSendToLogfire;
54
+ serializeAttributes: typeof serializeAttributes;
55
+ span: typeof span;
56
+ startSpan: typeof startSpan;
57
+ trace: typeof trace;
58
+ ULIDGenerator: typeof ULIDGenerator;
59
+ warning: typeof warning;
60
+ };
61
+ export default _default;
62
+
10
63
  export { DiagLogLevel }
11
64
 
12
65
  export declare interface LogfireConfigOptions {
@@ -38,7 +91,7 @@ export declare interface LogfireConfigOptions {
38
91
  /**
39
92
  * Options for scrubbing sensitive data. Set to False to disable.
40
93
  */
41
- scrubbing?: false | logfireApi.ScrubbingOptions;
94
+ scrubbing?: false | ScrubbingOptions;
42
95
  /**
43
96
  * Name of this service.
44
97
  */
package/dist/index.d.ts CHANGED
@@ -1,12 +1,65 @@
1
1
  import { BufferConfig } from '@opentelemetry/sdk-trace-web';
2
+ import { configureLogfireApi } from '@pydantic/logfire-api';
2
3
  import { ContextManager } from '@opentelemetry/api';
4
+ import { debug } from '@pydantic/logfire-api';
3
5
  import { DiagLogLevel } from '@opentelemetry/api';
6
+ import { error } from '@pydantic/logfire-api';
7
+ import { fatal } from '@pydantic/logfire-api';
8
+ import { info } from '@pydantic/logfire-api';
4
9
  import { Instrumentation } from '@opentelemetry/instrumentation';
5
- import * as logfireApi from '@pydantic/logfire-api';
10
+ import { log } from '@pydantic/logfire-api';
11
+ import { LogfireApiConfig } from '@pydantic/logfire-api';
12
+ import { LogfireAttributeScrubber } from '@pydantic/logfire-api';
13
+ import { NoopAttributeScrubber } from '@pydantic/logfire-api';
14
+ import { notice } from '@pydantic/logfire-api';
6
15
  import { OTLPTraceExporter } from '@opentelemetry/exporter-trace-otlp-http';
16
+ import { reportError as reportError_2 } from '@pydantic/logfire-api';
17
+ import { resolveBaseUrl } from '@pydantic/logfire-api';
18
+ import { resolveSendToLogfire } from '@pydantic/logfire-api';
19
+ import { ScrubbingOptions } from '@pydantic/logfire-api';
20
+ import { serializeAttributes } from '@pydantic/logfire-api';
21
+ import { span } from '@pydantic/logfire-api';
22
+ import { startSpan } from '@pydantic/logfire-api';
23
+ import { trace } from '@pydantic/logfire-api';
24
+ import { ULIDGenerator } from '@pydantic/logfire-api';
25
+ import { warning } from '@pydantic/logfire-api';
7
26
 
8
27
  export declare function configure(options: LogfireConfigOptions): () => Promise<void>;
9
28
 
29
+ declare const _default: {
30
+ configure: typeof configure;
31
+ configureLogfireApi: typeof configureLogfireApi;
32
+ debug: typeof debug;
33
+ DiagLogLevel: typeof DiagLogLevel;
34
+ error: typeof error;
35
+ fatal: typeof fatal;
36
+ info: typeof info;
37
+ Level: {
38
+ Trace: 1;
39
+ Debug: 5;
40
+ Info: 9;
41
+ Notice: 10;
42
+ Warning: 13;
43
+ Error: 17;
44
+ Fatal: 21;
45
+ };
46
+ log: typeof log;
47
+ logfireApiConfig: LogfireApiConfig;
48
+ LogfireAttributeScrubber: typeof LogfireAttributeScrubber;
49
+ NoopAttributeScrubber: typeof NoopAttributeScrubber;
50
+ notice: typeof notice;
51
+ reportError: typeof reportError_2;
52
+ resolveBaseUrl: typeof resolveBaseUrl;
53
+ resolveSendToLogfire: typeof resolveSendToLogfire;
54
+ serializeAttributes: typeof serializeAttributes;
55
+ span: typeof span;
56
+ startSpan: typeof startSpan;
57
+ trace: typeof trace;
58
+ ULIDGenerator: typeof ULIDGenerator;
59
+ warning: typeof warning;
60
+ };
61
+ export default _default;
62
+
10
63
  export { DiagLogLevel }
11
64
 
12
65
  export declare interface LogfireConfigOptions {
@@ -38,7 +91,7 @@ export declare interface LogfireConfigOptions {
38
91
  /**
39
92
  * Options for scrubbing sensitive data. Set to False to disable.
40
93
  */
41
- scrubbing?: false | logfireApi.ScrubbingOptions;
94
+ scrubbing?: false | ScrubbingOptions;
42
95
  /**
43
96
  * Name of this service.
44
97
  */
package/dist/index.js CHANGED
@@ -1,21 +1,20 @@
1
- var m = Object.defineProperty;
2
- var T = (t, e, r) => e in t ? m(t, e, { enumerable: !0, configurable: !0, writable: !0, value: r }) : t[e] = r;
3
- var i = (t, e, r) => T(t, typeof e != "symbol" ? e + "" : e, r);
4
- import { diag as a, DiagConsoleLogger as d } from "@opentelemetry/api";
5
- import { DiagLogLevel as le } from "@opentelemetry/api";
6
- import { registerInstrumentations as h } from "@opentelemetry/instrumentation";
7
- import { resourceFromAttributes as A } from "@opentelemetry/resources";
8
- import { SimpleSpanProcessor as p, WebTracerProvider as R, BatchSpanProcessor as S, StackContextManager as _ } from "@opentelemetry/sdk-trace-web";
9
- import { TELEMETRY_SDK_LANGUAGE_VALUE_WEBJS as w, ATTR_USER_AGENT_ORIGINAL as b, ATTR_TELEMETRY_SDK_VERSION as L, ATTR_TELEMETRY_SDK_NAME as v, ATTR_TELEMETRY_SDK_LANGUAGE as x, ATTR_SERVICE_VERSION as C, ATTR_SERVICE_NAME as D } from "@opentelemetry/semantic-conventions";
10
- import { ATTR_HTTP_URL as s, ATTR_BROWSER_PLATFORM as F, ATTR_BROWSER_MOBILE as M, ATTR_BROWSER_BRANDS as N, ATTR_DEPLOYMENT_ENVIRONMENT_NAME as O, ATTR_BROWSER_LANGUAGE as I } from "@opentelemetry/semantic-conventions/incubating";
11
- import * as P from "@pydantic/logfire-api";
12
- import { ULIDGenerator as B } from "@pydantic/logfire-api";
1
+ var d = Object.defineProperty;
2
+ var A = (t, e, r) => e in t ? d(t, e, { enumerable: !0, configurable: !0, writable: !0, value: r }) : t[e] = r;
3
+ var a = (t, e, r) => A(t, typeof e != "symbol" ? e + "" : e, r);
4
+ import { DiagLogLevel as p, diag as i, DiagConsoleLogger as h } from "@opentelemetry/api";
5
+ import { DiagLogLevel as Fe } from "@opentelemetry/api";
6
+ import { registerInstrumentations as S } from "@opentelemetry/instrumentation";
7
+ import { resourceFromAttributes as b } from "@opentelemetry/resources";
8
+ import { SimpleSpanProcessor as R, WebTracerProvider as _, BatchSpanProcessor as L, StackContextManager as w } from "@opentelemetry/sdk-trace-web";
9
+ import { TELEMETRY_SDK_LANGUAGE_VALUE_WEBJS as v, ATTR_USER_AGENT_ORIGINAL as x, ATTR_TELEMETRY_SDK_VERSION as C, ATTR_TELEMETRY_SDK_NAME as D, ATTR_TELEMETRY_SDK_LANGUAGE as F, ATTR_SERVICE_VERSION as N, ATTR_SERVICE_NAME as M } from "@opentelemetry/semantic-conventions";
10
+ import { ATTR_HTTP_URL as s, ATTR_BROWSER_PLATFORM as O, ATTR_BROWSER_MOBILE as I, ATTR_BROWSER_BRANDS as P, ATTR_DEPLOYMENT_ENVIRONMENT_NAME as B, ATTR_BROWSER_LANGUAGE as G } from "@opentelemetry/semantic-conventions/incubating";
11
+ import { warning as U, ULIDGenerator as g, trace as $, startSpan as k, span as y, serializeAttributes as V, resolveSendToLogfire as W, resolveBaseUrl as Y, reportError as H, notice as K, NoopAttributeScrubber as z, LogfireAttributeScrubber as J, logfireApiConfig as X, log as j, Level as q, info as Q, fatal as Z, error as ee, debug as re, configureLogfireApi as E } from "@pydantic/logfire-api";
13
12
  export * from "@pydantic/logfire-api";
14
- import { hrTimeToMicroseconds as c, ExportResultCode as G } from "@opentelemetry/core";
15
- import { OTLPExporterBase as U, mergeOtlpSharedConfigurationWithDefaults as $, getSharedConfigurationDefaults as k } from "@opentelemetry/otlp-exporter-base";
16
- import { createOtlpXhrExportDelegate as y } from "@opentelemetry/otlp-exporter-base/browser-http";
17
- import { JsonTraceSerializer as V } from "@opentelemetry/otlp-transformer";
18
- const u = "target_xpath", W = "event_type", Y = {
13
+ import { hrTimeToMicroseconds as c, ExportResultCode as te } from "@opentelemetry/core";
14
+ import { OTLPExporterBase as oe, mergeOtlpSharedConfigurationWithDefaults as ne, getSharedConfigurationDefaults as ie } from "@opentelemetry/otlp-exporter-base";
15
+ import { createOtlpXhrExportDelegate as ae } from "@opentelemetry/otlp-exporter-base/browser-http";
16
+ import { JsonTraceSerializer as se } from "@opentelemetry/otlp-transformer";
17
+ const u = "target_xpath", ce = "event_type", ue = {
19
18
  1: "trace",
20
19
  5: "debug",
21
20
  9: "info",
@@ -39,7 +38,7 @@ const u = "target_xpath", W = "event_type", Y = {
39
38
  trace: "#E3E3E3",
40
39
  warning: "#EFB77A"
41
40
  };
42
- class H {
41
+ class le {
43
42
  export(e, r) {
44
43
  this.sendSpans(e, r);
45
44
  }
@@ -76,24 +75,24 @@ class H {
76
75
  }
77
76
  sendSpans(e, r) {
78
77
  for (const n of e) {
79
- const o = Y[n.attributes["logfire.level_num"]] ?? "info", { attributes: E, name: g, ...f } = this.exportInfo(n);
78
+ const o = ue[n.attributes["logfire.level_num"]] ?? "info", { attributes: f, name: m, ...T } = this.exportInfo(n);
80
79
  console.log(
81
80
  `%cLogfire %c${o}`,
82
81
  "background-color: #E520E9; color: #FFFFFF",
83
82
  `background-color: ${l[`on-${o}`]}; color: ${l[o]}`,
84
- g,
85
- E,
86
- f
83
+ m,
84
+ f,
85
+ T
87
86
  );
88
87
  }
89
- r && r({ code: G.SUCCESS });
88
+ r && r({ code: te.SUCCESS });
90
89
  }
91
90
  }
92
- class K {
91
+ class ge {
93
92
  constructor(e, r) {
94
- i(this, "console");
95
- i(this, "wrapped");
96
- r && (this.console = new p(new H())), this.wrapped = e;
93
+ a(this, "console");
94
+ a(this, "wrapped");
95
+ r && (this.console = new R(new le())), this.wrapped = e;
97
96
  }
98
97
  async forceFlush() {
99
98
  var e;
@@ -109,24 +108,24 @@ class K {
109
108
  const o = new URL(e.attributes[s]);
110
109
  Reflect.set(e, "name", `${e.name} ${o.pathname}`);
111
110
  }
112
- u in e.attributes && Reflect.set(e, "name", `${e.attributes[W] ?? "unknown"} ${e.attributes[u] ?? ""}`), (n = this.console) == null || n.onStart(e, r), this.wrapped.onStart(e, r);
111
+ u in e.attributes && Reflect.set(e, "name", `${e.attributes[ce] ?? "unknown"} ${e.attributes[u] ?? ""}`), (n = this.console) == null || n.onStart(e, r), this.wrapped.onStart(e, r);
113
112
  }
114
113
  async shutdown() {
115
114
  var e;
116
115
  return await ((e = this.console) == null ? void 0 : e.shutdown()), this.wrapped.shutdown();
117
116
  }
118
117
  }
119
- class z extends U {
118
+ class Ee extends oe {
120
119
  constructor(e, r) {
121
120
  const o = {
122
- ...$(
121
+ ...ne(
123
122
  {
124
123
  compression: e.compression,
125
124
  concurrencyLimit: e.concurrencyLimit,
126
125
  timeoutMillis: e.timeoutMillis
127
126
  },
128
127
  {},
129
- k()
128
+ ie()
130
129
  ),
131
130
  agentOptions: { keepAlive: !0 },
132
131
  headers: () => ({
@@ -136,41 +135,41 @@ class z extends U {
136
135
  }),
137
136
  url: e.url ?? "http://localhost:4318/v1/traces"
138
137
  };
139
- super(y(o, V));
138
+ super(ae(o, se));
140
139
  }
141
140
  }
142
- function J() {
141
+ function fe() {
143
142
  return {};
144
143
  }
145
- function se(t) {
146
- t.diagLogLevel !== void 0 && a.setLogger(new d(), t.diagLogLevel), t.scrubbing !== void 0 && P.configureLogfireApi({ scrubbing: t.scrubbing });
147
- const e = A({
148
- [I]: navigator.language,
149
- [D]: t.serviceName ?? "logfire-browser",
150
- [C]: t.serviceVersion ?? "0.0.1",
151
- [x]: w,
152
- [v]: "logfire-browser",
153
- ...t.environment ? { [O]: t.environment } : {},
144
+ function me(t) {
145
+ t.diagLogLevel !== void 0 && i.setLogger(new h(), t.diagLogLevel), t.scrubbing !== void 0 && E({ scrubbing: t.scrubbing });
146
+ const e = b({
147
+ [G]: navigator.language,
148
+ [M]: t.serviceName ?? "logfire-browser",
149
+ [N]: t.serviceVersion ?? "0.0.1",
150
+ [F]: v,
151
+ [D]: "logfire-browser",
152
+ ...t.environment ? { [B]: t.environment } : {},
154
153
  // eslint-disable-next-line no-undef
155
- [L]: "0.9.0",
154
+ [C]: "0.10.0",
156
155
  ...navigator.userAgentData ? {
157
- [N]: navigator.userAgentData.brands.map((o) => `${o.brand} ${o.version}`),
158
- [M]: navigator.userAgentData.mobile,
159
- [F]: navigator.userAgentData.platform
156
+ [P]: navigator.userAgentData.brands.map((o) => `${o.brand} ${o.version}`),
157
+ [I]: navigator.userAgentData.mobile,
158
+ [O]: navigator.userAgentData.platform
160
159
  } : {
161
- [b]: navigator.userAgent
160
+ [x]: navigator.userAgent
162
161
  }
163
162
  });
164
- a.info("logfire-browser: starting");
165
- const r = new R({
166
- idGenerator: new B(),
163
+ i.info("logfire-browser: starting");
164
+ const r = new _({
165
+ idGenerator: new g(),
167
166
  resource: e,
168
167
  spanProcessors: [
169
- new K(
170
- new S(
171
- new z(
168
+ new ge(
169
+ new L(
170
+ new Ee(
172
171
  { ...t.traceExporterConfig, url: t.traceUrl },
173
- t.traceExporterHeaders ?? J
172
+ t.traceExporterHeaders ?? fe
174
173
  ),
175
174
  t.batchSpanProcessorConfig
176
175
  ),
@@ -179,17 +178,43 @@ function se(t) {
179
178
  ]
180
179
  });
181
180
  r.register({
182
- contextManager: t.contextManager ?? new _()
181
+ contextManager: t.contextManager ?? new w()
183
182
  });
184
- const n = h({
183
+ const n = S({
185
184
  instrumentations: t.instrumentations ?? [],
186
185
  tracerProvider: r
187
186
  });
188
187
  return async () => {
189
- a.info("logfire-browser: shutting down"), n(), await r.forceFlush(), await r.shutdown(), a.info("logfire-browser: shut down complete");
188
+ i.info("logfire-browser: shutting down"), n(), await r.forceFlush(), await r.shutdown(), i.info("logfire-browser: shut down complete");
190
189
  };
191
190
  }
191
+ const xe = {
192
+ configure: me,
193
+ configureLogfireApi: E,
194
+ debug: re,
195
+ DiagLogLevel: p,
196
+ error: ee,
197
+ fatal: Z,
198
+ info: Q,
199
+ // Re-export all from @pydantic/logfire-api
200
+ Level: q,
201
+ log: j,
202
+ logfireApiConfig: X,
203
+ LogfireAttributeScrubber: J,
204
+ NoopAttributeScrubber: z,
205
+ notice: K,
206
+ reportError: H,
207
+ resolveBaseUrl: Y,
208
+ resolveSendToLogfire: W,
209
+ serializeAttributes: V,
210
+ span: y,
211
+ startSpan: k,
212
+ trace: $,
213
+ ULIDGenerator: g,
214
+ warning: U
215
+ };
192
216
  export {
193
- le as DiagLogLevel,
194
- se as configure
217
+ Fe as DiagLogLevel,
218
+ me as configure,
219
+ xe as default
195
220
  };
package/package.json CHANGED
@@ -6,6 +6,10 @@
6
6
  "email": "engineering@pydantic.dev",
7
7
  "url": "https://pydantic.dev"
8
8
  },
9
+ "repository": {
10
+ "url": "https://github.com/pydantic/logfire-js",
11
+ "directory": "packages/logfire-browser"
12
+ },
9
13
  "sideEffects": false,
10
14
  "homepage": "https://pydantic.dev/logfire",
11
15
  "license": "MIT",
@@ -21,7 +25,7 @@
21
25
  "stats",
22
26
  "monitoring"
23
27
  ],
24
- "version": "0.9.0",
28
+ "version": "0.10.0",
25
29
  "type": "module",
26
30
  "main": "./dist/index.cjs",
27
31
  "module": "./dist/index.js",
@@ -46,7 +50,7 @@
46
50
  "typecheck": "tsc",
47
51
  "prepack": "cp ../../LICENSE .",
48
52
  "postpack": "rm LICENSE",
49
- "test": "vitest --passWithNoTests"
53
+ "test": "vitest run --passWithNoTests"
50
54
  },
51
55
  "dependencies": {
52
56
  "@opentelemetry/api": "^1.9.0",