@atrim/instrument-node 0.4.0 → 0.5.0-c05e3a1-20251119131235

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.
@@ -3,8 +3,8 @@ import { NodeSDKConfiguration, NodeSDK } from '@opentelemetry/sdk-node';
3
3
  import { Instrumentation } from '@opentelemetry/instrumentation';
4
4
  import { RequestOptions, IncomingMessage } from 'node:http';
5
5
  import { OTLPTraceExporter } from '@opentelemetry/exporter-trace-otlp-http';
6
- import { ConfigLoaderOptions, InstrumentationConfig, PatternMatcher } from '@atrim/instrument-core';
7
- export { ConfigLoaderOptions, InstrumentationConfig, PatternConfig, PatternMatcher, getPatternMatcher, loadConfig, shouldInstrumentSpan } from '@atrim/instrument-core';
6
+ import { InstrumentationConfig, PatternMatcher } from '@atrim/instrument-core';
7
+ export { InstrumentationConfig, PatternConfig, PatternMatcher, getPatternMatcher, shouldInstrumentSpan } from '@atrim/instrument-core';
8
8
  import * as effect_Cause from 'effect/Cause';
9
9
  import * as effect_Types from 'effect/Types';
10
10
  import { SpanProcessor, Span, ReadableSpan } from '@opentelemetry/sdk-trace-base';
@@ -45,6 +45,155 @@ declare function createOtlpExporter(options?: OtlpExporterOptions): OTLPTraceExp
45
45
  */
46
46
  declare function getOtlpEndpoint(options?: OtlpExporterOptions): string;
47
47
 
