autotel-cli 0.19.1 → 0.20.0
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/dist/index.js +24 -36
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -370,9 +370,6 @@ function createCodeFile() {
|
|
|
370
370
|
backendImports: [],
|
|
371
371
|
pluginImports: [],
|
|
372
372
|
subscriberImports: [],
|
|
373
|
-
loggerImports: [],
|
|
374
|
-
loggerSetup: null,
|
|
375
|
-
loggerExpr: null,
|
|
376
373
|
autoInstrumentations: [],
|
|
377
374
|
backendConfig: null,
|
|
378
375
|
subscribersConfig: [],
|
|
@@ -380,23 +377,11 @@ function createCodeFile() {
|
|
|
380
377
|
};
|
|
381
378
|
}
|
|
382
379
|
/**
|
|
383
|
-
*
|
|
384
|
-
*
|
|
385
|
-
*
|
|
380
|
+
* Add a name to the autoInstrumentations allowlist. For a logger this is what
|
|
381
|
+
* injects trace context: the app's own logger, created after init(), is
|
|
382
|
+
* patched as it loads, so it is never passed to init().
|
|
386
383
|
*/
|
|
387
|
-
function
|
|
388
|
-
file.loggerImports.push({
|
|
389
|
-
source: "pino",
|
|
390
|
-
default: "pino"
|
|
391
|
-
});
|
|
392
|
-
file.loggerSetup = `const logger = pino({ name: 'app', level: process.env.LOG_LEVEL ?? 'info' });`;
|
|
393
|
-
file.loggerExpr = "logger";
|
|
394
|
-
}
|
|
395
|
-
/**
|
|
396
|
-
* Add a logger to the autoInstrumentations array. For Winston/Bunyan this
|
|
397
|
-
* enables OpenTelemetry contrib's trace-context injection.
|
|
398
|
-
*/
|
|
399
|
-
function addAutoInstrumentationLogger(file, name) {
|
|
384
|
+
function addAutoInstrumentation(file, name) {
|
|
400
385
|
if (!file.autoInstrumentations.includes(name)) file.autoInstrumentations.push(name);
|
|
401
386
|
}
|
|
402
387
|
/**
|
|
@@ -502,17 +487,7 @@ function renderCodeFile(file) {
|
|
|
502
487
|
lines.push(renderImports(file.subscriberImports));
|
|
503
488
|
lines.push("");
|
|
504
489
|
}
|
|
505
|
-
if (file.loggerImports.length > 0) {
|
|
506
|
-
lines.push(SECTION_MARKER("LOGGER"));
|
|
507
|
-
lines.push(renderImports(file.loggerImports));
|
|
508
|
-
lines.push("");
|
|
509
|
-
}
|
|
510
|
-
if (file.loggerSetup !== null) {
|
|
511
|
-
lines.push(file.loggerSetup);
|
|
512
|
-
lines.push("");
|
|
513
|
-
}
|
|
514
490
|
lines.push("init({");
|
|
515
|
-
if (file.loggerExpr !== null) lines.push(` logger: ${file.loggerExpr},`);
|
|
516
491
|
if (file.autoInstrumentations.length > 0) {
|
|
517
492
|
const list = file.autoInstrumentations.map((n) => `'${n}'`).join(", ");
|
|
518
493
|
lines.push(` autoInstrumentations: [${list}],`);
|
|
@@ -2240,8 +2215,7 @@ function buildPlanFromDetection(opts) {
|
|
|
2240
2215
|
for (const pkg of p.packages.optional) prod.add(pkg);
|
|
2241
2216
|
for (const pkg of p.packages.devOnly) dev.add(pkg);
|
|
2242
2217
|
}
|
|
2243
|
-
if (detection.primaryLogger
|
|
2244
|
-
if (detection.autoInstrumentedDeps.length > 0 || detection.autoInstrumentLoggers.length > 0 || detection.primaryLogger === "winston" || detection.primaryLogger === "bunyan") prod.add("@opentelemetry/auto-instrumentations-node");
|
|
2218
|
+
if (detection.autoInstrumentedDeps.length > 0 || detection.autoInstrumentLoggers.length > 0 || detection.primaryLogger !== null) prod.add("@opentelemetry/auto-instrumentations-node");
|
|
2245
2219
|
const envVars = [];
|
|
2246
2220
|
const seenEnv = /* @__PURE__ */ new Set();
|
|
2247
2221
|
for (const p of presets) for (const ev of [...p.env.required, ...p.env.optional]) {
|
|
@@ -2496,7 +2470,7 @@ function renderPlanPreview(plan) {
|
|
|
2496
2470
|
const det = plan.detected;
|
|
2497
2471
|
const pkgList = det.packages.map((p) => `${p.name}@${p.version}`).join(", ");
|
|
2498
2472
|
lines.push(`${chalk.dim("Detected packages:")} ${pkgList || chalk.dim("(none)")}`);
|
|
2499
|
-
if (det.primaryLogger !== null) lines.push(`${chalk.dim("Logger:")} ${chalk.bold(det.primaryLogger)} ${chalk.dim("(
|
|
2473
|
+
if (det.primaryLogger !== null) lines.push(`${chalk.dim("Logger:")} ${chalk.bold(det.primaryLogger)} ${chalk.dim("(auto-instrumented)")}` + (det.autoInstrumentLoggers.length > 0 ? `, ${chalk.dim("+ auto-instrumented:")} ${det.autoInstrumentLoggers.join(", ")}` : ""));
|
|
2500
2474
|
if (det.autoInstrumentedDeps.length > 0) lines.push(`${chalk.dim("Covered by auto-instrumentations-node:")} ${det.autoInstrumentedDeps.join(", ")}`);
|
|
2501
2475
|
lines.push(`${chalk.dim("Backend:")} ${chalk.bold(det.backend.slug)} ${chalk.dim(`(${det.backend.source}${det.backend.detail ? `: ${det.backend.detail}` : ""})`)}`);
|
|
2502
2476
|
if (det.platform !== null) lines.push(`${chalk.dim("Platform:")} ${chalk.bold(det.platform)}`);
|
|
@@ -2759,6 +2733,15 @@ function isCI() {
|
|
|
2759
2733
|
//#endregion
|
|
2760
2734
|
//#region src/commands/init.ts
|
|
2761
2735
|
/**
|
|
2736
|
+
* Detected deps whose auto-instrumentation goes by another name. `next` and
|
|
2737
|
+
* `fastify` have none in auto-instrumentations-node; http covers them.
|
|
2738
|
+
*/
|
|
2739
|
+
const DEP_INSTRUMENTATION = {
|
|
2740
|
+
"@aws-sdk/client-s3": ["aws-sdk"],
|
|
2741
|
+
next: [],
|
|
2742
|
+
fastify: []
|
|
2743
|
+
};
|
|
2744
|
+
/**
|
|
2762
2745
|
* Run the init command.
|
|
2763
2746
|
*
|
|
2764
2747
|
* Order of operations:
|
|
@@ -2973,8 +2956,14 @@ function applyPlan(args) {
|
|
|
2973
2956
|
source: "autotel",
|
|
2974
2957
|
specifiers: ["init"]
|
|
2975
2958
|
});
|
|
2976
|
-
|
|
2977
|
-
|
|
2959
|
+
const detected = plan.detected;
|
|
2960
|
+
const loggers = [...detected?.primaryLogger ? [detected.primaryLogger] : [], ...detected?.autoInstrumentLoggers ?? []];
|
|
2961
|
+
const deps = detected?.autoInstrumentedDeps ?? [];
|
|
2962
|
+
if (loggers.length > 0 || deps.length > 0) for (const name of [
|
|
2963
|
+
"http",
|
|
2964
|
+
...loggers,
|
|
2965
|
+
...deps.flatMap((dep) => DEP_INSTRUMENTATION[dep] ?? [dep])
|
|
2966
|
+
]) addAutoInstrumentation(codeFile, name);
|
|
2978
2967
|
for (const preset of presets) {
|
|
2979
2968
|
for (const imp of preset.imports) addImport(codeFile, imp, preset.type === "backend" || preset.type === "platform" ? "backend" : preset.type === "plugin" ? "plugin" : preset.type === "subscriber" ? "subscriber" : void 0);
|
|
2980
2969
|
if (preset.configBlock.section === "BACKEND_CONFIG") setBackendConfig(codeFile, preset.configBlock.code);
|
|
@@ -2999,8 +2988,7 @@ function applyPlan(args) {
|
|
|
2999
2988
|
...codeFile.imports,
|
|
3000
2989
|
...codeFile.backendImports,
|
|
3001
2990
|
...codeFile.pluginImports,
|
|
3002
|
-
...codeFile.subscriberImports
|
|
3003
|
-
...codeFile.loggerImports
|
|
2991
|
+
...codeFile.subscriberImports
|
|
3004
2992
|
].map((i) => i.source));
|
|
3005
2993
|
const addedAuto = diffAutoInstrumentations(parsed, codeFile.autoInstrumentations);
|
|
3006
2994
|
const contentChanged = existing !== newContent;
|