@atrim/instrument-node 0.4.0 → 0.5.0-3a3dd2c-20251124202015

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.
@@ -5,12 +5,37 @@ var sdkNode = require('@opentelemetry/sdk-node');
5
5
  var sdkTraceBase = require('@opentelemetry/sdk-trace-base');
6
6
  var autoInstrumentationsNode = require('@opentelemetry/auto-instrumentations-node');
7
7
  var api = require('@opentelemetry/api');
8
- var fs = require('fs');
9
- var path = require('path');
8
+ var FileSystem = require('@effect/platform/FileSystem');
9
+ var HttpClient = require('@effect/platform/HttpClient');
10
+ var HttpClientRequest = require('@effect/platform/HttpClientRequest');
10
11
  var yaml = require('yaml');
11
12
  var zod = require('zod');
12
13
  var exporterTraceOtlpHttp = require('@opentelemetry/exporter-trace-otlp-http');
13
14
  var promises = require('fs/promises');
15
+ var path = require('path');
16
+ var platformNode = require('@effect/platform-node');
17
+ var platform = require('@effect/platform');
18
+
19
+ function _interopNamespace(e) {
20
+ if (e && e.__esModule) return e;
21
+ var n = Object.create(null);
22
+ if (e) {
23
+ Object.keys(e).forEach(function (k) {
24
+ if (k !== 'default') {
25
+ var d = Object.getOwnPropertyDescriptor(e, k);
26
+ Object.defineProperty(n, k, d.get ? d : {
27
+ enumerable: true,
28
+ get: function () { return e[k]; }
29
+ });
30
+ }
31
+ });
32
+ }
33
+ n.default = e;
34
+ return Object.freeze(n);
35
+ }
36
+
37
+ var HttpClient__namespace = /*#__PURE__*/_interopNamespace(HttpClient);
38
+ var HttpClientRequest__namespace = /*#__PURE__*/_interopNamespace(HttpClientRequest);
14
39
 
15
40
  var __defProp = Object.defineProperty;
16
41
  var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
@@ -51,13 +76,69 @@ var AutoIsolationConfigSchema = zod.z.object({
51
76
  add_metadata: zod.z.boolean().default(true)
52
77
  }).default({})
53
78
  });
79
+ var SpanNamingRuleSchema = zod.z.object({
80
+ // Match conditions (all specified conditions must match)
81
+ match: zod.z.object({
82
+ // Match by file path pattern (regex)
83
+ file: zod.z.string().optional(),
84
+ // Match by function name pattern (regex)
85
+ function: zod.z.string().optional(),
86
+ // Match by operator type (gen, all, forEach, etc.)
87
+ operator: zod.z.string().optional(),
88
+ // Match by call stack pattern (regex)
89
+ stack: zod.z.string().optional(),
90
+ // Match by fiber annotation key
91
+ annotation: zod.z.string().optional()
92
+ }),
93
+ // Name template with substitution variables
94
+ // Available: {operator}, {function}, {module}, {file}, {line}, {class}, {match:N}
95
+ name: zod.z.string()
96
+ });
97
+ var AutoTracingConfigSchema = zod.z.object({
98
+ // Global enable/disable for auto-tracing
99
+ enabled: zod.z.boolean().default(true),
100
+ // Span naming configuration
101
+ span_naming: zod.z.object({
102
+ // Default name template when no rules match
103
+ default: zod.z.string().default("effect.{operator}"),
104
+ // Custom naming rules (applied in order, first match wins)
105
+ rules: zod.z.array(SpanNamingRuleSchema).default([])
106
+ }).default({}),
107
+ // Pattern filtering
108
+ filter_patterns: zod.z.object({
109
+ // Only trace spans matching these patterns
110
+ include: zod.z.array(zod.z.string()).default([]),
111
+ // Exclude spans matching these patterns (takes precedence)
112
+ exclude: zod.z.array(zod.z.string()).default([])
113
+ }).default({}),
114
+ // Sampling configuration
115
+ sampling: zod.z.object({
116
+ // Sampling rate (0.0 to 1.0)
117
+ rate: zod.z.number().min(0).max(1).default(1),
118
+ // Only trace effects with duration > this value
119
+ min_duration: zod.z.string().default("0 millis")
120
+ }).default({})
121
+ });
54
122
  var HttpFilteringConfigSchema = zod.z.object({
55
123
  // Patterns to ignore for outgoing HTTP requests (string patterns only in YAML)
56
124
  ignore_outgoing_urls: zod.z.array(zod.z.string()).optional(),
57
125
  // Patterns to ignore for incoming HTTP requests (string patterns only in YAML)
58
126
  ignore_incoming_paths: zod.z.array(zod.z.string()).optional(),
59
127
  // Require parent span for outgoing requests (prevents root spans for HTTP calls)
60
- require_parent_for_outgoing_spans: zod.z.boolean().optional()
128
+ require_parent_for_outgoing_spans: zod.z.boolean().optional(),
129
+ // Trace context propagation configuration
130
+ // Controls which cross-origin requests receive W3C Trace Context headers (traceparent, tracestate)
131
+ propagate_trace_context: zod.z.object({
132
+ // Strategy for trace propagation
133
+ // - "all": Propagate to all cross-origin requests (may cause CORS errors)
134
+ // - "none": Never propagate trace headers
135
+ // - "same-origin": Only propagate to same-origin requests (default, safe)
136
+ // - "patterns": Propagate based on include_urls patterns
137
+ strategy: zod.z.enum(["all", "none", "same-origin", "patterns"]).default("same-origin"),
138
+ // URL patterns to include when strategy is "patterns"
139
+ // Supports regex patterns (e.g., "^https://api\\.myapp\\.com")
140
+ include_urls: zod.z.array(zod.z.string()).optional()
141
+ }).optional()
61
142
  });