48
+ /**
49
+ * Typed error hierarchy for @atrim/instrumentation
50
+ *
51
+ * These errors use Effect's Data.TaggedError for typed error handling
52
+ * with proper discriminated unions.
53
+ */
54
+ 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 & {
55
+ readonly _tag: "ConfigError";
56
+ } & Readonly<A>;
57
+ /**
58
+ * Base error for configuration-related failures
59
+ */
60
+ declare class ConfigError extends ConfigError_base<{
61
+ reason: string;
62
+ cause?: unknown;
63
+ }> {
64
+ }
65
+ 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 & {
66
+ readonly _tag: "ConfigUrlError";
67
+ } & Readonly<A>;
68
+ /**
69
+ * Error when fetching configuration from a URL fails
70
+ */
71
+ declare class ConfigUrlError extends ConfigUrlError_base<{
72
+ reason: string;
73
+ cause?: unknown;
74
+ }> {
75
+ }
76
+ 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 & {
77
+ readonly _tag: "ConfigValidationError";
78
+ } & Readonly<A>;
79
+ /**
80
+ * Error when configuration validation fails (invalid YAML, schema mismatch)
81
+ */
82
+ declare class ConfigValidationError extends ConfigValidationError_base<{
83
+ reason: string;
84
+ cause?: unknown;
85
+ }> {
86
+ }
87
+ 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 & {
88
+ readonly _tag: "ConfigFileError";
89
+ } & Readonly<A>;
90
+ /**
91
+ * Error when reading configuration from a file fails
92
+ */
93
+ declare class ConfigFileError extends ConfigFileError_base<{
94
+ reason: string;
95
+ cause?: unknown;
96
+ }> {
97
+ }
98
+ 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 & {
99
+ readonly _tag: "ServiceDetectionError";
100
+ } & Readonly<A>;
101
+ /**
102
+ * Error when service detection fails (package.json not found, invalid format)
103
+ */
104
+ declare class ServiceDetectionError extends ServiceDetectionError_base<{
105
+ reason: string;
106
+ cause?: unknown;
107
+ }> {
108
+ }
109
+ 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 & {
110
+ readonly _tag: "InitializationError";
111
+ } & Readonly<A>;
112
+ /**
113
+ * Error when OpenTelemetry SDK initialization fails
114
+ */
115
+ declare class InitializationError extends InitializationError_base<{
116
+ reason: string;
117
+ cause?: unknown;
118
+ }> {
119
+ }
120
+ 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 & {
121
+ readonly _tag: "ExportError";
122
+ } & Readonly<A>;
123
+ /**
124
+ * Error when span export fails (e.g., ECONNREFUSED to collector)
125
+ */
126
+ declare class ExportError extends ExportError_base<{
127
+ reason: string;
128
+ cause?: unknown;
129
+ }> {
130
+ }
131
+ 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 & {
132
+ readonly _tag: "ShutdownError";
133
+ } & Readonly<A>;
134
+ /**
135
+ * Error when shutting down the SDK fails
136
+ */
137
+ declare class ShutdownError extends ShutdownError_base<{
138
+ reason: string;
139
+ cause?: unknown;
140
+ }> {
141
+ }
142
+
143
+ /**
144
+ * Node.js configuration loader using Effect Platform
145
+ *
146
+ * Provides FileSystem and HttpClient layers for the core ConfigLoader service
147
+ */
148
+
149
+ /**
150
+ * Reset the cached loader (for testing purposes)
151
+ * @internal
152
+ */
153
+ declare function _resetConfigLoaderCache(): void;
154
+ /**
155
+ * Load configuration from URI (Promise-based convenience API)
156
+ *
157
+ * Automatically provides Node.js platform layers (FileSystem + HttpClient)
158
+ *
159
+ * @param uri - Configuration URI (file://, http://, https://, or relative path)
160
+ * @param options - Optional loading options (e.g., to disable caching)
161
+ * @returns Promise that resolves to validated configuration
162
+ */
163
+ declare function loadConfig(uri: string, options?: {
164
+ cacheTimeout?: number;
165
+ }): Promise<InstrumentationConfig>;
166
+ /**
167
+ * Load configuration from inline content (Promise-based convenience API)
168
+ *
169
+ * @param content - YAML string, JSON string, or plain object
170
+ * @returns Promise that resolves to validated configuration
171
+ */
172
+ declare function loadConfigFromInline(content: string | unknown): Promise<InstrumentationConfig>;
173
+ /**
174
+ * Legacy options interface for backward compatibility
175
+ */
176
+ interface ConfigLoaderOptions {
177
+ configPath?: string;
178
+ configUrl?: string;
179
+ config?: InstrumentationConfig;
180
+ cacheTimeout?: number;
181
+ }
182
+ /**
183
+ * Load configuration with priority order (backward compatible API)
184
+ *
185
+ * Priority order (highest to lowest):
186
+ * 1. Explicit config object (options.config)
187
+ * 2. Environment variable (ATRIM_INSTRUMENTATION_CONFIG)
188
+ * 3. Explicit path/URL (options.configPath or options.configUrl)
189
+ * 4. Project root file (./instrumentation.yaml)
190
+ * 5. Default config (built-in defaults)
191
+ *
192
+ * @param options - Configuration options
193
+ * @returns Promise that resolves to validated configuration
194
+ */
195
+ declare function loadConfigWithOptions(options?: ConfigLoaderOptions): Promise<InstrumentationConfig>;
196
+
48
197
  /**
49
198
  * NodeSDK Initialization
50
199
  *
@@ -156,101 +305,6 @@ declare function shutdownSdk(): Promise<void>;
156
305
  */
157
306
  declare function resetSdk(): void;
158
307
 
