@pydantic/logfire-browser 0.9.0 → 0.9.1
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 +30 -0
- package/dist/index.cjs +1 -1
- package/dist/index.js +1 -1
- package/package.json +5 -1
package/README.md
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
# Pydantic Logfire — JavaScript SDK
|
|
2
|
+
|
|
3
|
+
From the team behind [Pydantic Validation](https://pydantic.dev/), **Pydantic Logfire** is an observability platform built on the same belief as our open source library — that the most powerful tools can be easy to use.
|
|
4
|
+
|
|
5
|
+
What sets Logfire apart:
|
|
6
|
+
|
|
7
|
+
- **Simple and Powerful:** Logfire's dashboard is simple relative to the power it provides, ensuring your entire engineering team will actually use it.
|
|
8
|
+
- **SQL:** Query your data using standard SQL — all the control and (for many) nothing new to learn. Using SQL also means you can query your data with existing BI tools and database querying libraries.
|
|
9
|
+
- **OpenTelemetry:** Logfire is an opinionated wrapper around OpenTelemetry, allowing you to leverage existing tooling, infrastructure, and instrumentation for many common packages, and enabling support for virtually any language.
|
|
10
|
+
|
|
11
|
+
See the [documentation](https://logfire.pydantic.dev/docs/) for more information.
|
|
12
|
+
|
|
13
|
+
**Feel free to report issues and ask any questions about Logfire in this repository!**
|
|
14
|
+
|
|
15
|
+
This repo contains the JavaScript Browser SDK; the server application for recording and displaying data is closed source.
|
|
16
|
+
|
|
17
|
+
If you need to instrument your Node.js application, see the [`logfire` package](https://www.npmjs.com/package/logfire).
|
|
18
|
+
If you're instrumenting Cloudflare, see the [Logfire CF workers package](https://www.npmjs.com/package/@pydantic/logfire-cf-workers).
|
|
19
|
+
|
|
20
|
+
## Basic usage
|
|
21
|
+
|
|
22
|
+
See the [Logfire Browser docs for a primer](https://logfire.pydantic.dev/docs/integrations/javascript/browser/). Ready to run examples are available in the repository [in vanilla browser](https://github.com/pydantic/logfire-js/tree/main/examples/browser) and [Next.js variants](https://github.com/pydantic/logfire-js/tree/main/examples/nextjs-client-side-instrumentation).
|
|
23
|
+
|
|
24
|
+
## Contributing
|
|
25
|
+
|
|
26
|
+
See [CONTRIBUTING.md](https://github.com/pydantic/logfire-js/blob/main/CONTRIBUTING.md) for development instructions.
|
|
27
|
+
|
|
28
|
+
## License
|
|
29
|
+
|
|
30
|
+
MIT
|
package/dist/index.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var m=Object.defineProperty;var p=(r,e,t)=>e in r?m(r,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):r[e]=t;var l=(r,e,t)=>p(r,typeof e!="symbol"?e+"":e,t);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const s=require("@opentelemetry/api"),A=require("@opentelemetry/instrumentation"),_=require("@opentelemetry/resources"),c=require("@opentelemetry/sdk-trace-web"),a=require("@opentelemetry/semantic-conventions"),i=require("@opentelemetry/semantic-conventions/incubating"),u=require("@pydantic/logfire-api"),g=require("@opentelemetry/core"),E=require("@opentelemetry/otlp-exporter-base"),S=require("@opentelemetry/otlp-exporter-base/browser-http"),R=require("@opentelemetry/otlp-transformer");function w(r){const e=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(r){for(const t in r)if(t!=="default"){const o=Object.getOwnPropertyDescriptor(r,t);Object.defineProperty(e,t,o.get?o:{enumerable:!0,get:()=>r[t]})}}return e.default=r,Object.freeze(e)}const L=w(u),d="target_xpath",v="event_type",O={1:"trace",5:"debug",9:"info",10:"notice",13:"warning",17:"error",21:"fatal"},f={debug:"#E3E3E3",error:"#EA4335",fatal:"#EA4335",info:"#9EC1FB",notice:"#A5D490","on-debug":"#636262","on-error":"#FFEDE9","on-fatal":"#FFEDE9","on-info":"#063175","on-notice":"#222222","on-trace":"#636262","on-warning":"#613A0D",trace:"#E3E3E3",warning:"#EFB77A"};class D{export(e,t){this.sendSpans(e,t)}forceFlush(){return Promise.resolve()}shutdown(){return this.sendSpans([]),this.forceFlush()}exportInfo(e){var t;return{attributes:e.attributes,duration:g.hrTimeToMicroseconds(e.duration),events:e.events,id:e.spanContext().spanId,instrumentationScope:e.instrumentationScope,kind:e.kind,links:e.links,name:e.name,parentSpanContext:e.parentSpanContext,resource:{attributes:e.resource.attributes},status:e.status,timestamp:g.hrTimeToMicroseconds(e.startTime),traceId:e.spanContext().traceId,traceState:(t=e.spanContext().traceState)==null?void 0:t.serialize()}}sendSpans(e,t){for(const o of e){const n=O[o.attributes["logfire.level_num"]]??"info",{attributes:T,name:b,...h}=this.exportInfo(o);console.log(`%cLogfire %c${n}`,"background-color: #E520E9; color: #FFFFFF",`background-color: ${f[`on-${n}`]}; color: ${f[n]}`,b,T,h)}t&&t({code:g.ExportResultCode.SUCCESS})}}class x{constructor(e,t){l(this,"console");l(this,"wrapped");t&&(this.console=new c.SimpleSpanProcessor(new D)),this.wrapped=e}async forceFlush(){var e;return await((e=this.console)==null?void 0:e.forceFlush()),this.wrapped.forceFlush()}onEnd(e){var t;(t=this.console)==null||t.onEnd(e),this.wrapped.onEnd(e)}onStart(e,t){var o;if(i.ATTR_HTTP_URL in e.attributes){const n=new URL(e.attributes[i.ATTR_HTTP_URL]);Reflect.set(e,"name",`${e.name} ${n.pathname}`)}d in e.attributes&&Reflect.set(e,"name",`${e.attributes[v]??"unknown"} ${e.attributes[d]??""}`),(o=this.console)==null||o.onStart(e,t),this.wrapped.onStart(e,t)}async shutdown(){var e;return await((e=this.console)==null?void 0:e.shutdown()),this.wrapped.shutdown()}}class C extends E.OTLPExporterBase{constructor(e,t){const n={...E.mergeOtlpSharedConfigurationWithDefaults({compression:e.compression,concurrencyLimit:e.concurrencyLimit,timeoutMillis:e.timeoutMillis},{},E.getSharedConfigurationDefaults()),agentOptions:{keepAlive:!0},headers:()=>({"Content-Type":"application/json",...e.headers??{},...t?t():{}}),url:e.url??"http://localhost:4318/v1/traces"};super(S.createOtlpXhrExportDelegate(n,R.JsonTraceSerializer))}}function P(){return{}}function F(r){r.diagLogLevel!==void 0&&s.diag.setLogger(new s.DiagConsoleLogger,r.diagLogLevel),r.scrubbing!==void 0&&L.configureLogfireApi({scrubbing:r.scrubbing});const e=_.resourceFromAttributes({[i.ATTR_BROWSER_LANGUAGE]:navigator.language,[a.ATTR_SERVICE_NAME]:r.serviceName??"logfire-browser",[a.ATTR_SERVICE_VERSION]:r.serviceVersion??"0.0.1",[a.ATTR_TELEMETRY_SDK_LANGUAGE]:a.TELEMETRY_SDK_LANGUAGE_VALUE_WEBJS,[a.ATTR_TELEMETRY_SDK_NAME]:"logfire-browser",...r.environment?{[i.ATTR_DEPLOYMENT_ENVIRONMENT_NAME]:r.environment}:{},[a.ATTR_TELEMETRY_SDK_VERSION]:"0.9.
|
|
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.1",...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.js
CHANGED
|
@@ -152,7 +152,7 @@ function se(t) {
|
|
|
152
152
|
[v]: "logfire-browser",
|
|
153
153
|
...t.environment ? { [O]: t.environment } : {},
|
|
154
154
|
// eslint-disable-next-line no-undef
|
|
155
|
-
[L]: "0.9.
|
|
155
|
+
[L]: "0.9.1",
|
|
156
156
|
...navigator.userAgentData ? {
|
|
157
157
|
[N]: navigator.userAgentData.brands.map((o) => `${o.brand} ${o.version}`),
|
|
158
158
|
[M]: navigator.userAgentData.mobile,
|
package/package.json
CHANGED
|
@@ -6,6 +6,10 @@
|
|
|
6
6
|
"email": "engineering@pydantic.dev",
|
|
7
7
|
"url": "https://pydantic.dev"
|
|
8
8
|
},
|
|
9
|
+
"repository": {
|
|
10
|
+
"url": "https://github.com/pydantic/logfire-js",
|
|
11
|
+
"directory": "packages/logfire-browser"
|
|
12
|
+
},
|
|
9
13
|
"sideEffects": false,
|
|
10
14
|
"homepage": "https://pydantic.dev/logfire",
|
|
11
15
|
"license": "MIT",
|
|
@@ -21,7 +25,7 @@
|
|
|
21
25
|
"stats",
|
|
22
26
|
"monitoring"
|
|
23
27
|
],
|
|
24
|
-
"version": "0.9.
|
|
28
|
+
"version": "0.9.1",
|
|
25
29
|
"type": "module",
|
|
26
30
|
"main": "./dist/index.cjs",
|
|
27
31
|
"module": "./dist/index.js",
|