@atrim/instrument-node 0.1.0-7603d70-20251119002755

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.
@@ -0,0 +1,656 @@
1
+ import { Effect } from 'effect';
2
+ import { NodeSDKConfiguration, NodeSDK } from '@opentelemetry/sdk-node';
3
+ import { Instrumentation } from '@opentelemetry/instrumentation';
4
+ import { RequestOptions, IncomingMessage } from 'node:http';
5
+ import { OTLPTraceExporter } from '@opentelemetry/exporter-trace-otlp-http';
6
+ import { InstrumentationConfig, PatternMatcher } from '@atrim/instrument-core';
7
+ export { InstrumentationConfig, PatternConfig, PatternMatcher, getPatternMatcher, shouldInstrumentSpan } from '@atrim/instrument-core';
8
+ import * as effect_Cause from 'effect/Cause';
9
+ import * as effect_Types from 'effect/Types';
10
+ import { SpanProcessor, Span, ReadableSpan } from '@opentelemetry/sdk-trace-base';
11
+ import { Context, Span as Span$1 } from '@opentelemetry/api';
12
+
13
+ /**
14
+ * OTLP Exporter Factory
15
+ *
16
+ * Creates and configures OTLP trace exporters with smart defaults
17
+ */
18
+
19
+ interface OtlpExporterOptions {
20
+ /**
21
+ * OTLP endpoint URL
22
+ * Defaults to OTEL_EXPORTER_OTLP_ENDPOINT or http://localhost:4318/v1/traces
23
+ */
24
+ endpoint?: string;
25
+ /**
26
+ * Custom headers to send with requests
27
+ * Useful for authentication, custom routing, etc.
28
+ */
29
+ headers?: Record<string, string>;
30
+ }
31
+ /**
32
+ * Create an OTLP trace exporter with smart defaults
33
+ *
34
+ * Priority for endpoint:
35
+ * 1. Explicit endpoint option
36
+ * 2. OTEL_EXPORTER_OTLP_TRACES_ENDPOINT environment variable
37
+ * 3. OTEL_EXPORTER_OTLP_ENDPOINT environment variable
38
+ * 4. Default: http://localhost:4318/v1/traces
39
+ */
40
+ declare function createOtlpExporter(options?: OtlpExporterOptions): OTLPTraceExporter;
41
+ /**
42
+ * Get the OTLP endpoint that would be used with current configuration
43
+ *
44
+ * Useful for debugging and logging
45
+ */
46
+ declare function getOtlpEndpoint(options?: OtlpExporterOptions): string;
47
+
48
+ /**
49
+ * Node.js configuration loader using Effect Platform
50
+ *
51
+ * Provides FileSystem and HttpClient layers for the core ConfigLoader service
52
+ */
53
+
54
+ /**
55
+ * Reset the cached loader (for testing purposes)
56
+ * @internal
57
+ */
58
+ declare function _resetConfigLoaderCache(): void;
59
+ /**
60
+ * Load configuration from URI (Promise-based convenience API)
61
+ *
62
+ * Automatically provides Node.js platform layers (FileSystem + HttpClient)
63
+ *
64
+ * @param uri - Configuration URI (file://, http://, https://, or relative path)
65
+ * @param options - Optional loading options (e.g., to disable caching)
66
+ * @returns Promise that resolves to validated configuration
67
+ */
68
+ declare function loadConfig(uri: string, options?: {
69
+ cacheTimeout?: number;
70
+ }): Promise<InstrumentationConfig>;
71
+ /**
72
+ * Load configuration from inline content (Promise-based convenience API)
73
+ *
74
+ * @param content - YAML string, JSON string, or plain object
75
+ * @returns Promise that resolves to validated configuration
76
+ */
77
+ declare function loadConfigFromInline(content: string | unknown): Promise<InstrumentationConfig>;
78
+ /**
79
+ * Legacy options interface for backward compatibility
80
+ */
81
+ interface ConfigLoaderOptions {
82
+ configPath?: string;
83
+ configUrl?: string;
84
+ config?: InstrumentationConfig;
85
+ cacheTimeout?: number;
86
+ }
87
+ /**
88
+ * Load configuration with priority order (backward compatible API)
89
+ *
90
+ * Priority order (highest to lowest):
91
+ * 1. Explicit config object (options.config)
92
+ * 2. Environment variable (ATRIM_INSTRUMENTATION_CONFIG)
93
+ * 3. Explicit path/URL (options.configPath or options.configUrl)
94
+ * 4. Project root file (./instrumentation.yaml)
95
+ * 5. Default config (built-in defaults)
96
+ *
97
+ * @param options - Configuration options
98
+ * @returns Promise that resolves to validated configuration
99
+ */
100
+ declare function loadConfigWithOptions(options?: ConfigLoaderOptions): Promise<InstrumentationConfig>;
101
+
102
+ /**
103
+ * NodeSDK Initialization
104
+ *
105
+ * Provides comprehensive OpenTelemetry SDK initialization with smart defaults
106
+ */
107
+
108
+ interface SdkInitializationOptions extends ConfigLoaderOptions {
109
+ /**
110
+ * OTLP exporter configuration
111
+ */
112
+ otlp?: OtlpExporterOptions;
113
+ /**
114
+ * Service name
115
+ * If not provided, auto-detects from OTEL_SERVICE_NAME or package.json
116
+ */
117
+ serviceName?: string;
118
+ /**
119
+ * Service version
120
+ * If not provided, auto-detects from OTEL_SERVICE_VERSION or package.json
121
+ */
122
+ serviceVersion?: string;
123
+ /**
124
+ * Enable auto-instrumentation
125
+ * Default: auto-detected based on your runtime and framework
126
+ * - true: Enables Express, HTTP, and other common instrumentations
127
+ * - false: Disables all auto-instrumentation (manual spans only)
128
+ * - undefined: Smart detection (checks for Effect-TS usage)
129
+ */
130
+ autoInstrument?: boolean;
131
+ /**
132
+ * Custom instrumentations to add
133
+ * These are added in addition to auto-instrumentations (if enabled)
134
+ */
135
+ instrumentations?: Instrumentation[];
136
+ /**
137
+ * Advanced: Full NodeSDK configuration override
138
+ * Provides complete control over SDK initialization
139
+ */
140
+ sdk?: Partial<NodeSDKConfiguration>;
141
+ /**
142
+ * Disable automatic shutdown handler registration
143
+ * Default: false (automatic shutdown is enabled)
144
+ */
145
+ disableAutoShutdown?: boolean;
146
+ /**
147
+ * HTTP instrumentation filtering configuration
148
+ *
149
+ * Allows filtering of HTTP requests to prevent noisy traces
150
+ * (e.g., health checks, OTLP exports, internal endpoints)
151
+ *
152
+ * @example
153
+ * ```typescript
154
+ * // Pattern-based filtering
155
+ * http: {
156
+ * ignoreOutgoingUrls: [/\/health$/, /\/v1\/traces$/],
157
+ * ignoreIncomingPaths: [/^\/health$/]
158
+ * }
159
+ *
160
+ * // Custom hook for advanced filtering
161
+ * http: {
162
+ * ignoreOutgoingRequestHook: (req) => {
163
+ * const path = req.path || ''
164
+ * return path.includes('otel-collector')
165
+ * }
166
+ * }
167
+ * ```
168
+ */
169
+ http?: {
170
+ /**
171
+ * URL patterns to ignore for outgoing HTTP requests
172
+ * Can be strings or RegExp patterns
173
+ */
174
+ ignoreOutgoingUrls?: (string | RegExp)[];
175
+ /**
176
+ * Path patterns to ignore for incoming HTTP requests
177
+ * Can be strings or RegExp patterns
178
+ */
179
+ ignoreIncomingPaths?: (string | RegExp)[];
180
+ /**
181
+ * Custom hook for filtering outgoing HTTP requests
182
+ * Return true to ignore the request (no span created)
183
+ *
184
+ * Note: The request parameter is RequestOptions (from http.request()),
185
+ * not the ClientRequest object
186
+ */
187
+ ignoreOutgoingRequestHook?: (req: RequestOptions) => boolean;
188
+ /**
189
+ * Custom hook for filtering incoming HTTP requests
190
+ * Return true to ignore the request (no span created)
191
+ */
192
+ ignoreIncomingRequestHook?: (req: IncomingMessage) => boolean;
193
+ /**
194
+ * Require parent span for outgoing requests
195
+ * Prevents root spans for HTTP calls (useful for avoiding noise)
196
+ */
197
+ requireParentForOutgoingSpans?: boolean;
198
+ };
199
+ }
200
+ /**
201
+ * Get the current SDK instance
202
+ */
203
+ declare function getSdkInstance(): NodeSDK | null;
204
+ /**
205
+ * Shutdown the SDK
206
+ */
207
+ declare function shutdownSdk(): Promise<void>;
208
+ /**
209
+ * Reset SDK instance (useful for testing)
210
+ */
211
+ declare function resetSdk(): void;
212
+
213
+ /**
214
+ * Typed error hierarchy for @atrim/instrumentation
215
+ *
216
+ * These errors use Effect's Data.TaggedError for typed error handling
217
+ * with proper discriminated unions.
218
+ */
219
+ declare const ConfigError_base: new <A extends Record<string, any> = {}>(args: effect_Types.Equals<A, {}> extends true ? void : { readonly [P in keyof A as P extends "_tag" ? never : P]: A[P]; }) => effect_Cause.YieldableError & {
220
+ readonly _tag: "ConfigError";
221
+ } & Readonly<A>;
222
+ /**
223
+ * Base error for configuration-related failures
224
+ */
225
+ declare class ConfigError extends ConfigError_base<{
226
+ reason: string;
227
+ cause?: unknown;
228
+ }> {
229
+ }
230
+ declare const ConfigUrlError_base: new <A extends Record<string, any> = {}>(args: effect_Types.Equals<A, {}> extends true ? void : { readonly [P in keyof A as P extends "_tag" ? never : P]: A[P]; }) => effect_Cause.YieldableError & {
231
+ readonly _tag: "ConfigUrlError";
232
+ } & Readonly<A>;
233
+ /**
234
+ * Error when fetching configuration from a URL fails
235
+ */
236
+ declare class ConfigUrlError extends ConfigUrlError_base<{
237
+ reason: string;
238
+ cause?: unknown;
239
+ }> {
240
+ }
241
+ declare const ConfigValidationError_base: new <A extends Record<string, any> = {}>(args: effect_Types.Equals<A, {}> extends true ? void : { readonly [P in keyof A as P extends "_tag" ? never : P]: A[P]; }) => effect_Cause.YieldableError & {
242
+ readonly _tag: "ConfigValidationError";
243
+ } & Readonly<A>;
244
+ /**
245
+ * Error when configuration validation fails (invalid YAML, schema mismatch)
246
+ */
247
+ declare class ConfigValidationError extends ConfigValidationError_base<{
248
+ reason: string;
249
+ cause?: unknown;
250
+ }> {
251
+ }
252
+ declare const ConfigFileError_base: new <A extends Record<string, any> = {}>(args: effect_Types.Equals<A, {}> extends true ? void : { readonly [P in keyof A as P extends "_tag" ? never : P]: A[P]; }) => effect_Cause.YieldableError & {
253
+ readonly _tag: "ConfigFileError";
254
+ } & Readonly<A>;
255
+ /**
256
+ * Error when reading configuration from a file fails
257
+ */
258
+ declare class ConfigFileError extends ConfigFileError_base<{
259
+ reason: string;
260
+ cause?: unknown;
261
+ }> {
262
+ }
263
+ declare const ServiceDetectionError_base: new <A extends Record<string, any> = {}>(args: effect_Types.Equals<A, {}> extends true ? void : { readonly [P in keyof A as P extends "_tag" ? never : P]: A[P]; }) => effect_Cause.YieldableError & {
264
+ readonly _tag: "ServiceDetectionError";
265
+ } & Readonly<A>;
266
+ /**
267
+ * Error when service detection fails (package.json not found, invalid format)
268
+ */
269
+ declare class ServiceDetectionError extends ServiceDetectionError_base<{
270
+ reason: string;
271
+ cause?: unknown;
272
+ }> {
273
+ }
274
+ declare const InitializationError_base: new <A extends Record<string, any> = {}>(args: effect_Types.Equals<A, {}> extends true ? void : { readonly [P in keyof A as P extends "_tag" ? never : P]: A[P]; }) => effect_Cause.YieldableError & {
275
+ readonly _tag: "InitializationError";
276
+ } & Readonly<A>;
277
+ /**
278
+ * Error when OpenTelemetry SDK initialization fails
279
+ */
280
+ declare class InitializationError extends InitializationError_base<{
281
+ reason: string;
282
+ cause?: unknown;
283
+ }> {
284
+ }
285
+ declare const ExportError_base: new <A extends Record<string, any> = {}>(args: effect_Types.Equals<A, {}> extends true ? void : { readonly [P in keyof A as P extends "_tag" ? never : P]: A[P]; }) => effect_Cause.YieldableError & {
286
+ readonly _tag: "ExportError";
287
+ } & Readonly<A>;
288
+ /**
289
+ * Error when span export fails (e.g., ECONNREFUSED to collector)
290
+ */
291
+ declare class ExportError extends ExportError_base<{
292
+ reason: string;
293
+ cause?: unknown;
294
+ }> {
295
+ }
296
+ declare const ShutdownError_base: new <A extends Record<string, any> = {}>(args: effect_Types.Equals<A, {}> extends true ? void : { readonly [P in keyof A as P extends "_tag" ? never : P]: A[P]; }) => effect_Cause.YieldableError & {
297
+ readonly _tag: "ShutdownError";
298
+ } & Readonly<A>;
299
+ /**
300
+ * Error when shutting down the SDK fails
301
+ */
302
+ declare class ShutdownError extends ShutdownError_base<{
303
+ reason: string;
304
+ cause?: unknown;
305
+ }> {
306
+ }
307
+
308
+ /**
309
+ * Public API for standard OpenTelemetry usage
310
+ *
311
+ * This module provides the main entry point for complete OpenTelemetry
312
+ * initialization including NodeSDK, OTLP export, and pattern-based filtering.
313
+ *
314
+ * Available in two flavors:
315
+ * - Effect API (primary): For typed error handling and composability
316
+ * - Promise API (backward compatible): For traditional async/await usage
317
+ */
318
+
319
+ /**
320
+ * Initialize OpenTelemetry instrumentation with complete SDK setup
321
+ *
322
+ * This function provides a single-line initialization for OpenTelemetry:
323
+ * - Loads instrumentation.yaml configuration
324
+ * - Creates and configures OTLP exporter
325
+ * - Sets up pattern-based span filtering
326
+ * - Initializes NodeSDK with auto-instrumentations
327
+ * - Registers graceful shutdown handlers
328
+ *
329
+ * Configuration priority (highest to lowest):
330
+ * 1. Explicit config object (options.config)
331
+ * 2. Environment variable (ATRIM_INSTRUMENTATION_CONFIG)
332
+ * 3. Explicit path/URL (options.configPath or options.configUrl)
333
+ * 4. Project root file (./instrumentation.yaml)
334
+ * 5. Default config (built-in defaults)
335
+ *
336
+ * OTLP endpoint priority:
337
+ * 1. options.otlp.endpoint
338
+ * 2. OTEL_EXPORTER_OTLP_TRACES_ENDPOINT environment variable
339
+ * 3. OTEL_EXPORTER_OTLP_ENDPOINT environment variable
340
+ * 4. Default: http://localhost:4318/v1/traces
341
+ *
342
+ * Service name priority:
343
+ * 1. options.serviceName
344
+ * 2. OTEL_SERVICE_NAME environment variable
345
+ * 3. package.json name field
346
+ * 4. Default: 'unknown-service'
347
+ *
348
+ * @param options - Initialization options
349
+ * @returns The initialized NodeSDK instance
350
+ *
351
+ * @example
352
+ * ```typescript
353
+ * // Zero-config initialization (recommended)
354
+ * await initializeInstrumentation()
355
+ * // Auto-detects everything from env vars and package.json
356
+ *
357
+ * // With custom OTLP endpoint
358
+ * await initializeInstrumentation({
359
+ * otlp: {
360
+ * endpoint: 'https://otel-collector.company.com:4318'
361
+ * }
362
+ * })
363
+ *
364
+ * // With custom service name
365
+ * await initializeInstrumentation({
366
+ * serviceName: 'my-api-service',
367
+ * serviceVersion: '2.0.0'
368
+ * })
369
+ *
370
+ * // Disable auto-instrumentation (manual spans only)
371
+ * await initializeInstrumentation({
372
+ * autoInstrument: false
373
+ * })
374
+ *
375
+ * // With custom config file
376
+ * await initializeInstrumentation({
377
+ * configPath: './config/custom-instrumentation.yaml'
378
+ * })
379
+ *
380
+ * // With remote config URL
381
+ * await initializeInstrumentation({
382
+ * configUrl: 'https://config.company.com/instrumentation.yaml',
383
+ * cacheTimeout: 300_000 // 5 minutes
384
+ * })
385
+ *
386
+ * // Advanced: Full control
387
+ * await initializeInstrumentation({
388
+ * otlp: {
389
+ * endpoint: process.env.CUSTOM_ENDPOINT,
390
+ * headers: { 'x-api-key': 'secret' }
391
+ * },
392
+ * serviceName: 'my-service',
393
+ * autoInstrument: true,
394
+ * instrumentations: [], // custom instrumentations
395
+ * sdk: {
396
+ * // Additional NodeSDK configuration
397
+ * }
398
+ * })
399
+ * ```
400
+ */
401
+ declare function initializeInstrumentation(options?: SdkInitializationOptions): Promise<NodeSDK | null>;
402
+ /**
403
+ * Legacy initialization function for pattern-only mode
404
+ *
405
+ * This function only initializes pattern matching without setting up the NodeSDK.
406
+ * Use this if you want to manually configure OpenTelemetry while still using
407
+ * pattern-based filtering.
408
+ *
409
+ * @deprecated Use initializeInstrumentation() instead for complete setup
410
+ */
411
+ declare function initializePatternMatchingOnly(options?: SdkInitializationOptions): Promise<void>;
412
+ /**
413
+ * Initialize OpenTelemetry instrumentation (Effect version)
414
+ *
415
+ * Provides typed error handling and composability with Effect ecosystem.
416
+ * All errors are returned in the error channel, not thrown.
417
+ *
418
+ * @param options - Initialization options
419
+ * @returns Effect that yields the initialized NodeSDK or null
420
+ *
421
+ * @example
422
+ * ```typescript
423
+ * import { Effect } from 'effect'
424
+ * import { initializeInstrumentationEffect } from '@atrim/instrumentation'
425
+ *
426
+ * // Basic usage
427
+ * const program = initializeInstrumentationEffect()
428
+ *
429
+ * await Effect.runPromise(program)
430
+ *
431
+ * // With error handling
432
+ * const program = initializeInstrumentationEffect().pipe(
433
+ * Effect.catchTag('ConfigError', (error) => {
434
+ * console.error('Config error:', error.reason)
435
+ * return Effect.succeed(null)
436
+ * }),
437
+ * Effect.catchTag('InitializationError', (error) => {
438
+ * console.error('Init error:', error.reason)
439
+ * return Effect.succeed(null)
440
+ * })
441
+ * )
442
+ *
443
+ * await Effect.runPromise(program)
444
+ *
445
+ * // With custom options
446
+ * const program = initializeInstrumentationEffect({
447
+ * otlp: { endpoint: 'https://otel.company.com:4318' },
448
+ * serviceName: 'my-service'
449
+ * })
450
+ * ```
451
+ */
452
+ declare const initializeInstrumentationEffect: (options?: SdkInitializationOptions) => Effect.Effect<NodeSDK | null, InitializationError | ConfigError>;
453
+ /**
454
+ * Initialize pattern matching only (Effect version)
455
+ *
456
+ * Use this if you want manual OpenTelemetry setup with pattern filtering.
457
+ *
458
+ * @param options - Configuration options
459
+ * @returns Effect that yields void
460
+ *
461
+ * @example
462
+ * ```typescript
463
+ * import { Effect } from 'effect'
464
+ * import { initializePatternMatchingOnlyEffect } from '@atrim/instrumentation'
465
+ *
466
+ * const program = initializePatternMatchingOnlyEffect({
467
+ * configPath: './instrumentation.yaml'
468
+ * }).pipe(
469
+ * Effect.catchAll((error) => {
470
+ * console.error('Pattern matching setup failed:', error.reason)
471
+ * return Effect.succeed(undefined)
472
+ * })
473
+ * )
474
+ *
475
+ * await Effect.runPromise(program)
476
+ * ```
477
+ */
478
+ declare const initializePatternMatchingOnlyEffect: (options?: SdkInitializationOptions) => Effect.Effect<void, ConfigError>;
479
+
480
+ /**
481
+ * Service Detection Utilities
482
+ *
483
+ * Auto-detects service name and version from environment variables and package.json
484
+ * Uses Effect for typed error handling and composability
485
+ */
486
+
487
+ interface ServiceInfo {
488
+ name: string;
489
+ version?: string | undefined;
490
+ }
491
+ /**
492
+ * Detect service name and version (Effect version)
493
+ *
494
+ * Priority order:
495
+ * 1. OTEL_SERVICE_NAME environment variable
496
+ * 2. package.json name field
497
+ * 3. Fallback to 'unknown-service'
498
+ *
499
+ * Version:
500
+ * 1. OTEL_SERVICE_VERSION environment variable
501
+ * 2. package.json version field
502
+ * 3. undefined (not set)
503
+ *
504
+ * @returns Effect that yields ServiceInfo or ServiceDetectionError
505
+ */
506
+ declare const detectServiceInfo: Effect.Effect<ServiceInfo, ServiceDetectionError>;
507
+ /**
508
+ * Get service name with fallback (Effect version)
509
+ *
510
+ * Never fails - returns 'unknown-service' if detection fails
511
+ */
512
+ declare const getServiceName: Effect.Effect<string, never>;
513
+ /**
514
+ * Get service version with fallback (Effect version)
515
+ *
516
+ * Never fails - returns undefined if detection fails
517
+ */
518
+ declare const getServiceVersion: Effect.Effect<string | undefined, never>;
519
+ /**
520
+ * Get service info with fallback (Effect version)
521
+ *
522
+ * Never fails - returns default ServiceInfo if detection fails
523
+ */
524
+ declare const getServiceInfoWithFallback: Effect.Effect<ServiceInfo, never>;
525
+ /**
526
+ * Detect service name and version (Promise version)
527
+ *
528
+ * @deprecated Use `detectServiceInfo` Effect API for better error handling
529
+ * @returns Promise that resolves to ServiceInfo with fallback
530
+ */
531
+ declare function detectServiceInfoAsync(): Promise<ServiceInfo>;
532
+ /**
533
+ * Get service name with fallback (Promise version)
534
+ *
535
+ * @deprecated Use `getServiceName` Effect API
536
+ */
537
+ declare function getServiceNameAsync(): Promise<string>;
538
+ /**
539
+ * Get service version if available (Promise version)
540
+ *
541
+ * @deprecated Use `getServiceVersion` Effect API
542
+ */
543
+ declare function getServiceVersionAsync(): Promise<string | undefined>;
544
+
545
+ /**
546
+ * OpenTelemetry SpanProcessor for pattern-based filtering
547
+ *
548
+ * This processor filters spans based on configured patterns before they are exported.
549
+ * It wraps another processor (typically BatchSpanProcessor) and only forwards spans
550
+ * that match the instrumentation patterns.
551
+ */
552
+
553
+ /**
554
+ * SpanProcessor that filters spans based on pattern configuration
555
+ *
556
+ * This processor sits in the processing pipeline and decides whether a span
557
+ * should be forwarded to the next processor (for export) or dropped.
558
+ *
559
+ * Usage:
560
+ * ```typescript
561
+ * const exporter = new OTLPTraceExporter()
562
+ * const batchProcessor = new BatchSpanProcessor(exporter)
563
+ * const patternProcessor = new PatternSpanProcessor(config, batchProcessor)
564
+ *
565
+ * const sdk = new NodeSDK({
566
+ * spanProcessor: patternProcessor
567
+ * })
568
+ * ```
569
+ */
570
+ declare class PatternSpanProcessor implements SpanProcessor {
571
+ private matcher;
572
+ private wrappedProcessor;
573
+ constructor(config: InstrumentationConfig, wrappedProcessor: SpanProcessor);
574
+ /**
575
+ * Called when a span is started
576
+ *
577
+ * We check if the span should be instrumented here. If not, we can mark it
578
+ * to be dropped later in onEnd().
579
+ */
580
+ onStart(span: Span, parentContext: Context): void;
581
+ /**
582
+ * Called when a span is ended
583
+ *
584
+ * This is where we make the final decision on whether to export the span.
585
+ */
586
+ onEnd(span: ReadableSpan): void;
587
+ /**
588
+ * Shutdown the processor
589
+ */
590
+ shutdown(): Promise<void>;
591
+ /**
592
+ * Force flush any pending spans
593
+ */
594
+ forceFlush(): Promise<void>;
595
+ /**
596
+ * Get the pattern matcher (for debugging/testing)
597
+ */
598
+ getPatternMatcher(): PatternMatcher;
599
+ }
600
+
601
+ /**
602
+ * Standard OpenTelemetry span helpers (no Effect dependency)
603
+ *
604
+ * These helpers work with any OpenTelemetry span and don't require Effect-TS.
605
+ */
606
+
607
+ /**
608
+ * Set multiple attributes on a span at once
609
+ */
610
+ declare function setSpanAttributes(span: Span$1, attributes: Record<string, string | number | boolean>): void;
611
+ /**
612
+ * Record an exception on a span with optional context
613
+ */
614
+ declare function recordException(span: Span$1, error: Error, context?: Record<string, string | number | boolean>): void;
615
+ /**
616
+ * Mark a span as successful (OK status)
617
+ */
618
+ declare function markSpanSuccess(span: Span$1): void;
619
+ /**
620
+ * Mark a span as failed with an error message
621
+ */
622
+ declare function markSpanError(span: Span$1, message?: string): void;
623
+ /**
624
+ * Helper for HTTP request spans
625
+ */
626
+ declare function annotateHttpRequest(span: Span$1, method: string, url: string, statusCode?: number): void;
627
+ /**
628
+ * Helper for database query spans
629
+ */
630
+ declare function annotateDbQuery(span: Span$1, system: string, statement: string, table?: string): void;
631
+ /**
632
+ * Helper for cache operation spans
633
+ */
634
+ declare function annotateCacheOperation(span: Span$1, operation: 'get' | 'set' | 'delete' | 'clear', key: string, hit?: boolean): void;
635
+
636
+ /**
637
+ * Test utilities for handling shutdown errors during testing
638
+ */
639
+ /**
640
+ * Suppress ECONNREFUSED errors during shutdown in test environments
641
+ *
642
+ * This function installs error handlers that ignore connection refused errors
643
+ * when the OpenTelemetry SDK tries to export spans during shutdown. This is
644
+ * expected behavior when collectors are stopped before child processes finish.
645
+ *
646
+ * @example
647
+ * ```typescript
648
+ * import { suppressShutdownErrors } from '@atrim/instrumentation/test-utils'
649
+ *
650
+ * // Call at the start of your main function
651
+ * suppressShutdownErrors()
652
+ * ```
653
+ */
654
+ declare function suppressShutdownErrors(): void;
655
+
656
+ export { ConfigError, ConfigFileError, type ConfigLoaderOptions, ConfigUrlError, ConfigValidationError, ExportError, InitializationError, type OtlpExporterOptions, PatternSpanProcessor, type SdkInitializationOptions, ServiceDetectionError, type ServiceInfo, ShutdownError, annotateCacheOperation, annotateDbQuery, annotateHttpRequest, _resetConfigLoaderCache as clearConfigCache, createOtlpExporter, detectServiceInfoAsync as detectServiceInfo, detectServiceInfo as detectServiceInfoEffect, getOtlpEndpoint, getSdkInstance, getServiceInfoWithFallback, getServiceNameAsync as getServiceName, getServiceName as getServiceNameEffect, getServiceVersionAsync as getServiceVersion, getServiceVersion as getServiceVersionEffect, initializeInstrumentation, initializeInstrumentationEffect, initializePatternMatchingOnly, initializePatternMatchingOnlyEffect, loadConfig, loadConfigFromInline, loadConfigWithOptions, markSpanError, markSpanSuccess, recordException, resetSdk, setSpanAttributes, shutdownSdk, suppressShutdownErrors };