@pydantic/logfire-browser 0.2.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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2023 - present Pydantic Services inc.
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/dist/index.cjs ADDED
@@ -0,0 +1 @@
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const n=require("@opentelemetry/api"),u=require("@opentelemetry/context-zone"),l=require("@opentelemetry/exporter-trace-otlp-http"),f=require("@opentelemetry/instrumentation"),T=require("@opentelemetry/resources"),c=require("@opentelemetry/sdk-trace-web"),t=require("@opentelemetry/semantic-conventions"),i=require("@opentelemetry/semantic-conventions/incubating"),s=require("@pydantic/logfire-api");function b(e){const o=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(e){for(const r in e)if(r!=="default"){const a=Object.getOwnPropertyDescriptor(e,r);Object.defineProperty(o,r,a.get?a:{enumerable:!0,get:()=>e[r]})}}return o.default=e,Object.freeze(o)}const E=b(s);function A(e){e.diagLogLevel!==void 0&&n.diag.setLogger(new n.DiagConsoleLogger,e.diagLogLevel),e.scrubbing!==void 0&&E.configureLogfireApi({scrubbing:e.scrubbing});const o=T.resourceFromAttributes({[i.ATTR_BROWSER_LANGUAGE]:navigator.language,[t.ATTR_SERVICE_NAME]:e.serviceName??"logfire-browser",[t.ATTR_SERVICE_VERSION]:e.serviceVersion??"0.0.1",[t.ATTR_TELEMETRY_SDK_LANGUAGE]:t.TELEMETRY_SDK_LANGUAGE_VALUE_WEBJS,[t.ATTR_TELEMETRY_SDK_NAME]:"logfire-browser",[t.ATTR_TELEMETRY_SDK_VERSION]:"0.2.0",...navigator.userAgentData?{[i.ATTR_BROWSER_BRANDS]:navigator.userAgentData.brands.map(g=>`${g.brand} ${g.version}`),[i.ATTR_BROWSER_MOBILE]:navigator.userAgentData.mobile,[i.ATTR_BROWSER_PLATFORM]:navigator.userAgentData.platform}:{[t.ATTR_USER_AGENT_ORIGINAL]:navigator.userAgent}});n.diag.info("logfire-browser: starting");const r=new c.WebTracerProvider({idGenerator:new s.ULIDGenerator,resource:o,spanProcessors:[new c.BatchSpanProcessor(new l.OTLPTraceExporter({url:e.traceUrl}),e.batchSpanProcessorConfig)]});e.enableZoneContextManager!==!1&&(n.diag.info("logfire-browser: enable zone context manager"),r.register({contextManager:new u.ZoneContextManager}));const a=f.registerInstrumentations({instrumentations:e.instrumentations??[],tracerProvider:r});return async()=>{n.diag.info("logfire-browser: shutting down"),a(),await r.forceFlush(),await r.shutdown(),n.diag.info("logfire-browser: shut down complete")}}Object.defineProperty(exports,"DiagLogLevel",{enumerable:!0,get:()=>n.DiagLogLevel});exports.configure=A;Object.keys(s).forEach(e=>{e!=="default"&&!Object.prototype.hasOwnProperty.call(exports,e)&&Object.defineProperty(exports,e,{enumerable:!0,get:()=>s[e]})});
@@ -0,0 +1,48 @@
1
+ import { BufferConfig } from '@opentelemetry/sdk-trace-web';
2
+ import { DiagLogLevel } from '@opentelemetry/api';
3
+ import { Instrumentation } from '@opentelemetry/instrumentation';
4
+ import * as logfireApi from '@pydantic/logfire-api';
5
+
6
+ export declare function configure(options: LogfireConfigOptions): () => Promise<void>;
7
+
8
+ export { DiagLogLevel }
9
+
10
+ export declare interface LogfireConfigOptions {
11
+ /**
12
+ * The configuration of the batch span processor.
13
+ */
14
+ batchSpanProcessorConfig?: BufferConfig;
15
+ /**
16
+ * Defines the available internal logging levels for the diagnostic logger.
17
+ */
18
+ diagLogLevel?: DiagLogLevel;
19
+ /**
20
+ * Set to `false` to disable the [zone context manager](https://www.npmjs.com/package/@opentelemetry/context-zone) usage.
21
+ */
22
+ enableZoneContextManager?: boolean;
23
+ /**
24
+ * The instrumentations to register - a common one [is the fetch instrumentation](https://www.npmjs.com/package/@opentelemetry/instrumentation-fetch).
25
+ */
26
+ instrumentations?: (Instrumentation | Instrumentation[])[];
27
+ /**
28
+ * Options for scrubbing sensitive data. Set to False to disable.
29
+ */
30
+ scrubbing?: false | logfireApi.SrubbingOptions;
31
+ /**
32
+ * Name of this service.
33
+ */
34
+ serviceName?: string;
35
+ /**
36
+ * Version of this service.
37
+ */
38
+ serviceVersion?: string;
39
+ /**
40
+ * The URL of your trace exporter proxy endpoint.
41
+ */
42
+ traceUrl: string;
43
+ }
44
+
45
+
46
+ export * from "@pydantic/logfire-api";
47
+
48
+ export { }
@@ -0,0 +1,48 @@
1
+ import { BufferConfig } from '@opentelemetry/sdk-trace-web';
2
+ import { DiagLogLevel } from '@opentelemetry/api';
3
+ import { Instrumentation } from '@opentelemetry/instrumentation';
4
+ import * as logfireApi from '@pydantic/logfire-api';
5
+
6
+ export declare function configure(options: LogfireConfigOptions): () => Promise<void>;
7
+
8
+ export { DiagLogLevel }
9
+
10
+ export declare interface LogfireConfigOptions {
11
+ /**
12
+ * The configuration of the batch span processor.
13
+ */
14
+ batchSpanProcessorConfig?: BufferConfig;
15
+ /**
16
+ * Defines the available internal logging levels for the diagnostic logger.
17
+ */
18
+ diagLogLevel?: DiagLogLevel;
19
+ /**
20
+ * Set to `false` to disable the [zone context manager](https://www.npmjs.com/package/@opentelemetry/context-zone) usage.
21
+ */
22
+ enableZoneContextManager?: boolean;
23
+ /**
24
+ * The instrumentations to register - a common one [is the fetch instrumentation](https://www.npmjs.com/package/@opentelemetry/instrumentation-fetch).
25
+ */
26
+ instrumentations?: (Instrumentation | Instrumentation[])[];
27
+ /**
28
+ * Options for scrubbing sensitive data. Set to False to disable.
29
+ */
30
+ scrubbing?: false | logfireApi.SrubbingOptions;
31
+ /**
32
+ * Name of this service.
33
+ */
34
+ serviceName?: string;
35
+ /**
36
+ * Version of this service.
37
+ */
38
+ serviceVersion?: string;
39
+ /**
40
+ * The URL of your trace exporter proxy endpoint.
41
+ */
42
+ traceUrl: string;
43
+ }
44
+
45
+
46
+ export * from "@pydantic/logfire-api";
47
+
48
+ export { }
package/dist/index.js ADDED
@@ -0,0 +1,51 @@
1
+ import { diag as e, DiagConsoleLogger as i } from "@opentelemetry/api";
2
+ import { DiagLogLevel as V } from "@opentelemetry/api";
3
+ import { ZoneContextManager as g } from "@opentelemetry/context-zone";
4
+ import { OTLPTraceExporter as s } from "@opentelemetry/exporter-trace-otlp-http";
5
+ import { registerInstrumentations as f } from "@opentelemetry/instrumentation";
6
+ import { resourceFromAttributes as E } from "@opentelemetry/resources";
7
+ import { WebTracerProvider as T, BatchSpanProcessor as m } from "@opentelemetry/sdk-trace-web";
8
+ import { TELEMETRY_SDK_LANGUAGE_VALUE_WEBJS as A, ATTR_USER_AGENT_ORIGINAL as R, ATTR_TELEMETRY_SDK_VERSION as _, ATTR_TELEMETRY_SDK_NAME as c, ATTR_TELEMETRY_SDK_LANGUAGE as u, ATTR_SERVICE_VERSION as L, ATTR_SERVICE_NAME as l } from "@opentelemetry/semantic-conventions";
9
+ import { ATTR_BROWSER_PLATFORM as b, ATTR_BROWSER_MOBILE as w, ATTR_BROWSER_BRANDS as S, ATTR_BROWSER_LANGUAGE as v } from "@opentelemetry/semantic-conventions/incubating";
10
+ import * as p from "@pydantic/logfire-api";
11
+ import { ULIDGenerator as d } from "@pydantic/logfire-api";
12
+ export * from "@pydantic/logfire-api";
13
+ function U(r) {
14
+ r.diagLogLevel !== void 0 && e.setLogger(new i(), r.diagLogLevel), r.scrubbing !== void 0 && p.configureLogfireApi({ scrubbing: r.scrubbing });
15
+ const a = E({
16
+ [v]: navigator.language,
17
+ [l]: r.serviceName ?? "logfire-browser",
18
+ [L]: r.serviceVersion ?? "0.0.1",
19
+ [u]: A,
20
+ [c]: "logfire-browser",
21
+ // eslint-disable-next-line no-undef
22
+ [_]: "0.2.0",
23
+ ...navigator.userAgentData ? {
24
+ [S]: navigator.userAgentData.brands.map((t) => `${t.brand} ${t.version}`),
25
+ [w]: navigator.userAgentData.mobile,
26
+ [b]: navigator.userAgentData.platform
27
+ } : {
28
+ [R]: navigator.userAgent
29
+ }
30
+ });
31
+ e.info("logfire-browser: starting");
32
+ const o = new T({
33
+ idGenerator: new d(),
34
+ resource: a,
35
+ spanProcessors: [new m(new s({ url: r.traceUrl }), r.batchSpanProcessorConfig)]
36
+ });
37
+ r.enableZoneContextManager !== !1 && (e.info("logfire-browser: enable zone context manager"), o.register({
38
+ contextManager: new g()
39
+ }));
40
+ const n = f({
41
+ instrumentations: r.instrumentations ?? [],
42
+ tracerProvider: o
43
+ });
44
+ return async () => {
45
+ e.info("logfire-browser: shutting down"), n(), await o.forceFlush(), await o.shutdown(), e.info("logfire-browser: shut down complete");
46
+ };
47
+ }
48
+ export {
49
+ V as DiagLogLevel,
50
+ U as configure
51
+ };
package/package.json ADDED
@@ -0,0 +1,77 @@
1
+ {
2
+ "name": "@pydantic/logfire-browser",
3
+ "description": "JavaScript Browser SDK for Logfire - https://pydantic.dev/logfire",
4
+ "author": {
5
+ "name": "The Pydantic Team",
6
+ "email": "engineering@pydantic.dev",
7
+ "url": "https://pydantic.dev"
8
+ },
9
+ "sideEffects": false,
10
+ "homepage": "https://pydantic.dev/logfire",
11
+ "license": "MIT",
12
+ "publishConfig": {
13
+ "access": "public"
14
+ },
15
+ "keywords": [
16
+ "logfire",
17
+ "observability",
18
+ "opentelemetry",
19
+ "tracing",
20
+ "profiling",
21
+ "stats",
22
+ "monitoring"
23
+ ],
24
+ "version": "0.2.0",
25
+ "type": "module",
26
+ "main": "./dist/index.cjs",
27
+ "module": "./dist/index.js",
28
+ "types": "./dist/index.d.ts",
29
+ "exports": {
30
+ ".": {
31
+ "import": {
32
+ "types": "./dist/index.d.ts",
33
+ "default": "./dist/index.js"
34
+ },
35
+ "require": {
36
+ "types": "./dist/index.d.cts",
37
+ "default": "./dist/index.cjs"
38
+ }
39
+ }
40
+ },
41
+ "scripts": {
42
+ "dev": "vite build",
43
+ "build": "vite build",
44
+ "lint": "eslint",
45
+ "preview": "vite preview",
46
+ "typecheck": "tsc",
47
+ "prepack": "cp ../../LICENSE .",
48
+ "postpack": "rm LICENSE",
49
+ "test": "vitest --passWithNoTests"
50
+ },
51
+ "dependencies": {
52
+ "@opentelemetry/api": "^1.9.0",
53
+ "@opentelemetry/exporter-trace-otlp-http": "^0.202.0",
54
+ "@opentelemetry/instrumentation": "^0.202.0",
55
+ "@opentelemetry/resources": "^2.0.1",
56
+ "@pydantic/logfire-api": "*"
57
+ },
58
+ "peerDependencies": {
59
+ "@opentelemetry/sdk-trace-web": "^2.0.1",
60
+ "@opentelemetry/semantic-conventions": "^1.34.0"
61
+ },
62
+ "devDependencies": {
63
+ "@opentelemetry/sdk-trace-web": "^2.0.1",
64
+ "@opentelemetry/semantic-conventions": "^1.34.0",
65
+ "eslint": "^9.22.0",
66
+ "prettier": "3.5.3",
67
+ "typescript": "^5.8.2",
68
+ "user-agent-data-types": "^0.4.2",
69
+ "vite": "^6.2.0",
70
+ "vite-plugin-dts": "^4.5.3",
71
+ "vitest": "^3.1.1"
72
+ },
73
+ "files": [
74
+ "dist",
75
+ "LICENSE"
76
+ ]
77
+ }