@atrim/instrument-node 0.4.1 → 0.5.0-14fdea7-20260109020503
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 +27 -21
- package/target/dist/index.cjs +241 -61
- package/target/dist/index.cjs.map +1 -1
- package/target/dist/index.d.cts +28 -13
- package/target/dist/index.d.ts +28 -13
- package/target/dist/index.js +240 -61
- package/target/dist/index.js.map +1 -1
- package/target/dist/integrations/effect/auto/index.cjs +1276 -0
- package/target/dist/integrations/effect/auto/index.cjs.map +1 -0
- 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/auto/index.js +1229 -0
- package/target/dist/integrations/effect/auto/index.js.map +1 -0
- package/target/dist/integrations/effect/index.cjs +378 -131
- package/target/dist/integrations/effect/index.cjs.map +1 -1
- package/target/dist/integrations/effect/index.d.cts +206 -36
- package/target/dist/integrations/effect/index.d.ts +206 -36
- package/target/dist/integrations/effect/index.js +377 -135
- package/target/dist/integrations/effect/index.js.map +1 -1
package/target/dist/index.d.cts
CHANGED
|
@@ -46,35 +46,33 @@ declare function createOtlpExporter(options?: OtlpExporterOptions): OTLPTraceExp
|
|
|
46
46
|
declare function getOtlpEndpoint(options?: OtlpExporterOptions): string;
|
|
47
47
|
|
|
48
48
|
/**
|
|
49
|
-
* Node.js configuration loader
|
|
49
|
+
* Node.js configuration loader
|
|
50
50
|
*
|
|
51
|
-
* Provides
|
|
51
|
+
* Provides configuration loading using native Node.js APIs (fs, fetch)
|
|
52
|
+
* This module doesn't require Effect Platform, making it work without Effect installed.
|
|
52
53
|
*/
|
|
53
54
|
|
|
54
55
|
/**
|
|
55
|
-
*
|
|
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)
|
|
56
|
+
* Load configuration from URI (file path or URL)
|
|
63
57
|
*
|
|
64
58
|
* @param uri - Configuration URI (file://, http://, https://, or relative path)
|
|
65
|
-
* @param options - Optional loading options (e.g., to disable caching)
|
|
66
59
|
* @returns Promise that resolves to validated configuration
|
|
67
60
|
*/
|
|
68
|
-
declare function loadConfig(uri: string,
|
|
61
|
+
declare function loadConfig(uri: string, _options?: {
|
|
69
62
|
cacheTimeout?: number;
|
|
70
63
|
}): Promise<InstrumentationConfig>;
|
|
71
64
|
/**
|
|
72
|
-
* Load configuration from inline content
|
|
65
|
+
* Load configuration from inline content
|
|
73
66
|
*
|
|
74
67
|
* @param content - YAML string, JSON string, or plain object
|
|
75
68
|
* @returns Promise that resolves to validated configuration
|
|
76
69
|
*/
|
|
77
70
|
declare function loadConfigFromInline(content: string | unknown): Promise<InstrumentationConfig>;
|
|
71
|
+
/**
|
|
72
|
+
* Reset the config loader cache (no-op for native implementation)
|
|
73
|
+
* @internal
|
|
74
|
+
*/
|
|
75
|
+
declare function _resetConfigLoaderCache(): void;
|
|
78
76
|
/**
|
|
79
77
|
* Legacy options interface for backward compatibility
|
|
80
78
|
*/
|
|
@@ -548,6 +546,10 @@ declare function getServiceVersionAsync(): Promise<string | undefined>;
|
|
|
548
546
|
* This processor filters spans based on configured patterns before they are exported.
|
|
549
547
|
* It wraps another processor (typically BatchSpanProcessor) and only forwards spans
|
|
550
548
|
* that match the instrumentation patterns.
|
|
549
|
+
*
|
|
550
|
+
* Filtering is applied at two levels:
|
|
551
|
+
* 1. Span name patterns (instrument_patterns / ignore_patterns)
|
|
552
|
+
* 2. HTTP path patterns (http.ignore_incoming_paths) - for HTTP spans
|
|
551
553
|
*/
|
|
552
554
|
|
|
553
555
|
/**
|
|
@@ -570,6 +572,7 @@ declare function getServiceVersionAsync(): Promise<string | undefined>;
|
|
|
570
572
|
declare class PatternSpanProcessor implements SpanProcessor {
|
|
571
573
|
private matcher;
|
|
572
574
|
private wrappedProcessor;
|
|
575
|
+
private httpIgnorePatterns;
|
|
573
576
|
constructor(config: InstrumentationConfig, wrappedProcessor: SpanProcessor);
|
|
574
577
|
/**
|
|
575
578
|
* Called when a span is started
|
|
@@ -582,8 +585,20 @@ declare class PatternSpanProcessor implements SpanProcessor {
|
|
|
582
585
|
* Called when a span is ended
|
|
583
586
|
*
|
|
584
587
|
* This is where we make the final decision on whether to export the span.
|
|
588
|
+
* We check both span name patterns and HTTP path patterns.
|
|
585
589
|
*/
|
|
586
590
|
onEnd(span: ReadableSpan): void;
|
|
591
|
+
/**
|
|
592
|
+
* Check if span should be ignored based on HTTP path attributes
|
|
593
|
+
*
|
|
594
|
+
* This checks the span's url.path, http.route, or http.target attributes
|
|
595
|
+
* against the configured http.ignore_incoming_paths patterns.
|
|
596
|
+
*
|
|
597
|
+
* This enables filtering of Effect HTTP spans (and any other HTTP spans)
|
|
598
|
+
* based on path patterns, which is essential for filtering out OTLP
|
|
599
|
+
* endpoint requests like /v1/traces, /v1/logs, /v1/metrics.
|
|
600
|
+
*/
|
|
601
|
+
private shouldIgnoreHttpSpan;
|
|
587
602
|
/**
|
|
588
603
|
* Shutdown the processor
|
|
589
604
|
*/
|
package/target/dist/index.d.ts
CHANGED
|
@@ -46,35 +46,33 @@ declare function createOtlpExporter(options?: OtlpExporterOptions): OTLPTraceExp
|
|
|
46
46
|
declare function getOtlpEndpoint(options?: OtlpExporterOptions): string;
|
|
47
47
|
|
|
48
48
|
/**
|
|
49
|
-
* Node.js configuration loader
|
|
49
|
+
* Node.js configuration loader
|
|
50
50
|
*
|
|
51
|
-
* Provides
|
|
51
|
+
* Provides configuration loading using native Node.js APIs (fs, fetch)
|
|
52
|
+
* This module doesn't require Effect Platform, making it work without Effect installed.
|
|
52
53
|
*/
|
|
53
54
|
|
|
54
55
|
/**
|
|
55
|
-
*
|
|
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)
|
|
56
|
+
* Load configuration from URI (file path or URL)
|
|
63
57
|
*
|
|
64
58
|
* @param uri - Configuration URI (file://, http://, https://, or relative path)
|
|
65
|
-
* @param options - Optional loading options (e.g., to disable caching)
|
|
66
59
|
* @returns Promise that resolves to validated configuration
|
|
67
60
|
*/
|
|
68
|
-
declare function loadConfig(uri: string,
|
|
61
|
+
declare function loadConfig(uri: string, _options?: {
|
|
69
62
|
cacheTimeout?: number;
|
|
70
63
|
}): Promise<InstrumentationConfig>;
|
|
71
64
|
/**
|
|
72
|
-
* Load configuration from inline content
|
|
65
|
+
* Load configuration from inline content
|
|
73
66
|
*
|
|
74
67
|
* @param content - YAML string, JSON string, or plain object
|
|
75
68
|
* @returns Promise that resolves to validated configuration
|
|
76
69
|
*/
|
|
77
70
|
declare function loadConfigFromInline(content: string | unknown): Promise<InstrumentationConfig>;
|
|
71
|
+
/**
|
|
72
|
+
* Reset the config loader cache (no-op for native implementation)
|
|
73
|
+
* @internal
|
|
74
|
+
*/
|
|
75
|
+
declare function _resetConfigLoaderCache(): void;
|
|
78
76
|
/**
|
|
79
77
|
* Legacy options interface for backward compatibility
|
|
80
78
|
*/
|
|
@@ -548,6 +546,10 @@ declare function getServiceVersionAsync(): Promise<string | undefined>;
|
|
|
548
546
|
* This processor filters spans based on configured patterns before they are exported.
|
|
549
547
|
* It wraps another processor (typically BatchSpanProcessor) and only forwards spans
|
|
550
548
|
* that match the instrumentation patterns.
|
|
549
|
+
*
|
|
550
|
+
* Filtering is applied at two levels:
|
|
551
|
+
* 1. Span name patterns (instrument_patterns / ignore_patterns)
|
|
552
|
+
* 2. HTTP path patterns (http.ignore_incoming_paths) - for HTTP spans
|
|
551
553
|
*/
|
|
552
554
|
|
|
553
555
|
/**
|
|
@@ -570,6 +572,7 @@ declare function getServiceVersionAsync(): Promise<string | undefined>;
|
|
|
570
572
|
declare class PatternSpanProcessor implements SpanProcessor {
|
|
571
573
|
private matcher;
|
|
572
574
|
private wrappedProcessor;
|
|
575
|
+
private httpIgnorePatterns;
|
|
573
576
|
constructor(config: InstrumentationConfig, wrappedProcessor: SpanProcessor);
|
|
574
577
|
/**
|
|
575
578
|
* Called when a span is started
|
|
@@ -582,8 +585,20 @@ declare class PatternSpanProcessor implements SpanProcessor {
|
|
|
582
585
|
* Called when a span is ended
|
|
583
586
|
*
|
|
584
587
|
* This is where we make the final decision on whether to export the span.
|
|
588
|
+
* We check both span name patterns and HTTP path patterns.
|
|
585
589
|
*/
|
|
586
590
|
onEnd(span: ReadableSpan): void;
|
|
591
|
+
/**
|
|
592
|
+
* Check if span should be ignored based on HTTP path attributes
|
|
593
|
+
*
|
|
594
|
+
* This checks the span's url.path, http.route, or http.target attributes
|
|
595
|
+
* against the configured http.ignore_incoming_paths patterns.
|
|
596
|
+
*
|
|
597
|
+
* This enables filtering of Effect HTTP spans (and any other HTTP spans)
|
|
598
|
+
* based on path patterns, which is essential for filtering out OTLP
|
|
599
|
+
* endpoint requests like /v1/traces, /v1/logs, /v1/metrics.
|
|
600
|
+
*/
|
|
601
|
+
private shouldIgnoreHttpSpan;
|
|
587
602
|
/**
|
|
588
603
|
* Shutdown the processor
|
|
589
604
|
*/
|
package/target/dist/index.js
CHANGED
|
@@ -11,8 +11,7 @@ import { z } from 'zod';
|
|
|
11
11
|
import { OTLPTraceExporter } from '@opentelemetry/exporter-trace-otlp-http';
|
|
12
12
|
import { readFile } from 'fs/promises';
|
|
13
13
|
import { join } from 'path';
|
|
14
|
-
import {
|
|
15
|
-
import { FetchHttpClient } from '@effect/platform';
|
|
14
|
+
import { createRequire } from 'module';
|
|
16
15
|
|
|
17
16
|
var __defProp = Object.defineProperty;
|
|
18
17
|
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
@@ -53,13 +52,113 @@ var AutoIsolationConfigSchema = z.object({
|
|
|
53
52
|
add_metadata: z.boolean().default(true)
|
|
54
53
|
}).default({})
|
|
55
54
|
});
|
|
55
|
+
var SpanNamingRuleSchema = z.object({
|
|
56
|
+
// Match criteria (all specified criteria must match)
|
|
57
|
+
match: z.object({
|
|
58
|
+
// Regex pattern to match file path
|
|
59
|
+
file: z.string().optional(),
|
|
60
|
+
// Regex pattern to match function name
|
|
61
|
+
function: z.string().optional(),
|
|
62
|
+
// Regex pattern to match module name
|
|
63
|
+
module: z.string().optional()
|
|
64
|
+
}),
|
|
65
|
+
// Span name template with variables:
|
|
66
|
+
// {fiber_id} - Fiber ID
|
|
67
|
+
// {function} - Function name
|
|
68
|
+
// {module} - Module name
|
|
69
|
+
// {file} - File path
|
|
70
|
+
// {line} - Line number
|
|
71
|
+
// {operator} - Effect operator (gen, all, forEach, etc.)
|
|
72
|
+
// {match:field:N} - Captured regex group from match
|
|
73
|
+
name: z.string()
|
|
74
|
+
});
|
|
75
|
+
var AutoInstrumentationConfigSchema = z.object({
|
|
76
|
+
// Enable/disable auto-instrumentation
|
|
77
|
+
enabled: z.boolean().default(false),
|
|
78
|
+
// Tracing granularity
|
|
79
|
+
// - 'fiber': Trace at fiber creation (recommended, lower overhead)
|
|
80
|
+
// - 'operator': Trace each Effect operator (higher granularity, more overhead)
|
|
81
|
+
granularity: z.enum(["fiber", "operator"]).default("fiber"),
|
|
82
|
+
// Smart span naming configuration
|
|
83
|
+
span_naming: z.object({
|
|
84
|
+
// Default span name template when no rules match
|
|
85
|
+
default: z.string().default("effect.fiber.{fiber_id}"),
|
|
86
|
+
// Infer span names from source code (requires stack trace parsing)
|
|
87
|
+
// Adds ~50-100μs overhead per fiber
|
|
88
|
+
infer_from_source: z.boolean().default(true),
|
|
89
|
+
// Naming rules (first match wins)
|
|
90
|
+
rules: z.array(SpanNamingRuleSchema).default([])
|
|
91
|
+
}).default({}),
|
|
92
|
+
// Pattern-based filtering
|
|
93
|
+
filter: z.object({
|
|
94
|
+
// Only trace spans matching these patterns (empty = trace all)
|
|
95
|
+
include: z.array(z.string()).default([]),
|
|
96
|
+
// Never trace spans matching these patterns
|
|
97
|
+
exclude: z.array(z.string()).default([])
|
|
98
|
+
}).default({}),
|
|
99
|
+
// Performance controls
|
|
100
|
+
performance: z.object({
|
|
101
|
+
// Sample rate (0.0 - 1.0)
|
|
102
|
+
sampling_rate: z.number().min(0).max(1).default(1),
|
|
103
|
+
// Skip fibers shorter than this duration (e.g., "10ms", "100 millis")
|
|
104
|
+
min_duration: z.string().default("0ms"),
|
|
105
|
+
// Maximum concurrent traced fibers (0 = unlimited)
|
|
106
|
+
max_concurrent: z.number().default(0)
|
|
107
|
+
}).default({}),
|
|
108
|
+
// Automatic metadata extraction
|
|
109
|
+
metadata: z.object({
|
|
110
|
+
// Extract Effect fiber information
|
|
111
|
+
fiber_info: z.boolean().default(true),
|
|
112
|
+
// Extract source location (file:line)
|
|
113
|
+
source_location: z.boolean().default(true),
|
|
114
|
+
// Extract parent fiber information
|
|
115
|
+
parent_fiber: z.boolean().default(true)
|
|
116
|
+
}).default({})
|
|
117
|
+
});
|
|
56
118
|
var HttpFilteringConfigSchema = z.object({
|
|
57
119
|
// Patterns to ignore for outgoing HTTP requests (string patterns only in YAML)
|
|
58
120
|
ignore_outgoing_urls: z.array(z.string()).optional(),
|
|
59
121
|
// Patterns to ignore for incoming HTTP requests (string patterns only in YAML)
|
|
60
122
|
ignore_incoming_paths: z.array(z.string()).optional(),
|
|
61
123
|
// Require parent span for outgoing requests (prevents root spans for HTTP calls)
|
|
62
|
-
require_parent_for_outgoing_spans: z.boolean().optional()
|
|
124
|
+
require_parent_for_outgoing_spans: z.boolean().optional(),
|
|
125
|
+
// Trace context propagation configuration
|
|
126
|
+
// Controls which cross-origin requests receive W3C Trace Context headers (traceparent, tracestate)
|
|
127
|
+
propagate_trace_context: z.object({
|
|
128
|
+
// Strategy for trace propagation
|
|
129
|
+
// - "all": Propagate to all cross-origin requests (may cause CORS errors)
|
|
130
|
+
// - "none": Never propagate trace headers
|
|
131
|
+
// - "same-origin": Only propagate to same-origin requests (default, safe)
|
|
132
|
+
// - "patterns": Propagate based on include_urls patterns
|
|
133
|
+
strategy: z.enum(["all", "none", "same-origin", "patterns"]).default("same-origin"),
|
|
134
|
+
// URL patterns to include when strategy is "patterns"
|
|
135
|
+
// Supports regex patterns (e.g., "^https://api\\.myapp\\.com")
|
|
136
|
+
include_urls: z.array(z.string()).optional()
|
|
137
|
+
}).optional()
|
|
138
|
+
});
|
|
139
|
+
var ExporterConfigSchema = z.object({
|
|
140
|
+
// Exporter type: 'otlp' | 'console' | 'none'
|
|
141
|
+
// - 'otlp': Export to OTLP endpoint (production)
|
|
142
|
+
// - 'console': Log spans to console (development)
|
|
143
|
+
// - 'none': No export (disable tracing)
|
|
144
|
+
type: z.enum(["otlp", "console", "none"]).default("otlp"),
|
|
145
|
+
// OTLP endpoint URL (for type: otlp)
|
|
146
|
+
// Defaults to OTEL_EXPORTER_OTLP_ENDPOINT env var or http://localhost:4318
|
|
147
|
+
endpoint: z.string().optional(),
|
|
148
|
+
// Custom headers to send with OTLP requests (for type: otlp)
|
|
149
|
+
// Useful for authentication (x-api-key, Authorization, etc.)
|
|
150
|
+
headers: z.record(z.string()).optional(),
|
|
151
|
+
// Span processor type
|
|
152
|
+
// - 'batch': Batch spans for export (production, lower overhead)
|
|
153
|
+
// - 'simple': Export immediately (development, no batching delay)
|
|
154
|
+
processor: z.enum(["batch", "simple"]).default("batch"),
|
|
155
|
+
// Batch processor settings (for processor: batch)
|
|
156
|
+
batch: z.object({
|
|
157
|
+
// Max time to wait before exporting (milliseconds)
|
|
158
|
+
scheduled_delay_millis: z.number().default(1e3),
|
|
159
|
+
// Max batch size
|
|
160
|
+
max_export_batch_size: z.number().default(100)
|
|
161
|
+
}).optional()
|
|
63
162
|
});
|
|
64
163
|
var InstrumentationConfigSchema = z.object({
|
|
65
164
|
version: z.string(),
|
|
@@ -71,11 +170,54 @@ var InstrumentationConfigSchema = z.object({
|
|
|
71
170
|
ignore_patterns: z.array(PatternConfigSchema)
|
|
72
171
|
}),
|
|
73
172
|
effect: z.object({
|
|
173
|
+
// Enable/disable Effect tracing entirely
|
|
174
|
+
// When false, EffectInstrumentationLive returns Layer.empty
|
|
175
|
+
enabled: z.boolean().default(true),
|
|
176
|
+
// Exporter mode (legacy - use exporter.type instead):
|
|
177
|
+
// - "unified": Use global TracerProvider from Node SDK (recommended, enables filtering)
|
|
178
|
+
// - "standalone": Use Effect's own OTLP exporter (bypasses Node SDK filtering)
|
|
179
|
+
exporter: z.enum(["unified", "standalone"]).default("unified"),
|
|
180
|
+
// Exporter configuration (for auto-instrumentation)
|
|
181
|
+
exporter_config: ExporterConfigSchema.optional(),
|
|
74
182
|
auto_extract_metadata: z.boolean(),
|
|
75
|
-
auto_isolation: AutoIsolationConfigSchema.optional()
|
|
183
|
+
auto_isolation: AutoIsolationConfigSchema.optional(),
|
|
184
|
+
// Auto-instrumentation: automatic tracing of all Effect fibers
|
|
185
|
+
auto_instrumentation: AutoInstrumentationConfigSchema.optional()
|
|
76
186
|
}).optional(),
|
|
77
187
|
http: HttpFilteringConfigSchema.optional()
|
|
78
188
|
});
|
|
189
|
+
var defaultConfig = {
|
|
190
|
+
version: "1.0",
|
|
191
|
+
instrumentation: {
|
|
192
|
+
enabled: true,
|
|
193
|
+
logging: "on",
|
|
194
|
+
description: "Default instrumentation configuration",
|
|
195
|
+
instrument_patterns: [
|
|
196
|
+
{ pattern: "^app\\.", enabled: true, description: "Application operations" },
|
|
197
|
+
{ pattern: "^http\\.server\\.", enabled: true, description: "HTTP server operations" },
|
|
198
|
+
{ pattern: "^http\\.client\\.", enabled: true, description: "HTTP client operations" }
|
|
199
|
+
],
|
|
200
|
+
ignore_patterns: [
|
|
201
|
+
{ pattern: "^test\\.", description: "Test utilities" },
|
|
202
|
+
{ pattern: "^internal\\.", description: "Internal operations" },
|
|
203
|
+
{ pattern: "^health\\.", description: "Health checks" }
|
|
204
|
+
]
|
|
205
|
+
},
|
|
206
|
+
effect: {
|
|
207
|
+
enabled: true,
|
|
208
|
+
exporter: "unified",
|
|
209
|
+
auto_extract_metadata: true
|
|
210
|
+
}
|
|
211
|
+
};
|
|
212
|
+
function parseAndValidateConfig(content) {
|
|
213
|
+
let parsed;
|
|
214
|
+
if (typeof content === "string") {
|
|
215
|
+
parsed = parse(content);
|
|
216
|
+
} else {
|
|
217
|
+
parsed = content;
|
|
218
|
+
}
|
|
219
|
+
return InstrumentationConfigSchema.parse(parsed);
|
|
220
|
+
}
|
|
79
221
|
(class extends Data.TaggedError("ConfigError") {
|
|
80
222
|
get message() {
|
|
81
223
|
return this.reason;
|
|
@@ -253,7 +395,7 @@ var makeConfigLoader = Effect.gen(function* () {
|
|
|
253
395
|
})
|
|
254
396
|
});
|
|
255
397
|
});
|
|
256
|
-
|
|
398
|
+
Layer.effect(ConfigLoader, makeConfigLoader);
|
|
257
399
|
var PatternMatcher = class {
|
|
258
400
|
constructor(config) {
|
|
259
401
|
__publicField2(this, "ignorePatterns", []);
|
|
@@ -417,8 +559,14 @@ var PatternSpanProcessor = class {
|
|
|
417
559
|
constructor(config, wrappedProcessor) {
|
|
418
560
|
__publicField(this, "matcher");
|
|
419
561
|
__publicField(this, "wrappedProcessor");
|
|
562
|
+
__publicField(this, "httpIgnorePatterns", []);
|
|
420
563
|
this.matcher = new PatternMatcher(config);
|
|
421
564
|
this.wrappedProcessor = wrappedProcessor;
|
|
565
|
+
if (config.http?.ignore_incoming_paths) {
|
|
566
|
+
this.httpIgnorePatterns = config.http.ignore_incoming_paths.map(
|
|
567
|
+
(pattern) => new RegExp(pattern)
|
|
568
|
+
);
|
|
569
|
+
}
|
|
422
570
|
}
|
|
423
571
|
/**
|
|
424
572
|
* Called when a span is started
|
|
@@ -436,12 +584,40 @@ var PatternSpanProcessor = class {
|
|
|
436
584
|
* Called when a span is ended
|
|
437
585
|
*
|
|
438
586
|
* This is where we make the final decision on whether to export the span.
|
|
587
|
+
* We check both span name patterns and HTTP path patterns.
|
|
439
588
|
*/
|
|
440
589
|
onEnd(span) {
|
|
441
590
|
const spanName = span.name;
|
|
442
|
-
if (this.matcher.shouldInstrument(spanName)) {
|
|
443
|
-
|
|
591
|
+
if (!this.matcher.shouldInstrument(spanName)) {
|
|
592
|
+
return;
|
|
444
593
|
}
|
|
594
|
+
if (this.shouldIgnoreHttpSpan(span)) {
|
|
595
|
+
return;
|
|
596
|
+
}
|
|
597
|
+
this.wrappedProcessor.onEnd(span);
|
|
598
|
+
}
|
|
599
|
+
/**
|
|
600
|
+
* Check if span should be ignored based on HTTP path attributes
|
|
601
|
+
*
|
|
602
|
+
* This checks the span's url.path, http.route, or http.target attributes
|
|
603
|
+
* against the configured http.ignore_incoming_paths patterns.
|
|
604
|
+
*
|
|
605
|
+
* This enables filtering of Effect HTTP spans (and any other HTTP spans)
|
|
606
|
+
* based on path patterns, which is essential for filtering out OTLP
|
|
607
|
+
* endpoint requests like /v1/traces, /v1/logs, /v1/metrics.
|
|
608
|
+
*/
|
|
609
|
+
shouldIgnoreHttpSpan(span) {
|
|
610
|
+
if (this.httpIgnorePatterns.length === 0) {
|
|
611
|
+
return false;
|
|
612
|
+
}
|
|
613
|
+
const urlPath = span.attributes["url.path"];
|
|
614
|
+
const httpRoute = span.attributes["http.route"];
|
|
615
|
+
const httpTarget = span.attributes["http.target"];
|
|
616
|
+
const pathToCheck = urlPath || httpRoute || httpTarget;
|
|
617
|
+
if (!pathToCheck) {
|
|
618
|
+
return false;
|
|
619
|
+
}
|
|
620
|
+
return this.httpIgnorePatterns.some((pattern) => pattern.test(pathToCheck));
|
|
445
621
|
}
|
|
446
622
|
/**
|
|
447
623
|
* Shutdown the processor
|
|
@@ -679,83 +855,55 @@ async function getServiceNameAsync() {
|
|
|
679
855
|
async function getServiceVersionAsync() {
|
|
680
856
|
return Effect.runPromise(getServiceVersion);
|
|
681
857
|
}
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
);
|
|
685
|
-
|
|
686
|
-
function getCachedLoader() {
|
|
687
|
-
if (!cachedLoaderPromise) {
|
|
688
|
-
cachedLoaderPromise = Effect.runPromise(
|
|
689
|
-
Effect.gen(function* () {
|
|
690
|
-
return yield* ConfigLoader;
|
|
691
|
-
}).pipe(Effect.provide(NodeConfigLoaderLive))
|
|
692
|
-
);
|
|
693
|
-
}
|
|
694
|
-
return cachedLoaderPromise;
|
|
858
|
+
async function loadFromFile(filePath) {
|
|
859
|
+
const { readFile: readFile2 } = await import('fs/promises');
|
|
860
|
+
const content = await readFile2(filePath, "utf-8");
|
|
861
|
+
return parseAndValidateConfig(content);
|
|
695
862
|
}
|
|
696
|
-
function
|
|
697
|
-
|
|
863
|
+
async function loadFromUrl(url) {
|
|
864
|
+
const response = await fetch(url);
|
|
865
|
+
if (!response.ok) {
|
|
866
|
+
throw new Error(`Failed to fetch config from ${url}: ${response.statusText}`);
|
|
867
|
+
}
|
|
868
|
+
const content = await response.text();
|
|
869
|
+
return parseAndValidateConfig(content);
|
|
698
870
|
}
|
|
699
|
-
async function loadConfig(uri,
|
|
700
|
-
if (
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
return
|
|
871
|
+
async function loadConfig(uri, _options) {
|
|
872
|
+
if (uri.startsWith("http://") || uri.startsWith("https://")) {
|
|
873
|
+
return loadFromUrl(uri);
|
|
874
|
+
}
|
|
875
|
+
if (uri.startsWith("file://")) {
|
|
876
|
+
const filePath = uri.slice(7);
|
|
877
|
+
return loadFromFile(filePath);
|
|
706
878
|
}
|
|
707
|
-
|
|
708
|
-
return Effect.runPromise(loader.loadFromUri(uri));
|
|
879
|
+
return loadFromFile(uri);
|
|
709
880
|
}
|
|
710
881
|
async function loadConfigFromInline(content) {
|
|
711
|
-
|
|
712
|
-
return Effect.runPromise(loader.loadFromInline(content));
|
|
882
|
+
return parseAndValidateConfig(content);
|
|
713
883
|
}
|
|
714
|
-
function
|
|
715
|
-
return {
|
|
716
|
-
version: "1.0",
|
|
717
|
-
instrumentation: {
|
|
718
|
-
enabled: true,
|
|
719
|
-
logging: "on",
|
|
720
|
-
description: "Default instrumentation configuration",
|
|
721
|
-
instrument_patterns: [
|
|
722
|
-
{ pattern: "^app\\.", enabled: true, description: "Application operations" },
|
|
723
|
-
{ pattern: "^http\\.server\\.", enabled: true, description: "HTTP server operations" },
|
|
724
|
-
{ pattern: "^http\\.client\\.", enabled: true, description: "HTTP client operations" }
|
|
725
|
-
],
|
|
726
|
-
ignore_patterns: [
|
|
727
|
-
{ pattern: "^test\\.", description: "Test utilities" },
|
|
728
|
-
{ pattern: "^internal\\.", description: "Internal operations" },
|
|
729
|
-
{ pattern: "^health\\.", description: "Health checks" }
|
|
730
|
-
]
|
|
731
|
-
},
|
|
732
|
-
effect: {
|
|
733
|
-
auto_extract_metadata: true
|
|
734
|
-
}
|
|
735
|
-
};
|
|
884
|
+
function _resetConfigLoaderCache() {
|
|
736
885
|
}
|
|
737
886
|
async function loadConfigWithOptions(options = {}) {
|
|
738
|
-
const loadOptions = options.cacheTimeout !== void 0 ? { cacheTimeout: options.cacheTimeout } : void 0;
|
|
739
887
|
if (options.config) {
|
|
740
888
|
return loadConfigFromInline(options.config);
|
|
741
889
|
}
|
|
742
890
|
const envConfigPath = process.env.ATRIM_INSTRUMENTATION_CONFIG;
|
|
743
891
|
if (envConfigPath) {
|
|
744
|
-
return loadConfig(envConfigPath
|
|
892
|
+
return loadConfig(envConfigPath);
|
|
745
893
|
}
|
|
746
894
|
if (options.configUrl) {
|
|
747
|
-
return loadConfig(options.configUrl
|
|
895
|
+
return loadConfig(options.configUrl);
|
|
748
896
|
}
|
|
749
897
|
if (options.configPath) {
|
|
750
|
-
return loadConfig(options.configPath
|
|
898
|
+
return loadConfig(options.configPath);
|
|
751
899
|
}
|
|
752
900
|
const { existsSync } = await import('fs');
|
|
753
901
|
const { join: join2 } = await import('path');
|
|
754
902
|
const defaultPath = join2(process.cwd(), "instrumentation.yaml");
|
|
755
903
|
if (existsSync(defaultPath)) {
|
|
756
|
-
return loadConfig(defaultPath
|
|
904
|
+
return loadConfig(defaultPath);
|
|
757
905
|
}
|
|
758
|
-
return
|
|
906
|
+
return defaultConfig;
|
|
759
907
|
}
|
|
760
908
|
|
|
761
909
|
// src/core/sdk-initializer.ts
|
|
@@ -1047,9 +1195,39 @@ function logInitialization(config, serviceName, serviceVersion, options, autoIns
|
|
|
1047
1195
|
logger.log(` - OTLP endpoint: ${endpoint}`);
|
|
1048
1196
|
logger.log("");
|
|
1049
1197
|
}
|
|
1198
|
+
var require2 = createRequire(import.meta.url);
|
|
1199
|
+
function validateOpenTelemetryApi() {
|
|
1200
|
+
try {
|
|
1201
|
+
require2.resolve("@opentelemetry/api");
|
|
1202
|
+
} catch {
|
|
1203
|
+
throw new Error(
|
|
1204
|
+
"@atrim/instrument-node requires @opentelemetry/api as a peer dependency.\n\nInstall it with:\n npm install @opentelemetry/api\n\nOr with your preferred package manager:\n pnpm add @opentelemetry/api\n yarn add @opentelemetry/api\n bun add @opentelemetry/api"
|
|
1205
|
+
);
|
|
1206
|
+
}
|
|
1207
|
+
}
|
|
1208
|
+
function validateEffectDependencies() {
|
|
1209
|
+
const packages = ["effect", "@effect/opentelemetry", "@effect/platform"];
|
|
1210
|
+
for (const pkg of packages) {
|
|
1211
|
+
try {
|
|
1212
|
+
require2.resolve(pkg);
|
|
1213
|
+
} catch {
|
|
1214
|
+
return false;
|
|
1215
|
+
}
|
|
1216
|
+
}
|
|
1217
|
+
return true;
|
|
1218
|
+
}
|
|
1219
|
+
var validateDependencies = Effect.try({
|
|
1220
|
+
try: () => validateOpenTelemetryApi(),
|
|
1221
|
+
catch: (error) => new InitializationError2({
|
|
1222
|
+
reason: error instanceof Error ? error.message : "Dependency validation failed",
|
|
1223
|
+
cause: error
|
|
1224
|
+
})
|
|
1225
|
+
});
|
|
1226
|
+
Effect.sync(() => validateEffectDependencies());
|
|
1050
1227
|
|
|
1051
1228
|
// src/api.ts
|
|
1052
1229
|
async function initializeInstrumentation(options = {}) {
|
|
1230
|
+
validateOpenTelemetryApi();
|
|
1053
1231
|
const sdk = await initializeSdk(options);
|
|
1054
1232
|
if (sdk) {
|
|
1055
1233
|
const config = await loadConfigWithOptions(options);
|
|
@@ -1066,6 +1244,7 @@ async function initializePatternMatchingOnly(options = {}) {
|
|
|
1066
1244
|
);
|
|
1067
1245
|
}
|
|
1068
1246
|
var initializeInstrumentationEffect = (options = {}) => Effect.gen(function* () {
|
|
1247
|
+
yield* validateDependencies;
|
|
1069
1248
|
const sdk = yield* Effect.tryPromise({
|
|
1070
1249
|
try: () => initializeSdk(options),
|
|
1071
1250
|
catch: (error) => new InitializationError2({
|