@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.
- package/README.md +66 -0
- package/package.json +13 -7
- package/target/dist/index.cjs +310 -197
- package/target/dist/index.cjs.map +1 -1
- package/target/dist/index.d.cts +57 -3
- package/target/dist/index.d.ts +57 -3
- package/target/dist/index.js +288 -199
- package/target/dist/index.js.map +1 -1
- package/target/dist/integrations/effect/auto/index.cjs +276 -0
- package/target/dist/integrations/effect/auto/index.cjs.map +1 -0
- package/target/dist/integrations/effect/auto/index.d.cts +1513 -0
- package/target/dist/integrations/effect/auto/index.d.ts +1513 -0
- package/target/dist/integrations/effect/auto/index.js +264 -0
- package/target/dist/integrations/effect/auto/index.js.map +1 -0
- package/target/dist/integrations/effect/index.cjs +424 -206
- package/target/dist/integrations/effect/index.cjs.map +1 -1
- package/target/dist/integrations/effect/index.d.cts +204 -13
- package/target/dist/integrations/effect/index.d.ts +204 -13
- package/target/dist/integrations/effect/index.js +421 -208
- package/target/dist/integrations/effect/index.js.map +1 -1
|
@@ -0,0 +1,264 @@
|
|
|
1
|
+
import { Context, FiberRef, Effect as Effect$1, Layer } from 'effect';
|
|
2
|
+
|
|
3
|
+
// src/integrations/effect/auto/index.ts
|
|
4
|
+
|
|
5
|
+
// src/integrations/effect/auto/naming.ts
|
|
6
|
+
function parseCallStack(maxDepth = 15) {
|
|
7
|
+
const error = new Error();
|
|
8
|
+
const stack = error.stack || "";
|
|
9
|
+
const context = {
|
|
10
|
+
operator: "effect",
|
|
11
|
+
stack
|
|
12
|
+
};
|
|
13
|
+
const lines = stack.split("\n");
|
|
14
|
+
const skipPatterns = [
|
|
15
|
+
/node_modules/,
|
|
16
|
+
/at parseCallStack/,
|
|
17
|
+
/at resolveSpanName/,
|
|
18
|
+
/at autoTrace/,
|
|
19
|
+
/at Effect\.gen/,
|
|
20
|
+
/at Generator\.next/,
|
|
21
|
+
/at __awaiter/,
|
|
22
|
+
/at new Promise/,
|
|
23
|
+
/^Error$/,
|
|
24
|
+
/at Object\.<anonymous>/,
|
|
25
|
+
/at Module\._compile/,
|
|
26
|
+
/at processTicksAndRejections/,
|
|
27
|
+
/internal\//
|
|
28
|
+
];
|
|
29
|
+
let framesChecked = 0;
|
|
30
|
+
for (const line of lines) {
|
|
31
|
+
if (framesChecked >= maxDepth) break;
|
|
32
|
+
if (skipPatterns.some((pattern) => pattern.test(line))) {
|
|
33
|
+
continue;
|
|
34
|
+
}
|
|
35
|
+
framesChecked++;
|
|
36
|
+
const classMethodMatch = line.match(/at\s+(\w+)\.(\w+)\s+\(([^)]+):(\d+):\d+\)/);
|
|
37
|
+
if (classMethodMatch && classMethodMatch[1] && classMethodMatch[2]) {
|
|
38
|
+
const className = classMethodMatch[1];
|
|
39
|
+
const methodName = classMethodMatch[2];
|
|
40
|
+
if (!["Object", "Module", "Function"].includes(className)) {
|
|
41
|
+
context.class = className;
|
|
42
|
+
context.function = methodName;
|
|
43
|
+
if (classMethodMatch[3]) {
|
|
44
|
+
context.file = classMethodMatch[3];
|
|
45
|
+
context.module = extractModuleName(classMethodMatch[3]);
|
|
46
|
+
}
|
|
47
|
+
if (classMethodMatch[4]) {
|
|
48
|
+
context.line = parseInt(classMethodMatch[4], 10);
|
|
49
|
+
}
|
|
50
|
+
break;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
const functionMatch = line.match(/at\s+(\w+)\s+\(([^)]+):(\d+):\d+\)/);
|
|
54
|
+
if (functionMatch && functionMatch[1]) {
|
|
55
|
+
const name = functionMatch[1];
|
|
56
|
+
if (!["anonymous", "eval", "Object", "Module"].includes(name)) {
|
|
57
|
+
context.function = name;
|
|
58
|
+
if (functionMatch[2]) {
|
|
59
|
+
context.file = functionMatch[2];
|
|
60
|
+
context.module = extractModuleName(functionMatch[2]);
|
|
61
|
+
}
|
|
62
|
+
if (functionMatch[3]) {
|
|
63
|
+
context.line = parseInt(functionMatch[3], 10);
|
|
64
|
+
}
|
|
65
|
+
break;
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
const fileMatch = line.match(/\(([^)]+):(\d+):\d+\)/);
|
|
69
|
+
if (fileMatch && fileMatch[1] && fileMatch[2]) {
|
|
70
|
+
context.file = fileMatch[1];
|
|
71
|
+
context.line = parseInt(fileMatch[2], 10);
|
|
72
|
+
context.module = extractModuleName(fileMatch[1]);
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
return context;
|
|
76
|
+
}
|
|
77
|
+
function extractModuleName(filePath) {
|
|
78
|
+
const parts = filePath.split("/");
|
|
79
|
+
const fileName = parts[parts.length - 1] || "unknown";
|
|
80
|
+
return fileName.replace(/\.[^.]+$/, "");
|
|
81
|
+
}
|
|
82
|
+
function matchRule(rule, context) {
|
|
83
|
+
const captures = /* @__PURE__ */ new Map();
|
|
84
|
+
const match = rule.match;
|
|
85
|
+
if (match.file) {
|
|
86
|
+
if (!context.file) return { matched: false, captures };
|
|
87
|
+
const regex = new RegExp(match.file);
|
|
88
|
+
const result = regex.exec(context.file);
|
|
89
|
+
if (!result) return { matched: false, captures };
|
|
90
|
+
result.forEach((value, index) => {
|
|
91
|
+
if (index > 0 && value) {
|
|
92
|
+
captures.set(`match:${index}`, value);
|
|
93
|
+
}
|
|
94
|
+
});
|
|
95
|
+
}
|
|
96
|
+
if (match.function) {
|
|
97
|
+
if (!context.function) return { matched: false, captures };
|
|
98
|
+
const regex = new RegExp(match.function);
|
|
99
|
+
const result = regex.exec(context.function);
|
|
100
|
+
if (!result) return { matched: false, captures };
|
|
101
|
+
result.forEach((value, index) => {
|
|
102
|
+
if (index > 0 && value) {
|
|
103
|
+
captures.set(`match:${index}`, value);
|
|
104
|
+
}
|
|
105
|
+
});
|
|
106
|
+
}
|
|
107
|
+
if (match.operator) {
|
|
108
|
+
const regex = new RegExp(match.operator);
|
|
109
|
+
if (!regex.test(context.operator)) return { matched: false, captures };
|
|
110
|
+
}
|
|
111
|
+
if (match.stack) {
|
|
112
|
+
if (!context.stack) return { matched: false, captures };
|
|
113
|
+
const regex = new RegExp(match.stack);
|
|
114
|
+
const result = regex.exec(context.stack);
|
|
115
|
+
if (!result) return { matched: false, captures };
|
|
116
|
+
result.forEach((value, index) => {
|
|
117
|
+
if (index > 0 && value) {
|
|
118
|
+
captures.set(`match:${index}`, value);
|
|
119
|
+
}
|
|
120
|
+
});
|
|
121
|
+
}
|
|
122
|
+
if (match.annotation) {
|
|
123
|
+
if (!context.annotations?.has(match.annotation)) {
|
|
124
|
+
return { matched: false, captures };
|
|
125
|
+
}
|
|
126
|
+
const value = context.annotations.get(match.annotation);
|
|
127
|
+
if (value !== void 0) {
|
|
128
|
+
captures.set(`annotation:${match.annotation}`, String(value));
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
return { matched: true, captures };
|
|
132
|
+
}
|
|
133
|
+
function applyTemplate(template, context, captures) {
|
|
134
|
+
let result = template;
|
|
135
|
+
result = result.replace(/\{operator\}/g, context.operator);
|
|
136
|
+
result = result.replace(/\{function\}/g, context.function || "anonymous");
|
|
137
|
+
result = result.replace(/\{module\}/g, context.module || "unknown");
|
|
138
|
+
result = result.replace(/\{file\}/g, context.file || "unknown");
|
|
139
|
+
result = result.replace(/\{line\}/g, String(context.line || 0));
|
|
140
|
+
result = result.replace(/\{class\}/g, context.class || "");
|
|
141
|
+
for (const [key, value] of captures) {
|
|
142
|
+
result = result.replace(new RegExp(`\\{${key}\\}`, "g"), value);
|
|
143
|
+
}
|
|
144
|
+
result = result.replace(/\{[^}]+\}/g, "");
|
|
145
|
+
result = result.replace(/\.+/g, ".");
|
|
146
|
+
result = result.replace(/^\.+|\.+$/g, "");
|
|
147
|
+
return result || "effect.operation";
|
|
148
|
+
}
|
|
149
|
+
function resolveSpanName(config, context) {
|
|
150
|
+
for (const rule of config.rules) {
|
|
151
|
+
const matchResult = matchRule(rule, context);
|
|
152
|
+
if (matchResult.matched) {
|
|
153
|
+
return applyTemplate(rule.name, context, matchResult.captures);
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
return applyTemplate(config.default, context, /* @__PURE__ */ new Map());
|
|
157
|
+
}
|
|
158
|
+
function createSpanNameResolver(config) {
|
|
159
|
+
return (operator, contextOverrides) => {
|
|
160
|
+
const context = {
|
|
161
|
+
...parseCallStack(),
|
|
162
|
+
operator,
|
|
163
|
+
...contextOverrides
|
|
164
|
+
};
|
|
165
|
+
return resolveSpanName(config, context);
|
|
166
|
+
};
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
// src/integrations/effect/auto/index.ts
|
|
170
|
+
var AutoTracingConfig = class extends Context.Tag("AutoTracingConfig")() {
|
|
171
|
+
};
|
|
172
|
+
var autoTracingDisabled = FiberRef.unsafeMake(false);
|
|
173
|
+
var spanNameOverride = FiberRef.unsafeMake(void 0);
|
|
174
|
+
var defaultConfig = {
|
|
175
|
+
default: "effect.{operator}",
|
|
176
|
+
rules: []
|
|
177
|
+
};
|
|
178
|
+
var withoutAutoTracing = (self) => {
|
|
179
|
+
return Effect$1.locally(autoTracingDisabled, true)(self);
|
|
180
|
+
};
|
|
181
|
+
var setSpanName = (name) => (self) => {
|
|
182
|
+
return Effect$1.locally(spanNameOverride, name)(self);
|
|
183
|
+
};
|
|
184
|
+
function autoTrace(effect, operator) {
|
|
185
|
+
const context = parseCallStack();
|
|
186
|
+
const resolver = createSpanNameResolver(defaultConfig);
|
|
187
|
+
const spanName = resolver(operator, context);
|
|
188
|
+
return effect.pipe(Effect$1.withSpan(spanName));
|
|
189
|
+
}
|
|
190
|
+
function createAutoTracedGen() {
|
|
191
|
+
return function autoTracedGen(f) {
|
|
192
|
+
const effect = Effect$1.gen(f);
|
|
193
|
+
return autoTrace(effect, "gen");
|
|
194
|
+
};
|
|
195
|
+
}
|
|
196
|
+
function createAutoTracedAll() {
|
|
197
|
+
return function autoTracedAll(arg, options) {
|
|
198
|
+
const effect = Effect$1.all(arg, options);
|
|
199
|
+
return autoTrace(effect, "all");
|
|
200
|
+
};
|
|
201
|
+
}
|
|
202
|
+
function createAutoTracedForEach() {
|
|
203
|
+
return function autoTracedForEach(self, f, options) {
|
|
204
|
+
const effect = Effect$1.forEach(self, f, options);
|
|
205
|
+
return autoTrace(effect, "forEach");
|
|
206
|
+
};
|
|
207
|
+
}
|
|
208
|
+
function createAutoTracedTryPromise() {
|
|
209
|
+
return function autoTracedTryPromise(options) {
|
|
210
|
+
const effect = Effect$1.tryPromise(options);
|
|
211
|
+
return autoTrace(effect, "tryPromise");
|
|
212
|
+
};
|
|
213
|
+
}
|
|
214
|
+
function createAutoTracedPromise() {
|
|
215
|
+
return function autoTracedPromise(evaluate) {
|
|
216
|
+
const effect = Effect$1.promise(evaluate);
|
|
217
|
+
return autoTrace(effect, "promise");
|
|
218
|
+
};
|
|
219
|
+
}
|
|
220
|
+
var Effect = {
|
|
221
|
+
...Effect$1,
|
|
222
|
+
// Auto-traced operators
|
|
223
|
+
gen: createAutoTracedGen(),
|
|
224
|
+
all: createAutoTracedAll(),
|
|
225
|
+
forEach: createAutoTracedForEach(),
|
|
226
|
+
tryPromise: createAutoTracedTryPromise(),
|
|
227
|
+
promise: createAutoTracedPromise()
|
|
228
|
+
// TODO: Add more auto-traced operators as needed
|
|
229
|
+
// - race
|
|
230
|
+
// - raceAll
|
|
231
|
+
// - timeout
|
|
232
|
+
// - retry
|
|
233
|
+
// - etc.
|
|
234
|
+
};
|
|
235
|
+
var AutoTracingLive = Layer.succeed(AutoTracingConfig, {
|
|
236
|
+
enabled: true,
|
|
237
|
+
namingConfig: defaultConfig,
|
|
238
|
+
filterPatterns: {
|
|
239
|
+
include: [],
|
|
240
|
+
exclude: []
|
|
241
|
+
},
|
|
242
|
+
sampling: {
|
|
243
|
+
rate: 1,
|
|
244
|
+
minDuration: "0 millis"
|
|
245
|
+
}
|
|
246
|
+
});
|
|
247
|
+
function createAutoTracingLayer(config) {
|
|
248
|
+
return Layer.succeed(AutoTracingConfig, {
|
|
249
|
+
enabled: true,
|
|
250
|
+
namingConfig: config.namingConfig || defaultConfig,
|
|
251
|
+
filterPatterns: {
|
|
252
|
+
include: config.filterPatterns?.include || [],
|
|
253
|
+
exclude: config.filterPatterns?.exclude || []
|
|
254
|
+
},
|
|
255
|
+
sampling: {
|
|
256
|
+
rate: config.sampling?.rate ?? 1,
|
|
257
|
+
minDuration: config.sampling?.minDuration || "0 millis"
|
|
258
|
+
}
|
|
259
|
+
});
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
export { AutoTracingConfig, AutoTracingLive, Effect, autoTracingDisabled, createAutoTracingLayer, createSpanNameResolver, parseCallStack, resolveSpanName, setSpanName, spanNameOverride, withoutAutoTracing };
|
|
263
|
+
//# sourceMappingURL=index.js.map
|
|
264
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../../src/integrations/effect/auto/naming.ts","../../../../../src/integrations/effect/auto/index.ts"],"names":["EffectOriginal"],"mappings":";;;;;AA+DO,SAAS,cAAA,CAAe,WAAmB,EAAA,EAAuB;AACvE,EAAA,MAAM,KAAA,GAAQ,IAAI,KAAA,EAAM;AACxB,EAAA,MAAM,KAAA,GAAQ,MAAM,KAAA,IAAS,EAAA;AAE7B,EAAA,MAAM,OAAA,GAA6B;AAAA,IACjC,QAAA,EAAU,QAAA;AAAA,IACV;AAAA,GACF;AAEA,EAAA,MAAM,KAAA,GAAQ,KAAA,CAAM,KAAA,CAAM,IAAI,CAAA;AAG9B,EAAA,MAAM,YAAA,GAAe;AAAA,IACnB,cAAA;AAAA,IACA,mBAAA;AAAA,IACA,oBAAA;AAAA,IACA,cAAA;AAAA,IACA,gBAAA;AAAA,IACA,oBAAA;AAAA,IACA,cAAA;AAAA,IACA,gBAAA;AAAA,IACA,SAAA;AAAA,IACA,wBAAA;AAAA,IACA,qBAAA;AAAA,IACA,8BAAA;AAAA,IACA;AAAA,GACF;AAEA,EAAA,IAAI,aAAA,GAAgB,CAAA;A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A,IAAW;AAAC,KAC9C;AAAA,IACA,QAAA,EAAU;AAAA,MACR,IAAA,EAAM,MAAA,CAAO,QAAA,EAAU,IAAA,IAAQ,CAAA;AAAA,MAC/B,WAAA,EAAa,MAAA,CAAO,QAAA,EAAU,WAAA,IAAe;AAAA;AAC/C,GACD,CAAA;AACH","file":"index.js","sourcesContent":["/**\n * Span Naming System for Auto-Tracing\n *\n * Resolves span names from templates based on call context and configuration rules.\n *\n * Template variables:\n * - {operator} - Effect operator name (gen, all, forEach, etc.)\n * - {function} - Enclosing function name\n * - {module} - Module/file name without extension\n * - {file} - Full file path\n * - {line} - Line number\n * - {class} - Class name if in a method\n * - {match:N} - Captured group from regex match\n */\n\nimport type { SpanNamingRule } from '@atrim/instrument-core'\n\n/**\n * Context information for span naming\n */\nexport interface SpanNamingContext {\n /** Effect operator name (gen, all, forEach, etc.) */\n operator: string\n /** Enclosing function name */\n function?: string\n /** Module/file name without extension */\n module?: string\n /** Full file path */\n file?: string\n /** Line number */\n line?: number\n /** Class name if in a method */\n class?: string\n /** Call stack string */\n stack?: string\n /** Fiber annotations */\n annotations?: Map<string, unknown>\n}\n\n/**\n * Span naming configuration\n */\nexport interface SpanNamingConfig {\n /** Default template when no rules match */\n default: string\n /** Custom naming rules */\n rules: SpanNamingRule[]\n}\n\n/**\n * Result of template resolution with any captured groups\n */\ninterface MatchResult {\n matched: boolean\n captures: Map<string, string>\n}\n\n/**\n * Parse call stack to extract context information\n *\n * @param maxDepth - Maximum frames to search\n * @returns Context extracted from stack\n */\nexport function parseCallStack(maxDepth: number = 15): SpanNamingContext {\n const error = new Error()\n const stack = error.stack || ''\n\n const context: SpanNamingContext = {\n operator: 'effect',\n stack\n }\n\n const lines = stack.split('\\n')\n\n // Patterns to skip (internal frames)\n const skipPatterns = [\n /node_modules/,\n /at parseCallStack/,\n /at resolveSpanName/,\n /at autoTrace/,\n /at Effect\\.gen/,\n /at Generator\\.next/,\n /at __awaiter/,\n /at new Promise/,\n /^Error$/,\n /at Object\\.<anonymous>/,\n /at Module\\._compile/,\n /at processTicksAndRejections/,\n /internal\\//\n ]\n\n let framesChecked = 0\n\n for (const line of lines) {\n if (framesChecked >= maxDepth) break\n\n // Skip if matches any skip pattern\n if (skipPatterns.some((pattern) => pattern.test(line))) {\n continue\n }\n\n framesChecked++\n\n // Try to extract class.method format\n // Format: \" at ClassName.methodName (file:line:col)\"\n const classMethodMatch = line.match(/at\\s+(\\w+)\\.(\\w+)\\s+\\(([^)]+):(\\d+):\\d+\\)/)\n if (classMethodMatch && classMethodMatch[1] && classMethodMatch[2]) {\n const className = classMethodMatch[1]\n const methodName = classMethodMatch[2]\n\n if (!['Object', 'Module', 'Function'].includes(className)) {\n context.class = className\n context.function = methodName\n if (classMethodMatch[3]) {\n context.file = classMethodMatch[3]\n context.module = extractModuleName(classMethodMatch[3])\n }\n if (classMethodMatch[4]) {\n context.line = parseInt(classMethodMatch[4], 10)\n }\n break\n }\n }\n\n // Try to extract function name\n // Format: \" at functionName (file:line:col)\"\n const functionMatch = line.match(/at\\s+(\\w+)\\s+\\(([^)]+):(\\d+):\\d+\\)/)\n if (functionMatch && functionMatch[1]) {\n const name = functionMatch[1]\n if (!['anonymous', 'eval', 'Object', 'Module'].includes(name)) {\n context.function = name\n if (functionMatch[2]) {\n context.file = functionMatch[2]\n context.module = extractModuleName(functionMatch[2])\n }\n if (functionMatch[3]) {\n context.line = parseInt(functionMatch[3], 10)\n }\n break\n }\n }\n\n // Fallback: extract file:line without function name\n const fileMatch = line.match(/\\(([^)]+):(\\d+):\\d+\\)/)\n if (fileMatch && fileMatch[1] && fileMatch[2]) {\n context.file = fileMatch[1]\n context.line = parseInt(fileMatch[2], 10)\n context.module = extractModuleName(fileMatch[1])\n // Don't break - continue looking for function name\n }\n }\n\n return context\n}\n\n/**\n * Extract module name from file path\n */\nfunction extractModuleName(filePath: string): string {\n const parts = filePath.split('/')\n const fileName = parts[parts.length - 1] || 'unknown'\n return fileName.replace(/\\.[^.]+$/, '')\n}\n\n/**\n * Check if a rule matches the given context\n *\n * @param rule - Naming rule to check\n * @param context - Call context\n * @returns Match result with any captured groups\n */\nfunction matchRule(rule: SpanNamingRule, context: SpanNamingContext): MatchResult {\n const captures = new Map<string, string>()\n const match = rule.match\n\n // Check file pattern\n if (match.file) {\n if (!context.file) return { matched: false, captures }\n const regex = new RegExp(match.file)\n const result = regex.exec(context.file)\n if (!result) return { matched: false, captures }\n // Store captured groups\n result.forEach((value, index) => {\n if (index > 0 && value) {\n captures.set(`match:${index}`, value)\n }\n })\n }\n\n // Check function pattern\n if (match.function) {\n if (!context.function) return { matched: false, captures }\n const regex = new RegExp(match.function)\n const result = regex.exec(context.function)\n if (!result) return { matched: false, captures }\n // Store captured groups\n result.forEach((value, index) => {\n if (index > 0 && value) {\n captures.set(`match:${index}`, value)\n }\n })\n }\n\n // Check operator pattern\n if (match.operator) {\n const regex = new RegExp(match.operator)\n if (!regex.test(context.operator)) return { matched: false, captures }\n }\n\n // Check stack pattern\n if (match.stack) {\n if (!context.stack) return { matched: false, captures }\n const regex = new RegExp(match.stack)\n const result = regex.exec(context.stack)\n if (!result) return { matched: false, captures }\n // Store captured groups\n result.forEach((value, index) => {\n if (index > 0 && value) {\n captures.set(`match:${index}`, value)\n }\n })\n }\n\n // Check annotation\n if (match.annotation) {\n if (!context.annotations?.has(match.annotation)) {\n return { matched: false, captures }\n }\n const value = context.annotations.get(match.annotation)\n if (value !== undefined) {\n captures.set(`annotation:${match.annotation}`, String(value))\n }\n }\n\n return { matched: true, captures }\n}\n\n/**\n * Apply template substitution\n *\n * @param template - Name template with {variables}\n * @param context - Call context\n * @param captures - Captured regex groups\n * @returns Resolved span name\n */\nfunction applyTemplate(\n template: string,\n context: SpanNamingContext,\n captures: Map<string, string>\n): string {\n let result = template\n\n // Replace standard variables\n result = result.replace(/\\{operator\\}/g, context.operator)\n result = result.replace(/\\{function\\}/g, context.function || 'anonymous')\n result = result.replace(/\\{module\\}/g, context.module || 'unknown')\n result = result.replace(/\\{file\\}/g, context.file || 'unknown')\n result = result.replace(/\\{line\\}/g, String(context.line || 0))\n result = result.replace(/\\{class\\}/g, context.class || '')\n\n // Replace captured groups {match:N}\n for (const [key, value] of captures) {\n result = result.replace(new RegExp(`\\\\{${key}\\\\}`, 'g'), value)\n }\n\n // Clean up any unreplaced variables\n result = result.replace(/\\{[^}]+\\}/g, '')\n\n // Clean up empty segments (e.g., \"foo..bar\" -> \"foo.bar\")\n result = result.replace(/\\.+/g, '.')\n result = result.replace(/^\\.+|\\.+$/g, '')\n\n return result || 'effect.operation'\n}\n\n/**\n * Resolve span name from configuration and context\n *\n * @param config - Span naming configuration\n * @param context - Call context\n * @returns Resolved span name\n */\nexport function resolveSpanName(config: SpanNamingConfig, context: SpanNamingContext): string {\n // Try each rule in order\n for (const rule of config.rules) {\n const matchResult = matchRule(rule, context)\n if (matchResult.matched) {\n return applyTemplate(rule.name, context, matchResult.captures)\n }\n }\n\n // Use default template\n return applyTemplate(config.default, context, new Map())\n}\n\n/**\n * Create a span name resolver function\n *\n * @param config - Span naming configuration\n * @returns Function that resolves span names\n */\nexport function createSpanNameResolver(\n config: SpanNamingConfig\n): (operator: string, contextOverrides?: Partial<SpanNamingContext>) => string {\n return (operator: string, contextOverrides?: Partial<SpanNamingContext>) => {\n const context = {\n ...parseCallStack(),\n operator,\n ...contextOverrides\n }\n return resolveSpanName(config, context)\n }\n}\n","/**\n * Auto-Traced Effect Module\n *\n * Drop-in replacement for Effect with automatic tracing.\n * Import this instead of 'effect' to get automatic span creation.\n *\n * @example\n * ```typescript\n * // Instead of: import { Effect } from 'effect'\n * import { Effect } from '@atrim/instrument-node/effect/auto'\n *\n * // All operations are automatically traced\n * const program = Effect.gen(function* () {\n * yield* Effect.sleep('100 millis')\n * return 'done'\n * })\n * ```\n */\n\nimport { Effect as EffectOriginal, FiberRef, Layer, Context } from 'effect'\nimport {\n createSpanNameResolver,\n parseCallStack,\n type SpanNamingConfig,\n type SpanNamingContext\n} from './naming.js'\n\n// Don't re-export everything - let users import what they need from 'effect'\n// This avoids conflicts and bundle bloat\n\n/**\n * Auto-tracing configuration service\n */\nexport class AutoTracingConfig extends Context.Tag('AutoTracingConfig')<\n AutoTracingConfig,\n {\n readonly enabled: boolean\n readonly namingConfig: SpanNamingConfig\n readonly filterPatterns: {\n include: string[]\n exclude: string[]\n }\n readonly sampling: {\n rate: number\n minDuration: string\n }\n }\n>() {}\n\n/**\n * FiberRef to disable auto-tracing for specific effects\n */\nexport const autoTracingDisabled = FiberRef.unsafeMake(false)\n\n/**\n * FiberRef for custom span name override\n */\nexport const spanNameOverride = FiberRef.unsafeMake<string | undefined>(undefined)\n\n/**\n * Default auto-tracing configuration\n */\nconst defaultConfig: SpanNamingConfig = {\n default: 'effect.{operator}',\n rules: []\n}\n\n/**\n * Disable auto-tracing for the wrapped effect\n *\n * @example\n * ```typescript\n * const program = Effect.gen(function* () {\n * yield* internalWork()\n * }).pipe(withoutAutoTracing())\n * ```\n */\nexport const withoutAutoTracing = <A, E, R>(\n self: EffectOriginal.Effect<A, E, R>\n): EffectOriginal.Effect<A, E, R> => {\n return EffectOriginal.locally(autoTracingDisabled, true)(self)\n}\n\n/**\n * Set a custom span name for the wrapped effect\n *\n * @example\n * ```typescript\n * const program = Effect.gen(function* () {\n * yield* doWork()\n * }).pipe(setSpanName('custom.name'))\n * ```\n */\nexport const setSpanName =\n (name: string) =>\n <A, E, R>(self: EffectOriginal.Effect<A, E, R>): EffectOriginal.Effect<A, E, R> => {\n return EffectOriginal.locally(spanNameOverride, name)(self)\n }\n\n/**\n * Check if auto-tracing should be applied\n */\nfunction shouldTrace(name: string, config: SpanNamingConfig): boolean {\n // TODO: Implement filtering based on config\n return true\n}\n\n/**\n * Helper to wrap an effect with auto-tracing\n */\nfunction autoTrace<A, E, R>(\n effect: EffectOriginal.Effect<A, E, R>,\n operator: string\n): EffectOriginal.Effect<A, E, R> {\n const context = parseCallStack()\n const resolver = createSpanNameResolver(defaultConfig)\n const spanName = resolver(operator, context)\n\n return effect.pipe(EffectOriginal.withSpan(spanName))\n}\n\n/**\n * Create auto-traced version of Effect.gen\n */\nfunction createAutoTracedGen() {\n return function autoTracedGen(f: any) {\n const effect = EffectOriginal.gen(f)\n return autoTrace(effect, 'gen')\n }\n}\n\n/**\n * Create auto-traced version of Effect.all\n */\nfunction createAutoTracedAll() {\n return function autoTracedAll(arg: any, options?: any) {\n const effect = EffectOriginal.all(arg, options)\n return autoTrace(effect, 'all')\n }\n}\n\n/**\n * Create auto-traced version of Effect.forEach\n */\nfunction createAutoTracedForEach() {\n return function autoTracedForEach(self: any, f: any, options?: any) {\n const effect = EffectOriginal.forEach(self, f, options)\n return autoTrace(effect, 'forEach')\n }\n}\n\n/**\n * Create auto-traced version of Effect.tryPromise\n */\nfunction createAutoTracedTryPromise() {\n return function autoTracedTryPromise(options: any) {\n const effect = EffectOriginal.tryPromise(options)\n return autoTrace(effect, 'tryPromise')\n }\n}\n\n/**\n * Create auto-traced version of Effect.promise\n */\nfunction createAutoTracedPromise() {\n return function autoTracedPromise(evaluate: any) {\n const effect = EffectOriginal.promise(evaluate)\n return autoTrace(effect, 'promise')\n }\n}\n\n/**\n * Auto-traced Effect namespace\n *\n * Drop-in replacement for Effect with automatic tracing\n */\nexport const Effect = {\n ...EffectOriginal,\n\n // Auto-traced operators\n gen: createAutoTracedGen(),\n all: createAutoTracedAll(),\n forEach: createAutoTracedForEach(),\n tryPromise: createAutoTracedTryPromise(),\n promise: createAutoTracedPromise()\n\n // TODO: Add more auto-traced operators as needed\n // - race\n // - raceAll\n // - timeout\n // - retry\n // - etc.\n}\n\n/**\n * Create the AutoTracingLive layer\n *\n * @example\n * ```typescript\n * const program = Effect.gen(function* () {\n * yield* doWork()\n * })\n *\n * await Effect.runPromise(\n * program.pipe(Effect.provide(AutoTracingLive))\n * )\n * ```\n */\nexport const AutoTracingLive = Layer.succeed(AutoTracingConfig, {\n enabled: true,\n namingConfig: defaultConfig,\n filterPatterns: {\n include: [],\n exclude: []\n },\n sampling: {\n rate: 1.0,\n minDuration: '0 millis'\n }\n})\n\n/**\n * Create custom auto-tracing layer with configuration\n *\n * @example\n * ```typescript\n * const CustomAutoTracing = createAutoTracingLayer({\n * namingConfig: {\n * default: '{module}.{function}',\n * rules: [\n * {\n * match: { file: 'src/api/.*' },\n * name: 'api.{function}'\n * }\n * ]\n * },\n * filterPatterns: {\n * include: ['^app\\\\.', '^api\\\\.'],\n * exclude: ['^internal\\\\.']\n * },\n * sampling: {\n * rate: 0.1,\n * minDuration: '50 millis'\n * }\n * })\n * ```\n */\nexport function createAutoTracingLayer(config: {\n namingConfig?: SpanNamingConfig\n filterPatterns?: {\n include?: string[]\n exclude?: string[]\n }\n sampling?: {\n rate?: number\n minDuration?: string\n }\n}) {\n return Layer.succeed(AutoTracingConfig, {\n enabled: true,\n namingConfig: config.namingConfig || defaultConfig,\n filterPatterns: {\n include: config.filterPatterns?.include || [],\n exclude: config.filterPatterns?.exclude || []\n },\n sampling: {\n rate: config.sampling?.rate ?? 1.0,\n minDuration: config.sampling?.minDuration || '0 millis'\n }\n })\n}\n\n// Export naming utilities\nexport { parseCallStack, resolveSpanName, createSpanNameResolver } from './naming.js'\nexport type { SpanNamingContext, SpanNamingConfig } from './naming.js'\n"]}
|