@pydantic/logfire-browser 0.17.0-alpha.0 → 0.17.0-alpha.2

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
@@ -70,9 +70,13 @@ or 4 hours of total duration by default. Spans get `session.id` and
70
70
  `browser.session.id`; `session.id` is the OpenTelemetry semantic attribute and
71
71
  `browser.session.id` is emitted for Logfire Platform compatibility.
72
72
 
73
- By default, session-enabled spans also get `url.full` and `url.path` from the
74
- current page URL. If your app has sensitive query strings or fragments, provide
75
- a sanitizer or suppress URL attributes:
73
+ By default, session-enabled spans also get `logfire.page.url.full` and
74
+ `logfire.page.url.path` from the current page URL. During the alpha, the SDK
75
+ also emits compatibility `url.full` and `url.path` values with the same
76
+ sanitized page URL. Prefer `logfire.page.url.*` for page grouping because
77
+ OpenTelemetry fetch/resource spans may use `url.*` for the network target URL.
78
+ If your app has sensitive query strings or fragments, provide a sanitizer or
79
+ suppress URL attributes:
76
80
 
77
81
  ```js
78
82
  logfire.configure({
@@ -183,13 +187,14 @@ Metric data point attributes are intentionally low-cardinality:
183
187
  `web_vital.name` and `web_vital.rating` by default. They do not include
184
188
  `session.id`, `browser.session.id`, `url.full`, `url.path`, Web Vital
185
189
  ids/deltas, DOM selectors, attribution fields, or raw PerformanceEntry data. Use
186
- spans for raw-sample drilldown, session/replay correlation, exact URL context,
187
- and attribution selectors.
190
+ spans for raw-sample drilldown, session/replay correlation, exact page context,
191
+ and attribution selectors. When metrics are configured, Logfire Platform should
192
+ treat these histograms as the aggregate Web Vitals surface.
188
193
 
189
194
  For modern single-page apps, these are standard document-level Web Vitals, not
190
- route-level soft-navigation metrics. Span URL attributes describe the browser
191
- URL when the callback fires; route-specific Core Web Vitals need separate route
192
- or soft-navigation instrumentation. To add a route dimension to metrics, pass a
195
+ route-level soft-navigation metrics. Span page URL attributes describe the
196
+ browser URL when the callback fires; route-specific Core Web Vitals need
197
+ separate route or soft-navigation instrumentation. To add a route dimension to metrics, pass a
193
198
  low-cardinality template such as `/products/:id` through
194
199
  `rum.webVitals.metrics.attributes`.
195
200
 
@@ -225,10 +230,13 @@ logfire.configure({
225
230
  ```
226
231
 
227
232
  `sessionReplay` implies default browser session attributes. Replay chunks and
228
- browser spans share `session.id` / `browser.session.id`, and spans started
229
- while replay is active get `logfire.session_replay.active` and
230
- `logfire.session_replay.mode`. The browser integration intentionally does not
231
- poll active trace context into replay chunks.
233
+ browser spans share `session.id` / `browser.session.id`. Spans started after
234
+ replay has loaded and sampled into `full` or `buffer` mode get
235
+ `logfire.session_replay.active` and `logfire.session_replay.mode`. Those active
236
+ attributes are truthful best-effort annotations, not the primary correlation
237
+ key; early spans should be correlated to replay by browser session id and replay
238
+ time bounds. The browser integration intentionally does not poll active trace
239
+ context into replay chunks.
232
240
 
233
241
  Use a backend proxy for browser replay uploads. The proxy should authenticate
234
242
  the browser request with your application session or CSRF mechanism and add the