62
143
  var InstrumentationConfigSchema = zod.z.object({
63
144
  version: zod.z.string(),
@@ -70,238 +151,189 @@ var InstrumentationConfigSchema = zod.z.object({
70
151
  }),
71
152
  effect: zod.z.object({
72
153
  auto_extract_metadata: zod.z.boolean(),
73
- auto_isolation: AutoIsolationConfigSchema.optional()
154
+ auto_isolation: AutoIsolationConfigSchema.optional(),
155
+ auto_tracing: AutoTracingConfigSchema.optional()
74
156
  }).optional(),
75
157
  http: HttpFilteringConfigSchema.optional()
76
158
  });
77
159
  (class extends effect.Data.TaggedError("ConfigError") {
160
+ get message() {
161
+ return this.reason;
162
+ }
78
163
  });
79
164
  var ConfigUrlError = class extends effect.Data.TaggedError("ConfigUrlError") {
165
+ get message() {
166
+ return this.reason;
167
+ }
80
168
  };
81
169
  var ConfigValidationError = class extends effect.Data.TaggedError("ConfigValidationError") {
170
+ get message() {
171
+ return this.reason;
172
+ }
82
173
  };
83
174
  var ConfigFileError = class extends effect.Data.TaggedError("ConfigFileError") {
175
+ get message() {
176
+ return this.reason;
177
+ }
84
178
  };
85
179
  (class extends effect.Data.TaggedError("ServiceDetectionError") {
180
+ get message() {
181
+ return this.reason;
182
+ }
86
183
  });
87
184
  (class extends effect.Data.TaggedError("InitializationError") {
185
+ get message() {
186
+ return this.reason;
187
+ }
88
188
  });
89
189
  (class extends effect.Data.TaggedError("ExportError") {
190
+ get message() {
191
+ return this.reason;
192
+ }
90
193
  });
91
194
  (class extends effect.Data.TaggedError("ShutdownError") {
195
+ get message() {
196
+ return this.reason;
197
+ }
92
198
  });
93
199
  var SECURITY_DEFAULTS = {
94
200
  maxConfigSize: 1e6,
95
201
  // 1MB
96
- requestTimeout: 5e3,
97
- allowedProtocols: ["https:"],
98
- // Only HTTPS for remote configs
99
- cacheTimeout: 3e5
100
- // 5 minutes
202
+ requestTimeout: 5e3
203
+ // 5 seconds
101
204
  };
