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