@atrim/instrument-node 0.5.0 → 0.5.1-1451fcf-20260105212505

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.
@@ -1,4 +1,4 @@
1
- import { Layer, FiberSet as FiberSet$1, Effect } from 'effect';
1
+ import { Layer, Tracer, Effect, FiberSet as FiberSet$1 } from 'effect';
2
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';
@@ -6,9 +6,10 @@ import * as effect_Scope from 'effect/Scope';
6
6
  import { RuntimeFiber } from 'effect/Fiber';
7
7
 
8
8
  /**
9
- * Node.js configuration loader using Effect Platform
9
+ * Node.js configuration loader
10
10
  *
11
- * Provides FileSystem and HttpClient layers for the core ConfigLoader service
11
+ * Provides configuration loading using native Node.js APIs (fs, fetch)
12
+ * This module doesn't require Effect Platform, making it work without Effect installed.
12
13
  */
13
14
 
14
15
  /**
@@ -46,17 +47,12 @@ interface ConfigLoaderOptions {
46
47
  */
47
48
  interface EffectInstrumentationOptions extends ConfigLoaderOptions {
48
49
  /**
49
- * OTLP endpoint URL
50
- * @default process.env.OTEL_EXPORTER_OTLP_ENDPOINT || 'http://localhost:4318'
51
- */
52
- otlpEndpoint?: string;
53
- /**
54
- * Service name
50
+ * Service name for Effect spans
55
51
  * @default process.env.OTEL_SERVICE_NAME || 'effect-service'
56
52
  */
57
53
  serviceName?: string;
58
54
  /**
59
- * Service version
55
+ * Service version for Effect spans
60
56
  * @default process.env.npm_package_version || '1.0.0'
61
57
  */
62
58
  serviceVersion?: string;
@@ -66,20 +62,17 @@ interface EffectInstrumentationOptions extends ConfigLoaderOptions {
66
62
  */
67
63
  autoExtractMetadata?: boolean;
68
64
  /**
69
- * Whether to continue existing traces from NodeSDK auto-instrumentation
70
- *
71
- * When true (default):
72
- * - Effect spans become children of existing NodeSDK spans
73
- * - Example: HTTP request span → Effect business logic span
74
- * - Uses OpenTelemetry Context API for propagation
75
- *
76
- * When false:
77
- * - Effect operations always create new root spans
78
- * - Not recommended unless you have specific requirements
79
- *
80
- * @default true
65
+ * OTLP endpoint URL (only used when exporter mode is 'standalone')
66
+ * @default process.env.OTEL_EXPORTER_OTLP_ENDPOINT || 'http://localhost:4318'
81
67
  */
82
- continueExistingTraces?: boolean;
68
+ otlpEndpoint?: string;
69
+ /**
70
+ * Exporter mode:
71
+ * - 'unified': Use global TracerProvider from Node SDK (recommended, enables filtering)
72
+ * - 'standalone': Use Effect's own OTLP exporter (bypasses Node SDK filtering)
73
+ * @default 'unified'
74
+ */
75
+ exporterMode?: 'unified' | 'standalone';
83
76
  }
84
77
  /**
85
78
  * Create Effect instrumentation layer with custom options
@@ -118,11 +111,12 @@ declare function createEffectInstrumentation(options?: EffectInstrumentationOpti
118
111
  *
119
112
  * Uses the global OpenTelemetry tracer provider that was set up by
120
113
  * initializeInstrumentation(). This ensures all traces (Express, Effect, etc.)
121
- * go to the same OTLP endpoint.
114
+ * go through the same TracerProvider and PatternSpanProcessor.
122
115
  *
123
116
  * Context Propagation:
124
117
  * - Automatically continues traces from NodeSDK auto-instrumentation
125
118
  * - Effect spans become children of HTTP request spans
119
+ * - Respects http.ignore_incoming_paths and other filtering patterns
126
120
  * - No configuration needed
127
121
  *
128
122
  * @example
@@ -138,27 +132,115 @@ declare function createEffectInstrumentation(options?: EffectInstrumentationOpti
138
132
  * )
139
133
  * ```
140
134
  */
141
- declare const EffectInstrumentationLive: Layer.Layer<never, never, never>;
135
+ declare const EffectInstrumentationLive: Layer.Layer<Tracer.Tracer, never, never>;
142
136
 
143
137
  /**
144
138
  * Effect-specific span annotation helpers
139
+ *
140
+ * Provides reusable helper functions for adding common span attributes.
141
+ * These helpers follow OpenTelemetry semantic conventions and platform patterns.
142
+ *
143
+ * Usage:
144
+ * ```typescript
145
+ * Effect.gen(function* () {
146
+ * yield* annotateUser(userId, email)
147
+ * yield* annotateBatch(items.length, 5)
148
+ * const results = yield* storage.writeBatch(items)
149
+ * yield* annotateBatch(items.length, 5, results.success, results.failures)
150
+ * }).pipe(Effect.withSpan('storage.writeBatch'))
151
+ * ```
145
152
  */
146
- declare function annotateUser(_userId: string, _email?: string): void;
147
- declare function annotateDataSize(_bytes: number, _count: number): void;
148
- declare function annotateBatch(_size: number, _batchSize: number): void;
149
- declare function annotateLLM(_model: string, _operation: string, _inputTokens: number, _outputTokens: number): void;
150
- declare function annotateQuery(_query: string, _database: string): void;
151
- declare function annotateHttpRequest(_method: string, _url: string, _statusCode: number): void;
152
- declare function annotateError(_error: Error, _context?: Record<string, string | number | boolean>): void;
153
- declare function annotatePriority(_priority: string): void;
154
- declare function annotateCache(_operation: string, _hit: boolean): void;
153
+
154
+ /**
155
+ * Annotate span with user context
156
+ *
157
+ * @param userId - User identifier
158
+ * @param email - Optional user email
159
+ * @param username - Optional username
160
+ */
161
+ declare function annotateUser(userId: string, email?: string, username?: string): Effect.Effect<void, never, never>;
162
+ /**
163
+ * Annotate span with data size metrics
164
+ *
165
+ * @param bytes - Total bytes processed
166
+ * @param items - Number of items
167
+ * @param compressionRatio - Optional compression ratio
168
+ */
169
+ declare function annotateDataSize(bytes: number, items: number, compressionRatio?: number): Effect.Effect<void, never, never>;
170
+ /**
171
+ * Annotate span with batch operation metadata
172
+ *
173
+ * @param totalItems - Total number of items in batch
174
+ * @param batchSize - Size of each batch
175
+ * @param successCount - Optional number of successful items
176
+ * @param failureCount - Optional number of failed items
177
+ */
178
+ declare function annotateBatch(totalItems: number, batchSize: number, successCount?: number, failureCount?: number): Effect.Effect<void, never, never>;
179
+ /**
180
+ * Annotate span with LLM operation metadata
181
+ *
182
+ * @param model - Model name (e.g., 'gpt-4', 'claude-3-opus')
183
+ * @param provider - LLM provider (e.g., 'openai', 'anthropic')
184
+ * @param tokens - Optional token usage information
185
+ */
186
+ declare function annotateLLM(model: string, provider: string, tokens?: {
187
+ prompt?: number;
188
+ completion?: number;
189
+ total?: number;
190
+ }): Effect.Effect<void, never, never>;
191
+ /**
192
+ * Annotate span with database query metadata
193
+ *
194
+ * @param query - SQL query or query description
195
+ * @param duration - Optional query duration in milliseconds
196
+ * @param rowCount - Optional number of rows returned/affected
197
+ * @param database - Optional database name
198
+ */
199
+ declare function annotateQuery(query: string, duration?: number, rowCount?: number, database?: string): Effect.Effect<void, never, never>;
200
+ /**
201
+ * Annotate span with HTTP request metadata
202
+ *
203
+ * @param method - HTTP method (GET, POST, etc.)
204
+ * @param url - Request URL
205
+ * @param statusCode - Optional HTTP status code
206
+ * @param contentLength - Optional response content length
207
+ */
208
+ declare function annotateHttpRequest(method: string, url: string, statusCode?: number, contentLength?: number): Effect.Effect<void, never, never>;
209
+ /**
210
+ * Annotate span with error context
211
+ *
212
+ * @param error - Error object or message
213
+ * @param recoverable - Whether the error is recoverable
214
+ * @param errorType - Optional error type/category
215
+ */
216
+ declare function annotateError(error: Error | string, recoverable: boolean, errorType?: string): Effect.Effect<void, never, never>;
217
+ /**
218
+ * Annotate span with operation priority
219
+ *
220
+ * @param priority - Priority level (high, medium, low)
221
+ * @param reason - Optional reason for priority level
222
+ */
223
+ declare function annotatePriority(priority: 'high' | 'medium' | 'low', reason?: string): Effect.Effect<void, never, never>;
224
+ /**
225
+ * Annotate span with cache operation metadata
226
+ *
227
+ * @param hit - Whether the cache was hit
228
+ * @param key - Cache key
229
+ * @param ttl - Optional time-to-live in seconds
230
+ */
231
+ declare function annotateCache(hit: boolean, key: string, ttl?: number): Effect.Effect<void, never, never>;
155
232
 
156
233
  /**
157
234
  * Effect metadata extraction
158
235
  *
159
236
  * Automatically extracts metadata from Effect fibers and adds them as span attributes.
160
237
  * This provides valuable context about the Effect execution environment.
238
+ *
239
+ * Uses Effect's public APIs:
240
+ * - Fiber.getCurrentFiber() - Get current fiber information
241
+ * - Effect.currentSpan - Detect parent spans and nesting
161
242
  */
243
+
162
244
  /**
163
245
  * Metadata extracted from Effect fibers
164
246
  */
@@ -166,8 +248,95 @@ interface EffectMetadata {
166
248
  'effect.fiber.id'?: string;
167
249
  'effect.fiber.status'?: string;
168
250
  'effect.operation.root'?: boolean;
169
- 'effect.operation.interrupted'?: boolean;
251
+ 'effect.operation.nested'?: boolean;
252
+ 'effect.parent.span.id'?: string;
253
+ 'effect.parent.span.name'?: string;
254
+ 'effect.parent.trace.id'?: string;
170
255
  }
256
+ /**
257
+ * Extract Effect-native metadata from current execution context
258
+ *
259
+ * Uses Effect's native APIs:
260
+ * - Fiber.getCurrentFiber() - Get current fiber information
261
+ * - Effect.currentSpan - Detect parent spans and nesting
262
+ *
263
+ * @returns Effect that yields extracted metadata
264
+ */
265
+ declare function extractEffectMetadata(): Effect.Effect<EffectMetadata>;
266
+
267
+ /**
268
+ * Effect Auto-Enrichment Utilities
269
+ *
270
+ * Provides utilities for automatically extracting and enriching spans with Effect-native metadata.
271
+ *
272
+ * Usage:
273
+ * ```typescript
274
+ * import { autoEnrichSpan, withAutoEnrichedSpan } from '@atrim/instrument-node/effect'
275
+ *
276
+ * // Option 1: Manual enrichment
277
+ * Effect.gen(function* () {
278
+ * yield* autoEnrichSpan() // Auto-add Effect metadata
279
+ * yield* annotateBatch(items.length, 10) // Add custom attributes
280
+ * const result = yield* storage.writeBatch(items)
281
+ * return result
282
+ * }).pipe(Effect.withSpan('storage.writeBatch'))
283
+ *
284
+ * // Option 2: Automatic enrichment wrapper
285
+ * const instrumented = withAutoEnrichedSpan('storage.writeBatch')(
286
+ * Effect.gen(function* () {
287
+ * yield* annotateBatch(items.length, 10)
288
+ * return yield* storage.writeBatch(items)
289
+ * })
290
+ * )
291
+ * ```
292
+ */
293
+
294
+ /**
295
+ * Auto-enrich the current span with Effect metadata
296
+ *
297
+ * This function should be called within an Effect.withSpan() context.
298
+ * It extracts Effect metadata (fiber ID, status, parent span info)
299
+ * and adds it as span attributes.
300
+ *
301
+ * Best practice: Call this at the start of your instrumented Effect:
302
+ *
303
+ * ```typescript
304
+ * Effect.gen(function* () {
305
+ * yield* autoEnrichSpan() // Auto-add metadata
306
+ * yield* annotateBatch(items.length, 10) // Add custom attributes
307
+ * const result = yield* storage.writeBatch(items)
308
+ * return result
309
+ * }).pipe(Effect.withSpan('storage.writeBatch'))
310
+ * ```
311
+ *
312
+ * @returns Effect that annotates the current span with Effect metadata
313
+ */
314
+ declare function autoEnrichSpan(): Effect.Effect<void>;
315
+ /**
316
+ * Create a wrapper that combines Effect.withSpan with automatic enrichment
317
+ *
318
+ * This is a convenience function that wraps an Effect with both:
319
+ * 1. A span (via Effect.withSpan)
320
+ * 2. Automatic metadata extraction (via autoEnrichSpan)
321
+ *
322
+ * Usage:
323
+ * ```typescript
324
+ * const instrumented = withAutoEnrichedSpan('storage.writeBatch')(
325
+ * Effect.gen(function* () {
326
+ * yield* annotateBatch(items.length, 10)
327
+ * return yield* storage.writeBatch(items)
328
+ * })
329
+ * )
330
+ * ```
331
+ *
332
+ * @param spanName - The name of the span
333
+ * @param options - Optional span options
334
+ * @returns Function that wraps an Effect with an auto-enriched span
335
+ */
336
+ declare function withAutoEnrichedSpan<A, E, R>(spanName: string, options?: {
337
+ readonly attributes?: Record<string, unknown>;
338
+ readonly kind?: 'client' | 'server' | 'producer' | 'consumer' | 'internal';
339
+ }): (self: Effect.Effect<A, E, R>) => Effect.Effect<A, E, R>;
171
340
 
172
341
  /**
173
342
  * Options for span isolation when running effects in FiberSet
@@ -356,4 +525,4 @@ declare const FiberSet: {
356
525
  }) => Effect.Effect<RuntimeFiber<A, E>, never, R>;
357
526
  };
358
527
 
359
- export { EffectInstrumentationLive, type EffectMetadata, FiberSet, type IsolationOptions, annotateBatch, annotateCache, annotateDataSize, annotateError, annotateHttpRequest, annotateLLM, annotatePriority, annotateQuery, annotateSpawnedTasks, annotateUser, createEffectInstrumentation, runIsolated, runWithSpan };
528
+ export { EffectInstrumentationLive, type EffectMetadata, FiberSet, type IsolationOptions, annotateBatch, annotateCache, annotateDataSize, annotateError, annotateHttpRequest, annotateLLM, annotatePriority, annotateQuery, annotateSpawnedTasks, annotateUser, autoEnrichSpan, createEffectInstrumentation, extractEffectMetadata, runIsolated, runWithSpan, withAutoEnrichedSpan };
@@ -1,4 +1,4 @@
1
- import { Layer, FiberSet as FiberSet$1, Effect } from 'effect';
1
+ import { Layer, Tracer, Effect, FiberSet as FiberSet$1 } from 'effect';
2
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';
@@ -6,9 +6,10 @@ import * as effect_Scope from 'effect/Scope';
6
6
  import { RuntimeFiber } from 'effect/Fiber';
7
7
 
8
8
  /**
9
- * Node.js configuration loader using Effect Platform
9
+ * Node.js configuration loader
10
10
  *
11
- * Provides FileSystem and HttpClient layers for the core ConfigLoader service
11
+ * Provides configuration loading using native Node.js APIs (fs, fetch)
12
+ * This module doesn't require Effect Platform, making it work without Effect installed.
12
13
  */
13
14
 
14
15
  /**
@@ -46,17 +47,12 @@ interface ConfigLoaderOptions {
46
47
  */
47
48
  interface EffectInstrumentationOptions extends ConfigLoaderOptions {
48
49
  /**
49
- * OTLP endpoint URL
50
- * @default process.env.OTEL_EXPORTER_OTLP_ENDPOINT || 'http://localhost:4318'
51
- */
52
- otlpEndpoint?: string;
53
- /**
54
- * Service name
50
+ * Service name for Effect spans
55
51
  * @default process.env.OTEL_SERVICE_NAME || 'effect-service'
56
52
  */
57
53
  serviceName?: string;
58
54
  /**
59
- * Service version
55
+ * Service version for Effect spans
60
56
  * @default process.env.npm_package_version || '1.0.0'
61
57
  */
62
58
  serviceVersion?: string;
@@ -66,20 +62,17 @@ interface EffectInstrumentationOptions extends ConfigLoaderOptions {
66
62
  */
67
63
  autoExtractMetadata?: boolean;
68
64
  /**
69
- * Whether to continue existing traces from NodeSDK auto-instrumentation
70
- *
71
- * When true (default):
72
- * - Effect spans become children of existing NodeSDK spans
73
- * - Example: HTTP request span → Effect business logic span
74
- * - Uses OpenTelemetry Context API for propagation
75
- *
76
- * When false:
77
- * - Effect operations always create new root spans
78
- * - Not recommended unless you have specific requirements
79
- *
80
- * @default true
65
+ * OTLP endpoint URL (only used when exporter mode is 'standalone')
66
+ * @default process.env.OTEL_EXPORTER_OTLP_ENDPOINT || 'http://localhost:4318'
81
67
  */
82
- continueExistingTraces?: boolean;
68
+ otlpEndpoint?: string;
69
+ /**
70
+ * Exporter mode:
71
+ * - 'unified': Use global TracerProvider from Node SDK (recommended, enables filtering)
72
+ * - 'standalone': Use Effect's own OTLP exporter (bypasses Node SDK filtering)
73
+ * @default 'unified'
74
+ */
75
+ exporterMode?: 'unified' | 'standalone';
83
76
  }
84
77
  /**
85
78
  * Create Effect instrumentation layer with custom options
@@ -118,11 +111,12 @@ declare function createEffectInstrumentation(options?: EffectInstrumentationOpti
118
111
  *
119
112
  * Uses the global OpenTelemetry tracer provider that was set up by
120
113
  * initializeInstrumentation(). This ensures all traces (Express, Effect, etc.)
121
- * go to the same OTLP endpoint.
114
+ * go through the same TracerProvider and PatternSpanProcessor.
122
115
  *
123
116
  * Context Propagation:
124
117
  * - Automatically continues traces from NodeSDK auto-instrumentation
125
118
  * - Effect spans become children of HTTP request spans
119
+ * - Respects http.ignore_incoming_paths and other filtering patterns
126
120
  * - No configuration needed
127
121
  *
128
122
  * @example
@@ -138,27 +132,115 @@ declare function createEffectInstrumentation(options?: EffectInstrumentationOpti
138
132
  * )
139
133
  * ```
140
134
  */
141
- declare const EffectInstrumentationLive: Layer.Layer<never, never, never>;
135
+ declare const EffectInstrumentationLive: Layer.Layer<Tracer.Tracer, never, never>;
142
136
 
143
137
  /**
144
138
  * Effect-specific span annotation helpers
139
+ *
140
+ * Provides reusable helper functions for adding common span attributes.
141
+ * These helpers follow OpenTelemetry semantic conventions and platform patterns.
142
+ *
143
+ * Usage:
144
+ * ```typescript
145
+ * Effect.gen(function* () {
146
+ * yield* annotateUser(userId, email)
147
+ * yield* annotateBatch(items.length, 5)
148
+ * const results = yield* storage.writeBatch(items)
149
+ * yield* annotateBatch(items.length, 5, results.success, results.failures)
150
+ * }).pipe(Effect.withSpan('storage.writeBatch'))
151
+ * ```
145
152
  */
146
- declare function annotateUser(_userId: string, _email?: string): void;
147
- declare function annotateDataSize(_bytes: number, _count: number): void;
148
- declare function annotateBatch(_size: number, _batchSize: number): void;
149
- declare function annotateLLM(_model: string, _operation: string, _inputTokens: number, _outputTokens: number): void;
150
- declare function annotateQuery(_query: string, _database: string): void;
151
- declare function annotateHttpRequest(_method: string, _url: string, _statusCode: number): void;
152
- declare function annotateError(_error: Error, _context?: Record<string, string | number | boolean>): void;
153
- declare function annotatePriority(_priority: string): void;
154
- declare function annotateCache(_operation: string, _hit: boolean): void;
153
+
154
+ /**
155
+ * Annotate span with user context
156
+ *
157
+ * @param userId - User identifier
158
+ * @param email - Optional user email
159
+ * @param username - Optional username
160
+ */
161
+ declare function annotateUser(userId: string, email?: string, username?: string): Effect.Effect<void, never, never>;
162
+ /**
163
+ * Annotate span with data size metrics
164
+ *
165
+ * @param bytes - Total bytes processed
166
+ * @param items - Number of items
167
+ * @param compressionRatio - Optional compression ratio
168
+ */
169
+ declare function annotateDataSize(bytes: number, items: number, compressionRatio?: number): Effect.Effect<void, never, never>;
170
+ /**
171
+ * Annotate span with batch operation metadata
172
+ *
173
+ * @param totalItems - Total number of items in batch
174
+ * @param batchSize - Size of each batch
175
+ * @param successCount - Optional number of successful items
176
+ * @param failureCount - Optional number of failed items
177
+ */
178
+ declare function annotateBatch(totalItems: number, batchSize: number, successCount?: number, failureCount?: number): Effect.Effect<void, never, never>;
179
+ /**
180
+ * Annotate span with LLM operation metadata
181
+ *
182
+ * @param model - Model name (e.g., 'gpt-4', 'claude-3-opus')
183
+ * @param provider - LLM provider (e.g., 'openai', 'anthropic')
184
+ * @param tokens - Optional token usage information
185
+ */
186
+ declare function annotateLLM(model: string, provider: string, tokens?: {
187
+ prompt?: number;
188
+ completion?: number;
189
+ total?: number;
190
+ }): Effect.Effect<void, never, never>;
191
+ /**
192
+ * Annotate span with database query metadata
193
+ *
194
+ * @param query - SQL query or query description
195
+ * @param duration - Optional query duration in milliseconds
196
+ * @param rowCount - Optional number of rows returned/affected
197
+ * @param database - Optional database name
198
+ */
199
+ declare function annotateQuery(query: string, duration?: number, rowCount?: number, database?: string): Effect.Effect<void, never, never>;
200
+ /**
201
+ * Annotate span with HTTP request metadata
202
+ *
203
+ * @param method - HTTP method (GET, POST, etc.)
204
+ * @param url - Request URL
205
+ * @param statusCode - Optional HTTP status code
206
+ * @param contentLength - Optional response content length
207
+ */
208
+ declare function annotateHttpRequest(method: string, url: string, statusCode?: number, contentLength?: number): Effect.Effect<void, never, never>;
209
+ /**
210
+ * Annotate span with error context
211
+ *
212
+ * @param error - Error object or message
213
+ * @param recoverable - Whether the error is recoverable
214
+ * @param errorType - Optional error type/category
215
+ */
216
+ declare function annotateError(error: Error | string, recoverable: boolean, errorType?: string): Effect.Effect<void, never, never>;
217
+ /**
218
+ * Annotate span with operation priority
219
+ *
220
+ * @param priority - Priority level (high, medium, low)
221
+ * @param reason - Optional reason for priority level
222
+ */
223
+ declare function annotatePriority(priority: 'high' | 'medium' | 'low', reason?: string): Effect.Effect<void, never, never>;
224
+ /**
225
+ * Annotate span with cache operation metadata
226
+ *
227
+ * @param hit - Whether the cache was hit
228
+ * @param key - Cache key
229
+ * @param ttl - Optional time-to-live in seconds
230
+ */
231
+ declare function annotateCache(hit: boolean, key: string, ttl?: number): Effect.Effect<void, never, never>;
155
232
 
156
233
  /**
157
234
  * Effect metadata extraction
158
235
  *
159
236
  * Automatically extracts metadata from Effect fibers and adds them as span attributes.
160
237
  * This provides valuable context about the Effect execution environment.
238
+ *
239
+ * Uses Effect's public APIs:
240
+ * - Fiber.getCurrentFiber() - Get current fiber information
241
+ * - Effect.currentSpan - Detect parent spans and nesting
161
242
  */
243
+
162
244
  /**
163
245
  * Metadata extracted from Effect fibers
164
246
  */
@@ -166,8 +248,95 @@ interface EffectMetadata {
166
248
  'effect.fiber.id'?: string;
167
249
  'effect.fiber.status'?: string;
168
250
  'effect.operation.root'?: boolean;
169
- 'effect.operation.interrupted'?: boolean;
251
+ 'effect.operation.nested'?: boolean;
252
+ 'effect.parent.span.id'?: string;
253
+ 'effect.parent.span.name'?: string;
254
+ 'effect.parent.trace.id'?: string;
170
255
  }
256
+ /**
257
+ * Extract Effect-native metadata from current execution context
258
+ *
259
+ * Uses Effect's native APIs:
260
+ * - Fiber.getCurrentFiber() - Get current fiber information
261
+ * - Effect.currentSpan - Detect parent spans and nesting
262
+ *
263
+ * @returns Effect that yields extracted metadata
264
+ */
265
+ declare function extractEffectMetadata(): Effect.Effect<EffectMetadata>;
266
+
267
+ /**
268
+ * Effect Auto-Enrichment Utilities
269
+ *
270
+ * Provides utilities for automatically extracting and enriching spans with Effect-native metadata.
271
+ *
272
+ * Usage:
273
+ * ```typescript
274
+ * import { autoEnrichSpan, withAutoEnrichedSpan } from '@atrim/instrument-node/effect'
275
+ *
276
+ * // Option 1: Manual enrichment
277
+ * Effect.gen(function* () {
278
+ * yield* autoEnrichSpan() // Auto-add Effect metadata
279
+ * yield* annotateBatch(items.length, 10) // Add custom attributes
280
+ * const result = yield* storage.writeBatch(items)
281
+ * return result
282
+ * }).pipe(Effect.withSpan('storage.writeBatch'))
283
+ *
284
+ * // Option 2: Automatic enrichment wrapper
285
+ * const instrumented = withAutoEnrichedSpan('storage.writeBatch')(
286
+ * Effect.gen(function* () {
287
+ * yield* annotateBatch(items.length, 10)
288
+ * return yield* storage.writeBatch(items)
289
+ * })
290
+ * )
291
+ * ```
292
+ */
293
+
294
+ /**
295
+ * Auto-enrich the current span with Effect metadata
296
+ *
297
+ * This function should be called within an Effect.withSpan() context.
298
+ * It extracts Effect metadata (fiber ID, status, parent span info)
299
+ * and adds it as span attributes.
300
+ *
301
+ * Best practice: Call this at the start of your instrumented Effect:
302
+ *
303
+ * ```typescript
304
+ * Effect.gen(function* () {
305
+ * yield* autoEnrichSpan() // Auto-add metadata
306
+ * yield* annotateBatch(items.length, 10) // Add custom attributes
307
+ * const result = yield* storage.writeBatch(items)
308
+ * return result
309
+ * }).pipe(Effect.withSpan('storage.writeBatch'))
310
+ * ```
311
+ *
312
+ * @returns Effect that annotates the current span with Effect metadata
313
+ */
314
+ declare function autoEnrichSpan(): Effect.Effect<void>;
315
+ /**
316
+ * Create a wrapper that combines Effect.withSpan with automatic enrichment
317
+ *
318
+ * This is a convenience function that wraps an Effect with both:
319
+ * 1. A span (via Effect.withSpan)
320
+ * 2. Automatic metadata extraction (via autoEnrichSpan)
321
+ *
322
+ * Usage:
323
+ * ```typescript
324
+ * const instrumented = withAutoEnrichedSpan('storage.writeBatch')(
325
+ * Effect.gen(function* () {
326
+ * yield* annotateBatch(items.length, 10)
327
+ * return yield* storage.writeBatch(items)
328
+ * })
329
+ * )
330
+ * ```
331
+ *
332
+ * @param spanName - The name of the span
333
+ * @param options - Optional span options
334
+ * @returns Function that wraps an Effect with an auto-enriched span
335
+ */
336
+ declare function withAutoEnrichedSpan<A, E, R>(spanName: string, options?: {
337
+ readonly attributes?: Record<string, unknown>;
338
+ readonly kind?: 'client' | 'server' | 'producer' | 'consumer' | 'internal';
339
+ }): (self: Effect.Effect<A, E, R>) => Effect.Effect<A, E, R>;
171
340
 
172
341
  /**
173
342
  * Options for span isolation when running effects in FiberSet
@@ -356,4 +525,4 @@ declare const FiberSet: {
356
525
  }) => Effect.Effect<RuntimeFiber<A, E>, never, R>;
357
526
  };
358
527
 
359
- export { EffectInstrumentationLive, type EffectMetadata, FiberSet, type IsolationOptions, annotateBatch, annotateCache, annotateDataSize, annotateError, annotateHttpRequest, annotateLLM, annotatePriority, annotateQuery, annotateSpawnedTasks, annotateUser, createEffectInstrumentation, runIsolated, runWithSpan };
528
+ export { EffectInstrumentationLive, type EffectMetadata, FiberSet, type IsolationOptions, annotateBatch, annotateCache, annotateDataSize, annotateError, annotateHttpRequest, annotateLLM, annotatePriority, annotateQuery, annotateSpawnedTasks, annotateUser, autoEnrichSpan, createEffectInstrumentation, extractEffectMetadata, runIsolated, runWithSpan, withAutoEnrichedSpan };