@atrim/instrument-node 0.4.0 → 0.5.0-3a3dd2c-20251124202015
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 +66 -0
- package/package.json +13 -7
- package/target/dist/index.cjs +310 -197
- package/target/dist/index.cjs.map +1 -1
- package/target/dist/index.d.cts +57 -3
- package/target/dist/index.d.ts +57 -3
- package/target/dist/index.js +288 -199
- package/target/dist/index.js.map +1 -1
- package/target/dist/integrations/effect/auto/index.cjs +276 -0
- package/target/dist/integrations/effect/auto/index.cjs.map +1 -0
- package/target/dist/integrations/effect/auto/index.d.cts +1513 -0
- package/target/dist/integrations/effect/auto/index.d.ts +1513 -0
- package/target/dist/integrations/effect/auto/index.js +264 -0
- package/target/dist/integrations/effect/auto/index.js.map +1 -0
- package/target/dist/integrations/effect/index.cjs +424 -206
- package/target/dist/integrations/effect/index.cjs.map +1 -1
- package/target/dist/integrations/effect/index.d.cts +204 -13
- package/target/dist/integrations/effect/index.d.ts +204 -13
- package/target/dist/integrations/effect/index.js +421 -208
- package/target/dist/integrations/effect/index.js.map +1 -1
|
@@ -1,10 +1,26 @@
|
|
|
1
|
-
import { Layer, FiberSet as FiberSet$1
|
|
2
|
-
import {
|
|
1
|
+
import { Layer, Effect, FiberSet as FiberSet$1 } from 'effect';
|
|
2
|
+
import { InstrumentationConfig } from '@atrim/instrument-core';
|
|
3
3
|
import * as effect_Runtime from 'effect/Runtime';
|
|
4
4
|
import * as effect_FiberId from 'effect/FiberId';
|
|
5
5
|
import * as effect_Scope from 'effect/Scope';
|
|
6
6
|
import { RuntimeFiber } from 'effect/Fiber';
|
|
7
7
|
|
|
8
|
+
/**
|
|
9
|
+
* Node.js configuration loader using Effect Platform
|
|
10
|
+
*
|
|
11
|
+
* Provides FileSystem and HttpClient layers for the core ConfigLoader service
|
|
12
|
+
*/
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Legacy options interface for backward compatibility
|
|
16
|
+
*/
|
|
17
|
+
interface ConfigLoaderOptions {
|
|
18
|
+
configPath?: string;
|
|
19
|
+
configUrl?: string;
|
|
20
|
+
config?: InstrumentationConfig;
|
|
21
|
+
cacheTimeout?: number;
|
|
22
|
+
}
|
|
23
|
+
|
|
8
24
|
/**
|
|
9
25
|
* Effect-TS Tracer integration with context propagation
|
|
10
26
|
*
|
|
@@ -126,23 +142,111 @@ declare const EffectInstrumentationLive: Layer.Layer<never, never, never>;
|
|
|
126
142
|
|
|
127
143
|
/**
|
|
128
144
|
* Effect-specific span annotation helpers
|
|
145
|
+
*
|
|
146
|
+
* Provides reusable helper functions for adding common span attributes.
|
|
147
|
+
* These helpers follow OpenTelemetry semantic conventions and platform patterns.
|
|
148
|
+
*
|
|
149
|
+
* Usage:
|
|
150
|
+
* ```typescript
|
|
151
|
+
* Effect.gen(function* () {
|
|
152
|
+
* yield* annotateUser(userId, email)
|
|
153
|
+
* yield* annotateBatch(items.length, 5)
|
|
154
|
+
* const results = yield* storage.writeBatch(items)
|
|
155
|
+
* yield* annotateBatch(items.length, 5, results.success, results.failures)
|
|
156
|
+
* }).pipe(Effect.withSpan('storage.writeBatch'))
|
|
157
|
+
* ```
|
|
158
|
+
*/
|
|
159
|
+
|
|
160
|
+
/**
|
|
161
|
+
* Annotate span with user context
|
|
162
|
+
*
|
|
163
|
+
* @param userId - User identifier
|
|
164
|
+
* @param email - Optional user email
|
|
165
|
+
* @param username - Optional username
|
|
166
|
+
*/
|
|
167
|
+
declare function annotateUser(userId: string, email?: string, username?: string): Effect.Effect<void, never, never>;
|
|
168
|
+
/**
|
|
169
|
+
* Annotate span with data size metrics
|
|
170
|
+
*
|
|
171
|
+
* @param bytes - Total bytes processed
|
|
172
|
+
* @param items - Number of items
|
|
173
|
+
* @param compressionRatio - Optional compression ratio
|
|
174
|
+
*/
|
|
175
|
+
declare function annotateDataSize(bytes: number, items: number, compressionRatio?: number): Effect.Effect<void, never, never>;
|
|
176
|
+
/**
|
|
177
|
+
* Annotate span with batch operation metadata
|
|
178
|
+
*
|
|
179
|
+
* @param totalItems - Total number of items in batch
|
|
180
|
+
* @param batchSize - Size of each batch
|
|
181
|
+
* @param successCount - Optional number of successful items
|
|
182
|
+
* @param failureCount - Optional number of failed items
|
|
183
|
+
*/
|
|
184
|
+
declare function annotateBatch(totalItems: number, batchSize: number, successCount?: number, failureCount?: number): Effect.Effect<void, never, never>;
|
|
185
|
+
/**
|
|
186
|
+
* Annotate span with LLM operation metadata
|
|
187
|
+
*
|
|
188
|
+
* @param model - Model name (e.g., 'gpt-4', 'claude-3-opus')
|
|
189
|
+
* @param provider - LLM provider (e.g., 'openai', 'anthropic')
|
|
190
|
+
* @param tokens - Optional token usage information
|
|
191
|
+
*/
|
|
192
|
+
declare function annotateLLM(model: string, provider: string, tokens?: {
|
|
193
|
+
prompt?: number;
|
|
194
|
+
completion?: number;
|
|
195
|
+
total?: number;
|
|
196
|
+
}): Effect.Effect<void, never, never>;
|
|
197
|
+
/**
|
|
198
|
+
* Annotate span with database query metadata
|
|
199
|
+
*
|
|
200
|
+
* @param query - SQL query or query description
|
|
201
|
+
* @param duration - Optional query duration in milliseconds
|
|
202
|
+
* @param rowCount - Optional number of rows returned/affected
|
|
203
|
+
* @param database - Optional database name
|
|
204
|
+
*/
|
|
205
|
+
declare function annotateQuery(query: string, duration?: number, rowCount?: number, database?: string): Effect.Effect<void, never, never>;
|
|
206
|
+
/**
|
|
207
|
+
* Annotate span with HTTP request metadata
|
|
208
|
+
*
|
|
209
|
+
* @param method - HTTP method (GET, POST, etc.)
|
|
210
|
+
* @param url - Request URL
|
|
211
|
+
* @param statusCode - Optional HTTP status code
|
|
212
|
+
* @param contentLength - Optional response content length
|
|
213
|
+
*/
|
|
214
|
+
declare function annotateHttpRequest(method: string, url: string, statusCode?: number, contentLength?: number): Effect.Effect<void, never, never>;
|
|
215
|
+
/**
|
|
216
|
+
* Annotate span with error context
|
|
217
|
+
*
|
|
218
|
+
* @param error - Error object or message
|
|
219
|
+
* @param recoverable - Whether the error is recoverable
|
|
220
|
+
* @param errorType - Optional error type/category
|
|
221
|
+
*/
|
|
222
|
+
declare function annotateError(error: Error | string, recoverable: boolean, errorType?: string): Effect.Effect<void, never, never>;
|
|
223
|
+
/**
|
|
224
|
+
* Annotate span with operation priority
|
|
225
|
+
*
|
|
226
|
+
* @param priority - Priority level (high, medium, low)
|
|
227
|
+
* @param reason - Optional reason for priority level
|
|
228
|
+
*/
|
|
229
|
+
declare function annotatePriority(priority: 'high' | 'medium' | 'low', reason?: string): Effect.Effect<void, never, never>;
|
|
230
|
+
/**
|
|
231
|
+
* Annotate span with cache operation metadata
|
|
232
|
+
*
|
|
233
|
+
* @param hit - Whether the cache was hit
|
|
234
|
+
* @param key - Cache key
|
|
235
|
+
* @param ttl - Optional time-to-live in seconds
|
|
129
236
|
*/
|
|
130
|
-
declare function
|
|
131
|
-
declare function annotateDataSize(_bytes: number, _count: number): void;
|
|
132
|
-
declare function annotateBatch(_size: number, _batchSize: number): void;
|
|
133
|
-
declare function annotateLLM(_model: string, _operation: string, _inputTokens: number, _outputTokens: number): void;
|
|
134
|
-
declare function annotateQuery(_query: string, _database: string): void;
|
|
135
|
-
declare function annotateHttpRequest(_method: string, _url: string, _statusCode: number): void;
|
|
136
|
-
declare function annotateError(_error: Error, _context?: Record<string, string | number | boolean>): void;
|
|
137
|
-
declare function annotatePriority(_priority: string): void;
|
|
138
|
-
declare function annotateCache(_operation: string, _hit: boolean): void;
|
|
237
|
+
declare function annotateCache(hit: boolean, key: string, ttl?: number): Effect.Effect<void, never, never>;
|
|
139
238
|
|
|
140
239
|
/**
|
|
141
240
|
* Effect metadata extraction
|
|
142
241
|
*
|
|
143
242
|
* Automatically extracts metadata from Effect fibers and adds them as span attributes.
|
|
144
243
|
* This provides valuable context about the Effect execution environment.
|
|
244
|
+
*
|
|
245
|
+
* Uses Effect's public APIs:
|
|
246
|
+
* - Fiber.getCurrentFiber() - Get current fiber information
|
|
247
|
+
* - Effect.currentSpan - Detect parent spans and nesting
|
|
145
248
|
*/
|
|
249
|
+
|
|
146
250
|
/**
|
|
147
251
|
* Metadata extracted from Effect fibers
|
|
148
252
|
*/
|
|
@@ -150,8 +254,95 @@ interface EffectMetadata {
|
|
|
150
254
|
'effect.fiber.id'?: string;
|
|
151
255
|
'effect.fiber.status'?: string;
|
|
152
256
|
'effect.operation.root'?: boolean;
|
|
153
|
-
'effect.operation.
|
|
257
|
+
'effect.operation.nested'?: boolean;
|
|
258
|
+
'effect.parent.span.id'?: string;
|
|
259
|
+
'effect.parent.span.name'?: string;
|
|
260
|
+
'effect.parent.trace.id'?: string;
|
|
154
261
|
}
|
|
262
|
+
/**
|
|
263
|
+
* Extract Effect-native metadata from current execution context
|
|
264
|
+
*
|
|
265
|
+
* Uses Effect's native APIs:
|
|
266
|
+
* - Fiber.getCurrentFiber() - Get current fiber information
|
|
267
|
+
* - Effect.currentSpan - Detect parent spans and nesting
|
|
268
|
+
*
|
|
269
|
+
* @returns Effect that yields extracted metadata
|
|
270
|
+
*/
|
|
271
|
+
declare function extractEffectMetadata(): Effect.Effect<EffectMetadata>;
|
|
272
|
+
|
|
273
|
+
/**
|
|
274
|
+
* Effect Auto-Enrichment Utilities
|
|
275
|
+
*
|
|
276
|
+
* Provides utilities for automatically extracting and enriching spans with Effect-native metadata.
|
|
277
|
+
*
|
|
278
|
+
* Usage:
|
|
279
|
+
* ```typescript
|
|
280
|
+
* import { autoEnrichSpan, withAutoEnrichedSpan } from '@atrim/instrument-node/effect'
|
|
281
|
+
*
|
|
282
|
+
* // Option 1: Manual enrichment
|
|
283
|
+
* Effect.gen(function* () {
|
|
284
|
+
* yield* autoEnrichSpan() // Auto-add Effect metadata
|
|
285
|
+
* yield* annotateBatch(items.length, 10) // Add custom attributes
|
|
286
|
+
* const result = yield* storage.writeBatch(items)
|
|
287
|
+
* return result
|
|
288
|
+
* }).pipe(Effect.withSpan('storage.writeBatch'))
|
|
289
|
+
*
|
|
290
|
+
* // Option 2: Automatic enrichment wrapper
|
|
291
|
+
* const instrumented = withAutoEnrichedSpan('storage.writeBatch')(
|
|
292
|
+
* Effect.gen(function* () {
|
|
293
|
+
* yield* annotateBatch(items.length, 10)
|
|
294
|
+
* return yield* storage.writeBatch(items)
|
|
295
|
+
* })
|
|
296
|
+
* )
|
|
297
|
+
* ```
|
|
298
|
+
*/
|
|
299
|
+
|
|
300
|
+
/**
|
|
301
|
+
* Auto-enrich the current span with Effect metadata
|
|
302
|
+
*
|
|
303
|
+
* This function should be called within an Effect.withSpan() context.
|
|
304
|
+
* It extracts Effect metadata (fiber ID, status, parent span info)
|
|
305
|
+
* and adds it as span attributes.
|
|
306
|
+
*
|
|
307
|
+
* Best practice: Call this at the start of your instrumented Effect:
|
|
308
|
+
*
|
|
309
|
+
* ```typescript
|
|
310
|
+
* Effect.gen(function* () {
|
|
311
|
+
* yield* autoEnrichSpan() // Auto-add metadata
|
|
312
|
+
* yield* annotateBatch(items.length, 10) // Add custom attributes
|
|
313
|
+
* const result = yield* storage.writeBatch(items)
|
|
314
|
+
* return result
|
|
315
|
+
* }).pipe(Effect.withSpan('storage.writeBatch'))
|
|
316
|
+
* ```
|
|
317
|
+
*
|
|
318
|
+
* @returns Effect that annotates the current span with Effect metadata
|
|
319
|
+
*/
|
|
320
|
+
declare function autoEnrichSpan(): Effect.Effect<void>;
|
|
321
|
+
/**
|
|
322
|
+
* Create a wrapper that combines Effect.withSpan with automatic enrichment
|
|
323
|
+
*
|
|
324
|
+
* This is a convenience function that wraps an Effect with both:
|
|
325
|
+
* 1. A span (via Effect.withSpan)
|
|
326
|
+
* 2. Automatic metadata extraction (via autoEnrichSpan)
|
|
327
|
+
*
|
|
328
|
+
* Usage:
|
|
329
|
+
* ```typescript
|
|
330
|
+
* const instrumented = withAutoEnrichedSpan('storage.writeBatch')(
|
|
331
|
+
* Effect.gen(function* () {
|
|
332
|
+
* yield* annotateBatch(items.length, 10)
|
|
333
|
+
* return yield* storage.writeBatch(items)
|
|
334
|
+
* })
|
|
335
|
+
* )
|
|
336
|
+
* ```
|
|
337
|
+
*
|
|
338
|
+
* @param spanName - The name of the span
|
|
339
|
+
* @param options - Optional span options
|
|
340
|
+
* @returns Function that wraps an Effect with an auto-enriched span
|
|
341
|
+
*/
|
|
342
|
+
declare function withAutoEnrichedSpan<A, E, R>(spanName: string, options?: {
|
|
343
|
+
readonly attributes?: Record<string, unknown>;
|
|
344
|
+
readonly kind?: 'client' | 'server' | 'producer' | 'consumer' | 'internal';
|
|
345
|
+
}): (self: Effect.Effect<A, E, R>) => Effect.Effect<A, E, R>;
|
|
155
346
|
|
|
156
347
|
/**
|
|
157
348
|
* Options for span isolation when running effects in FiberSet
|
|
@@ -340,4 +531,4 @@ declare const FiberSet: {
|
|
|
340
531
|
}) => Effect.Effect<RuntimeFiber<A, E>, never, R>;
|
|
341
532
|
};
|
|
342
533
|
|
|
343
|
-
export { EffectInstrumentationLive, type EffectMetadata, FiberSet, type IsolationOptions, annotateBatch, annotateCache, annotateDataSize, annotateError, annotateHttpRequest, annotateLLM, annotatePriority, annotateQuery, annotateSpawnedTasks, annotateUser, createEffectInstrumentation, runIsolated, runWithSpan };
|
|
534
|
+
export { EffectInstrumentationLive, type EffectMetadata, FiberSet, type IsolationOptions, annotateBatch, annotateCache, annotateDataSize, annotateError, annotateHttpRequest, annotateLLM, annotatePriority, annotateQuery, annotateSpawnedTasks, annotateUser, autoEnrichSpan, createEffectInstrumentation, extractEffectMetadata, runIsolated, runWithSpan, withAutoEnrichedSpan };
|
|
@@ -1,10 +1,26 @@
|
|
|
1
|
-
import { Layer, FiberSet as FiberSet$1
|
|
2
|
-
import {
|
|
1
|
+
import { Layer, Effect, FiberSet as FiberSet$1 } from 'effect';
|
|
2
|
+
import { InstrumentationConfig } from '@atrim/instrument-core';
|
|
3
3
|
import * as effect_Runtime from 'effect/Runtime';
|
|
4
4
|
import * as effect_FiberId from 'effect/FiberId';
|
|
5
5
|
import * as effect_Scope from 'effect/Scope';
|
|
6
6
|
import { RuntimeFiber } from 'effect/Fiber';
|
|
7
7
|
|
|
8
|
+
/**
|
|
9
|
+
* Node.js configuration loader using Effect Platform
|
|
10
|
+
*
|
|
11
|
+
* Provides FileSystem and HttpClient layers for the core ConfigLoader service
|
|
12
|
+
*/
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Legacy options interface for backward compatibility
|
|
16
|
+
*/
|
|
17
|
+
interface ConfigLoaderOptions {
|
|
18
|
+
configPath?: string;
|
|
19
|
+
configUrl?: string;
|
|
20
|
+
config?: InstrumentationConfig;
|
|
21
|
+
cacheTimeout?: number;
|
|
22
|
+
}
|
|
23
|
+
|
|
8
24
|
/**
|
|
9
25
|
* Effect-TS Tracer integration with context propagation
|
|
10
26
|
*
|
|
@@ -126,23 +142,111 @@ declare const EffectInstrumentationLive: Layer.Layer<never, never, never>;
|
|
|
126
142
|
|
|
127
143
|
/**
|
|
128
144
|
* Effect-specific span annotation helpers
|
|
145
|
+
*
|
|
146
|
+
* Provides reusable helper functions for adding common span attributes.
|
|
147
|
+
* These helpers follow OpenTelemetry semantic conventions and platform patterns.
|
|
148
|
+
*
|
|
149
|
+
* Usage:
|
|
150
|
+
* ```typescript
|
|
151
|
+
* Effect.gen(function* () {
|
|
152
|
+
* yield* annotateUser(userId, email)
|
|
153
|
+
* yield* annotateBatch(items.length, 5)
|
|
154
|
+
* const results = yield* storage.writeBatch(items)
|
|
155
|
+
* yield* annotateBatch(items.length, 5, results.success, results.failures)
|
|
156
|
+
* }).pipe(Effect.withSpan('storage.writeBatch'))
|
|
157
|
+
* ```
|
|
158
|
+
*/
|
|
159
|
+
|
|
160
|
+
/**
|
|
161
|
+
* Annotate span with user context
|
|
162
|
+
*
|
|
163
|
+
* @param userId - User identifier
|
|
164
|
+
* @param email - Optional user email
|
|
165
|
+
* @param username - Optional username
|
|
166
|
+
*/
|
|
167
|
+
declare function annotateUser(userId: string, email?: string, username?: string): Effect.Effect<void, never, never>;
|
|
168
|
+
/**
|
|
169
|
+
* Annotate span with data size metrics
|
|
170
|
+
*
|
|
171
|
+
* @param bytes - Total bytes processed
|
|
172
|
+
* @param items - Number of items
|
|
173
|
+
* @param compressionRatio - Optional compression ratio
|
|
174
|
+
*/
|
|
175
|
+
declare function annotateDataSize(bytes: number, items: number, compressionRatio?: number): Effect.Effect<void, never, never>;
|
|
176
|
+
/**
|
|
177
|
+
* Annotate span with batch operation metadata
|
|
178
|
+
*
|
|
179
|
+
* @param totalItems - Total number of items in batch
|
|
180
|
+
* @param batchSize - Size of each batch
|
|
181
|
+
* @param successCount - Optional number of successful items
|
|
182
|
+
* @param failureCount - Optional number of failed items
|
|
183
|
+
*/
|
|
184
|
+
declare function annotateBatch(totalItems: number, batchSize: number, successCount?: number, failureCount?: number): Effect.Effect<void, never, never>;
|
|
185
|
+
/**
|
|
186
|
+
* Annotate span with LLM operation metadata
|
|
187
|
+
*
|
|
188
|
+
* @param model - Model name (e.g., 'gpt-4', 'claude-3-opus')
|
|
189
|
+
* @param provider - LLM provider (e.g., 'openai', 'anthropic')
|
|
190
|
+
* @param tokens - Optional token usage information
|
|
191
|
+
*/
|
|
192
|
+
declare function annotateLLM(model: string, provider: string, tokens?: {
|
|
193
|
+
prompt?: number;
|
|
194
|
+
completion?: number;
|
|
195
|
+
total?: number;
|
|
196
|
+
}): Effect.Effect<void, never, never>;
|
|
197
|
+
/**
|
|
198
|
+
* Annotate span with database query metadata
|
|
199
|
+
*
|
|
200
|
+
* @param query - SQL query or query description
|
|
201
|
+
* @param duration - Optional query duration in milliseconds
|
|
202
|
+
* @param rowCount - Optional number of rows returned/affected
|
|
203
|
+
* @param database - Optional database name
|
|
204
|
+
*/
|
|
205
|
+
declare function annotateQuery(query: string, duration?: number, rowCount?: number, database?: string): Effect.Effect<void, never, never>;
|
|
206
|
+
/**
|
|
207
|
+
* Annotate span with HTTP request metadata
|
|
208
|
+
*
|
|
209
|
+
* @param method - HTTP method (GET, POST, etc.)
|
|
210
|
+
* @param url - Request URL
|
|
211
|
+
* @param statusCode - Optional HTTP status code
|
|
212
|
+
* @param contentLength - Optional response content length
|
|
213
|
+
*/
|
|
214
|
+
declare function annotateHttpRequest(method: string, url: string, statusCode?: number, contentLength?: number): Effect.Effect<void, never, never>;
|
|
215
|
+
/**
|
|
216
|
+
* Annotate span with error context
|
|
217
|
+
*
|
|
218
|
+
* @param error - Error object or message
|
|
219
|
+
* @param recoverable - Whether the error is recoverable
|
|
220
|
+
* @param errorType - Optional error type/category
|
|
221
|
+
*/
|
|
222
|
+
declare function annotateError(error: Error | string, recoverable: boolean, errorType?: string): Effect.Effect<void, never, never>;
|
|
223
|
+
/**
|
|
224
|
+
* Annotate span with operation priority
|
|
225
|
+
*
|
|
226
|
+
* @param priority - Priority level (high, medium, low)
|
|
227
|
+
* @param reason - Optional reason for priority level
|
|
228
|
+
*/
|
|
229
|
+
declare function annotatePriority(priority: 'high' | 'medium' | 'low', reason?: string): Effect.Effect<void, never, never>;
|
|
230
|
+
/**
|
|
231
|
+
* Annotate span with cache operation metadata
|
|
232
|
+
*
|
|
233
|
+
* @param hit - Whether the cache was hit
|
|
234
|
+
* @param key - Cache key
|
|
235
|
+
* @param ttl - Optional time-to-live in seconds
|
|
129
236
|
*/
|
|
130
|
-
declare function
|
|
131
|
-
declare function annotateDataSize(_bytes: number, _count: number): void;
|
|
132
|
-
declare function annotateBatch(_size: number, _batchSize: number): void;
|
|
133
|
-
declare function annotateLLM(_model: string, _operation: string, _inputTokens: number, _outputTokens: number): void;
|
|
134
|
-
declare function annotateQuery(_query: string, _database: string): void;
|
|
135
|
-
declare function annotateHttpRequest(_method: string, _url: string, _statusCode: number): void;
|
|
136
|
-
declare function annotateError(_error: Error, _context?: Record<string, string | number | boolean>): void;
|
|
137
|
-
declare function annotatePriority(_priority: string): void;
|
|
138
|
-
declare function annotateCache(_operation: string, _hit: boolean): void;
|
|
237
|
+
declare function annotateCache(hit: boolean, key: string, ttl?: number): Effect.Effect<void, never, never>;
|
|
139
238
|
|
|
140
239
|
/**
|
|
141
240
|
* Effect metadata extraction
|
|
142
241
|
*
|
|
143
242
|
* Automatically extracts metadata from Effect fibers and adds them as span attributes.
|
|
144
243
|
* This provides valuable context about the Effect execution environment.
|
|
244
|
+
*
|
|
245
|
+
* Uses Effect's public APIs:
|
|
246
|
+
* - Fiber.getCurrentFiber() - Get current fiber information
|
|
247
|
+
* - Effect.currentSpan - Detect parent spans and nesting
|
|
145
248
|
*/
|
|
249
|
+
|
|
146
250
|
/**
|
|
147
251
|
* Metadata extracted from Effect fibers
|
|
148
252
|
*/
|
|
@@ -150,8 +254,95 @@ interface EffectMetadata {
|
|
|
150
254
|
'effect.fiber.id'?: string;
|
|
151
255
|
'effect.fiber.status'?: string;
|
|
152
256
|
'effect.operation.root'?: boolean;
|
|
153
|
-
'effect.operation.
|
|
257
|
+
'effect.operation.nested'?: boolean;
|
|
258
|
+
'effect.parent.span.id'?: string;
|
|
259
|
+
'effect.parent.span.name'?: string;
|
|
260
|
+
'effect.parent.trace.id'?: string;
|
|
154
261
|
}
|
|
262
|
+
/**
|
|
263
|
+
* Extract Effect-native metadata from current execution context
|
|
264
|
+
*
|
|
265
|
+
* Uses Effect's native APIs:
|
|
266
|
+
* - Fiber.getCurrentFiber() - Get current fiber information
|
|
267
|
+
* - Effect.currentSpan - Detect parent spans and nesting
|
|
268
|
+
*
|
|
269
|
+
* @returns Effect that yields extracted metadata
|
|
270
|
+
*/
|
|
271
|
+
declare function extractEffectMetadata(): Effect.Effect<EffectMetadata>;
|
|
272
|
+
|
|
273
|
+
/**
|
|
274
|
+
* Effect Auto-Enrichment Utilities
|
|
275
|
+
*
|
|
276
|
+
* Provides utilities for automatically extracting and enriching spans with Effect-native metadata.
|
|
277
|
+
*
|
|
278
|
+
* Usage:
|
|
279
|
+
* ```typescript
|
|
280
|
+
* import { autoEnrichSpan, withAutoEnrichedSpan } from '@atrim/instrument-node/effect'
|
|
281
|
+
*
|
|
282
|
+
* // Option 1: Manual enrichment
|
|
283
|
+
* Effect.gen(function* () {
|
|
284
|
+
* yield* autoEnrichSpan() // Auto-add Effect metadata
|
|
285
|
+
* yield* annotateBatch(items.length, 10) // Add custom attributes
|
|
286
|
+
* const result = yield* storage.writeBatch(items)
|
|
287
|
+
* return result
|
|
288
|
+
* }).pipe(Effect.withSpan('storage.writeBatch'))
|
|
289
|
+
*
|
|
290
|
+
* // Option 2: Automatic enrichment wrapper
|
|
291
|
+
* const instrumented = withAutoEnrichedSpan('storage.writeBatch')(
|
|
292
|
+
* Effect.gen(function* () {
|
|
293
|
+
* yield* annotateBatch(items.length, 10)
|
|
294
|
+
* return yield* storage.writeBatch(items)
|
|
295
|
+
* })
|
|
296
|
+
* )
|
|
297
|
+
* ```
|
|
298
|
+
*/
|
|
299
|
+
|
|
300
|
+
/**
|
|
301
|
+
* Auto-enrich the current span with Effect metadata
|
|
302
|
+
*
|
|
303
|
+
* This function should be called within an Effect.withSpan() context.
|
|
304
|
+
* It extracts Effect metadata (fiber ID, status, parent span info)
|
|
305
|
+
* and adds it as span attributes.
|
|
306
|
+
*
|
|
307
|
+
* Best practice: Call this at the start of your instrumented Effect:
|
|
308
|
+
*
|
|
309
|
+
* ```typescript
|
|
310
|
+
* Effect.gen(function* () {
|
|
311
|
+
* yield* autoEnrichSpan() // Auto-add metadata
|
|
312
|
+
* yield* annotateBatch(items.length, 10) // Add custom attributes
|
|
313
|
+
* const result = yield* storage.writeBatch(items)
|
|
314
|
+
* return result
|
|
315
|
+
* }).pipe(Effect.withSpan('storage.writeBatch'))
|
|
316
|
+
* ```
|
|
317
|
+
*
|
|
318
|
+
* @returns Effect that annotates the current span with Effect metadata
|
|
319
|
+
*/
|
|
320
|
+
declare function autoEnrichSpan(): Effect.Effect<void>;
|
|
321
|
+
/**
|
|
322
|
+
* Create a wrapper that combines Effect.withSpan with automatic enrichment
|
|
323
|
+
*
|
|
324
|
+
* This is a convenience function that wraps an Effect with both:
|
|
325
|
+
* 1. A span (via Effect.withSpan)
|
|
326
|
+
* 2. Automatic metadata extraction (via autoEnrichSpan)
|
|
327
|
+
*
|
|
328
|
+
* Usage:
|
|
329
|
+
* ```typescript
|
|
330
|
+
* const instrumented = withAutoEnrichedSpan('storage.writeBatch')(
|
|
331
|
+
* Effect.gen(function* () {
|
|
332
|
+
* yield* annotateBatch(items.length, 10)
|
|
333
|
+
* return yield* storage.writeBatch(items)
|
|
334
|
+
* })
|
|
335
|
+
* )
|
|
336
|
+
* ```
|
|
337
|
+
*
|
|
338
|
+
* @param spanName - The name of the span
|
|
339
|
+
* @param options - Optional span options
|
|
340
|
+
* @returns Function that wraps an Effect with an auto-enriched span
|
|
341
|
+
*/
|
|
342
|
+
declare function withAutoEnrichedSpan<A, E, R>(spanName: string, options?: {
|
|
343
|
+
readonly attributes?: Record<string, unknown>;
|
|
344
|
+
readonly kind?: 'client' | 'server' | 'producer' | 'consumer' | 'internal';
|
|
345
|
+
}): (self: Effect.Effect<A, E, R>) => Effect.Effect<A, E, R>;
|
|
155
346
|
|
|
156
347
|
/**
|
|
157
348
|
* Options for span isolation when running effects in FiberSet
|
|
@@ -340,4 +531,4 @@ declare const FiberSet: {
|
|
|
340
531
|
}) => Effect.Effect<RuntimeFiber<A, E>, never, R>;
|
|
341
532
|
};
|
|
342
533
|
|
|
343
|
-
export { EffectInstrumentationLive, type EffectMetadata, FiberSet, type IsolationOptions, annotateBatch, annotateCache, annotateDataSize, annotateError, annotateHttpRequest, annotateLLM, annotatePriority, annotateQuery, annotateSpawnedTasks, annotateUser, createEffectInstrumentation, runIsolated, runWithSpan };
|
|
534
|
+
export { EffectInstrumentationLive, type EffectMetadata, FiberSet, type IsolationOptions, annotateBatch, annotateCache, annotateDataSize, annotateError, annotateHttpRequest, annotateLLM, annotatePriority, annotateQuery, annotateSpawnedTasks, annotateUser, autoEnrichSpan, createEffectInstrumentation, extractEffectMetadata, runIsolated, runWithSpan, withAutoEnrichedSpan };
|