@xylabs/telemetry 5.0.83 → 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 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
- - [SpanConfig](#interfaces/SpanConfig)
28
+ | Interface | Description |
29
+ | ------ | ------ |
30
+ | [SpanConfig](#interfaces/SpanConfig) | Configuration options for span creation and execution. |
27
31
 
28
32
  ## Functions
29
33
 
30
- - [cloneContextWithoutSpan](#functions/cloneContextWithoutSpan)
31
- - [span](#functions/span)
32
- - [spanRoot](#functions/spanRoot)
33
- - [spanAsync](#functions/spanAsync)
34
- - [spanRootAsync](#functions/spanRootAsync)
35
- - [timeBudget](#functions/timeBudget)
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,23 +49,24 @@ Base functionality used throughout XY Labs TypeScript/JavaScript libraries
43
49
  ***
44
50
 
45
51
  ```ts
46
- function cloneContextWithoutSpan(activeCtx, configKeys?): Context;
52
+ function cloneContextWithoutSpan(activeCtx: Context, configKeys?: symbol[]): Context;
47
53
  ```
48
54
 
49
- ## Parameters
55
+ Creates a new OpenTelemetry context that preserves baggage and custom keys but has no active span.
50
56
 
51
- ### activeCtx
52
-
53
- `Context`
54
-
55
- ### configKeys?
57
+ ## Parameters
56
58
 
57
- `symbol`[] = `[]`
59
+ | Parameter | Type | Default value | Description |
60
+ | ------ | ------ | ------ | ------ |
61
+ | `activeCtx` | `Context` | `undefined` | The context to clone from. |
62
+ | `configKeys` | `symbol`[] | `[]` | Additional context keys to copy. |
58
63
 
59
64
  ## Returns
60
65
 
61
66
  `Context`
62
67
 
68
+ A new context with baggage but no parent span.
69
+
63
70
  ### <a id="span"></a>span
64
71
 
65
72
  [**@xylabs/telemetry**](#../README)
@@ -68,35 +75,33 @@ function cloneContextWithoutSpan(activeCtx, configKeys?): Context;
68
75
 
69
76
  ```ts
70
77
  function span<T>(
71
- name,
72
- fn,
73
- tracer?): T;
78
+ name: string,
79
+ fn: () => T,
80
+ tracer?: Tracer): T;
74
81
  ```
75
82
 
76
- ## Type Parameters
83
+ Executes a synchronous function within an OpenTelemetry span, recording status and exceptions.
77
84
 
78
- ### T
85
+ ## Type Parameters
79
86
 
80
- `T`
87
+ | Type Parameter |
88
+ | ------ |
89
+ | `T` |
81
90
 
82
91
  ## Parameters
83
92
 
84
- ### name
85
-
86
- `string`
87
-
88
- ### fn
89
-
90
- () => `T`
91
-
92
- ### tracer?
93
-
94
- `Tracer`
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. |
95
98
 
96
99
  ## Returns
97
100
 
98
101
  `T`
99
102
 
103
+ The return value of `fn`.
104
+
100
105
  ### <a id="spanAsync"></a>spanAsync
101
106
 
102
107
  [**@xylabs/telemetry**](#../README)
@@ -105,35 +110,33 @@ function span<T>(
105
110
 
106
111
  ```ts
107
112
  function spanAsync<T>(
108
- name,
109
- fn,
110
- __namedParameters?): Promise<T>;
113
+ name: string,
114
+ fn: () => Promise<T>,
115
+ config?: SpanConfig): Promise<T>;
111
116
  ```
112
117
 
113
- ## Type Parameters
118
+ Executes an async function within an OpenTelemetry span, with optional time budget monitoring.
114
119
 
115
- ### T
120
+ ## Type Parameters
116
121
 
117
- `T`
122
+ | Type Parameter |
123
+ | ------ |
124
+ | `T` |
118
125
 
119
126
  ## Parameters
120
127
 
121
- ### name
122
-
123
- `string`
124
-
125
- ### fn
126
-
127
- () => `Promise`\<`T`\>
128
-
129
- ### \_\_namedParameters?
130
-
131
- [`SpanConfig`](#../interfaces/SpanConfig) = `{}`
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). |
132
133
 
133
134
  ## Returns
134
135
 
135
136
  `Promise`\<`T`\>
136
137
 
138
+ The resolved value of `fn`.
139
+
137
140
  ### <a id="spanRoot"></a>spanRoot
138
141
 
139
142
  [**@xylabs/telemetry**](#../README)
@@ -142,35 +145,33 @@ __namedParameters?): Promise<T>;
142
145
 
143
146
  ```ts
144
147
  function spanRoot<T>(
145
- name,
146
- fn,
147
- tracer?): T;
148
+ name: string,
149
+ fn: () => T,
150
+ tracer?: Tracer): T;
148
151
  ```
149
152
 
150
- ## Type Parameters
153
+ Executes a synchronous function within a new root span that has no parent, even if a span is already active.
151
154
 
152
- ### T
155
+ ## Type Parameters
153
156
 
154
- `T`
157
+ | Type Parameter |
158
+ | ------ |
159
+ | `T` |
155
160
 
156
161
  ## Parameters
157
162
 
158
- ### name
159
-
160
- `string`
161
-
162
- ### fn
163
-
164
- () => `T`
165
-
166
- ### tracer?
167
-
168
- `Tracer`
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. |
169
168
 
170
169
  ## Returns
171
170
 
172
171
  `T`
173
172
 
173
+ The return value of `fn`.
174
+
174
175
  ### <a id="spanRootAsync"></a>spanRootAsync
175
176
 
176
177
  [**@xylabs/telemetry**](#../README)
@@ -179,35 +180,33 @@ function spanRoot<T>(
179
180
 
180
181
  ```ts
181
182
  function spanRootAsync<T>(
182
- name,
183
- fn,
184
- __namedParameters?): Promise<T>;
183
+ name: string,
184
+ fn: () => Promise<T>,
185
+ config?: SpanConfig): Promise<T>;
185
186
  ```
186
187
 
187
- ## Type Parameters
188
+ Executes an async function within a new root span (no parent), with optional time budget monitoring.
188
189
 
189
- ### T
190
+ ## Type Parameters
190
191
 
191
- `T`
192
+ | Type Parameter |
193
+ | ------ |
194
+ | `T` |
192
195
 
193
196
  ## Parameters
194
197
 
195
- ### name
196
-
197
- `string`
198
-
199
- ### fn
200
-
201
- () => `Promise`\<`T`\>
202
-
203
- ### \_\_namedParameters?
204
-
205
- [`SpanConfig`](#../interfaces/SpanConfig) = `{}`
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). |
206
203
 
207
204
  ## Returns
208
205
 
209
206
  `Promise`\<`T`\>
210
207
 
208
+ The resolved value of `fn`.
209
+
211
210
  ### <a id="timeBudget"></a>timeBudget
212
211
 
213
212
  [**@xylabs/telemetry**](#../README)
@@ -216,45 +215,37 @@ __namedParameters?): Promise<T>;
216
215
 
217
216
  ```ts
218
217
  function timeBudget<TResult>(
219
- name,
220
- logger,
221
- func,
222
- budget,
223
- status?): Promise<TResult>;
218
+ name: string,
219
+ logger: Logger | undefined,
220
+ func: () => Promise<TResult>,
221
+ budget: number,
222
+ status?: boolean): Promise<TResult>;
224
223
  ```
225
224
 
226
- ## Type Parameters
225
+ Executes an async function and logs a warning if it exceeds the given time budget.
227
226
 
228
- ### TResult
227
+ ## Type Parameters
229
228
 
230
- `TResult`
229
+ | Type Parameter |
230
+ | ------ |
231
+ | `TResult` |
231
232
 
232
233
  ## Parameters
233
234
 
234
- ### name
235
-
236
- `string`
237
-
238
- ### logger
239
-
240
- `Logger` | `undefined`
241
-
242
- ### func
243
-
244
- () => `Promise`\<`TResult`\>
245
-
246
- ### budget
247
-
248
- `number`
249
-
250
- ### status?
251
-
252
- `boolean` = `false`
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. |
253
242
 
254
243
  ## Returns
255
244
 
256
245
  `Promise`\<`TResult`\>
257
246
 
247
+ The result of the executed function.
248
+
258
249
  ### interfaces
259
250
 
260
251
  ### <a id="SpanConfig"></a>SpanConfig
@@ -263,29 +254,15 @@ status?): Promise<TResult>;
263
254
 
264
255
  ***
265
256
 
266
- ## Properties
267
-
268
- ### logger?
269
-
270
- ```ts
271
- optional logger: Logger | null;
272
- ```
273
-
274
- ***
275
-
276
- ### timeBudgetLimit?
257
+ Configuration options for span creation and execution.
277
258
 
278
- ```ts
279
- optional timeBudgetLimit: number;
280
- ```
281
-
282
- ***
283
-
284
- ### tracer?
259
+ ## Properties
285
260
 
286
- ```ts
287
- optional tracer: Tracer;
288
- ```
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. |
289
266
 
290
267
 
291
268
  Part of [sdk-js](https://www.npmjs.com/package/@xyo-network/sdk-js)
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/span.ts","../../src/timeBudget.ts"],"sourcesContent":["import type {\n Context,\n Tracer,\n} from '@opentelemetry/api'\nimport {\n context, propagation, ROOT_CONTEXT, SpanStatusCode, trace as TRACE_API,\n} from '@opentelemetry/api'\nimport type { Logger } from '@xylabs/logger'\nimport { isDefined } from '@xylabs/typeof'\n\nimport { timeBudget } from './timeBudget.ts'\n\nexport interface SpanConfig {\n logger?: Logger | null\n timeBudgetLimit?: number\n tracer?: Tracer\n}\n\nexport function cloneContextWithoutSpan(activeCtx: Context, configKeys: symbol[] = []): Context {\n // Start from root to ensure no span is propagated\n let newCtx = ROOT_CONTEXT\n\n // Copy baggage\n const baggage = propagation.getBaggage(activeCtx)\n if (baggage) {\n newCtx = propagation.setBaggage(newCtx, baggage)\n }\n\n // Copy custom config keys\n for (const key of configKeys) {\n const value = activeCtx.getValue(key)\n if (value !== undefined) {\n newCtx = newCtx.setValue(key, value)\n }\n }\n\n return newCtx\n}\n\nexport function span<T>(name: string, fn: () => T, tracer?: Tracer): T {\n const activeTracer = tracer ?? TRACE_API.getTracer(name)\n if (isDefined(activeTracer)) {\n const span = activeTracer.startSpan(name)\n return context.with(TRACE_API.setSpan(context.active(), span), () => {\n try {\n const result = fn()\n span.setStatus({ code: SpanStatusCode.OK })\n return result\n } catch (ex) {\n const error = ex as Error\n span.recordException(error)\n span.setStatus({ code: SpanStatusCode.ERROR, message: error.message })\n throw ex\n } finally {\n span.end()\n }\n })\n } else {\n return fn()\n }\n}\n\nexport function spanRoot<T>(name: string, fn: () => T, tracer?: Tracer): T {\n const activeTracer = tracer ?? TRACE_API.getTracer(name)\n if (isDefined(activeTracer)) {\n // Get current active context for configuration\n const activeContext = context.active()\n\n // Create a new context with no active span\n const noSpanContext = cloneContextWithoutSpan(activeContext)\n\n // Create a new span in the context without an active span\n const span = activeTracer.startSpan(name, {}, noSpanContext)\n\n // Use the active context but replace its span with our new root span\n return context.with(TRACE_API.setSpan(noSpanContext, span), () => {\n try {\n const result = fn()\n span.setStatus({ code: SpanStatusCode.OK })\n return result\n } catch (ex) {\n const error = ex as Error\n span.recordException(error)\n span.setStatus({ code: SpanStatusCode.ERROR, message: error.message })\n throw ex\n } finally {\n span.end()\n }\n })\n } else {\n return fn()\n }\n}\n\nexport async function spanAsync<T>(\n name: string,\n fn: () => Promise<T>,\n {\n timeBudgetLimit, logger, tracer,\n }: SpanConfig = {},\n): Promise<T> {\n const activeTracer = tracer ?? TRACE_API.getTracer(name)\n const funcToRun = isDefined(timeBudgetLimit) ? () => timeBudget(name, logger ?? console, fn, timeBudgetLimit) : fn\n if (isDefined(activeTracer)) {\n const span = activeTracer.startSpan(name)\n return await context.with(TRACE_API.setSpan(context.active(), span), async () => {\n try {\n const result = await funcToRun()\n span.setStatus({ code: SpanStatusCode.OK })\n return result\n } catch (ex) {\n const error = ex as Error\n span.recordException(error)\n span.setStatus({ code: SpanStatusCode.ERROR, message: error.message })\n throw ex\n } finally {\n span.end()\n }\n })\n } else {\n return await funcToRun()\n }\n}\n\nexport async function spanRootAsync<T>(\n name: string,\n fn: () => Promise<T>,\n {\n timeBudgetLimit, logger, tracer,\n }: SpanConfig = {},\n): Promise<T> {\n const funcToRun = isDefined(timeBudgetLimit) ? () => timeBudget(name, logger ?? console, fn, timeBudgetLimit) : fn\n const activeTracer = tracer ?? TRACE_API.getTracer(name)\n if (isDefined(activeTracer)) {\n const activeContext = context.active()\n\n const noSpanContext = cloneContextWithoutSpan(activeContext)\n\n // Create a new span in the context without an active span\n const span = activeTracer.startSpan(name, {}, noSpanContext)\n\n // Use the active context but replace its span with our new root span\n return await context.with(TRACE_API.setSpan(noSpanContext, span), async () => {\n try {\n const result = await funcToRun()\n span.setStatus({ code: SpanStatusCode.OK })\n return result\n } catch (ex) {\n const error = ex as Error\n span.recordException(error)\n span.setStatus({ code: SpanStatusCode.ERROR, message: error.message })\n throw ex\n } finally {\n span.end()\n }\n })\n } else {\n return await funcToRun()\n }\n}\n","import type { Logger } from '@xylabs/logger'\n\nexport async function timeBudget<TResult>(\n name: string,\n logger: Logger | undefined,\n func: () => Promise<TResult>,\n budget: number,\n status = false,\n): Promise<TResult> {\n const start = Date.now()\n const timer = status\n ? setInterval(() => {\n const duration = Date.now() - start\n if ((budget > 0) && (duration > budget)) {\n logger?.warn(`Function [${name}] execution is exceeding budget: ${duration}ms > ${budget}ms`)\n }\n }, Math.max(100, budget))\n : undefined\n\n const result = await func()\n const duration = Date.now() - start\n\n if (!timer && (budget > 0) && (duration > budget)) {\n logger?.warn(`Function [${name}] execution exceeded budget: ${duration}ms > ${budget}ms`)\n }\n if (timer) {\n clearInterval(timer)\n }\n return result\n}\n"],"mappings":";AAIA;AAAA,EACE;AAAA,EAAS;AAAA,EAAa;AAAA,EAAc;AAAA,EAAgB,SAAS;AAAA,OACxD;AAEP,SAAS,iBAAiB;;;ACN1B,eAAsB,WACpB,MACA,QACA,MACA,QACA,SAAS,OACS;AAClB,QAAM,QAAQ,KAAK,IAAI;AACvB,QAAM,QAAQ,SACV,YAAY,MAAM;AAChB,UAAMA,YAAW,KAAK,IAAI,IAAI;AAC9B,QAAK,SAAS,KAAOA,YAAW,QAAS;AACvC,cAAQ,KAAK,aAAa,IAAI,oCAAoCA,SAAQ,QAAQ,MAAM,IAAI;AAAA,IAC9F;AAAA,EACF,GAAG,KAAK,IAAI,KAAK,MAAM,CAAC,IACxB;AAEJ,QAAM,SAAS,MAAM,KAAK;AAC1B,QAAM,WAAW,KAAK,IAAI,IAAI;AAE9B,MAAI,CAAC,SAAU,SAAS,KAAO,WAAW,QAAS;AACjD,YAAQ,KAAK,aAAa,IAAI,gCAAgC,QAAQ,QAAQ,MAAM,IAAI;A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B;AACF;AAEA,eAAsB,cACpB,MACA,IACA;AAAA,EACE;AAAA,EAAiB;AAAA,EAAQ;AAC3B,IAAgB,CAAC,GACL;AACZ,QAAM,YAAY,UAAU,eAAe,IAAI,MAAM,WAAW,MAAM,UAAU,SAAS,IAAI,eAAe,IAAI;AAChH,QAAM,eAAe,UAAU,UAAU,UAAU,IAAI;AACvD,MAAI,UAAU,YAAY,GAAG;AAC3B,UAAM,gBAAgB,QAAQ,OAAO;AAErC,UAAM,gBAAgB,wBAAwB,aAAa;AAG3D,UAAMA,QAAO,aAAa,UAAU,MAAM,CAAC,GAAG,aAAa;AAG3D,WAAO,MAAM,QAAQ,KAAK,UAAU,QAAQ,eAAeA,KAAI,GAAG,YAAY;AAC5E,UAAI;AACF,cAAM,SAAS,MAAM,UAAU;AAC/B,QAAAA,MAAK,UAAU,EAAE,MAAM,eAAe,GAAG,CAAC;AAC1C,eAAO;AAAA,MACT,SAAS,IAAI;AACX,cAAM,QAAQ;AACd,QAAAA,MAAK,gBAAgB,KAAK;AAC1B,QAAAA,MAAK,UAAU,EAAE,MAAM,eAAe,OAAO,SAAS,MAAM,QAAQ,CAAC;AACrE,cAAM;AAAA,MACR,UAAE;AACA,QAAAA,MAAK,IAAI;AAAA,MACX;AAAA,IACF,CAAC;AAAA,EACH,OAAO;AACL,WAAO,MAAM,UAAU;AAAA,EACzB;AACF;","names":["duration","span"]}
1
+ {"version":3,"sources":["../../src/span.ts","../../src/timeBudget.ts"],"sourcesContent":["import type {\n Context,\n Tracer,\n} from '@opentelemetry/api'\nimport {\n context, propagation, ROOT_CONTEXT, SpanStatusCode, trace as TRACE_API,\n} from '@opentelemetry/api'\nimport type { Logger } from '@xylabs/logger'\nimport { isDefined } from '@xylabs/typeof'\n\nimport { timeBudget } from './timeBudget.ts'\n\n/** Configuration options for span creation and execution. */\nexport interface SpanConfig {\n /** Optional logger for time budget warnings. Falls back to console if not provided. */\n logger?: Logger | null\n /** Maximum allowed execution time in milliseconds before logging a warning. */\n timeBudgetLimit?: number\n /** OpenTelemetry tracer to use. Defaults to a tracer named after the span. */\n tracer?: Tracer\n}\n\n/**\n * Creates a new OpenTelemetry context that preserves baggage and custom keys but has no active span.\n * @param activeCtx - The context to clone from.\n * @param configKeys - Additional context keys to copy.\n * @returns A new context with baggage but no parent span.\n */\nexport function cloneContextWithoutSpan(activeCtx: Context, configKeys: symbol[] = []): Context {\n // Start from root to ensure no span is propagated\n let newCtx = ROOT_CONTEXT\n\n // Copy baggage\n const baggage = propagation.getBaggage(activeCtx)\n if (baggage) {\n newCtx = propagation.setBaggage(newCtx, baggage)\n }\n\n // Copy custom config keys\n for (const key of configKeys) {\n const value = activeCtx.getValue(key)\n if (value !== undefined) {\n newCtx = newCtx.setValue(key, value)\n }\n }\n\n return newCtx\n}\n\n/**\n * Executes a synchronous function within an OpenTelemetry span, recording status and exceptions.\n * @param name - The span name.\n * @param fn - The function to execute.\n * @param tracer - Optional tracer to use.\n * @returns The return value of `fn`.\n */\nexport function span<T>(name: string, fn: () => T, tracer?: Tracer): T {\n const activeTracer = tracer ?? TRACE_API.getTracer(name)\n if (isDefined(activeTracer)) {\n const span = activeTracer.startSpan(name)\n return context.with(TRACE_API.setSpan(context.active(), span), () => {\n try {\n const result = fn()\n span.setStatus({ code: SpanStatusCode.OK })\n return result\n } catch (ex) {\n const error = ex as Error\n span.recordException(error)\n span.setStatus({ code: SpanStatusCode.ERROR, message: error.message })\n throw ex\n } finally {\n span.end()\n }\n })\n } else {\n return fn()\n }\n}\n\n/**\n * Executes a synchronous function within a new root span that has no parent, even if a span is already active.\n * @param name - The span name.\n * @param fn - The function to execute.\n * @param tracer - Optional tracer to use.\n * @returns The return value of `fn`.\n */\nexport function spanRoot<T>(name: string, fn: () => T, tracer?: Tracer): T {\n const activeTracer = tracer ?? TRACE_API.getTracer(name)\n if (isDefined(activeTracer)) {\n // Get current active context for configuration\n const activeContext = context.active()\n\n // Create a new context with no active span\n const noSpanContext = cloneContextWithoutSpan(activeContext)\n\n // Create a new span in the context without an active span\n const span = activeTracer.startSpan(name, {}, noSpanContext)\n\n // Use the active context but replace its span with our new root span\n return context.with(TRACE_API.setSpan(noSpanContext, span), () => {\n try {\n const result = fn()\n span.setStatus({ code: SpanStatusCode.OK })\n return result\n } catch (ex) {\n const error = ex as Error\n span.recordException(error)\n span.setStatus({ code: SpanStatusCode.ERROR, message: error.message })\n throw ex\n } finally {\n span.end()\n }\n })\n } else {\n return fn()\n }\n}\n\n/**\n * Executes an async function within an OpenTelemetry span, with optional time budget monitoring.\n * @param name - The span name.\n * @param fn - The async function to execute.\n * @param config - Optional span configuration (tracer, logger, time budget).\n * @returns The resolved value of `fn`.\n */\nexport async function spanAsync<T>(\n name: string,\n fn: () => Promise<T>,\n {\n timeBudgetLimit, logger, tracer,\n }: SpanConfig = {},\n): Promise<T> {\n const activeTracer = tracer ?? TRACE_API.getTracer(name)\n const funcToRun = isDefined(timeBudgetLimit) ? () => timeBudget(name, logger ?? console, fn, timeBudgetLimit) : fn\n if (isDefined(activeTracer)) {\n const span = activeTracer.startSpan(name)\n return await context.with(TRACE_API.setSpan(context.active(), span), async () => {\n try {\n const result = await funcToRun()\n span.setStatus({ code: SpanStatusCode.OK })\n return result\n } catch (ex) {\n const error = ex as Error\n span.recordException(error)\n span.setStatus({ code: SpanStatusCode.ERROR, message: error.message })\n throw ex\n } finally {\n span.end()\n }\n })\n } else {\n return await funcToRun()\n }\n}\n\n/**\n * Executes an async function within a new root span (no parent), with optional time budget monitoring.\n * @param name - The span name.\n * @param fn - The async function to execute.\n * @param config - Optional span configuration (tracer, logger, time budget).\n * @returns The resolved value of `fn`.\n */\nexport async function spanRootAsync<T>(\n name: string,\n fn: () => Promise<T>,\n {\n timeBudgetLimit, logger, tracer,\n }: SpanConfig = {},\n): Promise<T> {\n const funcToRun = isDefined(timeBudgetLimit) ? () => timeBudget(name, logger ?? console, fn, timeBudgetLimit) : fn\n const activeTracer = tracer ?? TRACE_API.getTracer(name)\n if (isDefined(activeTracer)) {\n const activeContext = context.active()\n\n const noSpanContext = cloneContextWithoutSpan(activeContext)\n\n // Create a new span in the context without an active span\n const span = activeTracer.startSpan(name, {}, noSpanContext)\n\n // Use the active context but replace its span with our new root span\n return await context.with(TRACE_API.setSpan(noSpanContext, span), async () => {\n try {\n const result = await funcToRun()\n span.setStatus({ code: SpanStatusCode.OK })\n return result\n } catch (ex) {\n const error = ex as Error\n span.recordException(error)\n span.setStatus({ code: SpanStatusCode.ERROR, message: error.message })\n throw ex\n } finally {\n span.end()\n }\n })\n } else {\n return await funcToRun()\n }\n}\n","import type { Logger } from '@xylabs/logger'\n\n/**\n * Executes an async function and logs a warning if it exceeds the given time budget.\n * @param name - A label for the function, used in warning messages.\n * @param logger - The logger to use for budget-exceeded warnings.\n * @param func - The async function to execute.\n * @param budget - The time budget in milliseconds.\n * @param status - If true, logs periodic warnings while the function is still running.\n * @returns The result of the executed function.\n */\nexport async function timeBudget<TResult>(\n name: string,\n logger: Logger | undefined,\n func: () => Promise<TResult>,\n budget: number,\n status = false,\n): Promise<TResult> {\n const start = Date.now()\n const timer = status\n ? setInterval(() => {\n const duration = Date.now() - start\n if ((budget > 0) && (duration > budget)) {\n logger?.warn(`Function [${name}] execution is exceeding budget: ${duration}ms > ${budget}ms`)\n }\n }, Math.max(100, budget))\n : undefined\n\n const result = await func()\n const duration = Date.now() - start\n\n if (!timer && (budget > 0) && (duration > budget)) {\n logger?.warn(`Function [${name}] execution exceeded budget: ${duration}ms > ${budget}ms`)\n }\n if (timer) {\n clearInterval(timer)\n }\n return result\n}\n"],"mappings":";AAIA;AAAA,EACE;AAAA,EAAS;AAAA,EAAa;AAAA,EAAc;AAAA,EAAgB,SAAS;AAAA,OACxD;AAEP,SAAS,iBAAiB;;;ACG1B,eAAsB,WACpB,MACA,QACA,MACA,QACA,SAAS,OACS;AAClB,QAAM,QAAQ,KAAK,IAAI;AACvB,QAAM,QAAQ,SACV,YAAY,MAAM;AAChB,UAAMA,YAAW,KAAK,IAAI,IAA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,51 @@
1
1
  import type { Context, Tracer } from '@opentelemetry/api';
2
2
  import type { Logger } from '@xylabs/logger';
3
+ /** Configuration options for span creation and execution. */
3
4
  export interface SpanConfig {
5
+ /** Optional logger for time budget warnings. Falls back to console if not provided. */
4
6
  logger?: Logger | null;
7
+ /** Maximum allowed execution time in milliseconds before logging a warning. */
5
8
  timeBudgetLimit?: number;
9
+ /** OpenTelemetry tracer to use. Defaults to a tracer named after the span. */
6
10
  tracer?: Tracer;
7
11
  }
12
+ /**
13
+ * Creates a new OpenTelemetry context that preserves baggage and custom keys but has no active span.
14
+ * @param activeCtx - The context to clone from.
15
+ * @param configKeys - Additional context keys to copy.
16
+ * @returns A new context with baggage but no parent span.
17
+ */
8
18
  export declare function cloneContextWithoutSpan(activeCtx: Context, configKeys?: symbol[]): Context;
19
+ /**
20
+ * Executes a synchronous function within an OpenTelemetry span, recording status and exceptions.
21
+ * @param name - The span name.
22
+ * @param fn - The function to execute.
23
+ * @param tracer - Optional tracer to use.
24
+ * @returns The return value of `fn`.
25
+ */
9
26
  export declare function span<T>(name: string, fn: () => T, tracer?: Tracer): T;
27
+ /**
28
+ * Executes a synchronous function within a new root span that has no parent, even if a span is already active.
29
+ * @param name - The span name.
30
+ * @param fn - The function to execute.
31
+ * @param tracer - Optional tracer to use.
32
+ * @returns The return value of `fn`.
33
+ */
10
34
  export declare function spanRoot<T>(name: string, fn: () => T, tracer?: Tracer): T;
35
+ /**
36
+ * Executes an async function within an OpenTelemetry span, with optional time budget monitoring.
37
+ * @param name - The span name.
38
+ * @param fn - The async function to execute.
39
+ * @param config - Optional span configuration (tracer, logger, time budget).
40
+ * @returns The resolved value of `fn`.
41
+ */
11
42
  export declare function spanAsync<T>(name: string, fn: () => Promise<T>, { timeBudgetLimit, logger, tracer, }?: SpanConfig): Promise<T>;
43
+ /**
44
+ * Executes an async function within a new root span (no parent), with optional time budget monitoring.
45
+ * @param name - The span name.
46
+ * @param fn - The async function to execute.
47
+ * @param config - Optional span configuration (tracer, logger, time budget).
48
+ * @returns The resolved value of `fn`.
49
+ */
12
50
  export declare function spanRootAsync<T>(name: string, fn: () => Promise<T>, { timeBudgetLimit, logger, tracer, }?: SpanConfig): Promise<T>;
13
51
  //# sourceMappingURL=span.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"span.d.ts","sourceRoot":"","sources":["../../src/span.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,OAAO,EACP,MAAM,EACP,MAAM,oBAAoB,CAAA;AAI3B,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAA;AAK5C,MAAM,WAAW,UAAU;IACzB,MAAM,CAAC,EAAE,MAAM,GAAG,IAAI,CAAA;IACtB,eAAe,CAAC,EAAE,MAAM,CAAA;IACxB,MAAM,CAAC,EAAE,MAAM,CAAA;CAChB;AAED,wBAAgB,uBAAuB,CAAC,SAAS,EAAE,OAAO,EAAE,UAAU,GAAE,MAAM,EAAO,GAAG,OAAO,CAmB9F;AAED,wBAAgB,IAAI,CAAC,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,CAAC,EAAE,MAAM,CAAC,EAAE,MAAM,GAAG,CAAC,CAqBrE;AAED,wBAAgB,QAAQ,CAAC,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,CAAC,EAAE,MAAM,CAAC,EAAE,MAAM,GAAG,CAAC,CA8BzE;AAED,wBAAsB,SAAS,CAAC,CAAC,EAC/B,IAAI,EAAE,MAAM,EACZ,EAAE,EAAE,MAAM,OAAO,CAAC,CAAC,CAAC,EACpB,EACE,eAAe,EAAE,MAAM,EAAE,MAAM,GAChC,GAAE,UAAe,GACjB,OAAO,CAAC,CAAC,CAAC,CAsBZ;AAED,wBAAsB,aAAa,CAAC,CAAC,EACnC,IAAI,EAAE,MAAM,EACZ,EAAE,EAAE,MAAM,OAAO,CAAC,CAAC,CAAC,EACpB,EACE,eAAe,EAAE,MAAM,EAAE,MAAM,GACh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EAAE,MAAM,EAAE,MAAM,GAChC,GAAE,UAAe,GACjB,OAAO,CAAC,CAAC,CAAC,CA6BZ"}
@@ -1,3 +1,12 @@
1
1
  import type { Logger } from '@xylabs/logger';
2
+ /**
3
+ * Executes an async function and logs a warning if it exceeds the given time budget.
4
+ * @param name - A label for the function, used in warning messages.
5
+ * @param logger - The logger to use for budget-exceeded warnings.
6
+ * @param func - The async function to execute.
7
+ * @param budget - The time budget in milliseconds.
8
+ * @param status - If true, logs periodic warnings while the function is still running.
9
+ * @returns The result of the executed function.
10
+ */
2
11
  export declare function timeBudget<TResult>(name: string, logger: Logger | undefined, func: () => Promise<TResult>, budget: number, status?: boolean): Promise<TResult>;
3
12
  //# sourceMappingURL=timeBudget.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"timeBudget.d.ts","sourceRoot":"","sources":["../../src/timeBudget.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAA;AAE5C,wBAAsB,UAAU,CAAC,OAAO,EACtC,IAAI,EAAE,MAAM,EACZ,MAAM,EAAE,MAAM,GAAG,SAAS,EAC1B,IAAI,EAAE,MAAM,OAAO,CAAC,OAAO,CAAC,EAC5B,MAAM,EAAE,MAAM,EACd,MAAM,UAAQ,GACb,OAAO,CAAC,OAAO,CAAC,CAqBlB"}
1
+ {"version":3,"file":"timeBudget.d.ts","sourceRoot":"","sources":["../../src/timeBudget.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAA;AAE5C;;;;;;;;GAQG;AACH,wBAAsB,UAAU,CAAC,OAAO,EACtC,IAAI,EAAE,MAAM,EACZ,MAAM,EAAE,MAAM,GAAG,SAAS,EAC1B,IAAI,EAAE,MAAM,OAAO,CAAC,OAAO,CAAC,EAC5B,MAAM,EAAE,MAAM,EACd,MAAM,UAAQ,GACb,OAAO,CAAC,OAAO,CAAC,CAqBlB"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@xylabs/telemetry",
3
- "version": "5.0.83",
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.83",
47
- "@xylabs/typeof": "~5.0.83"
46
+ "@xylabs/logger": "~5.0.86",
47
+ "@xylabs/typeof": "~5.0.86"
48
48
  },
49
49
  "devDependencies": {
50
- "@xylabs/ts-scripts-yarn3": "~7.4.11",
51
- "@xylabs/tsconfig": "~7.4.11",
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
  },