@xylabs/telemetry-exporter 5.0.82 → 5.0.84
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
|
@@ -37,6 +37,9 @@ Base functionality used throughout XY Labs TypeScript/JavaScript libraries
|
|
|
37
37
|
|
|
38
38
|
***
|
|
39
39
|
|
|
40
|
+
A console span exporter that formats spans with color-coded durations using chalk.
|
|
41
|
+
Spans are filtered by a configurable log level based on their duration.
|
|
42
|
+
|
|
40
43
|
## Extends
|
|
41
44
|
|
|
42
45
|
- `ConsoleSpanExporter`
|
|
@@ -77,6 +80,8 @@ ConsoleSpanExporter.constructor
|
|
|
77
80
|
readonly static durationToLogLevel: number[];
|
|
78
81
|
```
|
|
79
82
|
|
|
83
|
+
Duration thresholds (in ms) that map to increasing log levels.
|
|
84
|
+
|
|
80
85
|
***
|
|
81
86
|
|
|
82
87
|
### logLevelToChalkColor
|
|
@@ -85,6 +90,8 @@ readonly static durationToLogLevel: number[];
|
|
|
85
90
|
readonly static logLevelToChalkColor: ChalkInstance[];
|
|
86
91
|
```
|
|
87
92
|
|
|
93
|
+
Chalk color functions corresponding to each log level.
|
|
94
|
+
|
|
88
95
|
***
|
|
89
96
|
|
|
90
97
|
### logger
|
|
@@ -103,6 +110,8 @@ logger: Logger;
|
|
|
103
110
|
get logLevel(): number;
|
|
104
111
|
```
|
|
105
112
|
|
|
113
|
+
The minimum log level required for a span to be exported.
|
|
114
|
+
|
|
106
115
|
#### Returns
|
|
107
116
|
|
|
108
117
|
`number`
|
|
@@ -141,16 +150,22 @@ ConsoleSpanExporter.export
|
|
|
141
150
|
logColor(level): ChalkInstance;
|
|
142
151
|
```
|
|
143
152
|
|
|
153
|
+
Returns the chalk color function for the given log level.
|
|
154
|
+
|
|
144
155
|
### Parameters
|
|
145
156
|
|
|
146
157
|
#### level
|
|
147
158
|
|
|
148
159
|
`number`
|
|
149
160
|
|
|
161
|
+
The log level index.
|
|
162
|
+
|
|
150
163
|
### Returns
|
|
151
164
|
|
|
152
165
|
`ChalkInstance`
|
|
153
166
|
|
|
167
|
+
A chalk color function.
|
|
168
|
+
|
|
154
169
|
***
|
|
155
170
|
|
|
156
171
|
### spanLevel()
|
|
@@ -159,16 +174,22 @@ logColor(level): ChalkInstance;
|
|
|
159
174
|
spanLevel(span): number;
|
|
160
175
|
```
|
|
161
176
|
|
|
177
|
+
Determines the log level of a span based on its duration.
|
|
178
|
+
|
|
162
179
|
### Parameters
|
|
163
180
|
|
|
164
181
|
#### span
|
|
165
182
|
|
|
166
183
|
`ReadableSpan`
|
|
167
184
|
|
|
185
|
+
The span to evaluate.
|
|
186
|
+
|
|
168
187
|
### Returns
|
|
169
188
|
|
|
170
189
|
`number`
|
|
171
190
|
|
|
191
|
+
The numeric log level (index into durationToLogLevel).
|
|
192
|
+
|
|
172
193
|
### functions
|
|
173
194
|
|
|
174
195
|
### <a id="spanDurationInMillis"></a>spanDurationInMillis
|
|
@@ -181,16 +202,22 @@ spanLevel(span): number;
|
|
|
181
202
|
function spanDurationInMillis(span): number;
|
|
182
203
|
```
|
|
183
204
|
|
|
205
|
+
Calculates the duration of a span in milliseconds from its high-resolution time tuple.
|
|
206
|
+
|
|
184
207
|
## Parameters
|
|
185
208
|
|
|
186
209
|
### span
|
|
187
210
|
|
|
188
211
|
`ReadableSpan`
|
|
189
212
|
|
|
213
|
+
The span to measure.
|
|
214
|
+
|
|
190
215
|
## Returns
|
|
191
216
|
|
|
192
217
|
`number`
|
|
193
218
|
|
|
219
|
+
The span duration in milliseconds.
|
|
220
|
+
|
|
194
221
|
|
|
195
222
|
Part of [sdk-js](https://www.npmjs.com/package/@xyo-network/sdk-js)
|
|
196
223
|
|
|
@@ -1,16 +1,38 @@
|
|
|
1
1
|
import type { ReadableSpan } from '@opentelemetry/sdk-trace-base';
|
|
2
2
|
import { ConsoleSpanExporter } from '@opentelemetry/sdk-trace-base';
|
|
3
3
|
import type { Logger } from '@xylabs/logger';
|
|
4
|
+
/**
|
|
5
|
+
* Calculates the duration of a span in milliseconds from its high-resolution time tuple.
|
|
6
|
+
* @param span - The span to measure.
|
|
7
|
+
* @returns The span duration in milliseconds.
|
|
8
|
+
*/
|
|
4
9
|
export declare function spanDurationInMillis(span: ReadableSpan): number;
|
|
10
|
+
/**
|
|
11
|
+
* A console span exporter that formats spans with color-coded durations using chalk.
|
|
12
|
+
* Spans are filtered by a configurable log level based on their duration.
|
|
13
|
+
*/
|
|
5
14
|
export declare class XyConsoleSpanExporter extends ConsoleSpanExporter {
|
|
15
|
+
/** Duration thresholds (in ms) that map to increasing log levels. */
|
|
6
16
|
static readonly durationToLogLevel: number[];
|
|
17
|
+
/** Chalk color functions corresponding to each log level. */
|
|
7
18
|
static readonly logLevelToChalkColor: import("chalk").ChalkInstance[];
|
|
8
19
|
logger: Logger;
|
|
9
20
|
private _logLevel;
|
|
10
21
|
constructor(logLevel?: number, logger?: Logger);
|
|
22
|
+
/** The minimum log level required for a span to be exported. */
|
|
11
23
|
get logLevel(): number;
|
|
12
24
|
export(spans: ReadableSpan[]): void;
|
|
25
|
+
/**
|
|
26
|
+
* Returns the chalk color function for the given log level.
|
|
27
|
+
* @param level - The log level index.
|
|
28
|
+
* @returns A chalk color function.
|
|
29
|
+
*/
|
|
13
30
|
logColor(level: number): import("chalk").ChalkInstance;
|
|
31
|
+
/**
|
|
32
|
+
* Determines the log level of a span based on its duration.
|
|
33
|
+
* @param span - The span to evaluate.
|
|
34
|
+
* @returns The numeric log level (index into durationToLogLevel).
|
|
35
|
+
*/
|
|
14
36
|
spanLevel(span: ReadableSpan): number;
|
|
15
37
|
}
|
|
16
38
|
//# sourceMappingURL=XyConsoleSpanExporter.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"XyConsoleSpanExporter.d.ts","sourceRoot":"","sources":["../../src/XyConsoleSpanExporter.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,+BAA+B,C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,MAAM,CAAC,KAAK,EAAE,YAAY,EAAE,GAAG,IAAI;IAe5C;;;;OAIG;IACH,QAAQ,CAAC,KAAK,EAAE,MAAM;IAItB;;;;OAIG;IACH,SAAS,CAAC,IAAI,EAAE,YAAY;CAW7B"}
|
package/dist/neutral/index.mjs
CHANGED
|
@@ -5,6 +5,7 @@ function spanDurationInMillis(span) {
|
|
|
5
5
|
return span.duration[0] * 1e3 + span.duration[1] / 1e6;
|
|
6
6
|
}
|
|
7
7
|
var XyConsoleSpanExporter = class _XyConsoleSpanExporter extends ConsoleSpanExporter {
|
|
8
|
+
/** Duration thresholds (in ms) that map to increasing log levels. */
|
|
8
9
|
static durationToLogLevel = [
|
|
9
10
|
0,
|
|
10
11
|
1,
|
|
@@ -12,6 +13,7 @@ var XyConsoleSpanExporter = class _XyConsoleSpanExporter extends ConsoleSpanExpo
|
|
|
12
13
|
100,
|
|
13
14
|
1e3
|
|
14
15
|
];
|
|
16
|
+
/** Chalk color functions corresponding to each log level. */
|
|
15
17
|
static logLevelToChalkColor = [
|
|
16
18
|
chalk.grey,
|
|
17
19
|
chalk.white,
|
|
@@ -26,6 +28,7 @@ var XyConsoleSpanExporter = class _XyConsoleSpanExporter extends ConsoleSpanExpo
|
|
|
26
28
|
this._logLevel = logLevel;
|
|
27
29
|
this.logger = logger;
|
|
28
30
|
}
|
|
31
|
+
/** The minimum log level required for a span to be exported. */
|
|
29
32
|
get logLevel() {
|
|
30
33
|
return this._logLevel;
|
|
31
34
|
}
|
|
@@ -43,9 +46,19 @@ var XyConsoleSpanExporter = class _XyConsoleSpanExporter extends ConsoleSpanExpo
|
|
|
43
46
|
].join(", ")));
|
|
44
47
|
}
|
|
45
48
|
}
|
|
49
|
+
/**
|
|
50
|
+
* Returns the chalk color function for the given log level.
|
|
51
|
+
* @param level - The log level index.
|
|
52
|
+
* @returns A chalk color function.
|
|
53
|
+
*/
|
|
46
54
|
logColor(level) {
|
|
47
55
|
return _XyConsoleSpanExporter.logLevelToChalkColor[level] ?? chalk.magenta;
|
|
48
56
|
}
|
|
57
|
+
/**
|
|
58
|
+
* Determines the log level of a span based on its duration.
|
|
59
|
+
* @param span - The span to evaluate.
|
|
60
|
+
* @returns The numeric log level (index into durationToLogLevel).
|
|
61
|
+
*/
|
|
49
62
|
spanLevel(span) {
|
|
50
63
|
let logLevel = 0;
|
|
51
64
|
const duration = spanDurationInMillis(span);
|
|
@@ -1 +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 type { Logger } from '@xylabs/logger'\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 logger: Logger\n private _logLevel: number\n\n constructor(logLevel = 0, logger: Logger = console) {\n super()\n this._logLevel = logLevel\n this.logger = logger\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 this.logger.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;AAEpC,OAAO,WAAW;
|
|
1
|
+
{"version":3,"sources":["../../src/XyConsoleSpanExporter.ts"],"sourcesContent":["import type { ReadableSpan } from '@opentelemetry/sdk-trace-base'\nimport { ConsoleSpanExporter } from '@opentelemetry/sdk-trace-base'\nimport type { Logger } from '@xylabs/logger'\nimport chalk from 'chalk'\n\n/**\n * Calculates the duration of a span in milliseconds from its high-resolution time tuple.\n * @param span - The span to measure.\n * @returns The span duration in milliseconds.\n */\nexport function spanDurationInMillis(span: ReadableSpan) {\n return span.duration[0] * 1000 + span.duration[1] / 1e6\n}\n\n/**\n * A console span exporter that formats spans with color-coded durations using chalk.\n * Spans are filtered by a configurable log level based on their duration.\n */\nexport class XyConsoleSpanExporter extends ConsoleSpanExporter {\n /** Duration thresholds (in ms) that map to increasing log levels. */\n static readonly durationToLogLevel = [\n 0,\n 1,\n 10,\n 100,\n 1000,\n ]\n\n /** Chalk color functions corresponding to each log level. */\n static readonly logLevelToChalkColor = [\n chalk.grey,\n chalk.white,\n chalk.green,\n chalk.yellow,\n chalk.red,\n ]\n\n logger: Logger\n private _logLevel: number\n\n constructor(logLevel = 0, logger: Logger = console) {\n super()\n this._logLevel = logLevel\n this.logger = logger\n }\n\n /** The minimum log level required for a span to be exported. */\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 this.logger.log(chalk.grey([\n `Span [${span.name}]`,\n this.logColor(spanLevel)(`${duration}ms`),\n `TraceId: ${span.spanContext().traceId}`,\n ].join(', ')))\n }\n }\n\n /**\n * Returns the chalk color function for the given log level.\n * @param level - The log level index.\n * @returns A chalk color function.\n */\n logColor(level: number) {\n return XyConsoleSpanExporter.logLevelToChalkColor[level] ?? chalk.magenta\n }\n\n /**\n * Determines the log level of a span based on its duration.\n * @param span - The span to evaluate.\n * @returns The numeric log level (index into durationToLogLevel).\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;AAEpC,OAAO,WAAW;AAOX,SAAS,qBAAqB,MAAoB;AACvD,SAAO,KAAK,SAAS,CAAC,IAAI,MAAO,KAAK,SAAS,CAAC,IAAI;AACtD;AAMO,IAAM,wBAAN,MAAM,+BAA8B,oBAAoB;AAAA;AAAA,EAE7D,OAAgB,qBAAqB;AAAA,IACnC;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACF;AAAA;AAAA,EAGA,OAAgB,uBAAuB;AAAA,IACrC,MAAM;AAAA,IACN,MAAM;AAAA,IACN,MAAM;AAAA,IACN,MAAM;AAAA,IACN,MAAM;AAAA,EACR;AAAA,EAEA;AAAA,EACQ;AAAA,EAER,YAAY,WAAW,GAAG,SAAiB,SAAS;AAClD,UAAM;AACN,SAAK,YAAY;AACjB,SAAK,SAAS;AAAA,EAChB;AAAA;AAAA,EAGA,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,WAAK,OAAO,IAAI,MAAM,KAAK;AAAA,QACzB,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;AAAA;AAAA;AAAA;AAAA;AAAA,EAOA,SAAS,OAAe;AACtB,WAAO,uBAAsB,qBAAqB,KAAK,KAAK,MAAM;AAAA,EACpE;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOA,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":[]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@xylabs/telemetry-exporter",
|
|
3
|
-
"version": "5.0.
|
|
3
|
+
"version": "5.0.84",
|
|
4
4
|
"description": "Base functionality used throughout XY Labs TypeScript/JavaScript libraries",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"hex",
|
|
@@ -43,13 +43,13 @@
|
|
|
43
43
|
],
|
|
44
44
|
"dependencies": {
|
|
45
45
|
"@opentelemetry/sdk-trace-base": "^2.6.0",
|
|
46
|
-
"@xylabs/logger": "~5.0.
|
|
46
|
+
"@xylabs/logger": "~5.0.84",
|
|
47
47
|
"chalk": "~5.6.2"
|
|
48
48
|
},
|
|
49
49
|
"devDependencies": {
|
|
50
50
|
"@opentelemetry/api": "^1.9.0",
|
|
51
|
-
"@xylabs/ts-scripts-yarn3": "~7.4.
|
|
52
|
-
"@xylabs/tsconfig": "~7.4.
|
|
51
|
+
"@xylabs/ts-scripts-yarn3": "~7.4.13",
|
|
52
|
+
"@xylabs/tsconfig": "~7.4.13",
|
|
53
53
|
"typescript": "~5.9.3",
|
|
54
54
|
"vitest": "^4.0.18"
|
|
55
55
|
},
|