@pydantic/logfire-browser 0.8.1 → 0.9.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/dist/index.cjs +1 -1
- package/dist/index.d.cts +4 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.js +163 -83
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var
|
|
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]})});
|
package/dist/index.d.cts
CHANGED
|
@@ -14,6 +14,10 @@ export declare interface LogfireConfigOptions {
|
|
|
14
14
|
* The configuration of the batch span processor.
|
|
15
15
|
*/
|
|
16
16
|
batchSpanProcessorConfig?: BufferConfig;
|
|
17
|
+
/**
|
|
18
|
+
* Whether to log the spans to the console in addition to sending them to the Logfire API.
|
|
19
|
+
*/
|
|
20
|
+
console?: boolean;
|
|
17
21
|
/**
|
|
18
22
|
* Pass a context manager (e.g. ZoneContextManager) to use.
|
|
19
23
|
*/
|
package/dist/index.d.ts
CHANGED
|
@@ -14,6 +14,10 @@ export declare interface LogfireConfigOptions {
|
|
|
14
14
|
* The configuration of the batch span processor.
|
|
15
15
|
*/
|
|
16
16
|
batchSpanProcessorConfig?: BufferConfig;
|
|
17
|
+
/**
|
|
18
|
+
* Whether to log the spans to the console in addition to sending them to the Logfire API.
|
|
19
|
+
*/
|
|
20
|
+
console?: boolean;
|
|
17
21
|
/**
|
|
18
22
|
* Pass a context manager (e.g. ZoneContextManager) to use.
|
|
19
23
|
*/
|
package/dist/index.js
CHANGED
|
@@ -1,115 +1,195 @@
|
|
|
1
|
-
var
|
|
2
|
-
var T = (e, r
|
|
3
|
-
var i = (e, r
|
|
4
|
-
import { diag as a, DiagConsoleLogger as
|
|
5
|
-
import { DiagLogLevel as
|
|
6
|
-
import { registerInstrumentations as
|
|
7
|
-
import { resourceFromAttributes as
|
|
8
|
-
import { WebTracerProvider as
|
|
9
|
-
import { TELEMETRY_SDK_LANGUAGE_VALUE_WEBJS as
|
|
10
|
-
import { ATTR_BROWSER_PLATFORM as
|
|
11
|
-
import * as
|
|
12
|
-
import { ULIDGenerator as
|
|
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";
|
|
13
13
|
export * from "@pydantic/logfire-api";
|
|
14
|
-
import {
|
|
15
|
-
import {
|
|
16
|
-
import {
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
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 = {
|
|
19
|
+
1: "trace",
|
|
20
|
+
5: "debug",
|
|
21
|
+
9: "info",
|
|
22
|
+
10: "notice",
|
|
23
|
+
13: "warning",
|
|
24
|
+
17: "error",
|
|
25
|
+
21: "fatal"
|
|
26
|
+
}, l = {
|
|
27
|
+
debug: "#E3E3E3",
|
|
28
|
+
error: "#EA4335",
|
|
29
|
+
fatal: "#EA4335",
|
|
30
|
+
info: "#9EC1FB",
|
|
31
|
+
notice: "#A5D490",
|
|
32
|
+
"on-debug": "#636262",
|
|
33
|
+
"on-error": "#FFEDE9",
|
|
34
|
+
"on-fatal": "#FFEDE9",
|
|
35
|
+
"on-info": "#063175",
|
|
36
|
+
"on-notice": "#222222",
|
|
37
|
+
"on-trace": "#636262",
|
|
38
|
+
"on-warning": "#613A0D",
|
|
39
|
+
trace: "#E3E3E3",
|
|
40
|
+
warning: "#EFB77A"
|
|
41
|
+
};
|
|
42
|
+
class H {
|
|
43
|
+
export(e, r) {
|
|
44
|
+
this.sendSpans(e, r);
|
|
45
|
+
}
|
|
46
|
+
forceFlush() {
|
|
47
|
+
return Promise.resolve();
|
|
48
|
+
}
|
|
49
|
+
shutdown() {
|
|
50
|
+
return this.sendSpans([]), this.forceFlush();
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* converts span info into more readable format
|
|
54
|
+
* @param span
|
|
55
|
+
*/
|
|
56
|
+
exportInfo(e) {
|
|
57
|
+
var r;
|
|
58
|
+
return {
|
|
59
|
+
attributes: e.attributes,
|
|
60
|
+
duration: c(e.duration),
|
|
61
|
+
events: e.events,
|
|
62
|
+
id: e.spanContext().spanId,
|
|
63
|
+
instrumentationScope: e.instrumentationScope,
|
|
64
|
+
kind: e.kind,
|
|
65
|
+
links: e.links,
|
|
66
|
+
name: e.name,
|
|
67
|
+
parentSpanContext: e.parentSpanContext,
|
|
68
|
+
resource: {
|
|
69
|
+
attributes: e.resource.attributes
|
|
70
|
+
},
|
|
71
|
+
status: e.status,
|
|
72
|
+
timestamp: c(e.startTime),
|
|
73
|
+
traceId: e.spanContext().traceId,
|
|
74
|
+
traceState: (r = e.spanContext().traceState) == null ? void 0 : r.serialize()
|
|
75
|
+
};
|
|
76
|
+
}
|
|
77
|
+
sendSpans(e, r) {
|
|
78
|
+
for (const n of e) {
|
|
79
|
+
const o = Y[n.attributes["logfire.level_num"]] ?? "info", { attributes: E, name: g, ...f } = this.exportInfo(n);
|
|
80
|
+
console.log(
|
|
81
|
+
`%cLogfire %c${o}`,
|
|
82
|
+
"background-color: #E520E9; color: #FFFFFF",
|
|
83
|
+
`background-color: ${l[`on-${o}`]}; color: ${l[o]}`,
|
|
84
|
+
g,
|
|
85
|
+
E,
|
|
86
|
+
f
|
|
87
|
+
);
|
|
88
|
+
}
|
|
89
|
+
r && r({ code: G.SUCCESS });
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
class K {
|
|
93
|
+
constructor(e, r) {
|
|
94
|
+
i(this, "console");
|
|
95
|
+
i(this, "wrapped");
|
|
96
|
+
r && (this.console = new p(new H())), this.wrapped = e;
|
|
97
|
+
}
|
|
98
|
+
async forceFlush() {
|
|
99
|
+
var e;
|
|
100
|
+
return await ((e = this.console) == null ? void 0 : e.forceFlush()), this.wrapped.forceFlush();
|
|
101
|
+
}
|
|
102
|
+
onEnd(e) {
|
|
103
|
+
var r;
|
|
104
|
+
(r = this.console) == null || r.onEnd(e), this.wrapped.onEnd(e);
|
|
105
|
+
}
|
|
106
|
+
onStart(e, r) {
|
|
107
|
+
var n;
|
|
108
|
+
if (s in e.attributes) {
|
|
109
|
+
const o = new URL(e.attributes[s]);
|
|
110
|
+
Reflect.set(e, "name", `${e.name} ${o.pathname}`);
|
|
111
|
+
}
|
|
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);
|
|
113
|
+
}
|
|
114
|
+
async shutdown() {
|
|
115
|
+
var e;
|
|
116
|
+
return await ((e = this.console) == null ? void 0 : e.shutdown()), this.wrapped.shutdown();
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
class z extends U {
|
|
120
|
+
constructor(e, r) {
|
|
121
|
+
const o = {
|
|
122
|
+
...$(
|
|
21
123
|
{
|
|
22
|
-
compression:
|
|
23
|
-
concurrencyLimit:
|
|
24
|
-
timeoutMillis:
|
|
124
|
+
compression: e.compression,
|
|
125
|
+
concurrencyLimit: e.concurrencyLimit,
|
|
126
|
+
timeoutMillis: e.timeoutMillis
|
|
25
127
|
},
|
|
26
128
|
{},
|
|
27
|
-
|
|
129
|
+
k()
|
|
28
130
|
),
|
|
29
131
|
agentOptions: { keepAlive: !0 },
|
|
30
132
|
headers: () => ({
|
|
31
133
|
"Content-Type": "application/json",
|
|
32
|
-
...
|
|
33
|
-
...
|
|
134
|
+
...e.headers ?? {},
|
|
135
|
+
...r ? r() : {}
|
|
34
136
|
}),
|
|
35
|
-
url:
|
|
137
|
+
url: e.url ?? "http://localhost:4318/v1/traces"
|
|
36
138
|
};
|
|
37
|
-
super(
|
|
139
|
+
super(y(o, V));
|
|
38
140
|
}
|
|
39
141
|
}
|
|
40
|
-
|
|
41
|
-
function y() {
|
|
142
|
+
function J() {
|
|
42
143
|
return {};
|
|
43
144
|
}
|
|
44
|
-
function
|
|
45
|
-
|
|
46
|
-
const
|
|
47
|
-
[
|
|
48
|
-
[
|
|
49
|
-
[
|
|
50
|
-
[
|
|
51
|
-
[
|
|
52
|
-
...
|
|
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 } : {},
|
|
53
154
|
// eslint-disable-next-line no-undef
|
|
54
|
-
[
|
|
155
|
+
[L]: "0.9.0",
|
|
55
156
|
...navigator.userAgentData ? {
|
|
56
|
-
[
|
|
57
|
-
[
|
|
58
|
-
[
|
|
157
|
+
[N]: navigator.userAgentData.brands.map((o) => `${o.brand} ${o.version}`),
|
|
158
|
+
[M]: navigator.userAgentData.mobile,
|
|
159
|
+
[F]: navigator.userAgentData.platform
|
|
59
160
|
} : {
|
|
60
|
-
[
|
|
161
|
+
[b]: navigator.userAgent
|
|
61
162
|
}
|
|
62
163
|
});
|
|
63
164
|
a.info("logfire-browser: starting");
|
|
64
|
-
const
|
|
65
|
-
idGenerator: new
|
|
66
|
-
resource:
|
|
165
|
+
const r = new R({
|
|
166
|
+
idGenerator: new B(),
|
|
167
|
+
resource: e,
|
|
67
168
|
spanProcessors: [
|
|
68
|
-
new
|
|
69
|
-
new
|
|
70
|
-
new
|
|
71
|
-
{ ...
|
|
72
|
-
|
|
169
|
+
new K(
|
|
170
|
+
new S(
|
|
171
|
+
new z(
|
|
172
|
+
{ ...t.traceExporterConfig, url: t.traceUrl },
|
|
173
|
+
t.traceExporterHeaders ?? J
|
|
73
174
|
),
|
|
74
|
-
|
|
75
|
-
)
|
|
175
|
+
t.batchSpanProcessorConfig
|
|
176
|
+
),
|
|
177
|
+
!!t.console
|
|
76
178
|
)
|
|
77
179
|
]
|
|
78
180
|
});
|
|
79
|
-
|
|
80
|
-
contextManager:
|
|
181
|
+
r.register({
|
|
182
|
+
contextManager: t.contextManager ?? new _()
|
|
81
183
|
});
|
|
82
|
-
const
|
|
83
|
-
instrumentations:
|
|
84
|
-
tracerProvider:
|
|
184
|
+
const n = h({
|
|
185
|
+
instrumentations: t.instrumentations ?? [],
|
|
186
|
+
tracerProvider: r
|
|
85
187
|
});
|
|
86
188
|
return async () => {
|
|
87
|
-
a.info("logfire-browser: shutting down"),
|
|
189
|
+
a.info("logfire-browser: shutting down"), n(), await r.forceFlush(), await r.shutdown(), a.info("logfire-browser: shut down complete");
|
|
88
190
|
};
|
|
89
191
|
}
|
|
90
|
-
class V {
|
|
91
|
-
constructor(r) {
|
|
92
|
-
i(this, "wrapped");
|
|
93
|
-
this.wrapped = r;
|
|
94
|
-
}
|
|
95
|
-
async forceFlush() {
|
|
96
|
-
return this.wrapped.forceFlush();
|
|
97
|
-
}
|
|
98
|
-
onEnd(r) {
|
|
99
|
-
this.wrapped.onEnd(r);
|
|
100
|
-
}
|
|
101
|
-
onStart(r, t) {
|
|
102
|
-
if (s in r.attributes) {
|
|
103
|
-
const o = new URL(r.attributes[s]);
|
|
104
|
-
Reflect.set(r, "name", `${r.name} ${o.pathname}`);
|
|
105
|
-
}
|
|
106
|
-
c in r.attributes && Reflect.set(r, "name", `${r.attributes[U] ?? "unknown"} ${r.attributes[c] ?? ""}`), this.wrapped.onStart(r, t);
|
|
107
|
-
}
|
|
108
|
-
async shutdown() {
|
|
109
|
-
return this.wrapped.shutdown();
|
|
110
|
-
}
|
|
111
|
-
}
|
|
112
192
|
export {
|
|
113
|
-
|
|
114
|
-
|
|
193
|
+
le as DiagLogLevel,
|
|
194
|
+
se as configure
|
|
115
195
|
};
|