159
- /**
160
- * Typed error hierarchy for @atrim/instrumentation
161
- *
162
- * These errors use Effect's Data.TaggedError for typed error handling
163
- * with proper discriminated unions.
164
- */
165
- 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 & {
166
- readonly _tag: "ConfigError";
167
- } & Readonly<A>;
168
- /**
169
- * Base error for configuration-related failures
170
- */
171
- declare class ConfigError extends ConfigError_base<{
172
- reason: string;
173
- cause?: unknown;
174
- }> {
175
- }
176
- 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 & {
177
- readonly _tag: "ConfigUrlError";
178
- } & Readonly<A>;
179
- /**
180
- * Error when fetching configuration from a URL fails
181
- */
182
- declare class ConfigUrlError extends ConfigUrlError_base<{
183
- reason: string;
184
- cause?: unknown;
185
- }> {
186
- }
187
- 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 & {
188
- readonly _tag: "ConfigValidationError";
189
- } & Readonly<A>;
190
- /**
191
- * Error when configuration validation fails (invalid YAML, schema mismatch)
192
- */
193
- declare class ConfigValidationError extends ConfigValidationError_base<{
194
- reason: string;
195
- cause?: unknown;
196
- }> {
197
- }
198
- 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 & {
199
- readonly _tag: "ConfigFileError";
200
- } & Readonly<A>;
201
- /**
202
- * Error when reading configuration from a file fails
203
- */
204
- declare class ConfigFileError extends ConfigFileError_base<{
205
- reason: string;
206
- cause?: unknown;
207
- }> {
208
- }
209
- 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 & {
210
- readonly _tag: "ServiceDetectionError";
211
- } & Readonly<A>;
212
- /**
213
- * Error when service detection fails (package.json not found, invalid format)
214
- */
215
- declare class ServiceDetectionError extends ServiceDetectionError_base<{
216
- reason: string;
217
- cause?: unknown;
218
- }> {
219
- }
220
- 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 & {
221
- readonly _tag: "InitializationError";
222
- } & Readonly<A>;
223
- /**
224
- * Error when OpenTelemetry SDK initialization fails
225
- */
226
- declare class InitializationError extends InitializationError_base<{
227
- reason: string;
228
- cause?: unknown;
229
- }> {
230
- }
231
- 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 & {
232
- readonly _tag: "ExportError";
233
- } & Readonly<A>;
234
- /**
235
- * Error when span export fails (e.g., ECONNREFUSED to collector)
236
- */
237
- declare class ExportError extends ExportError_base<{
238
- reason: string;
239
- cause?: unknown;
240
- }> {
241
- }
242
- 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 & {
243
- readonly _tag: "ShutdownError";
244
- } & Readonly<A>;
245
- /**
246
- * Error when shutting down the SDK fails
247
- */
248
- declare class ShutdownError extends ShutdownError_base<{
249
- reason: string;
250
- cause?: unknown;
251
- }> {
252
- }
253
-
254
308
  /**
255
309
  * Public API for standard OpenTelemetry usage
256
310
  *
@@ -344,17 +398,6 @@ declare class ShutdownError extends ShutdownError_base<{
344
398
  * })
345
399
  * ```
346
400
  */
347
- declare function initializeInstrumentation(options?: SdkInitializationOptions): Promise<NodeSDK | null>;
348
- /**
349
- * Legacy initialization function for pattern-only mode
350
- *
351
- * This function only initializes pattern matching without setting up the NodeSDK.
352
- * Use this if you want to manually configure OpenTelemetry while still using
353
- * pattern-based filtering.
354
- *
355
- * @deprecated Use initializeInstrumentation() instead for complete setup
356
- */
357
- declare function initializePatternMatchingOnly(options?: SdkInitializationOptions): Promise<void>;
358
401
  /**
359
402
  * Initialize OpenTelemetry instrumentation (Effect version)
360
403
  *
@@ -367,15 +410,14 @@ declare function initializePatternMatchingOnly(options?: SdkInitializationOption
367
410
  * @example
368
411
  * ```typescript
369
412
  * import { Effect } from 'effect'
370
- * import { initializeInstrumentationEffect } from '@atrim/instrumentation'
371
- *
372
- * // Basic usage
373
- * const program = initializeInstrumentationEffect()
413
+ * import { initializeInstrumentation } from '@atrim/instrumentation'
374
414
  *
415
+ * // Zero-config initialization (recommended)
416
+ * const program = initializeInstrumentation()
375
417
  * await Effect.runPromise(program)
376
418
  *
377
419
  * // With error handling
378
- * const program = initializeInstrumentationEffect().pipe(
420
+ * const program = initializeInstrumentation().pipe(
379
421
  * Effect.catchTag('ConfigError', (error) => {
380
422
  * console.error('Config error:', error.reason)
381
423
  * return Effect.succeed(null)
@@ -386,18 +428,16 @@ declare function initializePatternMatchingOnly(options?: SdkInitializationOption
386
428
  * })
387
429
  * )
388
430
  *
389
- * await Effect.runPromise(program)
390
- *
391
- * // With custom options
392
- * const program = initializeInstrumentationEffect({
431
+ * // With custom OTLP endpoint
432
+ * const program = initializeInstrumentation({
393
433
  * otlp: { endpoint: 'https://otel.company.com:4318' },
394
434
  * serviceName: 'my-service'
395
435
  * })
396
436
  * ```
397
437
  */
