@xylabs/telemetry 4.9.5

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,165 @@
1
+ GNU LESSER GENERAL PUBLIC LICENSE
2
+ Version 3, 29 June 2007
3
+
4
+ Copyright (C) 2007 Free Software Foundation, Inc. <https://fsf.org/>
5
+ Everyone is permitted to copy and distribute verbatim copies
6
+ of this license document, but changing it is not allowed.
7
+
8
+
9
+ This version of the GNU Lesser General Public License incorporates
10
+ the terms and conditions of version 3 of the GNU General Public
11
+ License, supplemented by the additional permissions listed below.
12
+
13
+ 0. Additional Definitions.
14
+
15
+ As used herein, "this License" refers to version 3 of the GNU Lesser
16
+ General Public License, and the "GNU GPL" refers to version 3 of the GNU
17
+ General Public License.
18
+
19
+ "The Library" refers to a covered work governed by this License,
20
+ other than an Application or a Combined Work as defined below.
21
+
22
+ An "Application" is any work that makes use of an interface provided
23
+ by the Library, but which is not otherwise based on the Library.
24
+ Defining a subclass of a class defined by the Library is deemed a mode
25
+ of using an interface provided by the Library.
26
+
27
+ A "Combined Work" is a work produced by combining or linking an
28
+ Application with the Library. The particular version of the Library
29
+ with which the Combined Work was made is also called the "Linked
30
+ Version".
31
+
32
+ The "Minimal Corresponding Source" for a Combined Work means the
33
+ Corresponding Source for the Combined Work, excluding any source code
34
+ for portions of the Combined Work that, considered in isolation, are
35
+ based on the Application, and not on the Linked Version.
36
+
37
+ The "Corresponding Application Code" for a Combined Work means the
38
+ object code and/or source code for the Application, including any data
39
+ and utility programs needed for reproducing the Combined Work from the
40
+ Application, but excluding the System Libraries of the Combined Work.
41
+
42
+ 1. Exception to Section 3 of the GNU GPL.
43
+
44
+ You may convey a covered work under sections 3 and 4 of this License
45
+ without being bound by section 3 of the GNU GPL.
46
+
47
+ 2. Conveying Modified Versions.
48
+
49
+ If you modify a copy of the Library, and, in your modifications, a
50
+ facility refers to a function or data to be supplied by an Application
51
+ that uses the facility (other than as an argument passed when the
52
+ facility is invoked), then you may convey a copy of the modified
53
+ version:
54
+
55
+ a) under this License, provided that you make a good faith effort to
56
+ ensure that, in the event an Application does not supply the
57
+ function or data, the facility still operates, and performs
58
+ whatever part of its purpose remains meaningful, or
59
+
60
+ b) under the GNU GPL, with none of the additional permissions of
61
+ this License applicable to that copy.
62
+
63
+ 3. Object Code Incorporating Material from Library Header Files.
64
+
65
+ The object code form of an Application may incorporate material from
66
+ a header file that is part of the Library. You may convey such object
67
+ code under terms of your choice, provided that, if the incorporated
68
+ material is not limited to numerical parameters, data structure
69
+ layouts and accessors, or small macros, inline functions and templates
70
+ (ten or fewer lines in length), you do both of the following:
71
+
72
+ a) Give prominent notice with each copy of the object code that the
73
+ Library is used in it and that the Library and its use are
74
+ covered by this License.
75
+
76
+ b) Accompany the object code with a copy of the GNU GPL and this license
77
+ document.
78
+
79
+ 4. Combined Works.
80
+
81
+ You may convey a Combined Work under terms of your choice that,
82
+ taken together, effectively do not restrict modification of the
83
+ portions of the Library contained in the Combined Work and reverse
84
+ engineering for debugging such modifications, if you also do each of
85
+ the following:
86
+
87
+ a) Give prominent notice with each copy of the Combined Work that
88
+ the Library is used in it and that the Library and its use are
89
+ covered by this License.
90
+
91
+ b) Accompany the Combined Work with a copy of the GNU GPL and this license
92
+ document.
93
+
94
+ c) For a Combined Work that displays copyright notices during
95
+ execution, include the copyright notice for the Library among
96
+ these notices, as well as a reference directing the user to the
97
+ copies of the GNU GPL and this license document.
98
+
99
+ d) Do one of the following:
100
+
101
+ 0) Convey the Minimal Corresponding Source under the terms of this
102
+ License, and the Corresponding Application Code in a form
103
+ suitable for, and under terms that permit, the user to
104
+ recombine or relink the Application with a modified version of
105
+ the Linked Version to produce a modified Combined Work, in the
106
+ manner specified by section 6 of the GNU GPL for conveying
107
+ Corresponding Source.
108
+
109
+ 1) Use a suitable shared library mechanism for linking with the
110
+ Library. A suitable mechanism is one that (a) uses at run time
111
+ a copy of the Library already present on the user's computer
112
+ system, and (b) will operate properly with a modified version
113
+ of the Library that is interface-compatible with the Linked
114
+ Version.
115
+
116
+ e) Provide Installation Information, but only if you would otherwise
117
+ be required to provide such information under section 6 of the
118
+ GNU GPL, and only to the extent that such information is
119
+ necessary to install and execute a modified version of the
120
+ Combined Work produced by recombining or relinking the
121
+ Application with a modified version of the Linked Version. (If
122
+ you use option 4d0, the Installation Information must accompany
123
+ the Minimal Corresponding Source and Corresponding Application
124
+ Code. If you use option 4d1, you must provide the Installation
125
+ Information in the manner specified by section 6 of the GNU GPL
126
+ for conveying Corresponding Source.)
127
+
128
+ 5. Combined Libraries.
129
+
130
+ You may place library facilities that are a work based on the
131
+ Library side by side in a single library together with other library
132
+ facilities that are not Applications and are not covered by this
133
+ License, and convey such a combined library under terms of your
134
+ choice, if you do both of the following:
135
+
136
+ a) Accompany the combined library with a copy of the same work based
137
+ on the Library, uncombined with any other library facilities,
138
+ conveyed under the terms of this License.
139
+
140
+ b) Give prominent notice with the combined library that part of it
141
+ is a work based on the Library, and explaining where to find the
142
+ accompanying uncombined form of the same work.
143
+
144
+ 6. Revised Versions of the GNU Lesser General Public License.
145
+
146
+ The Free Software Foundation may publish revised and/or new versions
147
+ of the GNU Lesser General Public License from time to time. Such new
148
+ versions will be similar in spirit to the present version, but may
149
+ differ in detail to address new problems or concerns.
150
+
151
+ Each version is given a distinguishing version number. If the
152
+ Library as you received it specifies that a certain numbered version
153
+ of the GNU Lesser General Public License "or any later version"
154
+ applies to it, you have the option of following the terms and
155
+ conditions either of that published version or of any later version
156
+ published by the Free Software Foundation. If the Library as you
157
+ received it does not specify a version number of the GNU Lesser
158
+ General Public License, you may choose any version of the GNU Lesser
159
+ General Public License ever published by the Free Software Foundation.
160
+
161
+ If the Library as you received it specifies that a proxy can decide
162
+ whether future versions of the GNU Lesser General Public License shall
163
+ apply, that proxy's public statement of acceptance of any version is
164
+ permanent authorization for you to choose that version for the
165
+ Library.
package/README.md ADDED
@@ -0,0 +1,69 @@
1
+ [![logo][]](https://xylabs.com)
2
+
3
+ # @xylabs/storage
4
+
5
+ [![npm-badge][]][npm-link]
6
+ [![npm-downloads-badge][]][npm-link]
7
+ [![jsdelivr-badge][]][jsdelivr-link]
8
+ [![npm-license-badge][]](LICENSE)
9
+ [![socket-badge][]][socket-link]
10
+
11
+ > XY Labs Indexed DB Helpers
12
+
13
+ ## Table of Contents
14
+
15
+ - [Description](#description)
16
+ - [Install](#install)
17
+ - [Maintainers](#maintainers)
18
+ - [License](#license)
19
+ - [Credits](#credits)
20
+
21
+ ## Description
22
+
23
+ Various Indexed DB Helper Functions
24
+
25
+ ## Install
26
+
27
+ Using npm:
28
+
29
+ ```sh
30
+ npm i --save @xylabs/storage
31
+ ```
32
+
33
+ Using yarn:
34
+
35
+ ```sh
36
+ yarn add @xylabs/storage
37
+ ```
38
+
39
+ ## Documentation
40
+ [Developer Reference](https://xylabs.github.io/sdk-js)
41
+
42
+ ## Maintainers
43
+
44
+ - [Arie Trouw](https://github.com/arietrouw) ([arietrouw.com](https://arietrouw.com))
45
+ - [Joel Carter](https://github.com/JoelBCarter)
46
+ - [Matt Jones](https://github.com/jonesmac)
47
+ - [Jordan Trouw](https://github.com/jordantrouw)
48
+
49
+ ## License
50
+
51
+ See the [LICENSE](LICENSE) file for license details
52
+
53
+ ## Credits
54
+
55
+ [Made with 🔥and ❄️ by XY Labs](https://xylabs.com)
56
+
57
+ [logo]: https://cdn.xy.company/img/brand/XYPersistentCompany_Logo_Icon_Colored.svg
58
+
59
+ [npm-badge]: https://img.shields.io/npm/v/@xylabs/storage.svg
60
+ [npm-link]: https://www.npmjs.com/package/@xylabs/storage
61
+
62
+ [npm-downloads-badge]: https://img.shields.io/npm/dw/@xylabs/storage
63
+ [npm-license-badge]: https://img.shields.io/npm/l/@xylabs/storage
64
+
65
+ [jsdelivr-badge]: https://data.jsdelivr.com/v1/package/npm/@xylabs/storage/badge
66
+ [jsdelivr-link]: https://www.jsdelivr.com/package/npm/@xylabs/storage
67
+
68
+ [socket-badge]: https://socket.dev/api/badge/npm/package/@xylabs/storage
69
+ [socket-link]: https://socket.dev/npm/package/@xylabs/storage
@@ -0,0 +1,63 @@
1
+ // src/XyConsoleSpanExporter.ts
2
+ import { ConsoleSpanExporter } from "@opentelemetry/sdk-trace-base";
3
+ import chalk from "chalk";
4
+ function spanDurationInMillis(span) {
5
+ return span.duration[0] * 1e3 + span.duration[1] / 1e6;
6
+ }
7
+ var XyConsoleSpanExporter = class _XyConsoleSpanExporter extends ConsoleSpanExporter {
8
+ static durationToLogLevel = [
9
+ 0,
10
+ 1,
11
+ 10,
12
+ 100,
13
+ 1e3
14
+ ];
15
+ static logLevelToChalkColor = [
16
+ chalk.grey,
17
+ chalk.white,
18
+ chalk.green,
19
+ chalk.yellow,
20
+ chalk.red
21
+ ];
22
+ _logLevel;
23
+ constructor(logLevel = 0) {
24
+ super();
25
+ this._logLevel = logLevel;
26
+ }
27
+ get logLevel() {
28
+ return this._logLevel;
29
+ }
30
+ export(spans) {
31
+ for (const span of spans) {
32
+ const spanLevel = this.spanLevel(span);
33
+ if (spanLevel < this.logLevel) {
34
+ continue;
35
+ }
36
+ const duration = spanDurationInMillis(span);
37
+ console.log(chalk.grey([
38
+ `Span [${span.name}]`,
39
+ this.logColor(spanLevel)(`${duration}ms`),
40
+ `TraceId: ${span.spanContext().traceId}`
41
+ ].join(", ")));
42
+ }
43
+ }
44
+ logColor(level) {
45
+ return _XyConsoleSpanExporter.logLevelToChalkColor[level] ?? chalk.magenta;
46
+ }
47
+ spanLevel(span) {
48
+ let logLevel = 0;
49
+ const duration = spanDurationInMillis(span);
50
+ for (let x = _XyConsoleSpanExporter.durationToLogLevel.length - 1; x >= 0; x--) {
51
+ if (duration > _XyConsoleSpanExporter.durationToLogLevel[x]) {
52
+ logLevel = x;
53
+ break;
54
+ }
55
+ }
56
+ return logLevel;
57
+ }
58
+ };
59
+ export {
60
+ XyConsoleSpanExporter,
61
+ spanDurationInMillis
62
+ };
63
+ //# sourceMappingURL=index.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/XyConsoleSpanExporter.ts"],"sourcesContent":["import type { ReadableSpan } from '@opentelemetry/sdk-trace-base'\nimport { ConsoleSpanExporter } from '@opentelemetry/sdk-trace-base'\nimport chalk from 'chalk'\n\nexport function spanDurationInMillis(span: ReadableSpan) {\n return span.duration[0] * 1000 + span.duration[1] / 1e6\n}\n\nexport class XyConsoleSpanExporter extends ConsoleSpanExporter {\n static readonly durationToLogLevel = [\n 0,\n 1,\n 10,\n 100,\n 1000,\n ]\n\n static readonly logLevelToChalkColor = [\n chalk.grey,\n chalk.white,\n chalk.green,\n chalk.yellow,\n chalk.red,\n ]\n\n private _logLevel: number\n\n constructor(logLevel = 0) {\n super()\n this._logLevel = logLevel\n }\n\n get logLevel() {\n return this._logLevel\n }\n\n override export(spans: ReadableSpan[]): void {\n for (const span of spans) {\n const spanLevel = this.spanLevel(span)\n if (spanLevel < this.logLevel) {\n continue\n }\n const duration = spanDurationInMillis(span)\n console.log(chalk.grey([\n `Span [${span.name}]`,\n this.logColor(spanLevel)(`${duration}ms`),\n `TraceId: ${span.spanContext().traceId}`,\n ].join(', ')))\n }\n }\n\n logColor(level: number) {\n return XyConsoleSpanExporter.logLevelToChalkColor[level] ?? chalk.magenta\n }\n\n spanLevel(span: ReadableSpan) {\n let logLevel = 0\n const duration = spanDurationInMillis(span)\n for (let x = XyConsoleSpanExporter.durationToLogLevel.length - 1; x >= 0; x--) {\n if (duration > XyConsoleSpanExporter.durationToLogLevel[x]) {\n logLevel = x\n break\n }\n }\n return logLevel\n }\n}\n"],"mappings":";AACA,SAAS,2BAA2B;AACpC,OAAO,WAAW;AAEX,SAAS,qBAAqB,MAAoB;AACvD,SAAO,KAAK,SAAS,CAAC,IAAI,MAAO,KAAK,SAAS,CAAC,IAAI;AACtD;AAEO,IAAM,wBAAN,MAAM,+BAA8B,oBAAoB;AAAA,EAC7D,OAAgB,qBAAqB;AAAA,IACnC;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACF;AAAA,EAEA,OAAgB,uBAAuB;AAAA,IACrC,MAAM;AAAA,IACN,MAAM;AAAA,IACN,MAAM;AAAA,IACN,MAAM;AAAA,IACN,MAAM;AAAA,EACR;AAAA,EAEQ;AAAA,EAER,YAAY,WAAW,GAAG;AACxB,UAAM;AACN,SAAK,YAAY;AAAA,EACnB;AAAA,EAEA,IAAI,WAAW;AACb,WAAO,KAAK;AAAA,EACd;AAAA,EAES,OAAO,OAA6B;AAC3C,eAAW,QAAQ,OAAO;AACxB,YAAM,YAAY,KAAK,UAAU,IAAI;AACrC,UAAI,YAAY,KAAK,UAAU;AAC7B;AAAA,MACF;AACA,YAAM,WAAW,qBAAqB,IAAI;AAC1C,cAAQ,IAAI,MAAM,KAAK;AAAA,QACrB,SAAS,KAAK,IAAI;AAAA,QAClB,KAAK,SAAS,SAAS,EAAE,GAAG,QAAQ,IAAI;AAAA,QACxC,YAAY,KAAK,YAAY,EAAE,OAAO;AAAA,MACxC,EAAE,KAAK,IAAI,CAAC,CAAC;AAAA,IACf;AAAA,EACF;AAAA,EAEA,SAAS,OAAe;AACtB,WAAO,uBAAsB,qBAAqB,KAAK,KAAK,MAAM;AAAA,EACpE;AAAA,EAEA,UAAU,MAAoB;AAC5B,QAAI,WAAW;AACf,UAAM,WAAW,qBAAqB,IAAI;AAC1C,aAAS,IAAI,uBAAsB,mBAAmB,SAAS,GAAG,KAAK,GAAG,KAAK;AAC7E,UAAI,WAAW,uBAAsB,mBAAmB,CAAC,GAAG;AAC1D,mBAAW;AACX;AAAA,MACF;AAAA,IACF;AACA,WAAO;AAAA,EACT;AACF;","names":[]}
@@ -0,0 +1,14 @@
1
+ import type { ReadableSpan } from '@opentelemetry/sdk-trace-base';
2
+ import { ConsoleSpanExporter } from '@opentelemetry/sdk-trace-base';
3
+ export declare function spanDurationInMillis(span: ReadableSpan): number;
4
+ export declare class XyConsoleSpanExporter extends ConsoleSpanExporter {
5
+ static readonly durationToLogLevel: number[];
6
+ static readonly logLevelToChalkColor: import("chalk").ChalkInstance[];
7
+ private _logLevel;
8
+ constructor(logLevel?: number);
9
+ get logLevel(): number;
10
+ export(spans: ReadableSpan[]): void;
11
+ logColor(level: number): import("chalk").ChalkInstance;
12
+ spanLevel(span: ReadableSpan): number;
13
+ }
14
+ //# sourceMappingURL=XyConsoleSpanExporter.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"XyConsoleSpanExporter.d.ts","sourceRoot":"","sources":["../../src/XyConsoleSpanExporter.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,+BAA+B,CAAA;AACjE,OAAO,EAAE,mBAAmB,EAAE,MAAM,+BAA+B,CAAA;AAGnE,wBAAgB,oBAAoB,CAAC,IAAI,EAAE,YAAY,UAEtD;AAED,qBAAa,qBAAsB,SAAQ,mBAAmB;IAC5D,MAAM,CAAC,QAAQ,CAAC,kBAAkB,WAMjC;IAED,MAAM,CAAC,QAAQ,CAAC,oBAAoB,kCAMnC;IAED,OAAO,CAAC,SAAS,CAAQ;gBAEb,QAAQ,SAAI;IAKxB,IAAI,QAAQ,WAEX;IAEQ,MAAM,CAAC,KAAK,EAAE,YAAY,EAAE,GAAG,IAAI;IAe5C,QAAQ,CAAC,KAAK,EAAE,MAAM;IAItB,SAAS,CAAC,IAAI,EAAE,YAAY;CAW7B"}
@@ -0,0 +1,2 @@
1
+ export * from './XyConsoleSpanExporter.ts';
2
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,4BAA4B,CAAA"}
package/package.json ADDED
@@ -0,0 +1,57 @@
1
+ {
2
+ "name": "@xylabs/telemetry",
3
+ "version": "4.9.5",
4
+ "description": "Base functionality used throughout XY Labs TypeScript/JavaScript libraries",
5
+ "keywords": [
6
+ "hex",
7
+ "xylabs",
8
+ "utility",
9
+ "typescript",
10
+ "esm"
11
+ ],
12
+ "homepage": "https://xylabs.com",
13
+ "bugs": {
14
+ "url": "git+https://github.com/xylabs/sdk-js/issues",
15
+ "email": "support@xylabs.com"
16
+ },
17
+ "repository": {
18
+ "type": "git",
19
+ "url": "git+https://github.com/xylabs/sdk-js.git"
20
+ },
21
+ "license": "LGPL-3.0-only",
22
+ "author": {
23
+ "name": "XY Labs Development Team",
24
+ "email": "support@xylabs.com",
25
+ "url": "https://xylabs.com"
26
+ },
27
+ "sideEffects": false,
28
+ "type": "module",
29
+ "exports": {
30
+ ".": {
31
+ "types": "./dist/types/index.d.ts",
32
+ "default": "./dist/neutral/index.mjs"
33
+ },
34
+ "./package.json": "./package.json"
35
+ },
36
+ "module": "./dist/neutral/index.mjs",
37
+ "types": "./dist/types/index.d.ts",
38
+ "workspaces": [
39
+ "packages/**/*"
40
+ ],
41
+ "dependencies": {
42
+ "@opentelemetry/api": "^1.9.0",
43
+ "@opentelemetry/sdk-trace-base": "^2.0.0",
44
+ "chalk": "^5.4.1"
45
+ },
46
+ "devDependencies": {
47
+ "@xylabs/ts-scripts-yarn3": "^6.5.5",
48
+ "@xylabs/tsconfig": "^6.5.5",
49
+ "typescript": "^5.8.3"
50
+ },
51
+ "engines": {
52
+ "node": ">=18"
53
+ },
54
+ "publishConfig": {
55
+ "access": "public"
56
+ }
57
+ }
@@ -0,0 +1,67 @@
1
+ import type { ReadableSpan } from '@opentelemetry/sdk-trace-base'
2
+ import { ConsoleSpanExporter } from '@opentelemetry/sdk-trace-base'
3
+ import chalk from 'chalk'
4
+
5
+ export function spanDurationInMillis(span: ReadableSpan) {
6
+ return span.duration[0] * 1000 + span.duration[1] / 1e6
7
+ }
8
+
9
+ export class XyConsoleSpanExporter extends ConsoleSpanExporter {
10
+ static readonly durationToLogLevel = [
11
+ 0,
12
+ 1,
13
+ 10,
14
+ 100,
15
+ 1000,
16
+ ]
17
+
18
+ static readonly logLevelToChalkColor = [
19
+ chalk.grey,
20
+ chalk.white,
21
+ chalk.green,
22
+ chalk.yellow,
23
+ chalk.red,
24
+ ]
25
+
26
+ private _logLevel: number
27
+
28
+ constructor(logLevel = 0) {
29
+ super()
30
+ this._logLevel = logLevel
31
+ }
32
+
33
+ get logLevel() {
34
+ return this._logLevel
35
+ }
36
+
37
+ override export(spans: ReadableSpan[]): void {
38
+ for (const span of spans) {
39
+ const spanLevel = this.spanLevel(span)
40
+ if (spanLevel < this.logLevel) {
41
+ continue
42
+ }
43
+ const duration = spanDurationInMillis(span)
44
+ console.log(chalk.grey([
45
+ `Span [${span.name}]`,
46
+ this.logColor(spanLevel)(`${duration}ms`),
47
+ `TraceId: ${span.spanContext().traceId}`,
48
+ ].join(', ')))
49
+ }
50
+ }
51
+
52
+ logColor(level: number) {
53
+ return XyConsoleSpanExporter.logLevelToChalkColor[level] ?? chalk.magenta
54
+ }
55
+
56
+ spanLevel(span: ReadableSpan) {
57
+ let logLevel = 0
58
+ const duration = spanDurationInMillis(span)
59
+ for (let x = XyConsoleSpanExporter.durationToLogLevel.length - 1; x >= 0; x--) {
60
+ if (duration > XyConsoleSpanExporter.durationToLogLevel[x]) {
61
+ logLevel = x
62
+ break
63
+ }
64
+ }
65
+ return logLevel
66
+ }
67
+ }
package/src/index.ts ADDED
@@ -0,0 +1 @@
1
+ export * from './XyConsoleSpanExporter.ts'
package/xy.config.ts ADDED
@@ -0,0 +1,10 @@
1
+ import type { XyTsupConfig } from '@xylabs/ts-scripts-yarn3'
2
+ const config: XyTsupConfig = {
3
+ compile: {
4
+ browser: {},
5
+ neutral: { src: true },
6
+ node: {},
7
+ },
8
+ }
9
+
10
+ export default config