package/dist/index.cjs CHANGED
@@ -1 +1 @@
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");function l(){let e=globalThis;try{let t=(e.location??e.window?.location)?.href;return t===void 0||t===``?void 0:new URL(t)}catch{return}}var u=class{replayState;sessionManager;constructor(e,t){this.sessionManager=e,this.replayState=t}async forceFlush(){return Promise.resolve()}onEnd(e){}onStart(e,t){let n=this.sessionManager.touch();e.setAttribute(`session.id`,n.id),e.setAttribute(`browser.session.id`,n.id);let r=this.replayState?.getState();r!==void 0&&(e.setAttribute(`logfire.session_replay.active`,r.active),e.setAttribute(`logfire.session_replay.mode`,r.mode));let i=l();if(i===void 0)return;let a;try{a=this.sessionManager.getUrlAttributes(i)}catch{return}a?.full!==void 0&&e.setAttribute(`url.full`,a.full),a?.path!==void 0&&e.setAttribute(`url.path`,a.path)}async shutdown(){return Promise.resolve()}};const d={idleTimeoutMs:30*6e4,maxDurationMs:240*6e4,storageKey:`lf_browser_session`};function f(){try{return globalThis.sessionStorage??null}catch{return null}}function p(){let e=globalThis.crypto;if(typeof e?.randomUUID==`function`)return e.randomUUID();if(typeof e?.getRandomValues==`function`){let t=new Uint8Array(16);return e.getRandomValues(t),Array.from(t,e=>e.toString(16).padStart(2,`0`)).join(``)}return`${Date.now().toString(36)}-${Math.random().toString(36).slice(2)}-${Math.random().toString(36).slice(2)}`}function m(e){if(typeof e!=`object`||!e)return!1;let t=e;return typeof t.id==`string`&&t.id.length>0&&typeof t.startedAt==`number`&&Number.isFinite(t.startedAt)&&typeof t.lastActivityAt==`number`&&Number.isFinite(t.lastActivityAt)}var h=class{generateId;idleTimeoutMs;maxDurationMs;now;storage;storageKey;urlAttributes;memorySession;constructor(e={}){this.generateId=e.generateId??p,this.idleTimeoutMs=e.idleTimeoutMs??d.idleTimeoutMs,this.maxDurationMs=e.maxDurationMs??d.maxDurationMs,this.now=e.now??Date.now,this.storage=e.storage===void 0?f():e.storage,this.storageKey=e.storageKey??d.storageKey,this.urlAttributes=e.urlAttributes}getSession(){return this.getSessionAt(this.now())}peekSessionId(){return this.memorySession?.id}touch(){let e=this.now(),t={...this.getSessionAt(e),lastActivityAt:e};return this.writeSession(t),t}reset(){return this.createSession(this.now())}getUrlAttributes(e){if(this.urlAttributes!==!1)return typeof this.urlAttributes==`function`?this.urlAttributes(e):{full:e.href,path:e.pathname}}createSession(e){let t={id:this.generateId(),lastActivityAt:e,startedAt:e};return this.writeSession(t),t}getSessionAt(e){let t=this.readSession();return t!==void 0&&!this.isExpired(t,e)?t:this.createSession(e)}isExpired(e,t){return t-e.lastActivityAt>this.idleTimeoutMs||t-e.startedAt>this.maxDurationMs}readSession(){if(this.storage!==null)try{let e=this.storage.getItem(this.storageKey);if(e!==null){let t=JSON.parse(e);if(m(t))return this.memorySession=t,t}}catch{return this.memorySession}return this.memorySession}writeSession(e){if(this.memorySession=e,this.storage!==null)try{this.storage.setItem(this.storageKey,JSON.stringify(e))}catch{}}};let g;function _(e){if(e===void 0||e===!1){g=void 0;return}let t=new h(e===!0?{}:e);return g=t,t}function v(){return g?.touch().id}function y(e){g===e&&(g=void 0)}var b=class{replay;setReplay(e){this.replay=e}clear(){this.replay=void 0}getState(){let e=this.replay?.mode;if(!(this.replay?.recording!==!0||e!==`full`&&e!==`buffer`))return{active:!0,mode:e}}};async function x(t,n,r,i){try{if(n.touch(),n.peekSessionId()===void 0)throw Error(`logfire-browser: sessionReplay requires an active browser session id`);let e=await t.load(),a=S(t,n,i),o=C(e.startSessionReplay(a),r);return o.recording&&(o.mode===`full`||o.mode===`buffer`)&&r.setReplay(o),o}catch(n){r.clear(),e.diag.error(`logfire-browser: failed to start session replay; install @pydantic/logfire-session-replay and verify sessionReplay config`,n),t.onError?.(n);return}}function S(e,t,n){let r={getSessionId:()=>t.peekSessionId(),ignoreUrlPatterns:[...w(e.replayUrl,n),...e.ignoreUrlPatterns??[]],redactUrlPatterns:e.redactUrlPatterns??[],replayUrl:e.replayUrl};return e.headers!==void 0&&(r.headers=e.headers),e.token!==void 0&&(r.token=e.token),e.sessionSampleRate!==void 0&&(r.sessionSampleRate=e.sessionSampleRate),e.onErrorSampleRate!==void 0&&(r.onErrorSampleRate=e.onErrorSampleRate),e.maskAllInputs!==void 0&&(r.maskAllInputs=e.maskAllInputs),e.maskTextSelector!==void 0&&(r.maskTextSelector=e.maskTextSelector),e.blockSelector!==void 0&&(r.blockSelector=e.blockSelector),e.flushIntervalMs!==void 0&&(r.flushIntervalMs=e.flushIntervalMs),e.maxBufferBytes!==void 0&&(r.maxBufferBytes=e.maxBufferBytes),e.distinctId!==void 0&&(r.distinctId=e.distinctId),e.getDistinctId!==void 0&&(r.getDistinctId=e.getDistinctId),e.captureConsole!==void 0&&(r.captureConsole=e.captureConsole),e.captureNetwork!==void 0&&(r.captureNetwork=e.captureNetwork),e.captureNavigation!==void 0&&(r.captureNavigation=e.captureNavigation),e.onError!==void 0&&(r.onError=e.onError),e.fetchImpl!==void 0&&(r.fetchImpl=e.fetchImpl),r}function C(e,t){let n;return{get mode(){return e.mode},get recording(){return e.recording},flush:async()=>e.flush(),getSessionId:()=>e.getSessionId(),stop:async()=>(n??=(async()=>{try{await e.stop()}finally{t.clear()}})(),n)}}function w(e,t){return[t.traceUrl,t.metricUrl,e].flatMap(e=>{let t=T(e);return t===void 0?[]:[t]})}function T(e){if(e===void 0||e.length===0)return;let t=e.replace(/\/+$/u,``);return RegExp(`^${E(t)}(?:[/?#]|$)`,`u`)}function E(e){return e.replace(/[.*+?^${}()|[\]\\]/gu,`\\$&`)}let D,O;function k(e){let t=!1;return{async shutdown(){return t?Promise.resolve():(t=!0,e?.shutdown(),O===e&&(O=void 0),Promise.resolve())}}}function A(e,t,n){if(typeof n==`string`||typeof n==`boolean`){e[t]=n;return}typeof n==`number`&&Number.isFinite(n)&&(e[t]=n)}function j(e={}){let t={};return e.reportAllChanges!==void 0&&(t.reportAllChanges=e.reportAllChanges),e.generateTarget!==void 0&&(t.generateTarget=e.generateTarget),t}function M(e={}){return{...j(e),includeProcessedEventEntries:e.includeProcessedEventEntries??!1}}function N(e){let t={};return A(t,`web_vital.name`,e.name),A(t,`web_vital.value`,e.value),A(t,`web_vital.delta`,e.delta),A(t,`web_vital.id`,e.id),A(t,`web_vital.rating`,e.rating),A(t,`web_vital.navigation_type`,e.navigationType),t}function P(e){let t=N(e);switch(e.name){case`LCP`:{let{attribution:n}=e;A(t,`web_vital.lcp.target`,n.target),A(t,`web_vital.lcp.element`,n.target),A(t,`web_vital.lcp.url`,n.url),A(t,`web_vital.lcp.time_to_first_byte`,n.timeToFirstByte),A(t,`web_vital.lcp.resource_load_delay`,n.resourceLoadDelay),A(t,`web_vital.lcp.resource_load_duration`,n.resourceLoadDuration),A(t,`web_vital.lcp.element_render_delay`,n.elementRenderDelay);break}case`INP`:{let{attribution:n}=e;A(t,`web_vital.inp.target`,n.interactionTarget),A(t,`web_vital.inp.interaction_type`,n.interactionType),A(t,`web_vital.inp.interaction_time`,n.interactionTime),A(t,`web_vital.inp.input_delay`,n.inputDelay),A(t,`web_vital.inp.processing_duration`,n.processingDuration),A(t,`web_vital.inp.presentation_delay`,n.presentationDelay),A(t,`web_vital.inp.load_state`,n.loadState);break}case`CLS`:{let{attribution:n}=e;A(t,`web_vital.cls.largest_shift_target`,n.largestShiftTarget),A(t,`web_vital.cls.largest_shift_time`,n.largestShiftTime),A(t,`web_vital.cls.largest_shift_value`,n.largestShiftValue),A(t,`web_vital.cls.load_state`,n.loadState);break}case`FCP`:{let{attribution:n}=e;A(t,`web_vital.fcp.time_to_first_byte`,n.timeToFirstByte),A(t,`web_vital.fcp.first_byte_to_fcp`,n.firstByteToFCP),A(t,`web_vital.fcp.load_state`,n.loadState);break}case`TTFB`:{let{attribution:n}=e;A(t,`web_vital.ttfb.waiting_duration`,n.waitingDuration),A(t,`web_vital.ttfb.cache_duration`,n.cacheDuration),A(t,`web_vital.ttfb.dns_duration`,n.dnsDuration),A(t,`web_vital.ttfb.connection_duration`,n.connectionDuration),A(t,`web_vital.ttfb.request_duration`,n.requestDuration);break}default:break}return t}function F(t){try{let n=e.trace.getTracer(`logfire-web-vitals`).startSpan(`web_vital.${t.name.toLowerCase()}`);try{n.setAttributes(P(t))}finally{n.end()}}catch(t){e.diag.error(`logfire-browser: failed to report Web Vital`,t)}}function I(t,n){if(n!==void 0)try{n.record(t)}catch(t){e.diag.error(`logfire-browser: failed to report Web Vital metric`,t)}}function L(e,t){F(e),I(e,t)}function R(e,t={}){let n=j(t),r=e=>{L(e,O)};e.onLCP(r,n),e.onINP(r,M(t)),e.onCLS(r,n),e.onFCP(r,n),e.onTTFB(r,n)}async function z(t={}){return t.metricRecorder!==void 0&&(O=t.metricRecorder),D??=import(`web-vitals/attribution`).then(e=>{R(e,t)}).catch(t=>{e.diag.error(`logfire-browser: failed to start Web Vitals reporting`,t)}),await D,k(t.metricRecorder)}const B=`target_xpath`,V={1:`trace`,5:`debug`,9:`info`,10:`notice`,13:`warning`,17:`error`,21:`fatal`},H={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 U=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=V[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: ${H[`on-${e}`]}; color: ${H[e]}`,r,n,i)}t&&t({code:c.ExportResultCode.SUCCESS})}},W=class{console;wrapped;constructor(e,t){t&&(this.console=new i.SimpleSpanProcessor(new U)),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(B in e.attributes){let t=String(e.attributes.event_type??`unknown`),n=String(e.attributes[B]??``);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 G(){return{}}function K(e){if(!(e===void 0||e===!1))return e===!0?{}:e}function q(e){if(!(e===void 0||e===!1)){if(e.metricUrl===``)throw Error(`logfire-browser: metrics.metricUrl must be a non-empty browser-safe metrics proxy URL`);return e}}function J(e){if(!(e?.metrics===void 0||e.metrics===!1))return e.metrics===!0?{}:e.metrics}function Y(e){if(!(e===void 0||e===!1))return e}function X(e,t){let n=K(e?.webVitals),r=t!==void 0;if(n===void 0&&!r)return e?.session;if(e?.session===!1)throw Error(r?`logfire-browser: sessionReplay requires browser session attributes; remove rum.session: false or disable sessionReplay`:`logfire-browser: rum.webVitals requires browser session attributes; remove rum.session: false or disable rum.webVitals`);return e?.session??!0}async function Z(e,t){return{...typeof e==`function`?await e():e??{},...t()}}function Q(c){c.diagLogLevel!==void 0&&e.diag.setLogger(new e.DiagConsoleLogger,c.diagLogLevel);let l=K(c.rum?.webVitals),d=Y(c.sessionReplay),f=q(c.metrics),p=J(l);if(p!==void 0&&f===void 0)throw Error(`logfire-browser: rum.webVitals.metrics requires top-level metrics.metricUrl`);let m=X(c.rum,d),h={errorFingerprinting:c.errorFingerprinting??!1};c.baggage!==void 0&&(h.baggage=c.baggage),c.jsonSchema!==void 0&&(h.jsonSchema=c.jsonSchema),c.minLevel!==void 0&&(h.minLevel=c.minLevel),c.scrubbing!==void 0&&(h.scrubbing=c.scrubbing),(0,s.configureLogfireApi)(h);let g=(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]:`0.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 v=c.sampling?.head,S=v!==void 0&&v<1?new i.ParentBasedSampler({root:new i.TraceIdRatioBasedSampler(v)}):void 0,C=new W(new i.BatchSpanProcessor(new t.OTLPTraceExporter({...c.traceExporterConfig,headers:async()=>Z(c.traceExporterConfig?.headers,c.traceExporterHeaders??G),url:c.traceUrl}),c.batchSpanProcessorConfig),!!c.console);c.sampling?.tail&&(C=new s.TailSamplingProcessor(C,c.sampling.tail));let w=_(m),T=new b,E=[];w!==void 0&&E.push(new u(w,T)),E.push(...c.spanProcessors??[],C);let D=new i.WebTracerProvider({idGenerator:new s.ULIDGenerator,resource:g,...S?{sampler:S}:{},spanProcessors:E});D.register({contextManager:c.contextManager??new i.StackContextManager});let O=(0,n.registerInstrumentations)({instrumentations:c.instrumentations??[],tracerProvider:D}),k=d===void 0||w===void 0?void 0:x(d,w,T,{metricUrl:f?.metricUrl,traceUrl:c.traceUrl}),A=f===void 0?void 0:Promise.resolve().then(()=>require("./browserMetrics-sqpejR9C.cjs")).then(async({startBrowserMetrics:e})=>e(f,g)).catch(t=>{e.diag.error(`logfire-browser: failed to start browser metrics`,t)}),j=l===void 0?void 0:p===void 0?z(l).catch(t=>{e.diag.error(`logfire-browser: failed to start Web Vitals reporting`,t)}):(async()=>{let e=await A;if(e===void 0)throw Error(`logfire-browser: failed to start Web Vitals metrics because browser metrics transport did not start`);return z({...l,metricRecorder:e.createWebVitalsMetricRecorder(p)})})().catch(t=>{e.diag.error(`logfire-browser: failed to start Web Vitals reporting`,t)}),M;return()=>(M??=(async()=>{let t,n=(n,r)=>{let i=r instanceof Error?r:Error(String(r));t??=i,e.diag.error(`logfire-browser: ${n} failed during shutdown`,i)},r=async(e,t)=>{try{await t()}catch(t){n(e,t)}};if(e.diag.info(`logfire-browser: shutting down`),k!==void 0&&(T.clear(),await r(`session replay shutdown`,async()=>{await(await k)?.stop()})),await r(`instrumentation unregister`,O),j!==void 0&&await r(`web vitals shutdown`,async()=>{await(await j)?.shutdown()}),A!==void 0&&(await r(`metric provider force flush`,async()=>{await(await A)?.forceFlush()}),await r(`metric provider shutdown`,async()=>{await(await A)?.shutdown()})),await r(`force flush`,async()=>D.forceFlush()),await r(`tracer provider shutdown`,async()=>D.shutdown()),w!==void 0&&await r(`browser session cleanup`,()=>{y(w)}),t!==void 0)throw Error(t.message,{cause:t});e.diag.info(`logfire-browser: shut down complete`)})(),M)}const $={configure:Q,configureLogfireApi:s.configureLogfireApi,debug:s.debug,DiagLogLevel:e.DiagLogLevel,error:s.error,fatal:s.fatal,getBrowserSessionId:v,info:s.info,instrument:s.instrument,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,startPendingSpan:s.startPendingSpan,startSpan:s.startSpan,trace:s.trace,ULIDGenerator:s.ULIDGenerator,warning:s.warning,withSettings:s.withSettings,withTags:s.withTags};Object.defineProperty(exports,"DiagLogLevel",{enumerable:!0,get:function(){return e.DiagLogLevel}}),exports.configure=Q,exports.default=$,exports.getBrowserSessionId=v,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]}})});
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");function l(){let e=globalThis;try{let t=(e.location??e.window?.location)?.href;return t===void 0||t===``?void 0:new URL(t)}catch{return}}var u=class{replayState;sessionManager;constructor(e,t){this.sessionManager=e,this.replayState=t}async forceFlush(){return Promise.resolve()}onEnd(e){}onStart(e,t){let n=this.sessionManager.touch();e.setAttribute(`session.id`,n.id),e.setAttribute(`browser.session.id`,n.id);let r=this.replayState?.getState();r!==void 0&&(e.setAttribute(`logfire.session_replay.active`,r.active),e.setAttribute(`logfire.session_replay.mode`,r.mode));let i=l();if(i===void 0)return;let a;try{a=this.sessionManager.getUrlAttributes(i)}catch{return}a?.full!==void 0&&(e.setAttribute(`logfire.page.url.full`,a.full),e.setAttribute(`url.full`,a.full)),a?.path!==void 0&&(e.setAttribute(`logfire.page.url.path`,a.path),e.setAttribute(`url.path`,a.path))}async shutdown(){return Promise.resolve()}};const d={idleTimeoutMs:30*6e4,maxDurationMs:240*6e4,storageKey:`lf_browser_session`};function f(){try{return globalThis.sessionStorage??null}catch{return null}}function p(){let e=globalThis.crypto;if(typeof e?.randomUUID==`function`)return e.randomUUID();if(typeof e?.getRandomValues==`function`){let t=new Uint8Array(16);return e.getRandomValues(t),Array.from(t,e=>e.toString(16).padStart(2,`0`)).join(``)}return`${Date.now().toString(36)}-${Math.random().toString(36).slice(2)}-${Math.random().toString(36).slice(2)}`}function m(e){if(typeof e!=`object`||!e)return!1;let t=e;return typeof t.id==`string`&&t.id.length>0&&typeof t.startedAt==`number`&&Number.isFinite(t.startedAt)&&typeof t.lastActivityAt==`number`&&Number.isFinite(t.lastActivityAt)}var h=class{generateId;idleTimeoutMs;maxDurationMs;now;storage;storageKey;urlAttributes;memorySession;constructor(e={}){this.generateId=e.generateId??p,this.idleTimeoutMs=e.idleTimeoutMs??d.idleTimeoutMs,this.maxDurationMs=e.maxDurationMs??d.maxDurationMs,this.now=e.now??Date.now,this.storage=e.storage===void 0?f():e.storage,this.storageKey=e.storageKey??d.storageKey,this.urlAttributes=e.urlAttributes}getSession(){return this.getSessionAt(this.now())}peekSessionId(){return this.memorySession?.id}touch(){let e=this.now(),t={...this.getSessionAt(e),lastActivityAt:e};return this.writeSession(t),t}reset(){return this.createSession(this.now())}getUrlAttributes(e){if(this.urlAttributes!==!1)return typeof this.urlAttributes==`function`?this.urlAttributes(e):{full:e.href,path:e.pathname}}createSession(e){let t={id:this.generateId(),lastActivityAt:e,startedAt:e};return this.writeSession(t),t}getSessionAt(e){let t=this.readSession();return t!==void 0&&!this.isExpired(t,e)?t:this.createSession(e)}isExpired(e,t){return t-e.lastActivityAt>this.idleTimeoutMs||t-e.startedAt>this.maxDurationMs}readSession(){if(this.storage!==null)try{let e=this.storage.getItem(this.storageKey);if(e!==null){let t=JSON.parse(e);if(m(t))return this.memorySession=t,t}}catch{return this.memorySession}return this.memorySession}writeSession(e){if(this.memorySession=e,this.storage!==null)try{this.storage.setItem(this.storageKey,JSON.stringify(e))}catch{}}};let g;function _(e){if(e===void 0||e===!1){g=void 0;return}let t=new h(e===!0?{}:e);return g=t,t}function v(){return g?.touch().id}function y(e){g===e&&(g=void 0)}var b=class{replay;setReplay(e){this.replay=e}clear(){this.replay=void 0}getState(){let e=this.replay?.mode;if(!(this.replay?.recording!==!0||e!==`full`&&e!==`buffer`))return{active:!0,mode:e}}};async function x(t,n,r,i){try{if(n.touch(),n.peekSessionId()===void 0)throw Error(`logfire-browser: sessionReplay requires an active browser session id`);let e=await t.load(),a=S(t,n,i),o=C(e.startSessionReplay(a),r);return o.recording&&(o.mode===`full`||o.mode===`buffer`)&&r.setReplay(o),o}catch(n){r.clear(),e.diag.error(`logfire-browser: failed to start session replay; install @pydantic/logfire-session-replay and verify sessionReplay config`,n),t.onError?.(n);return}}function S(e,t,n){let r={getSessionId:()=>t.peekSessionId(),ignoreUrlPatterns:[...w(e.replayUrl,n),...e.ignoreUrlPatterns??[]],redactUrlPatterns:e.redactUrlPatterns??[],replayUrl:e.replayUrl};return e.headers!==void 0&&(r.headers=e.headers),e.token!==void 0&&(r.token=e.token),e.sessionSampleRate!==void 0&&(r.sessionSampleRate=e.sessionSampleRate),e.onErrorSampleRate!==void 0&&(r.onErrorSampleRate=e.onErrorSampleRate),e.maskAllInputs!==void 0&&(r.maskAllInputs=e.maskAllInputs),e.maskTextSelector!==void 0&&(r.maskTextSelector=e.maskTextSelector),e.blockSelector!==void 0&&(r.blockSelector=e.blockSelector),e.flushIntervalMs!==void 0&&(r.flushIntervalMs=e.flushIntervalMs),e.maxBufferBytes!==void 0&&(r.maxBufferBytes=e.maxBufferBytes),e.distinctId!==void 0&&(r.distinctId=e.distinctId),e.getDistinctId!==void 0&&(r.getDistinctId=e.getDistinctId),e.captureConsole!==void 0&&(r.captureConsole=e.captureConsole),e.captureNetwork!==void 0&&(r.captureNetwork=e.captureNetwork),e.captureNavigation!==void 0&&(r.captureNavigation=e.captureNavigation),e.onError!==void 0&&(r.onError=e.onError),e.fetchImpl!==void 0&&(r.fetchImpl=e.fetchImpl),r}function C(e,t){let n;return{get mode(){return e.mode},get recording(){return e.recording},flush:async()=>e.flush(),getSessionId:()=>e.getSessionId(),stop:async()=>(n??=(async()=>{try{await e.stop()}finally{t.clear()}})(),n)}}function w(e,t){return[t.traceUrl,t.metricUrl,e].flatMap(e=>{let t=T(e);return t===void 0?[]:[t]})}function T(e){if(e===void 0||e.length===0)return;let t=e.replace(/\/+$/u,``);return RegExp(`^${E(t)}(?:[/?#]|$)`,`u`)}function E(e){return e.replace(/[.*+?^${}()|[\]\\]/gu,`\\$&`)}let D,O,k;function A(e,t){let n=!1;return{async shutdown(){return n?Promise.resolve():(n=!0,e?.shutdown(),O===e&&(O=void 0),k===t&&(k=void 0),Promise.resolve())}}}function j(e,t,n){if(typeof n==`string`||typeof n==`boolean`){e[t]=n;return}typeof n==`number`&&Number.isFinite(n)&&(e[t]=n)}function M(e={}){let t={};return e.reportAllChanges!==void 0&&(t.reportAllChanges=e.reportAllChanges),e.generateTarget!==void 0&&(t.generateTarget=e.generateTarget),t}function N(e={}){return{...M(e),includeProcessedEventEntries:e.includeProcessedEventEntries??!1}}function ee(e){let t={};return j(t,`web_vital.name`,e.name),j(t,`web_vital.value`,e.value),j(t,`web_vital.delta`,e.delta),j(t,`web_vital.id`,e.id),j(t,`web_vital.rating`,e.rating),j(t,`web_vital.navigation_type`,e.navigationType),t}function P(e){let t=ee(e);switch(e.name){case`LCP`:{let{attribution:n}=e;j(t,`web_vital.lcp.target`,n.target),j(t,`web_vital.lcp.element`,n.target),j(t,`web_vital.lcp.url`,n.url),j(t,`web_vital.lcp.time_to_first_byte`,n.timeToFirstByte),j(t,`web_vital.lcp.resource_load_delay`,n.resourceLoadDelay),j(t,`web_vital.lcp.resource_load_duration`,n.resourceLoadDuration),j(t,`web_vital.lcp.element_render_delay`,n.elementRenderDelay);break}case`INP`:{let{attribution:n}=e;j(t,`web_vital.inp.target`,n.interactionTarget),j(t,`web_vital.inp.interaction_type`,n.interactionType),j(t,`web_vital.inp.interaction_time`,n.interactionTime),j(t,`web_vital.inp.input_delay`,n.inputDelay),j(t,`web_vital.inp.processing_duration`,n.processingDuration),j(t,`web_vital.inp.presentation_delay`,n.presentationDelay),j(t,`web_vital.inp.load_state`,n.loadState);break}case`CLS`:{let{attribution:n}=e;j(t,`web_vital.cls.largest_shift_target`,n.largestShiftTarget),j(t,`web_vital.cls.largest_shift_time`,n.largestShiftTime),j(t,`web_vital.cls.largest_shift_value`,n.largestShiftValue),j(t,`web_vital.cls.load_state`,n.loadState);break}case`FCP`:{let{attribution:n}=e;j(t,`web_vital.fcp.time_to_first_byte`,n.timeToFirstByte),j(t,`web_vital.fcp.first_byte_to_fcp`,n.firstByteToFCP),j(t,`web_vital.fcp.load_state`,n.loadState);break}case`TTFB`:{let{attribution:n}=e;j(t,`web_vital.ttfb.waiting_duration`,n.waitingDuration),j(t,`web_vital.ttfb.cache_duration`,n.cacheDuration),j(t,`web_vital.ttfb.dns_duration`,n.dnsDuration),j(t,`web_vital.ttfb.connection_duration`,n.connectionDuration),j(t,`web_vital.ttfb.request_duration`,n.requestDuration);break}default:break}return t}function F(t,n){if(n===void 0){e.diag.error(`logfire-browser: failed to report Web Vital`,Error(`missing Web Vitals tracer`));return}try{let e=n.startSpan(`web_vital.${t.name.toLowerCase()}`);try{e.setAttributes(P(t))}finally{e.end()}}catch(t){e.diag.error(`logfire-browser: failed to report Web Vital`,t)}}function I(t,n){if(n!==void 0)try{n.record(t)}catch(t){e.diag.error(`logfire-browser: failed to report Web Vital metric`,t)}}function L(e,t,n){F(e,n),I(e,t)}function R(e,t){let n=M(t),r=e=>{L(e,O,k)};e.onLCP(r,n),e.onINP(r,N(t)),e.onCLS(r,n),e.onFCP(r,n),e.onTTFB(r,n)}async function z(t){return t.metricRecorder!==void 0&&(O=t.metricRecorder),k=t.tracer,D??=import(`web-vitals/attribution`).then(e=>{R(e,t)}).catch(t=>{e.diag.error(`logfire-browser: failed to start Web Vitals reporting`,t)}),await D,A(t.metricRecorder,t.tracer)}const B=`target_xpath`,V={1:`trace`,5:`debug`,9:`info`,10:`notice`,13:`warning`,17:`error`,21:`fatal`},H={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 U=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=V[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: ${H[`on-${e}`]}; color: ${H[e]}`,r,n,i)}t&&t({code:c.ExportResultCode.SUCCESS})}},W=class{console;wrapped;constructor(e,t){t&&(this.console=new i.SimpleSpanProcessor(new U)),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(B in e.attributes){let t=String(e.attributes.event_type??`unknown`),n=String(e.attributes[B]??``);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 G(){return{}}function K(e){if(!(e===void 0||e===!1))return e===!0?{}:e}function q(e){if(!(e===void 0||e===!1)){if(e.metricUrl===``)throw Error(`logfire-browser: metrics.metricUrl must be a non-empty browser-safe metrics proxy URL`);return e}}function J(e){if(!(e?.metrics===void 0||e.metrics===!1))return e.metrics===!0?{}:e.metrics}function Y(e){if(!(e===void 0||e===!1))return e}function X(e,t){let n=K(e?.webVitals),r=t!==void 0;if(n===void 0&&!r)return e?.session;if(e?.session===!1)throw Error(r?`logfire-browser: sessionReplay requires browser session attributes; remove rum.session: false or disable sessionReplay`:`logfire-browser: rum.webVitals requires browser session attributes; remove rum.session: false or disable rum.webVitals`);return e?.session??!0}async function Z(e,t){return{...typeof e==`function`?await e():e??{},...t()}}function Q(e){return Array.isArray(e)?e:[e]}function te(e){return(e??[]).flatMap(e=>Q(typeof e==`function`?e():e))}function ne(e){if(e===void 0||e===!1)return;if(e===!0)return{};let{enabled:t,...n}=e;return t===!1?void 0:n}function re(){}function ie(t){let r=(0,n.registerInstrumentations)({instrumentations:te(t.instrumentations),tracerProvider:t.tracerProvider}),i=ne(t.autoInstrumentations),a=i===void 0?void 0:import(`@opentelemetry/auto-instrumentations-web`).then(({getWebAutoInstrumentations:e})=>(0,n.registerInstrumentations)({instrumentations:e(i),tracerProvider:t.tracerProvider})).catch(t=>(e.diag.error(`logfire-browser: failed to start browser auto-instrumentations`,t),re)),o;return async()=>(o??=(async()=>{(await a)?.(),r()})(),o)}function $(n){n.diagLogLevel!==void 0&&e.diag.setLogger(new e.DiagConsoleLogger,n.diagLogLevel);let c=K(n.rum?.webVitals),l=Y(n.sessionReplay),d=q(n.metrics),f=J(c);if(f!==void 0&&d===void 0)throw Error(`logfire-browser: rum.webVitals.metrics requires top-level metrics.metricUrl`);let p=X(n.rum,l),m={errorFingerprinting:n.errorFingerprinting??!1};n.baggage!==void 0&&(m.baggage=n.baggage),n.jsonSchema!==void 0&&(m.jsonSchema=n.jsonSchema),n.minLevel!==void 0&&(m.minLevel=n.minLevel),n.scrubbing!==void 0&&(m.scrubbing=n.scrubbing),(0,s.configureLogfireApi)(m);let h=(0,r.resourceFromAttributes)(n.resourceAttributes??{}).merge((0,r.resourceFromAttributes)({[o.ATTR_BROWSER_LANGUAGE]:navigator.language,[a.ATTR_SERVICE_NAME]:n.serviceName??`logfire-browser`,[a.ATTR_SERVICE_VERSION]:n.serviceVersion??`0.0.1`,[a.ATTR_TELEMETRY_SDK_LANGUAGE]:a.TELEMETRY_SDK_LANGUAGE_VALUE_WEBJS,[a.ATTR_TELEMETRY_SDK_NAME]:`logfire-browser`,...n.environment!==void 0&&n.environment!==``?{[o.ATTR_DEPLOYMENT_ENVIRONMENT_NAME]:n.environment}:{},[a.ATTR_TELEMETRY_SDK_VERSION]:`0.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 g=n.sampling?.head,v=g!==void 0&&g<1?new i.ParentBasedSampler({root:new i.TraceIdRatioBasedSampler(g)}):void 0,S=new W(new i.BatchSpanProcessor(new t.OTLPTraceExporter({...n.traceExporterConfig,headers:async()=>Z(n.traceExporterConfig?.headers,n.traceExporterHeaders??G),url:n.traceUrl}),n.batchSpanProcessorConfig),!!n.console);n.sampling?.tail&&(S=new s.TailSamplingProcessor(S,n.sampling.tail));let C=_(p),w=new b,T=[];C!==void 0&&T.push(new u(C,w)),T.push(...n.spanProcessors??[],S);let E=new i.WebTracerProvider({idGenerator:new s.ULIDGenerator,resource:h,...v?{sampler:v}:{},spanProcessors:T});E.register({contextManager:n.contextManager??new i.StackContextManager});let D=ie({autoInstrumentations:n.autoInstrumentations,instrumentations:n.instrumentations,tracerProvider:E}),O=l===void 0||C===void 0?void 0:x(l,C,w,{metricUrl:d?.metricUrl,traceUrl:n.traceUrl}),k=d===void 0?void 0:Promise.resolve().then(()=>require("./browserMetrics-sqpejR9C.cjs")).then(async({startBrowserMetrics:e})=>e(d,h)).catch(t=>{e.diag.error(`logfire-browser: failed to start browser metrics`,t)}),A=c===void 0?void 0:f===void 0?z({...c,tracer:E.getTracer(`logfire-web-vitals`)}).catch(t=>{e.diag.error(`logfire-browser: failed to start Web Vitals reporting`,t)}):(async()=>{let e=await k;if(e===void 0)throw Error(`logfire-browser: failed to start Web Vitals metrics because browser metrics transport did not start`);return z({...c,metricRecorder:e.createWebVitalsMetricRecorder(f),tracer:E.getTracer(`logfire-web-vitals`)})})().catch(t=>{e.diag.error(`logfire-browser: failed to start Web Vitals reporting`,t)}),j;return()=>(j??=(async()=>{let t,n=(n,r)=>{let i=r instanceof Error?r:Error(String(r));t??=i,e.diag.error(`logfire-browser: ${n} failed during shutdown`,i)},r=async(e,t)=>{try{await t()}catch(t){n(e,t)}};if(e.diag.info(`logfire-browser: shutting down`),O!==void 0&&(w.clear(),await r(`session replay shutdown`,async()=>{await(await O)?.stop()})),await r(`instrumentation unregister`,D),A!==void 0&&await r(`web vitals shutdown`,async()=>{await(await A)?.shutdown()}),k!==void 0&&(await r(`metric provider force flush`,async()=>{await(await k)?.forceFlush()}),await r(`metric provider shutdown`,async()=>{await(await k)?.shutdown()})),await r(`force flush`,async()=>E.forceFlush()),await r(`tracer provider shutdown`,async()=>E.shutdown()),C!==void 0&&await r(`browser session cleanup`,()=>{y(C)}),t!==void 0)throw Error(t.message,{cause:t});e.diag.info(`logfire-browser: shut down complete`)})(),j)}const ae={configure:$,configureLogfireApi:s.configureLogfireApi,debug:s.debug,DiagLogLevel:e.DiagLogLevel,error:s.error,fatal:s.fatal,getBrowserSessionId:v,info:s.info,instrument:s.instrument,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,startPendingSpan:s.startPendingSpan,startSpan:s.startSpan,trace:s.trace,ULIDGenerator:s.ULIDGenerator,warning:s.warning,withSettings:s.withSettings,withTags:s.withTags};Object.defineProperty(exports,"DiagLogLevel",{enumerable:!0,get:function(){return e.DiagLogLevel}}),exports.configure=$,exports.default=ae,exports.getBrowserSessionId=v,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
@@ -2,7 +2,8 @@ import { Attributes, ContextManager, DiagLogLevel, DiagLogLevel as DiagLogLevel$
2
2
  import { OTLPTraceExporter } from "@opentelemetry/exporter-trace-otlp-http";
3
3
  import { Instrumentation } from "@opentelemetry/instrumentation";
4
4
  import { BufferConfig, SpanProcessor } from "@opentelemetry/sdk-trace-web";
5
- import { BaggageOptions, JsonSchemaMode, Level, LogfireAttributeScrubber, MinLevel, NoopAttributeScrubber, SamplingOptions, ScrubbingOptions, ULIDGenerator, configureLogfireApi, debug, error, fatal, info, instrument, log, logfireApiConfig, notice, reportError, resolveBaseUrl, resolveSendToLogfire, serializeAttributes, span, startPendingSpan, startSpan, trace as trace$1, warning, withSettings, withTags } from "logfire";
5
+ import { BaggageOptions, JsonSchemaMode, Level, LogfireAttributeScrubber, MinLevel, NoopAttributeScrubber, SamplingOptions, ScrubbingOptions, ULIDGenerator, configureLogfireApi, debug, error, fatal, info, instrument, log, logfireApiConfig, notice, reportError, resolveBaseUrl, resolveSendToLogfire, serializeAttributes, span, startPendingSpan, startSpan, trace, warning, withSettings, withTags } from "logfire";
6
+ import { InstrumentationConfigMap } from "@opentelemetry/auto-instrumentations-web";
6
7
  import { OTLPMetricExporterOptions } from "@opentelemetry/exporter-metrics-otlp-http";
7
8
  import { MetricReader, PeriodicExportingMetricReaderOptions } from "@opentelemetry/sdk-metrics";
8
9
  import { MetricWithAttribution } from "web-vitals/attribution";
@@ -185,6 +186,10 @@ interface BrowserSessionReplayOptions {
185
186
  //#endregion
186
187
  //#region src/index.d.ts
187
188
  type TraceExporterConfig = NonNullable<typeof OTLPTraceExporter extends (new (config: infer T) => unknown) ? T : never>;
189
+ type BrowserInstrumentationInput = Instrumentation | Instrumentation[] | (() => Instrumentation | Instrumentation[]);
190
+ type AutoInstrumentationsConfig = InstrumentationConfigMap & {
191
+ enabled?: boolean;
192
+ };
188
193
  interface LogfireConfigOptions {
189
194
  /**
190
195
  * The configuration of the batch span processor.
@@ -223,9 +228,16 @@ interface LogfireConfigOptions {
223
228
  */
224
229
  jsonSchema?: JsonSchemaMode;
225
230
  /**
226
- * The instrumentations to register - a common one [is the fetch instrumentation](https://www.npmjs.com/package/@opentelemetry/instrumentation-fetch).
231
+ * Lazily register OpenTelemetry browser auto-instrumentations after the
232
+ * Logfire browser provider and session span processor are ready. Disabled by
233
+ * default. Pass an object to configure `getWebAutoInstrumentations()`.
234
+ */
235
+ autoInstrumentations?: boolean | AutoInstrumentationsConfig;
236
+ /**
237
+ * The instrumentations to register. Pass factories when construction should
238
+ * happen after the Logfire browser provider is registered.
227
239
  */
228
- instrumentations?: (Instrumentation | Instrumentation[])[];
240
+ instrumentations?: BrowserInstrumentationInput[];
229
241
  /**
230
242
  * Minimum Logfire level to emit for manual log-like spans.
231
243
  *
@@ -324,10 +336,10 @@ declare const defaultExport: {
324
336
  span: typeof span;
325
337
  startPendingSpan: typeof startPendingSpan;
326
338
  startSpan: typeof startSpan;
327
- trace: typeof trace$1;
339
+ trace: typeof trace;
328
340
  warning: typeof warning;
329
341
  withSettings: typeof withSettings;
330
342
  withTags: typeof withTags;
331
343
  };
332
344
  //#endregion
333
- export { type BrowserMetricsOptions, type BrowserSessionOptions, type BrowserSessionReplayOptions, type BrowserSessionUrlAttributes, type BrowserWebVitalsMetricOptions, type BrowserWebVitalsOptions, DiagLogLevel, LogfireConfigOptions, type RUMOptions, configure, defaultExport as default, getBrowserSessionId };
345
+ export { AutoInstrumentationsConfig, BrowserInstrumentationInput, type BrowserMetricsOptions, type BrowserSessionOptions, type BrowserSessionReplayOptions, type BrowserSessionUrlAttributes, type BrowserWebVitalsMetricOptions, type BrowserWebVitalsOptions, DiagLogLevel, LogfireConfigOptions, type RUMOptions, configure, defaultExport as default, getBrowserSessionId };
package/dist/index.d.ts CHANGED
@@ -2,7 +2,8 @@ import { Attributes, ContextManager, DiagLogLevel, DiagLogLevel as DiagLogLevel$
2
2
  import { OTLPTraceExporter } from "@opentelemetry/exporter-trace-otlp-http";
3
3
  import { Instrumentation } from "@opentelemetry/instrumentation";
4
4
  import { BufferConfig, SpanProcessor } from "@opentelemetry/sdk-trace-web";
5
- import { BaggageOptions, JsonSchemaMode, Level, LogfireAttributeScrubber, MinLevel, NoopAttributeScrubber, SamplingOptions, ScrubbingOptions, ULIDGenerator, configureLogfireApi, debug, error, fatal, info, instrument, log, logfireApiConfig, notice, reportError, resolveBaseUrl, resolveSendToLogfire, serializeAttributes, span, startPendingSpan, startSpan, trace as trace$1, warning, withSettings, withTags } from "logfire";
5
+ import { BaggageOptions, JsonSchemaMode, Level, LogfireAttributeScrubber, MinLevel, NoopAttributeScrubber, SamplingOptions, ScrubbingOptions, ULIDGenerator, configureLogfireApi, debug, error, fatal, info, instrument, log, logfireApiConfig, notice, reportError, resolveBaseUrl, resolveSendToLogfire, serializeAttributes, span, startPendingSpan, startSpan, trace, warning, withSettings, withTags } from "logfire";
6
+ import { InstrumentationConfigMap } from "@opentelemetry/auto-instrumentations-web";
6
7
  import { OTLPMetricExporterOptions } from "@opentelemetry/exporter-metrics-otlp-http";
7
8
  import { MetricReader, PeriodicExportingMetricReaderOptions } from "@opentelemetry/sdk-metrics";
8
9
  import { MetricWithAttribution } from "web-vitals/attribution";
@@ -185,6 +186,10 @@ interface BrowserSessionReplayOptions {
185
186
  //#endregion
186
187
  //#region src/index.d.ts
187
188
  type TraceExporterConfig = NonNullable<typeof OTLPTraceExporter extends (new (config: infer T) => unknown) ? T : never>;
189
+ type BrowserInstrumentationInput = Instrumentation | Instrumentation[] | (() => Instrumentation | Instrumentation[]);
190
+ type AutoInstrumentationsConfig = InstrumentationConfigMap & {
191
+ enabled?: boolean;
192
+ };
188
193
  interface LogfireConfigOptions {
189
194
  /**
190
195
  * The configuration of the batch span processor.
@@ -223,9 +228,16 @@ interface LogfireConfigOptions {
223
228
  */
224
229
  jsonSchema?: JsonSchemaMode;
225
230
  /**
226
- * The instrumentations to register - a common one [is the fetch instrumentation](https://www.npmjs.com/package/@opentelemetry/instrumentation-fetch).
231
+ * Lazily register OpenTelemetry browser auto-instrumentations after the
232
+ * Logfire browser provider and session span processor are ready. Disabled by
233
+ * default. Pass an object to configure `getWebAutoInstrumentations()`.
234
+ */
235
+ autoInstrumentations?: boolean | AutoInstrumentationsConfig;
236
+ /**
237
+ * The instrumentations to register. Pass factories when construction should
238
+ * happen after the Logfire browser provider is registered.
227
239
  */
228
- instrumentations?: (Instrumentation | Instrumentation[])[];
240
+ instrumentations?: BrowserInstrumentationInput[];
229
241
  /**
230
242
  * Minimum Logfire level to emit for manual log-like spans.
231
243
  *
@@ -324,10 +336,10 @@ declare const defaultExport: {
324
336
  span: typeof span;
325
337
  startPendingSpan: typeof startPendingSpan;
326
338
  startSpan: typeof startSpan;
327
- trace: typeof trace$1;
339
+ trace: typeof trace;
328
340
  warning: typeof warning;
329
341
  withSettings: typeof withSettings;
330
342
  withTags: typeof withTags;
331
343
  };
332
344
  //#endregion
333
- export { type BrowserMetricsOptions, type BrowserSessionOptions, type BrowserSessionReplayOptions, type BrowserSessionUrlAttributes, type BrowserWebVitalsMetricOptions, type BrowserWebVitalsOptions, DiagLogLevel, LogfireConfigOptions, type RUMOptions, configure, defaultExport as default, getBrowserSessionId };
345
+ export { AutoInstrumentationsConfig, BrowserInstrumentationInput, type BrowserMetricsOptions, type BrowserSessionOptions, type BrowserSessionReplayOptions, type BrowserSessionUrlAttributes, type BrowserWebVitalsMetricOptions, type BrowserWebVitalsOptions, DiagLogLevel, LogfireConfigOptions, type RUMOptions, configure, defaultExport as default, getBrowserSessionId };
package/dist/index.js CHANGED
@@ -1 +1 @@
1
- import{DiagConsoleLogger as e,DiagLogLevel as t,DiagLogLevel as n,diag as r,trace as i}from"@opentelemetry/api";import{OTLPTraceExporter as a}from"@opentelemetry/exporter-trace-otlp-http";import{registerInstrumentations as o}from"@opentelemetry/instrumentation";import{resourceFromAttributes as s}from"@opentelemetry/resources";import{BatchSpanProcessor as ee,ParentBasedSampler as te,SimpleSpanProcessor as c,StackContextManager as l,TraceIdRatioBasedSampler as ne,WebTracerProvider as re}from"@opentelemetry/sdk-trace-web";import{ATTR_SERVICE_NAME as ie,ATTR_SERVICE_VERSION as ae,ATTR_TELEMETRY_SDK_LANGUAGE as oe,ATTR_TELEMETRY_SDK_NAME as se,ATTR_TELEMETRY_SDK_VERSION as ce,ATTR_USER_AGENT_ORIGINAL as u,TELEMETRY_SDK_LANGUAGE_VALUE_WEBJS as d}from"@opentelemetry/semantic-conventions";import{ATTR_BROWSER_BRANDS as f,ATTR_BROWSER_LANGUAGE as le,ATTR_BROWSER_MOBILE as ue,ATTR_BROWSER_PLATFORM as de,ATTR_DEPLOYMENT_ENVIRONMENT_NAME as fe,ATTR_HTTP_URL as p}from"@opentelemetry/semantic-conventions/incubating";import{Level as m,LogfireAttributeScrubber as h,NoopAttributeScrubber as g,TailSamplingProcessor as pe,ULIDGenerator as _,configureLogfireApi as v,debug as y,error as b,fatal as x,info as S,instrument as C,log as w,logfireApiConfig as T,notice as E,reportError as D,resolveBaseUrl as O,resolveSendToLogfire as k,serializeAttributes as A,span as j,startPendingSpan as M,startSpan as N,trace as P,warning as F,withSettings as I,withTags as L}from"logfire";import{ExportResultCode as R,hrTimeToMicroseconds as z}from"@opentelemetry/core";export*from"logfire";function B(){let e=globalThis;try{let t=(e.location??e.window?.location)?.href;return t===void 0||t===``?void 0:new URL(t)}catch{return}}var me=class{replayState;sessionManager;constructor(e,t){this.sessionManager=e,this.replayState=t}async forceFlush(){return Promise.resolve()}onEnd(e){}onStart(e,t){let n=this.sessionManager.touch();e.setAttribute(`session.id`,n.id),e.setAttribute(`browser.session.id`,n.id);let r=this.replayState?.getState();r!==void 0&&(e.setAttribute(`logfire.session_replay.active`,r.active),e.setAttribute(`logfire.session_replay.mode`,r.mode));let i=B();if(i===void 0)return;let a;try{a=this.sessionManager.getUrlAttributes(i)}catch{return}a?.full!==void 0&&e.setAttribute(`url.full`,a.full),a?.path!==void 0&&e.setAttribute(`url.path`,a.path)}async shutdown(){return Promise.resolve()}};const V={idleTimeoutMs:30*6e4,maxDurationMs:240*6e4,storageKey:`lf_browser_session`};function he(){try{return globalThis.sessionStorage??null}catch{return null}}function ge(){let e=globalThis.crypto;if(typeof e?.randomUUID==`function`)return e.randomUUID();if(typeof e?.getRandomValues==`function`){let t=new Uint8Array(16);return e.getRandomValues(t),Array.from(t,e=>e.toString(16).padStart(2,`0`)).join(``)}return`${Date.now().toString(36)}-${Math.random().toString(36).slice(2)}-${Math.random().toString(36).slice(2)}`}function _e(e){if(typeof e!=`object`||!e)return!1;let t=e;return typeof t.id==`string`&&t.id.length>0&&typeof t.startedAt==`number`&&Number.isFinite(t.startedAt)&&typeof t.lastActivityAt==`number`&&Number.isFinite(t.lastActivityAt)}var ve=class{generateId;idleTimeoutMs;maxDurationMs;now;storage;storageKey;urlAttributes;memorySession;constructor(e={}){this.generateId=e.generateId??ge,this.idleTimeoutMs=e.idleTimeoutMs??V.idleTimeoutMs,this.maxDurationMs=e.maxDurationMs??V.maxDurationMs,this.now=e.now??Date.now,this.storage=e.storage===void 0?he():e.storage,this.storageKey=e.storageKey??V.storageKey,this.urlAttributes=e.urlAttributes}getSession(){return this.getSessionAt(this.now())}peekSessionId(){return this.memorySession?.id}touch(){let e=this.now(),t={...this.getSessionAt(e),lastActivityAt:e};return this.writeSession(t),t}reset(){return this.createSession(this.now())}getUrlAttributes(e){if(this.urlAttributes!==!1)return typeof this.urlAttributes==`function`?this.urlAttributes(e):{full:e.href,path:e.pathname}}createSession(e){let t={id:this.generateId(),lastActivityAt:e,startedAt:e};return this.writeSession(t),t}getSessionAt(e){let t=this.readSession();return t!==void 0&&!this.isExpired(t,e)?t:this.createSession(e)}isExpired(e,t){return t-e.lastActivityAt>this.idleTimeoutMs||t-e.startedAt>this.maxDurationMs}readSession(){if(this.storage!==null)try{let e=this.storage.getItem(this.storageKey);if(e!==null){let t=JSON.parse(e);if(_e(t))return this.memorySession=t,t}}catch{return this.memorySession}return this.memorySession}writeSession(e){if(this.memorySession=e,this.storage!==null)try{this.storage.setItem(this.storageKey,JSON.stringify(e))}catch{}}};let H;function ye(e){if(e===void 0||e===!1){H=void 0;return}let t=new ve(e===!0?{}:e);return H=t,t}function U(){return H?.touch().id}function be(e){H===e&&(H=void 0)}var xe=class{replay;setReplay(e){this.replay=e}clear(){this.replay=void 0}getState(){let e=this.replay?.mode;if(!(this.replay?.recording!==!0||e!==`full`&&e!==`buffer`))return{active:!0,mode:e}}};async function Se(e,t,n,i){try{if(t.touch(),t.peekSessionId()===void 0)throw Error(`logfire-browser: sessionReplay requires an active browser session id`);let r=await e.load(),a=Ce(e,t,i),o=we(r.startSessionReplay(a),n);return o.recording&&(o.mode===`full`||o.mode===`buffer`)&&n.setReplay(o),o}catch(t){n.clear(),r.error(`logfire-browser: failed to start session replay; install @pydantic/logfire-session-replay and verify sessionReplay config`,t),e.onError?.(t);return}}function Ce(e,t,n){let r={getSessionId:()=>t.peekSessionId(),ignoreUrlPatterns:[...Te(e.replayUrl,n),...e.ignoreUrlPatterns??[]],redactUrlPatterns:e.redactUrlPatterns??[],replayUrl:e.replayUrl};return e.headers!==void 0&&(r.headers=e.headers),e.token!==void 0&&(r.token=e.token),e.sessionSampleRate!==void 0&&(r.sessionSampleRate=e.sessionSampleRate),e.onErrorSampleRate!==void 0&&(r.onErrorSampleRate=e.onErrorSampleRate),e.maskAllInputs!==void 0&&(r.maskAllInputs=e.maskAllInputs),e.maskTextSelector!==void 0&&(r.maskTextSelector=e.maskTextSelector),e.blockSelector!==void 0&&(r.blockSelector=e.blockSelector),e.flushIntervalMs!==void 0&&(r.flushIntervalMs=e.flushIntervalMs),e.maxBufferBytes!==void 0&&(r.maxBufferBytes=e.maxBufferBytes),e.distinctId!==void 0&&(r.distinctId=e.distinctId),e.getDistinctId!==void 0&&(r.getDistinctId=e.getDistinctId),e.captureConsole!==void 0&&(r.captureConsole=e.captureConsole),e.captureNetwork!==void 0&&(r.captureNetwork=e.captureNetwork),e.captureNavigation!==void 0&&(r.captureNavigation=e.captureNavigation),e.onError!==void 0&&(r.onError=e.onError),e.fetchImpl!==void 0&&(r.fetchImpl=e.fetchImpl),r}function we(e,t){let n;return{get mode(){return e.mode},get recording(){return e.recording},flush:async()=>e.flush(),getSessionId:()=>e.getSessionId(),stop:async()=>(n??=(async()=>{try{await e.stop()}finally{t.clear()}})(),n)}}function Te(e,t){return[t.traceUrl,t.metricUrl,e].flatMap(e=>{let t=Ee(e);return t===void 0?[]:[t]})}function Ee(e){if(e===void 0||e.length===0)return;let t=e.replace(/\/+$/u,``);return RegExp(`^${De(t)}(?:[/?#]|$)`,`u`)}function De(e){return e.replace(/[.*+?^${}()|[\]\\]/gu,`\\$&`)}let W,G;function Oe(e){let t=!1;return{async shutdown(){return t?Promise.resolve():(t=!0,e?.shutdown(),G===e&&(G=void 0),Promise.resolve())}}}function K(e,t,n){if(typeof n==`string`||typeof n==`boolean`){e[t]=n;return}typeof n==`number`&&Number.isFinite(n)&&(e[t]=n)}function q(e={}){let t={};return e.reportAllChanges!==void 0&&(t.reportAllChanges=e.reportAllChanges),e.generateTarget!==void 0&&(t.generateTarget=e.generateTarget),t}function ke(e={}){return{...q(e),includeProcessedEventEntries:e.includeProcessedEventEntries??!1}}function Ae(e){let t={};return K(t,`web_vital.name`,e.name),K(t,`web_vital.value`,e.value),K(t,`web_vital.delta`,e.delta),K(t,`web_vital.id`,e.id),K(t,`web_vital.rating`,e.rating),K(t,`web_vital.navigation_type`,e.navigationType),t}function je(e){let t=Ae(e);switch(e.name){case`LCP`:{let{attribution:n}=e;K(t,`web_vital.lcp.target`,n.target),K(t,`web_vital.lcp.element`,n.target),K(t,`web_vital.lcp.url`,n.url),K(t,`web_vital.lcp.time_to_first_byte`,n.timeToFirstByte),K(t,`web_vital.lcp.resource_load_delay`,n.resourceLoadDelay),K(t,`web_vital.lcp.resource_load_duration`,n.resourceLoadDuration),K(t,`web_vital.lcp.element_render_delay`,n.elementRenderDelay);break}case`INP`:{let{attribution:n}=e;K(t,`web_vital.inp.target`,n.interactionTarget),K(t,`web_vital.inp.interaction_type`,n.interactionType),K(t,`web_vital.inp.interaction_time`,n.interactionTime),K(t,`web_vital.inp.input_delay`,n.inputDelay),K(t,`web_vital.inp.processing_duration`,n.processingDuration),K(t,`web_vital.inp.presentation_delay`,n.presentationDelay),K(t,`web_vital.inp.load_state`,n.loadState);break}case`CLS`:{let{attribution:n}=e;K(t,`web_vital.cls.largest_shift_target`,n.largestShiftTarget),K(t,`web_vital.cls.largest_shift_time`,n.largestShiftTime),K(t,`web_vital.cls.largest_shift_value`,n.largestShiftValue),K(t,`web_vital.cls.load_state`,n.loadState);break}case`FCP`:{let{attribution:n}=e;K(t,`web_vital.fcp.time_to_first_byte`,n.timeToFirstByte),K(t,`web_vital.fcp.first_byte_to_fcp`,n.firstByteToFCP),K(t,`web_vital.fcp.load_state`,n.loadState);break}case`TTFB`:{let{attribution:n}=e;K(t,`web_vital.ttfb.waiting_duration`,n.waitingDuration),K(t,`web_vital.ttfb.cache_duration`,n.cacheDuration),K(t,`web_vital.ttfb.dns_duration`,n.dnsDuration),K(t,`web_vital.ttfb.connection_duration`,n.connectionDuration),K(t,`web_vital.ttfb.request_duration`,n.requestDuration);break}default:break}return t}function Me(e){try{let t=i.getTracer(`logfire-web-vitals`).startSpan(`web_vital.${e.name.toLowerCase()}`);try{t.setAttributes(je(e))}finally{t.end()}}catch(e){r.error(`logfire-browser: failed to report Web Vital`,e)}}function Ne(e,t){if(t!==void 0)try{t.record(e)}catch(e){r.error(`logfire-browser: failed to report Web Vital metric`,e)}}function Pe(e,t){Me(e),Ne(e,t)}function Fe(e,t={}){let n=q(t),r=e=>{Pe(e,G)};e.onLCP(r,n),e.onINP(r,ke(t)),e.onCLS(r,n),e.onFCP(r,n),e.onTTFB(r,n)}async function J(e={}){return e.metricRecorder!==void 0&&(G=e.metricRecorder),W??=import(`web-vitals/attribution`).then(t=>{Fe(t,e)}).catch(e=>{r.error(`logfire-browser: failed to start Web Vitals reporting`,e)}),await W,Oe(e.metricRecorder)}const Y=`target_xpath`,Ie={1:`trace`,5:`debug`,9:`info`,10:`notice`,13:`warning`,17:`error`,21:`fatal`},X={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 Le=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:z(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:z(e.startTime),traceId:e.spanContext().traceId,traceState:e.spanContext().traceState?.serialize()}}sendSpans(e,t){for(let t of e){let e=Ie[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: ${X[`on-${e}`]}; color: ${X[e]}`,r,n,i)}t&&t({code:R.SUCCESS})}},Re=class{console;wrapped;constructor(e,t){t&&(this.console=new c(new Le)),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(p in e.attributes){let t=new URL(e.attributes[p]);Reflect.set(e,`name`,`${e.name} ${t.pathname}`)}if(Y in e.attributes){let t=String(e.attributes.event_type??`unknown`),n=String(e.attributes[Y]??``);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 ze(){return{}}function Z(e){if(!(e===void 0||e===!1))return e===!0?{}:e}function Be(e){if(!(e===void 0||e===!1)){if(e.metricUrl===``)throw Error(`logfire-browser: metrics.metricUrl must be a non-empty browser-safe metrics proxy URL`);return e}}function Ve(e){if(!(e?.metrics===void 0||e.metrics===!1))return e.metrics===!0?{}:e.metrics}function Q(e){if(!(e===void 0||e===!1))return e}function He(e,t){let n=Z(e?.webVitals),r=t!==void 0;if(n===void 0&&!r)return e?.session;if(e?.session===!1)throw Error(r?`logfire-browser: sessionReplay requires browser session attributes; remove rum.session: false or disable sessionReplay`:`logfire-browser: rum.webVitals requires browser session attributes; remove rum.session: false or disable rum.webVitals`);return e?.session??!0}async function Ue(e,t){return{...typeof e==`function`?await e():e??{},...t()}}function $(t){t.diagLogLevel!==void 0&&r.setLogger(new e,t.diagLogLevel);let n=Z(t.rum?.webVitals),i=Q(t.sessionReplay),c=Be(t.metrics),p=Ve(n);if(p!==void 0&&c===void 0)throw Error(`logfire-browser: rum.webVitals.metrics requires top-level metrics.metricUrl`);let m=He(t.rum,i),h={errorFingerprinting:t.errorFingerprinting??!1};t.baggage!==void 0&&(h.baggage=t.baggage),t.jsonSchema!==void 0&&(h.jsonSchema=t.jsonSchema),t.minLevel!==void 0&&(h.minLevel=t.minLevel),t.scrubbing!==void 0&&(h.scrubbing=t.scrubbing),v(h);let g=s(t.resourceAttributes??{}).merge(s({[le]:navigator.language,[ie]:t.serviceName??`logfire-browser`,[ae]:t.serviceVersion??`0.0.1`,[oe]:d,[se]:`logfire-browser`,...t.environment!==void 0&&t.environment!==``?{[fe]:t.environment}:{},[ce]:`0.0.0`,...navigator.userAgentData?{[f]:navigator.userAgentData.brands.map(e=>`${e.brand} ${e.version}`),[ue]:navigator.userAgentData.mobile,[de]:navigator.userAgentData.platform}:{[u]:navigator.userAgent}}));r.info(`logfire-browser: starting`);let y=t.sampling?.head,b=y!==void 0&&y<1?new te({root:new ne(y)}):void 0,x=new Re(new ee(new a({...t.traceExporterConfig,headers:async()=>Ue(t.traceExporterConfig?.headers,t.traceExporterHeaders??ze),url:t.traceUrl}),t.batchSpanProcessorConfig),!!t.console);t.sampling?.tail&&(x=new pe(x,t.sampling.tail));let S=ye(m),C=new xe,w=[];S!==void 0&&w.push(new me(S,C)),w.push(...t.spanProcessors??[],x);let T=new re({idGenerator:new _,resource:g,...b?{sampler:b}:{},spanProcessors:w});T.register({contextManager:t.contextManager??new l});let E=o({instrumentations:t.instrumentations??[],tracerProvider:T}),D=i===void 0||S===void 0?void 0:Se(i,S,C,{metricUrl:c?.metricUrl,traceUrl:t.traceUrl}),O=c===void 0?void 0:import(`./browserMetrics-Bx5fHWgu.js`).then(async({startBrowserMetrics:e})=>e(c,g)).catch(e=>{r.error(`logfire-browser: failed to start browser metrics`,e)}),k=n===void 0?void 0:p===void 0?J(n).catch(e=>{r.error(`logfire-browser: failed to start Web Vitals reporting`,e)}):(async()=>{let e=await O;if(e===void 0)throw Error(`logfire-browser: failed to start Web Vitals metrics because browser metrics transport did not start`);return J({...n,metricRecorder:e.createWebVitalsMetricRecorder(p)})})().catch(e=>{r.error(`logfire-browser: failed to start Web Vitals reporting`,e)}),A;return()=>(A??=(async()=>{let e,t=(t,n)=>{let i=n instanceof Error?n:Error(String(n));e??=i,r.error(`logfire-browser: ${t} failed during shutdown`,i)},n=async(e,n)=>{try{await n()}catch(n){t(e,n)}};if(r.info(`logfire-browser: shutting down`),D!==void 0&&(C.clear(),await n(`session replay shutdown`,async()=>{await(await D)?.stop()})),await n(`instrumentation unregister`,E),k!==void 0&&await n(`web vitals shutdown`,async()=>{await(await k)?.shutdown()}),O!==void 0&&(await n(`metric provider force flush`,async()=>{await(await O)?.forceFlush()}),await n(`metric provider shutdown`,async()=>{await(await O)?.shutdown()})),await n(`force flush`,async()=>T.forceFlush()),await n(`tracer provider shutdown`,async()=>T.shutdown()),S!==void 0&&await n(`browser session cleanup`,()=>{be(S)}),e!==void 0)throw Error(e.message,{cause:e});r.info(`logfire-browser: shut down complete`)})(),A)}const We={configure:$,configureLogfireApi:v,debug:y,DiagLogLevel:n,error:b,fatal:x,getBrowserSessionId:U,info:S,instrument:C,Level:m,log:w,logfireApiConfig:T,LogfireAttributeScrubber:h,NoopAttributeScrubber:g,notice:E,reportError:D,resolveBaseUrl:O,resolveSendToLogfire:k,serializeAttributes:A,span:j,startPendingSpan:M,startSpan:N,trace:P,ULIDGenerator:_,warning:F,withSettings:I,withTags:L};export{t as DiagLogLevel,$ as configure,We as default,U as getBrowserSessionId};
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 ee,TraceIdRatioBasedSampler as te,WebTracerProvider as ne}from"@opentelemetry/sdk-trace-web";import{ATTR_SERVICE_NAME as re,ATTR_SERVICE_VERSION as ie,ATTR_TELEMETRY_SDK_LANGUAGE as ae,ATTR_TELEMETRY_SDK_NAME as oe,ATTR_TELEMETRY_SDK_VERSION as se,ATTR_USER_AGENT_ORIGINAL as ce,TELEMETRY_SDK_LANGUAGE_VALUE_WEBJS as le}from"@opentelemetry/semantic-conventions";import{ATTR_BROWSER_BRANDS as ue,ATTR_BROWSER_LANGUAGE as de,ATTR_BROWSER_MOBILE as fe,ATTR_BROWSER_PLATFORM as pe,ATTR_DEPLOYMENT_ENVIRONMENT_NAME as u,ATTR_HTTP_URL as d}from"@opentelemetry/semantic-conventions/incubating";import{Level as f,LogfireAttributeScrubber as p,NoopAttributeScrubber as m,TailSamplingProcessor as me,ULIDGenerator as h,configureLogfireApi as g,debug as _,error as v,fatal as y,info as b,instrument as x,log as S,logfireApiConfig as C,notice as w,reportError as T,resolveBaseUrl as E,resolveSendToLogfire as D,serializeAttributes as O,span as k,startPendingSpan as A,startSpan as j,trace as M,warning as N,withSettings as P,withTags as F}from"logfire";import{ExportResultCode as I,hrTimeToMicroseconds as L}from"@opentelemetry/core";export*from"logfire";function R(){let e=globalThis;try{let t=(e.location??e.window?.location)?.href;return t===void 0||t===``?void 0:new URL(t)}catch{return}}var z=class{replayState;sessionManager;constructor(e,t){this.sessionManager=e,this.replayState=t}async forceFlush(){return Promise.resolve()}onEnd(e){}onStart(e,t){let n=this.sessionManager.touch();e.setAttribute(`session.id`,n.id),e.setAttribute(`browser.session.id`,n.id);let r=this.replayState?.getState();r!==void 0&&(e.setAttribute(`logfire.session_replay.active`,r.active),e.setAttribute(`logfire.session_replay.mode`,r.mode));let i=R();if(i===void 0)return;let a;try{a=this.sessionManager.getUrlAttributes(i)}catch{return}a?.full!==void 0&&(e.setAttribute(`logfire.page.url.full`,a.full),e.setAttribute(`url.full`,a.full)),a?.path!==void 0&&(e.setAttribute(`logfire.page.url.path`,a.path),e.setAttribute(`url.path`,a.path))}async shutdown(){return Promise.resolve()}};const B={idleTimeoutMs:30*6e4,maxDurationMs:240*6e4,storageKey:`lf_browser_session`};function he(){try{return globalThis.sessionStorage??null}catch{return null}}function ge(){let e=globalThis.crypto;if(typeof e?.randomUUID==`function`)return e.randomUUID();if(typeof e?.getRandomValues==`function`){let t=new Uint8Array(16);return e.getRandomValues(t),Array.from(t,e=>e.toString(16).padStart(2,`0`)).join(``)}return`${Date.now().toString(36)}-${Math.random().toString(36).slice(2)}-${Math.random().toString(36).slice(2)}`}function _e(e){if(typeof e!=`object`||!e)return!1;let t=e;return typeof t.id==`string`&&t.id.length>0&&typeof t.startedAt==`number`&&Number.isFinite(t.startedAt)&&typeof t.lastActivityAt==`number`&&Number.isFinite(t.lastActivityAt)}var ve=class{generateId;idleTimeoutMs;maxDurationMs;now;storage;storageKey;urlAttributes;memorySession;constructor(e={}){this.generateId=e.generateId??ge,this.idleTimeoutMs=e.idleTimeoutMs??B.idleTimeoutMs,this.maxDurationMs=e.maxDurationMs??B.maxDurationMs,this.now=e.now??Date.now,this.storage=e.storage===void 0?he():e.storage,this.storageKey=e.storageKey??B.storageKey,this.urlAttributes=e.urlAttributes}getSession(){return this.getSessionAt(this.now())}peekSessionId(){return this.memorySession?.id}touch(){let e=this.now(),t={...this.getSessionAt(e),lastActivityAt:e};return this.writeSession(t),t}reset(){return this.createSession(this.now())}getUrlAttributes(e){if(this.urlAttributes!==!1)return typeof this.urlAttributes==`function`?this.urlAttributes(e):{full:e.href,path:e.pathname}}createSession(e){let t={id:this.generateId(),lastActivityAt:e,startedAt:e};return this.writeSession(t),t}getSessionAt(e){let t=this.readSession();return t!==void 0&&!this.isExpired(t,e)?t:this.createSession(e)}isExpired(e,t){return t-e.lastActivityAt>this.idleTimeoutMs||t-e.startedAt>this.maxDurationMs}readSession(){if(this.storage!==null)try{let e=this.storage.getItem(this.storageKey);if(e!==null){let t=JSON.parse(e);if(_e(t))return this.memorySession=t,t}}catch{return this.memorySession}return this.memorySession}writeSession(e){if(this.memorySession=e,this.storage!==null)try{this.storage.setItem(this.storageKey,JSON.stringify(e))}catch{}}};let V;function ye(e){if(e===void 0||e===!1){V=void 0;return}let t=new ve(e===!0?{}:e);return V=t,t}function H(){return V?.touch().id}function be(e){V===e&&(V=void 0)}var xe=class{replay;setReplay(e){this.replay=e}clear(){this.replay=void 0}getState(){let e=this.replay?.mode;if(!(this.replay?.recording!==!0||e!==`full`&&e!==`buffer`))return{active:!0,mode:e}}};async function Se(e,t,n,i){try{if(t.touch(),t.peekSessionId()===void 0)throw Error(`logfire-browser: sessionReplay requires an active browser session id`);let r=await e.load(),a=Ce(e,t,i),o=we(r.startSessionReplay(a),n);return o.recording&&(o.mode===`full`||o.mode===`buffer`)&&n.setReplay(o),o}catch(t){n.clear(),r.error(`logfire-browser: failed to start session replay; install @pydantic/logfire-session-replay and verify sessionReplay config`,t),e.onError?.(t);return}}function Ce(e,t,n){let r={getSessionId:()=>t.peekSessionId(),ignoreUrlPatterns:[...Te(e.replayUrl,n),...e.ignoreUrlPatterns??[]],redactUrlPatterns:e.redactUrlPatterns??[],replayUrl:e.replayUrl};return e.headers!==void 0&&(r.headers=e.headers),e.token!==void 0&&(r.token=e.token),e.sessionSampleRate!==void 0&&(r.sessionSampleRate=e.sessionSampleRate),e.onErrorSampleRate!==void 0&&(r.onErrorSampleRate=e.onErrorSampleRate),e.maskAllInputs!==void 0&&(r.maskAllInputs=e.maskAllInputs),e.maskTextSelector!==void 0&&(r.maskTextSelector=e.maskTextSelector),e.blockSelector!==void 0&&(r.blockSelector=e.blockSelector),e.flushIntervalMs!==void 0&&(r.flushIntervalMs=e.flushIntervalMs),e.maxBufferBytes!==void 0&&(r.maxBufferBytes=e.maxBufferBytes),e.distinctId!==void 0&&(r.distinctId=e.distinctId),e.getDistinctId!==void 0&&(r.getDistinctId=e.getDistinctId),e.captureConsole!==void 0&&(r.captureConsole=e.captureConsole),e.captureNetwork!==void 0&&(r.captureNetwork=e.captureNetwork),e.captureNavigation!==void 0&&(r.captureNavigation=e.captureNavigation),e.onError!==void 0&&(r.onError=e.onError),e.fetchImpl!==void 0&&(r.fetchImpl=e.fetchImpl),r}function we(e,t){let n;return{get mode(){return e.mode},get recording(){return e.recording},flush:async()=>e.flush(),getSessionId:()=>e.getSessionId(),stop:async()=>(n??=(async()=>{try{await e.stop()}finally{t.clear()}})(),n)}}function Te(e,t){return[t.traceUrl,t.metricUrl,e].flatMap(e=>{let t=Ee(e);return t===void 0?[]:[t]})}function Ee(e){if(e===void 0||e.length===0)return;let t=e.replace(/\/+$/u,``);return RegExp(`^${De(t)}(?:[/?#]|$)`,`u`)}function De(e){return e.replace(/[.*+?^${}()|[\]\\]/gu,`\\$&`)}let U,W,G;function Oe(e,t){let n=!1;return{async shutdown(){return n?Promise.resolve():(n=!0,e?.shutdown(),W===e&&(W=void 0),G===t&&(G=void 0),Promise.resolve())}}}function K(e,t,n){if(typeof n==`string`||typeof n==`boolean`){e[t]=n;return}typeof n==`number`&&Number.isFinite(n)&&(e[t]=n)}function q(e={}){let t={};return e.reportAllChanges!==void 0&&(t.reportAllChanges=e.reportAllChanges),e.generateTarget!==void 0&&(t.generateTarget=e.generateTarget),t}function ke(e={}){return{...q(e),includeProcessedEventEntries:e.includeProcessedEventEntries??!1}}function Ae(e){let t={};return K(t,`web_vital.name`,e.name),K(t,`web_vital.value`,e.value),K(t,`web_vital.delta`,e.delta),K(t,`web_vital.id`,e.id),K(t,`web_vital.rating`,e.rating),K(t,`web_vital.navigation_type`,e.navigationType),t}function je(e){let t=Ae(e);switch(e.name){case`LCP`:{let{attribution:n}=e;K(t,`web_vital.lcp.target`,n.target),K(t,`web_vital.lcp.element`,n.target),K(t,`web_vital.lcp.url`,n.url),K(t,`web_vital.lcp.time_to_first_byte`,n.timeToFirstByte),K(t,`web_vital.lcp.resource_load_delay`,n.resourceLoadDelay),K(t,`web_vital.lcp.resource_load_duration`,n.resourceLoadDuration),K(t,`web_vital.lcp.element_render_delay`,n.elementRenderDelay);break}case`INP`:{let{attribution:n}=e;K(t,`web_vital.inp.target`,n.interactionTarget),K(t,`web_vital.inp.interaction_type`,n.interactionType),K(t,`web_vital.inp.interaction_time`,n.interactionTime),K(t,`web_vital.inp.input_delay`,n.inputDelay),K(t,`web_vital.inp.processing_duration`,n.processingDuration),K(t,`web_vital.inp.presentation_delay`,n.presentationDelay),K(t,`web_vital.inp.load_state`,n.loadState);break}case`CLS`:{let{attribution:n}=e;K(t,`web_vital.cls.largest_shift_target`,n.largestShiftTarget),K(t,`web_vital.cls.largest_shift_time`,n.largestShiftTime),K(t,`web_vital.cls.largest_shift_value`,n.largestShiftValue),K(t,`web_vital.cls.load_state`,n.loadState);break}case`FCP`:{let{attribution:n}=e;K(t,`web_vital.fcp.time_to_first_byte`,n.timeToFirstByte),K(t,`web_vital.fcp.first_byte_to_fcp`,n.firstByteToFCP),K(t,`web_vital.fcp.load_state`,n.loadState);break}case`TTFB`:{let{attribution:n}=e;K(t,`web_vital.ttfb.waiting_duration`,n.waitingDuration),K(t,`web_vital.ttfb.cache_duration`,n.cacheDuration),K(t,`web_vital.ttfb.dns_duration`,n.dnsDuration),K(t,`web_vital.ttfb.connection_duration`,n.connectionDuration),K(t,`web_vital.ttfb.request_duration`,n.requestDuration);break}default:break}return t}function Me(e,t){if(t===void 0){r.error(`logfire-browser: failed to report Web Vital`,Error(`missing Web Vitals tracer`));return}try{let n=t.startSpan(`web_vital.${e.name.toLowerCase()}`);try{n.setAttributes(je(e))}finally{n.end()}}catch(e){r.error(`logfire-browser: failed to report Web Vital`,e)}}function Ne(e,t){if(t!==void 0)try{t.record(e)}catch(e){r.error(`logfire-browser: failed to report Web Vital metric`,e)}}function Pe(e,t,n){Me(e,n),Ne(e,t)}function Fe(e,t){let n=q(t),r=e=>{Pe(e,W,G)};e.onLCP(r,n),e.onINP(r,ke(t)),e.onCLS(r,n),e.onFCP(r,n),e.onTTFB(r,n)}async function J(e){return e.metricRecorder!==void 0&&(W=e.metricRecorder),G=e.tracer,U??=import(`web-vitals/attribution`).then(t=>{Fe(t,e)}).catch(e=>{r.error(`logfire-browser: failed to start Web Vitals reporting`,e)}),await U,Oe(e.metricRecorder,e.tracer)}const Y=`target_xpath`,Ie={1:`trace`,5:`debug`,9:`info`,10:`notice`,13:`warning`,17:`error`,21:`fatal`},X={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 Le=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:L(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:L(e.startTime),traceId:e.spanContext().traceId,traceState:e.spanContext().traceState?.serialize()}}sendSpans(e,t){for(let t of e){let e=Ie[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: ${X[`on-${e}`]}; color: ${X[e]}`,r,n,i)}t&&t({code:I.SUCCESS})}},Re=class{console;wrapped;constructor(e,t){t&&(this.console=new l(new Le)),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(d in e.attributes){let t=new URL(e.attributes[d]);Reflect.set(e,`name`,`${e.name} ${t.pathname}`)}if(Y in e.attributes){let t=String(e.attributes.event_type??`unknown`),n=String(e.attributes[Y]??``);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 ze(){return{}}function Z(e){if(!(e===void 0||e===!1))return e===!0?{}:e}function Be(e){if(!(e===void 0||e===!1)){if(e.metricUrl===``)throw Error(`logfire-browser: metrics.metricUrl must be a non-empty browser-safe metrics proxy URL`);return e}}function Ve(e){if(!(e?.metrics===void 0||e.metrics===!1))return e.metrics===!0?{}:e.metrics}function He(e){if(!(e===void 0||e===!1))return e}function Ue(e,t){let n=Z(e?.webVitals),r=t!==void 0;if(n===void 0&&!r)return e?.session;if(e?.session===!1)throw Error(r?`logfire-browser: sessionReplay requires browser session attributes; remove rum.session: false or disable sessionReplay`:`logfire-browser: rum.webVitals requires browser session attributes; remove rum.session: false or disable rum.webVitals`);return e?.session??!0}async function We(e,t){return{...typeof e==`function`?await e():e??{},...t()}}function Ge(e){return Array.isArray(e)?e:[e]}function Q(e){return(e??[]).flatMap(e=>Ge(typeof e==`function`?e():e))}function Ke(e){if(e===void 0||e===!1)return;if(e===!0)return{};let{enabled:t,...n}=e;return t===!1?void 0:n}function qe(){}function Je(e){let t=a({instrumentations:Q(e.instrumentations),tracerProvider:e.tracerProvider}),n=Ke(e.autoInstrumentations),i=n===void 0?void 0:import(`@opentelemetry/auto-instrumentations-web`).then(({getWebAutoInstrumentations:t})=>a({instrumentations:t(n),tracerProvider:e.tracerProvider})).catch(e=>(r.error(`logfire-browser: failed to start browser auto-instrumentations`,e),qe)),o;return async()=>(o??=(async()=>{(await i)?.(),t()})(),o)}function $(t){t.diagLogLevel!==void 0&&r.setLogger(new e,t.diagLogLevel);let n=Z(t.rum?.webVitals),a=He(t.sessionReplay),l=Be(t.metrics),d=Ve(n);if(d!==void 0&&l===void 0)throw Error(`logfire-browser: rum.webVitals.metrics requires top-level metrics.metricUrl`);let f=Ue(t.rum,a),p={errorFingerprinting:t.errorFingerprinting??!1};t.baggage!==void 0&&(p.baggage=t.baggage),t.jsonSchema!==void 0&&(p.jsonSchema=t.jsonSchema),t.minLevel!==void 0&&(p.minLevel=t.minLevel),t.scrubbing!==void 0&&(p.scrubbing=t.scrubbing),g(p);let m=o(t.resourceAttributes??{}).merge(o({[de]:navigator.language,[re]:t.serviceName??`logfire-browser`,[ie]:t.serviceVersion??`0.0.1`,[ae]:le,[oe]:`logfire-browser`,...t.environment!==void 0&&t.environment!==``?{[u]:t.environment}:{},[se]:`0.0.0`,...navigator.userAgentData?{[ue]:navigator.userAgentData.brands.map(e=>`${e.brand} ${e.version}`),[fe]:navigator.userAgentData.mobile,[pe]:navigator.userAgentData.platform}:{[ce]:navigator.userAgent}}));r.info(`logfire-browser: starting`);let _=t.sampling?.head,v=_!==void 0&&_<1?new c({root:new te(_)}):void 0,y=new Re(new s(new i({...t.traceExporterConfig,headers:async()=>We(t.traceExporterConfig?.headers,t.traceExporterHeaders??ze),url:t.traceUrl}),t.batchSpanProcessorConfig),!!t.console);t.sampling?.tail&&(y=new me(y,t.sampling.tail));let b=ye(f),x=new xe,S=[];b!==void 0&&S.push(new z(b,x)),S.push(...t.spanProcessors??[],y);let C=new ne({idGenerator:new h,resource:m,...v?{sampler:v}:{},spanProcessors:S});C.register({contextManager:t.contextManager??new ee});let w=Je({autoInstrumentations:t.autoInstrumentations,instrumentations:t.instrumentations,tracerProvider:C}),T=a===void 0||b===void 0?void 0:Se(a,b,x,{metricUrl:l?.metricUrl,traceUrl:t.traceUrl}),E=l===void 0?void 0:import(`./browserMetrics-Bx5fHWgu.js`).then(async({startBrowserMetrics:e})=>e(l,m)).catch(e=>{r.error(`logfire-browser: failed to start browser metrics`,e)}),D=n===void 0?void 0:d===void 0?J({...n,tracer:C.getTracer(`logfire-web-vitals`)}).catch(e=>{r.error(`logfire-browser: failed to start Web Vitals reporting`,e)}):(async()=>{let e=await E;if(e===void 0)throw Error(`logfire-browser: failed to start Web Vitals metrics because browser metrics transport did not start`);return J({...n,metricRecorder:e.createWebVitalsMetricRecorder(d),tracer:C.getTracer(`logfire-web-vitals`)})})().catch(e=>{r.error(`logfire-browser: failed to start Web Vitals reporting`,e)}),O;return()=>(O??=(async()=>{let e,t=(t,n)=>{let i=n instanceof Error?n:Error(String(n));e??=i,r.error(`logfire-browser: ${t} failed during shutdown`,i)},n=async(e,n)=>{try{await n()}catch(n){t(e,n)}};if(r.info(`logfire-browser: shutting down`),T!==void 0&&(x.clear(),await n(`session replay shutdown`,async()=>{await(await T)?.stop()})),await n(`instrumentation unregister`,w),D!==void 0&&await n(`web vitals shutdown`,async()=>{await(await D)?.shutdown()}),E!==void 0&&(await n(`metric provider force flush`,async()=>{await(await E)?.forceFlush()}),await n(`metric provider shutdown`,async()=>{await(await E)?.shutdown()})),await n(`force flush`,async()=>C.forceFlush()),await n(`tracer provider shutdown`,async()=>C.shutdown()),b!==void 0&&await n(`browser session cleanup`,()=>{be(b)}),e!==void 0)throw Error(e.message,{cause:e});r.info(`logfire-browser: shut down complete`)})(),O)}const Ye={configure:$,configureLogfireApi:g,debug:_,DiagLogLevel:n,error:v,fatal:y,getBrowserSessionId:H,info:b,instrument:x,Level:f,log:S,logfireApiConfig:C,LogfireAttributeScrubber:p,NoopAttributeScrubber:m,notice:w,reportError:T,resolveBaseUrl:E,resolveSendToLogfire:D,serializeAttributes:O,span:k,startPendingSpan:A,startSpan:j,trace:M,ULIDGenerator:h,warning:N,withSettings:P,withTags:F};export{t as DiagLogLevel,$ as configure,Ye as default,H as getBrowserSessionId};
package/package.json CHANGED
@@ -25,7 +25,7 @@
25
25
  "stats",
26
26
  "monitoring"
27
27
  ],
28
- "version": "0.17.0-alpha.0",
28
+ "version": "0.17.0-alpha.2",
29
29
  "type": "module",
30
30
  "main": "./dist/index.cjs",
31
31
  "module": "./dist/index.js",
@@ -44,6 +44,7 @@
44
44
  },
45
45
  "dependencies": {
46
46
  "@opentelemetry/api": "^1.9.1",
47
+ "@opentelemetry/auto-instrumentations-web": ">=0.64.0 <0.100.0",
47
48
  "@opentelemetry/core": "^2.8.0",
48
49
  "@opentelemetry/exporter-metrics-otlp-http": ">=0.219.0 <0.300.0",
49
50
  "@opentelemetry/exporter-trace-otlp-http": ">=0.219.0 <0.300.0",
@@ -56,7 +57,7 @@
56
57
  "peerDependencies": {
57
58
  "@opentelemetry/sdk-trace-web": "^2.8.0",
58
59
  "@opentelemetry/semantic-conventions": "^1.41.1",
59
- "@pydantic/logfire-session-replay": "0.1.0-alpha.0"
60
+ "@pydantic/logfire-session-replay": "0.1.0-alpha.1"
60
61
  },
61
62
  "peerDependenciesMeta": {
62
63
  "@pydantic/logfire-session-replay": {
@@ -67,7 +68,7 @@
67
68
  "@opentelemetry/sdk-trace-web": "^2.8.0",
68
69
  "@opentelemetry/semantic-conventions": "^1.41.1",
69
70
  "user-agent-data-types": "^0.4.2",
70
- "@pydantic/logfire-session-replay": "0.1.0-alpha.0"
71
+ "@pydantic/logfire-session-replay": "0.1.0-alpha.1"
71
72
  },
72
73
  "files": [
73
74
  "dist",