398
- declare const initializeInstrumentationEffect: (options?: SdkInitializationOptions) => Effect.Effect<NodeSDK | null, InitializationError | ConfigError>;
438
+ declare const initializeInstrumentation: (options?: SdkInitializationOptions) => Effect.Effect<NodeSDK | null, InitializationError | ConfigError>;
399
439
  /**
400
- * Initialize pattern matching only (Effect version)
440
+ * Initialize pattern matching only
401
441
  *
402
442
  * Use this if you want manual OpenTelemetry setup with pattern filtering.
403
443
  *
@@ -407,9 +447,9 @@ declare const initializeInstrumentationEffect: (options?: SdkInitializationOptio
407
447
  * @example
408
448
  * ```typescript
409
449
  * import { Effect } from 'effect'
410
- * import { initializePatternMatchingOnlyEffect } from '@atrim/instrumentation'
450
+ * import { initializePatternMatchingOnly } from '@atrim/instrumentation'
411
451
  *
412
- * const program = initializePatternMatchingOnlyEffect({
452
+ * const program = initializePatternMatchingOnly({
413
453
  * configPath: './instrumentation.yaml'
414
454
  * }).pipe(
415
455
  * Effect.catchAll((error) => {
@@ -421,7 +461,7 @@ declare const initializeInstrumentationEffect: (options?: SdkInitializationOptio
421
461
  * await Effect.runPromise(program)
422
462
  * ```
423
463
  */
424
- declare const initializePatternMatchingOnlyEffect: (options?: SdkInitializationOptions) => Effect.Effect<void, ConfigError>;
464
+ declare const initializePatternMatchingOnly: (options?: SdkInitializationOptions) => Effect.Effect<void, ConfigError>;
425
465
 
426
466
  /**
427
467
  * Service Detection Utilities
@@ -468,25 +508,6 @@ declare const getServiceVersion: Effect.Effect<string | undefined, never>;
468
508
  * Never fails - returns default ServiceInfo if detection fails
469
509
  */
470
510
  declare const getServiceInfoWithFallback: Effect.Effect<ServiceInfo, never>;
471
- /**
472
- * Detect service name and version (Promise version)
473
- *
474
- * @deprecated Use `detectServiceInfo` Effect API for better error handling
475
- * @returns Promise that resolves to ServiceInfo with fallback
476
- */
477
- declare function detectServiceInfoAsync(): Promise<ServiceInfo>;
478
- /**
479
- * Get service name with fallback (Promise version)
480
- *
481
- * @deprecated Use `getServiceName` Effect API
482
- */
483
- declare function getServiceNameAsync(): Promise<string>;
484
- /**
485
- * Get service version if available (Promise version)
486
- *
487
- * @deprecated Use `getServiceVersion` Effect API
488
- */
489
- declare function getServiceVersionAsync(): Promise<string | undefined>;
490
511
 
491
512
  /**
492
513
  * OpenTelemetry SpanProcessor for pattern-based filtering
@@ -599,4 +620,4 @@ declare function annotateCacheOperation(span: Span$1, operation: 'get' | 'set' |
599
620
  */
600
621
  declare function suppressShutdownErrors(): void;
601
622
 
602
- export { ConfigError, ConfigFileError, ConfigUrlError, ConfigValidationError, ExportError, InitializationError, type OtlpExporterOptions, PatternSpanProcessor, type SdkInitializationOptions, ServiceDetectionError, type ServiceInfo, ShutdownError, annotateCacheOperation, annotateDbQuery, annotateHttpRequest, 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, markSpanError, markSpanSuccess, recordException, resetSdk, setSpanAttributes, shutdownSdk, suppressShutdownErrors };
623
+ 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, detectServiceInfo, getOtlpEndpoint, getSdkInstance, getServiceInfoWithFallback, getServiceName, getServiceVersion, initializeInstrumentation, initializePatternMatchingOnly, loadConfig, loadConfigFromInline, loadConfigWithOptions, markSpanError, markSpanSuccess, recordException, resetSdk, setSpanAttributes, shutdownSdk, suppressShutdownErrors };