102
- function getDefaultConfig() {
103
- return {
104
- version: "1.0",
105
- instrumentation: {
106
- enabled: true,
107
- logging: "on",
108
- description: "Default instrumentation configuration",
109
- instrument_patterns: [
110
- { pattern: "^app\\.", enabled: true, description: "Application operations" },
111
- { pattern: "^http\\.server\\.", enabled: true, description: "HTTP server operations" },
112
- { pattern: "^http\\.client\\.", enabled: true, description: "HTTP client operations" }
113
- ],
114
- ignore_patterns: [
115
- { pattern: "^test\\.", description: "Test utilities" },
116
- { pattern: "^internal\\.", description: "Internal operations" },
117
- { pattern: "^health\\.", description: "Health checks" }
118
- ]
119
- },
120
- effect: {
121
- auto_extract_metadata: true
122
- }
123
- };
124
- }
125
- var validateConfigEffect = (rawConfig) => effect.Effect.try({
126
- try: () => InstrumentationConfigSchema.parse(rawConfig),
127
- catch: (error) => new ConfigValidationError({
128
- reason: "Invalid configuration schema",
129
- cause: error
130
- })
131
- });
132
- var loadConfigFromFileEffect = (filePath) => effect.Effect.gen(function* () {
133
- const fileContents = yield* effect.Effect.try({
134
- try: () => fs.readFileSync(filePath, "utf8"),
135
- catch: (error) => new ConfigFileError({
136
- reason: `Failed to read config file at ${filePath}`,
205
+ var ConfigLoader = class extends effect.Context.Tag("ConfigLoader")() {
206
+ };
207
+ var parseYamlContent = (content, uri) => effect.Effect.gen(function* () {
208
+ const parsed = yield* effect.Effect.try({
209
+ try: () => yaml.parse(content),
210
+ catch: (error) => new ConfigValidationError({
211
+ reason: uri ? `Failed to parse YAML from ${uri}` : "Failed to parse YAML",
212
+ cause: error
213
+ })
214
+ });
215
+ return yield* effect.Effect.try({
216
+ try: () => InstrumentationConfigSchema.parse(parsed),
217
+ catch: (error) => new ConfigValidationError({
218
+ reason: uri ? `Invalid configuration schema from ${uri}` : "Invalid configuration schema",
137
219
  cause: error
138
220
  })
139
221
  });
140
- if (fileContents.length > SECURITY_DEFAULTS.maxConfigSize) {
222
+ });
223
+ var loadFromFileWithFs = (fs, path, uri) => effect.Effect.gen(function* () {
224
+ const content = yield* fs.readFileString(path).pipe(
225
+ effect.Effect.mapError(
226
+ (error) => new ConfigFileError({
227
+ reason: `Failed to read config file at ${uri}`,
228
+ cause: error
229
+ })
230
+ )
231
+ );
232
+ if (content.length > SECURITY_DEFAULTS.maxConfigSize) {
141
233
  return yield* effect.Effect.fail(
142
234
  new ConfigFileError({
143
235
  reason: `Config file exceeds maximum size of ${SECURITY_DEFAULTS.maxConfigSize} bytes`
144
236
  })
145
237
  );
146
238
  }
147
- let rawConfig;
148
- try {
149
- rawConfig = yaml.parse(fileContents);
150
- } catch (error) {
151
- return yield* effect.Effect.fail(
152
- new ConfigValidationError({
153
- reason: "Invalid YAML syntax",
154
- cause: error
155
- })
156
- );
157
- }
158
- return yield* validateConfigEffect(rawConfig);
239
+ return yield* parseYamlContent(content, uri);
159
240
  });
160
- var fetchAndParseConfig = (url) => effect.Effect.gen(function* () {
161
- let urlObj;
162
- try {
163
- urlObj = new URL(url);
164
- } catch (error) {
165
- return yield* effect.Effect.fail(
166
- new ConfigUrlError({
167
- reason: `Invalid URL: ${url}`,
168
- cause: error
241
+ var loadFromHttpWithClient = (client, url) => effect.Effect.scoped(
242
+ effect.Effect.gen(function* () {
243
+ if (url.startsWith("http://")) {
244
+ return yield* effect.Effect.fail(
245
+ new ConfigUrlError({
246
+ reason: "Insecure protocol: only HTTPS URLs are allowed"
247
+ })
248
+ );
249
+ }
250
+ const request = HttpClientRequest__namespace.get(url).pipe(
251
+ HttpClientRequest__namespace.setHeaders({
252
+ Accept: "application/yaml, text/yaml, application/x-yaml"
169
253
  })
170
254
  );
171
- }
172
- if (!SECURITY_DEFAULTS.allowedProtocols.includes(urlObj.protocol)) {
173
- return yield* effect.Effect.fail(
174
- new ConfigUrlError({
175
- reason: `Insecure protocol ${urlObj.protocol}. Only ${SECURITY_DEFAULTS.allowedProtocols.join(", ")} are allowed`
255
+ const response = yield* client.execute(request).pipe(
256
+ effect.Effect.timeout(`${SECURITY_DEFAULTS.requestTimeout} millis`),
257
+ effect.Effect.mapError((error) => {
258
+ if (error._tag === "TimeoutException") {
259
+ return new ConfigUrlError({
260
+ reason: `Config fetch timeout after ${SECURITY_DEFAULTS.requestTimeout}ms from ${url}`
261
+ });
262
+ }
263
+ return new ConfigUrlError({
264
+ reason: `Failed to load config from URL: ${url}`,
265
+ cause: error
266
+ });
176
267
  })
177
268
  );
178
- }
179
- const response = yield* effect.Effect.tryPromise({
180
- try: () => fetch(url, {
181
- redirect: "follow",
182
- headers: {
183
- Accept: "application/yaml, text/yaml, text/x-yaml"
184
- }
185
- }),
186
- catch: (error) => new ConfigUrlError({
187
- reason: `Failed to load config from URL ${url}`,
188
- cause: error
189
- })
190
- }).pipe(
191
- effect.Effect.timeout(effect.Duration.millis(SECURITY_DEFAULTS.requestTimeout)),
192
- effect.Effect.retry({
193
- times: 3,
194
- schedule: effect.Schedule.exponential(effect.Duration.millis(100))
195
- }),
196
- effect.Effect.catchAll((error) => {
197
- if (error._tag === "TimeoutException") {
198
- return effect.Effect.fail(
199
- new ConfigUrlError({
200
- reason: `Config fetch timeout after ${SECURITY_DEFAULTS.requestTimeout}ms`
269
+ if (response.status >= 400) {
270
+ return yield* effect.Effect.fail(
271
+ new ConfigUrlError({
272
+ reason: `HTTP ${response.status} from ${url}`
273
+ })
274
+ );
275
+ }
276
+ const text = yield* response.text.pipe(
277
+ effect.Effect.mapError(
278
+ (error) => new ConfigUrlError({
279
+ reason: `Failed to read response body from ${url}`,
280
+ cause: error
281
+ })
282
+ )
283
+ );
284
+ if (text.length > SECURITY_DEFAULTS.maxConfigSize) {
285
+ return yield* effect.Effect.fail(
286
+ new ConfigUrlError({
287
+ reason: `Config exceeds maximum size of ${SECURITY_DEFAULTS.maxConfigSize} bytes`
288
+ })
289
+ );
290
+ }
291
+ return yield* parseYamlContent(text, url);
292
+ })
293
+ );
294
+ var makeConfigLoader = effect.Effect.gen(function* () {
295
+ const fs = yield* effect.Effect.serviceOption(FileSystem.FileSystem);
296
+ const http = yield* HttpClient__namespace.HttpClient;
297
+ const loadFromUriUncached = (uri) => effect.Effect.gen(function* () {
298
+ if (uri.startsWith("file://")) {
299
+ const path = uri.slice(7);
300
+ if (fs._tag === "None") {
301
+ return yield* effect.Effect.fail(
302
+ new ConfigFileError({
303
+ reason: "FileSystem not available (browser environment?)",
304
+ cause: { uri }
201
305
  })
202
306
  );
203
307
  }
204
- return effect.Effect.fail(error);
205
- })
206
- );
207
- if (!response.ok) {
208
- return yield* effect.Effect.fail(
209
- new ConfigUrlError({
210
- reason: `HTTP ${response.status}: ${response.statusText}`
211
- })
212
- );
213
- }
214
- const contentLength = response.headers.get("content-length");
215
- if (contentLength && parseInt(contentLength) > SECURITY_DEFAULTS.maxConfigSize) {
216
- return yield* effect.Effect.fail(
217
- new ConfigUrlError({
218
- reason: `Config exceeds maximum size of ${SECURITY_DEFAULTS.maxConfigSize} bytes`
219
- })
220
- );
221
- }
222
- const text = yield* effect.Effect.tryPromise({
223
- try: () => response.text(),
224
- catch: (error) => new ConfigUrlError({
225
- reason: "Failed to read response body",
226
- cause: error
308
+ return yield* loadFromFileWithFs(fs.value, path, uri);
309
+ }
310
+ if (uri.startsWith("http://") || uri.startsWith("https://")) {
311
+ return yield* loadFromHttpWithClient(http, uri);
312
+ }
313
+ if (fs._tag === "Some") {
314
+ return yield* loadFromFileWithFs(fs.value, uri, uri);
315
+ } else {
316
+ return yield* loadFromHttpWithClient(http, uri);
317
+ }
318
+ });
319
+ const loadFromUriCached = yield* effect.Effect.cachedFunction(loadFromUriUncached);
320
+ return ConfigLoader.of({
321
+ loadFromUri: loadFromUriCached,
322
+ loadFromInline: (content) => effect.Effect.gen(function* () {
323
+ if (typeof content === "string") {
324
+ return yield* parseYamlContent(content);
325
+ }
326
+ return yield* effect.Effect.try({
327
+ try: () => InstrumentationConfigSchema.parse(content),
328
+ catch: (error) => new ConfigValidationError({
329
+ reason: "Invalid configuration schema",
330
+ cause: error
331
+ })
332
+ });
227
333
  })
228
334
  });
229
- if (text.length > SECURITY_DEFAULTS.maxConfigSize) {
230
- return yield* effect.Effect.fail(
231
- new ConfigUrlError({
232
- reason: `Config exceeds maximum size of ${SECURITY_DEFAULTS.maxConfigSize} bytes`
233
- })
234
- );
235
- }
236
- let rawConfig;
237
- try {
238
- rawConfig = yaml.parse(text);
239
- } catch (error) {
240
- return yield* effect.Effect.fail(
241
- new ConfigValidationError({
242
- reason: "Invalid YAML syntax",
243
- cause: error
244
- })
245
- );
246
- }
247
- return yield* validateConfigEffect(rawConfig);
248
- });
249
- var makeConfigCache = () => effect.Cache.make({
250
- capacity: 100,
251
- timeToLive: effect.Duration.minutes(5),
252
- lookup: (url) => fetchAndParseConfig(url)
253
- });
254
- var cacheInstance = null;
255
- var getCache = effect.Effect.gen(function* () {
256
- if (!cacheInstance) {
257
- cacheInstance = yield* makeConfigCache();
258
- }
259
- return cacheInstance;
260
- });
261
- var loadConfigFromUrlEffect = (url, cacheTimeout = SECURITY_DEFAULTS.cacheTimeout) => effect.Effect.gen(function* () {
262
- if (cacheTimeout === 0) {
263
- return yield* fetchAndParseConfig(url);
264
- }
265
- const cache = yield* getCache;
266
- return yield* cache.get(url);
267
335
  });
268
- var loadConfigEffect = (options = {}) => effect.Effect.gen(function* () {
269
- if (options.config) {
270
- return yield* validateConfigEffect(options.config);
271
- }
272
- const envConfigPath = process.env.ATRIM_INSTRUMENTATION_CONFIG;
273
- if (envConfigPath) {
274
- if (envConfigPath.startsWith("http://") || envConfigPath.startsWith("https://")) {
275
- return yield* loadConfigFromUrlEffect(envConfigPath, options.cacheTimeout);
276
- }
277
- return yield* loadConfigFromFileEffect(envConfigPath);
278
- }
279
- if (options.configUrl) {
280
- return yield* loadConfigFromUrlEffect(options.configUrl, options.cacheTimeout);
281
- }
282
- if (options.configPath) {
283
- return yield* loadConfigFromFileEffect(options.configPath);
284
- }
285
- const defaultPath = path.join(process.cwd(), "instrumentation.yaml");
286
- const exists = yield* effect.Effect.sync(() => fs.existsSync(defaultPath));
287
- if (exists) {
288
- return yield* loadConfigFromFileEffect(defaultPath);
289
- }
290
- return getDefaultConfig();
291
- });
292
- async function loadConfig(options = {}) {
293
- return effect.Effect.runPromise(
294
- loadConfigEffect(options).pipe(
295
- // Convert typed errors to regular Error with reason message for backward compatibility
296
- effect.Effect.mapError((error) => {
297
- const message = error.reason;
298
- const newError = new Error(message);
299
- newError.cause = error.cause;
300
- return newError;
301
- })
302
- )
303
- );
304
- }
336
+ var ConfigLoaderLive = effect.Layer.effect(ConfigLoader, makeConfigLoader);
305
337
  var PatternMatcher = class {
306
338
  constructor(config) {
307
339
  __publicField2(this, "ignorePatterns", []);
@@ -727,6 +759,84 @@ async function getServiceNameAsync() {
727
759
  async function getServiceVersionAsync() {
728
760
  return effect.Effect.runPromise(getServiceVersion);
729
761
  }
762
+ var NodeConfigLoaderLive = ConfigLoaderLive.pipe(
763
+ effect.Layer.provide(effect.Layer.mergeAll(platformNode.NodeContext.layer, platform.FetchHttpClient.layer))
764
+ );
765
+ var cachedLoaderPromise = null;
766
+ function getCachedLoader() {
767
+ if (!cachedLoaderPromise) {
768
+ cachedLoaderPromise = effect.Effect.runPromise(
769
+ effect.Effect.gen(function* () {
770
+ return yield* ConfigLoader;
771
+ }).pipe(effect.Effect.provide(NodeConfigLoaderLive))
772
+ );
773
+ }
774
+ return cachedLoaderPromise;
775
+ }
776
+ function _resetConfigLoaderCache() {
777
+ cachedLoaderPromise = null;
778
+ }
779
+ async function loadConfig(uri, options) {
780
+ if (options?.cacheTimeout === 0) {
781
+ const program = effect.Effect.gen(function* () {
782
+ const loader2 = yield* ConfigLoader;
783
+ return yield* loader2.loadFromUri(uri);
784
+ });
785
+ return effect.Effect.runPromise(program.pipe(effect.Effect.provide(NodeConfigLoaderLive)));
786
+ }
787
+ const loader = await getCachedLoader();
788
+ return effect.Effect.runPromise(loader.loadFromUri(uri));
789
+ }
790
+ async function loadConfigFromInline(content) {
791
+ const loader = await getCachedLoader();
792
+ return effect.Effect.runPromise(loader.loadFromInline(content));
793
+ }
794
+ function getDefaultConfig() {
795
+ return {
796
+ version: "1.0",
797
+ instrumentation: {
798
+ enabled: true,
799
+ logging: "on",
800
+ description: "Default instrumentation configuration",
801
+ instrument_patterns: [
802
+ { pattern: "^app\\.", enabled: true, description: "Application operations" },
803
+ { pattern: "^http\\.server\\.", enabled: true, description: "HTTP server operations" },
804
+ { pattern: "^http\\.client\\.", enabled: true, description: "HTTP client operations" }
805
+ ],
806
+ ignore_patterns: [
807
+ { pattern: "^test\\.", description: "Test utilities" },
808
+ { pattern: "^internal\\.", description: "Internal operations" },
809
+ { pattern: "^health\\.", description: "Health checks" }
810
+ ]
811
+ },
812
+ effect: {
813
+ auto_extract_metadata: true
814
+ }
815
+ };
816
+ }
817
+ async function loadConfigWithOptions(options = {}) {
818
+ const loadOptions = options.cacheTimeout !== void 0 ? { cacheTimeout: options.cacheTimeout } : void 0;
819
+ if (options.config) {
820
+ return loadConfigFromInline(options.config);
821
+ }
822
+ const envConfigPath = process.env.ATRIM_INSTRUMENTATION_CONFIG;
823
+ if (envConfigPath) {
824
+ return loadConfig(envConfigPath, loadOptions);
825
+ }
826
+ if (options.configUrl) {
827
+ return loadConfig(options.configUrl, loadOptions);
828
+ }
829
+ if (options.configPath) {
830
+ return loadConfig(options.configPath, loadOptions);
831
+ }
832
+ const { existsSync } = await import('fs');
833
+ const { join: join2 } = await import('path');
834
+ const defaultPath = join2(process.cwd(), "instrumentation.yaml");
835
+ if (existsSync(defaultPath)) {
836
+ return loadConfig(defaultPath, loadOptions);
837
+ }
838
+ return getDefaultConfig();
839
+ }
730
840
 
731
841
  // src/core/sdk-initializer.ts
732
842
  var sdkInstance = null;
@@ -866,7 +976,7 @@ async function initializeSdk(options = {}) {
866
976
  }
867
977
  }
868
978
  async function performInitialization(options) {
869
- const config = await loadConfig(options);
979
+ const config = await loadConfigWithOptions(options);
870
980
  const loggingLevel = config.instrumentation.logging || "on";
871
981
  logger.setLevel(loggingLevel);
872
982
  const alreadyInitialized = isTracingAlreadyInitialized();
@@ -1022,13 +1132,13 @@ function logInitialization(config, serviceName, serviceVersion, options, autoIns
1022
1132
  async function initializeInstrumentation(options = {}) {
1023
1133
  const sdk = await initializeSdk(options);
1024
1134
  if (sdk) {
1025
- const config = await loadConfig(options);
1135
+ const config = await loadConfigWithOptions(options);
1026
1136
  initializePatternMatcher(config);
1027
1137
  }
1028
1138
  return sdk;
1029
1139
  }
1030
1140
  async function initializePatternMatchingOnly(options = {}) {
1031
- const config = await loadConfig(options);
1141
+ const config = await loadConfigWithOptions(options);
1032
1142
  initializePatternMatcher(config);
1033
1143
  logger.log("@atrim/instrumentation: Pattern matching initialized (legacy mode)");
1034
1144
  logger.log(
@@ -1045,7 +1155,7 @@ var initializeInstrumentationEffect = (options = {}) => effect.Effect.gen(functi
1045
1155
  });
1046
1156
  if (sdk) {
1047
1157
  yield* effect.Effect.tryPromise({
1048
- try: () => loadConfig(options),
1158
+ try: () => loadConfigWithOptions(options),
1049
1159
  catch: (error) => new ConfigError2({
1050
1160
  reason: "Failed to load config for pattern matcher",
1051
1161
  cause: error
@@ -1062,7 +1172,7 @@ var initializeInstrumentationEffect = (options = {}) => effect.Effect.gen(functi
1062
1172
  });
1063
1173
  var initializePatternMatchingOnlyEffect = (options = {}) => effect.Effect.gen(function* () {
1064
1174
  const config = yield* effect.Effect.tryPromise({
1065
- try: () => loadConfig(options),
1175
+ try: () => loadConfigWithOptions(options),
1066
1176
  catch: (error) => new ConfigError2({
1067
1177
  reason: "Failed to load configuration",
1068
1178
  cause: error
@@ -1184,6 +1294,7 @@ exports.ShutdownError = ShutdownError2;
1184
1294
  exports.annotateCacheOperation = annotateCacheOperation;
1185
1295
  exports.annotateDbQuery = annotateDbQuery;
1186
1296
  exports.annotateHttpRequest = annotateHttpRequest;
1297
+ exports.clearConfigCache = _resetConfigLoaderCache;
1187
1298
  exports.createOtlpExporter = createOtlpExporter;
1188
1299
  exports.detectServiceInfo = detectServiceInfoAsync;
1189
1300
  exports.detectServiceInfoEffect = detectServiceInfo;
@@ -1200,6 +1311,8 @@ exports.initializeInstrumentationEffect = initializeInstrumentationEffect;
1200
1311
  exports.initializePatternMatchingOnly = initializePatternMatchingOnly;
1201
1312
  exports.initializePatternMatchingOnlyEffect = initializePatternMatchingOnlyEffect;
1202
1313
  exports.loadConfig = loadConfig;
1314
+ exports.loadConfigFromInline = loadConfigFromInline;
1315
+ exports.loadConfigWithOptions = loadConfigWithOptions;
1203
1316
  exports.markSpanError = markSpanError;
1204
1317
  exports.markSpanSuccess = markSpanSuccess;
1205
1318
  exports.recordException = recordException;