@xylabs/telemetry 5.0.84 → 5.0.86
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 +82 -175
- package/package.json +5 -5
package/README.md
CHANGED
|
@@ -15,6 +15,8 @@
|
|
|
15
15
|
|
|
16
16
|
Base functionality used throughout XY Labs TypeScript/JavaScript libraries
|
|
17
17
|
|
|
18
|
+
|
|
19
|
+
|
|
18
20
|
## Reference
|
|
19
21
|
|
|
20
22
|
**@xylabs/telemetry**
|
|
@@ -23,16 +25,20 @@ Base functionality used throughout XY Labs TypeScript/JavaScript libraries
|
|
|
23
25
|
|
|
24
26
|
## Interfaces
|
|
25
27
|
|
|
26
|
-
|
|
28
|
+
| Interface | Description |
|
|
29
|
+
| ------ | ------ |
|
|
30
|
+
| [SpanConfig](#interfaces/SpanConfig) | Configuration options for span creation and execution. |
|
|
27
31
|
|
|
28
32
|
## Functions
|
|
29
33
|
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
34
|
+
| Function | Description |
|
|
35
|
+
| ------ | ------ |
|
|
36
|
+
| [cloneContextWithoutSpan](#functions/cloneContextWithoutSpan) | Creates a new OpenTelemetry context that preserves baggage and custom keys but has no active span. |
|
|
37
|
+
| [span](#functions/span) | Executes a synchronous function within an OpenTelemetry span, recording status and exceptions. |
|
|
38
|
+
| [spanRoot](#functions/spanRoot) | Executes a synchronous function within a new root span that has no parent, even if a span is already active. |
|
|
39
|
+
| [spanAsync](#functions/spanAsync) | Executes an async function within an OpenTelemetry span, with optional time budget monitoring. |
|
|
40
|
+
| [spanRootAsync](#functions/spanRootAsync) | Executes an async function within a new root span (no parent), with optional time budget monitoring. |
|
|
41
|
+
| [timeBudget](#functions/timeBudget) | Executes an async function and logs a warning if it exceeds the given time budget. |
|
|
36
42
|
|
|
37
43
|
### functions
|
|
38
44
|
|
|
@@ -43,24 +49,17 @@ Base functionality used throughout XY Labs TypeScript/JavaScript libraries
|
|
|
43
49
|
***
|
|
44
50
|
|
|
45
51
|
```ts
|
|
46
|
-
function cloneContextWithoutSpan(activeCtx, configKeys
|
|
52
|
+
function cloneContextWithoutSpan(activeCtx: Context, configKeys?: symbol[]): Context;
|
|
47
53
|
```
|
|
48
54
|
|
|
49
55
|
Creates a new OpenTelemetry context that preserves baggage and custom keys but has no active span.
|
|
50
56
|
|
|
51
57
|
## Parameters
|
|
52
58
|
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
`Context`
|
|
56
|
-
|
|
57
|
-
The context to clone from.
|
|
58
|
-
|
|
59
|
-
### configKeys?
|
|
60
|
-
|
|
61
|
-
`symbol`[] = `[]`
|
|
62
|
-
|
|
63
|
-
Additional context keys to copy.
|
|
59
|
+
| Parameter | Type | Default value | Description |
|
|
60
|
+
| ------ | ------ | ------ | ------ |
|
|
61
|
+
| `activeCtx` | `Context` | `undefined` | The context to clone from. |
|
|
62
|
+
| `configKeys` | `symbol`[] | `[]` | Additional context keys to copy. |
|
|
64
63
|
|
|
65
64
|
## Returns
|
|
66
65
|
|
|
@@ -76,38 +75,26 @@ A new context with baggage but no parent span.
|
|
|
76
75
|
|
|
77
76
|
```ts
|
|
78
77
|
function span<T>(
|
|
79
|
-
name,
|
|
80
|
-
fn,
|
|
81
|
-
tracer
|
|
78
|
+
name: string,
|
|
79
|
+
fn: () => T,
|
|
80
|
+
tracer?: Tracer): T;
|
|
82
81
|
```
|
|
83
82
|
|
|
84
83
|
Executes a synchronous function within an OpenTelemetry span, recording status and exceptions.
|
|
85
84
|
|
|
86
85
|
## Type Parameters
|
|
87
86
|
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
`T`
|
|
87
|
+
| Type Parameter |
|
|
88
|
+
| ------ |
|
|
89
|
+
| `T` |
|
|
91
90
|
|
|
92
91
|
## Parameters
|
|
93
92
|
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
`string`
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
### fn
|
|
101
|
-
|
|
102
|
-
() => `T`
|
|
103
|
-
|
|
104
|
-
The function to execute.
|
|
105
|
-
|
|
106
|
-
### tracer?
|
|
107
|
-
|
|
108
|
-
`Tracer`
|
|
109
|
-
|
|
110
|
-
Optional tracer to use.
|
|
93
|
+
| Parameter | Type | Description |
|
|
94
|
+
| ------ | ------ | ------ |
|
|
95
|
+
| `name` | `string` | The span name. |
|
|
96
|
+
| `fn` | () => `T` | The function to execute. |
|
|
97
|
+
| `tracer?` | `Tracer` | Optional tracer to use. |
|
|
111
98
|
|
|
112
99
|
## Returns
|
|
113
100
|
|
|
@@ -123,38 +110,26 @@ The return value of `fn`.
|
|
|
123
110
|
|
|
124
111
|
```ts
|
|
125
112
|
function spanAsync<T>(
|
|
126
|
-
name,
|
|
127
|
-
fn
|
|
128
|
-
config
|
|
113
|
+
name: string,
|
|
114
|
+
fn: () => Promise<T>,
|
|
115
|
+
config?: SpanConfig): Promise<T>;
|
|
129
116
|
```
|
|
130
117
|
|
|
131
118
|
Executes an async function within an OpenTelemetry span, with optional time budget monitoring.
|
|
132
119
|
|
|
133
120
|
## Type Parameters
|
|
134
121
|
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
`T`
|
|
122
|
+
| Type Parameter |
|
|
123
|
+
| ------ |
|
|
124
|
+
| `T` |
|
|
138
125
|
|
|
139
126
|
## Parameters
|
|
140
127
|
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
`string`
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
### fn
|
|
148
|
-
|
|
149
|
-
() => `Promise`\<`T`\>
|
|
150
|
-
|
|
151
|
-
The async function to execute.
|
|
152
|
-
|
|
153
|
-
### config?
|
|
154
|
-
|
|
155
|
-
[`SpanConfig`](#../interfaces/SpanConfig) = `{}`
|
|
156
|
-
|
|
157
|
-
Optional span configuration (tracer, logger, time budget).
|
|
128
|
+
| Parameter | Type | Description |
|
|
129
|
+
| ------ | ------ | ------ |
|
|
130
|
+
| `name` | `string` | The span name. |
|
|
131
|
+
| `fn` | () => `Promise`\<`T`\> | The async function to execute. |
|
|
132
|
+
| `config` | [`SpanConfig`](#../interfaces/SpanConfig) | Optional span configuration (tracer, logger, time budget). |
|
|
158
133
|
|
|
159
134
|
## Returns
|
|
160
135
|
|
|
@@ -170,38 +145,26 @@ The resolved value of `fn`.
|
|
|
170
145
|
|
|
171
146
|
```ts
|
|
172
147
|
function spanRoot<T>(
|
|
173
|
-
name,
|
|
174
|
-
fn,
|
|
175
|
-
tracer
|
|
148
|
+
name: string,
|
|
149
|
+
fn: () => T,
|
|
150
|
+
tracer?: Tracer): T;
|
|
176
151
|
```
|
|
177
152
|
|
|
178
153
|
Executes a synchronous function within a new root span that has no parent, even if a span is already active.
|
|
179
154
|
|
|
180
155
|
## Type Parameters
|
|
181
156
|
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
`T`
|
|
157
|
+
| Type Parameter |
|
|
158
|
+
| ------ |
|
|
159
|
+
| `T` |
|
|
185
160
|
|
|
186
161
|
## Parameters
|
|
187
162
|
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
`string`
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
### fn
|
|
195
|
-
|
|
196
|
-
() => `T`
|
|
197
|
-
|
|
198
|
-
The function to execute.
|
|
199
|
-
|
|
200
|
-
### tracer?
|
|
201
|
-
|
|
202
|
-
`Tracer`
|
|
203
|
-
|
|
204
|
-
Optional tracer to use.
|
|
163
|
+
| Parameter | Type | Description |
|
|
164
|
+
| ------ | ------ | ------ |
|
|
165
|
+
| `name` | `string` | The span name. |
|
|
166
|
+
| `fn` | () => `T` | The function to execute. |
|
|
167
|
+
| `tracer?` | `Tracer` | Optional tracer to use. |
|
|
205
168
|
|
|
206
169
|
## Returns
|
|
207
170
|
|
|
@@ -217,38 +180,26 @@ The return value of `fn`.
|
|
|
217
180
|
|
|
218
181
|
```ts
|
|
219
182
|
function spanRootAsync<T>(
|
|
220
|
-
name,
|
|
221
|
-
fn
|
|
222
|
-
config
|
|
183
|
+
name: string,
|
|
184
|
+
fn: () => Promise<T>,
|
|
185
|
+
config?: SpanConfig): Promise<T>;
|
|
223
186
|
```
|
|
224
187
|
|
|
225
188
|
Executes an async function within a new root span (no parent), with optional time budget monitoring.
|
|
226
189
|
|
|
227
190
|
## Type Parameters
|
|
228
191
|
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
`T`
|
|
192
|
+
| Type Parameter |
|
|
193
|
+
| ------ |
|
|
194
|
+
| `T` |
|
|
232
195
|
|
|
233
196
|
## Parameters
|
|
234
197
|
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
`string`
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
### fn
|
|
242
|
-
|
|
243
|
-
() => `Promise`\<`T`\>
|
|
244
|
-
|
|
245
|
-
The async function to execute.
|
|
246
|
-
|
|
247
|
-
### config?
|
|
248
|
-
|
|
249
|
-
[`SpanConfig`](#../interfaces/SpanConfig) = `{}`
|
|
250
|
-
|
|
251
|
-
Optional span configuration (tracer, logger, time budget).
|
|
198
|
+
| Parameter | Type | Description |
|
|
199
|
+
| ------ | ------ | ------ |
|
|
200
|
+
| `name` | `string` | The span name. |
|
|
201
|
+
| `fn` | () => `Promise`\<`T`\> | The async function to execute. |
|
|
202
|
+
| `config` | [`SpanConfig`](#../interfaces/SpanConfig) | Optional span configuration (tracer, logger, time budget). |
|
|
252
203
|
|
|
253
204
|
## Returns
|
|
254
205
|
|
|
@@ -264,52 +215,30 @@ The resolved value of `fn`.
|
|
|
264
215
|
|
|
265
216
|
```ts
|
|
266
217
|
function timeBudget<TResult>(
|
|
267
|
-
name,
|
|
268
|
-
logger,
|
|
269
|
-
func
|
|
270
|
-
budget,
|
|
271
|
-
status
|
|
218
|
+
name: string,
|
|
219
|
+
logger: Logger | undefined,
|
|
220
|
+
func: () => Promise<TResult>,
|
|
221
|
+
budget: number,
|
|
222
|
+
status?: boolean): Promise<TResult>;
|
|
272
223
|
```
|
|
273
224
|
|
|
274
225
|
Executes an async function and logs a warning if it exceeds the given time budget.
|
|
275
226
|
|
|
276
227
|
## Type Parameters
|
|
277
228
|
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
`TResult`
|
|
229
|
+
| Type Parameter |
|
|
230
|
+
| ------ |
|
|
231
|
+
| `TResult` |
|
|
281
232
|
|
|
282
233
|
## Parameters
|
|
283
234
|
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
`string`
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
The logger to use for budget-exceeded warnings.
|
|
293
|
-
|
|
294
|
-
`Logger` | `undefined`
|
|
295
|
-
|
|
296
|
-
### func
|
|
297
|
-
|
|
298
|
-
() => `Promise`\<`TResult`\>
|
|
299
|
-
|
|
300
|
-
The async function to execute.
|
|
301
|
-
|
|
302
|
-
### budget
|
|
303
|
-
|
|
304
|
-
`number`
|
|
305
|
-
|
|
306
|
-
The time budget in milliseconds.
|
|
307
|
-
|
|
308
|
-
### status?
|
|
309
|
-
|
|
310
|
-
`boolean` = `false`
|
|
311
|
-
|
|
312
|
-
If true, logs periodic warnings while the function is still running.
|
|
235
|
+
| Parameter | Type | Default value | Description |
|
|
236
|
+
| ------ | ------ | ------ | ------ |
|
|
237
|
+
| `name` | `string` | `undefined` | A label for the function, used in warning messages. |
|
|
238
|
+
| `logger` | `Logger` \| `undefined` | `undefined` | The logger to use for budget-exceeded warnings. |
|
|
239
|
+
| `func` | () => `Promise`\<`TResult`\> | `undefined` | The async function to execute. |
|
|
240
|
+
| `budget` | `number` | `undefined` | The time budget in milliseconds. |
|
|
241
|
+
| `status` | `boolean` | `false` | If true, logs periodic warnings while the function is still running. |
|
|
313
242
|
|
|
314
243
|
## Returns
|
|
315
244
|
|
|
@@ -329,33 +258,11 @@ Configuration options for span creation and execution.
|
|
|
329
258
|
|
|
330
259
|
## Properties
|
|
331
260
|
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
Optional logger for time budget warnings. Falls back to console if not provided.
|
|
339
|
-
|
|
340
|
-
***
|
|
341
|
-
|
|
342
|
-
### timeBudgetLimit?
|
|
343
|
-
|
|
344
|
-
```ts
|
|
345
|
-
optional timeBudgetLimit: number;
|
|
346
|
-
```
|
|
347
|
-
|
|
348
|
-
Maximum allowed execution time in milliseconds before logging a warning.
|
|
349
|
-
|
|
350
|
-
***
|
|
351
|
-
|
|
352
|
-
### tracer?
|
|
353
|
-
|
|
354
|
-
```ts
|
|
355
|
-
optional tracer: Tracer;
|
|
356
|
-
```
|
|
357
|
-
|
|
358
|
-
OpenTelemetry tracer to use. Defaults to a tracer named after the span.
|
|
261
|
+
| Property | Type | Description |
|
|
262
|
+
| ------ | ------ | ------ |
|
|
263
|
+
| <a id="logger"></a> `logger?` | `Logger` \| `null` | Optional logger for time budget warnings. Falls back to console if not provided. |
|
|
264
|
+
| <a id="timebudgetlimit"></a> `timeBudgetLimit?` | `number` | Maximum allowed execution time in milliseconds before logging a warning. |
|
|
265
|
+
| <a id="tracer"></a> `tracer?` | `Tracer` | OpenTelemetry tracer to use. Defaults to a tracer named after the span. |
|
|
359
266
|
|
|
360
267
|
|
|
361
268
|
Part of [sdk-js](https://www.npmjs.com/package/@xyo-network/sdk-js)
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@xylabs/telemetry",
|
|
3
|
-
"version": "5.0.
|
|
3
|
+
"version": "5.0.86",
|
|
4
4
|
"description": "Base functionality used throughout XY Labs TypeScript/JavaScript libraries",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"hex",
|
|
@@ -43,12 +43,12 @@
|
|
|
43
43
|
],
|
|
44
44
|
"dependencies": {
|
|
45
45
|
"@opentelemetry/api": "^1.9.0",
|
|
46
|
-
"@xylabs/logger": "~5.0.
|
|
47
|
-
"@xylabs/typeof": "~5.0.
|
|
46
|
+
"@xylabs/logger": "~5.0.86",
|
|
47
|
+
"@xylabs/typeof": "~5.0.86"
|
|
48
48
|
},
|
|
49
49
|
"devDependencies": {
|
|
50
|
-
"@xylabs/ts-scripts-yarn3": "~7.4.
|
|
51
|
-
"@xylabs/tsconfig": "~7.4.
|
|
50
|
+
"@xylabs/ts-scripts-yarn3": "~7.4.16",
|
|
51
|
+
"@xylabs/tsconfig": "~7.4.16",
|
|
52
52
|
"typescript": "~5.9.3",
|
|
53
53
|
"vitest": "~4.0.18"
|
|
54
54
|
},
|