@trazum/cli 1.70.0 → 1.71.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@trazum/cli",
3
- "version": "1.70.0",
3
+ "version": "1.71.0",
4
4
  "description": "Trazum CLI: find where your LLM bill goes, price every finding per month, and enforce token budgets in CI.",
5
5
  "license": "MIT",
6
6
  "author": "David Mu\u00f1oz Rey",
@@ -37,7 +37,7 @@
37
37
  "prepublishOnly": "npm run build && npm test"
38
38
  },
39
39
  "dependencies": {
40
- "@trazum/core": "1.70.0"
40
+ "@trazum/core": "1.71.0"
41
41
  },
42
42
  "devDependencies": {
43
43
  "@types/node": "^26.2.0",
package/src/i18n/en.ts CHANGED
@@ -60,6 +60,7 @@ ${bold('USAGE')}
60
60
  trazum rollup <document...|dir> [--json] [--html-out <file>]
61
61
  trazum position <usage.jsonl>
62
62
  trazum from-claude-code <file|dir> [--label <name>] [-o <file>]
63
+ trazum from-otel <file|dir> [--label-from-service] [-o <file>]
63
64
  trazum pulse [--max-stale-hours <n>]
64
65
  trazum bench [--workload <id>] [--record <file>] [--against <file> --max-ratio <n>] [--json]
65
66
  trazum write [--answers <file>] [--json] [-o <file>]
@@ -137,6 +138,17 @@ ${bold('OPTIONS FOR write')}
137
138
  --calls <n> Calls per month, for the estimate.
138
139
  --avg-output <n> Average output tokens per call, for the estimate.
139
140
 
141
+ ${bold('OPTIONS FOR from-otel')}
142
+ --label-from-service Label each record with its span's service name,
143
+ so a per-service bill falls out.
144
+ -o, --out <file> Write the usage log there instead of stdout.
145
+
146
+ OpenTelemetry GenAI spans, read as a usage log: model, timestamp, label and
147
+ the token counts from each gen_ai.* span — and nothing else. Prompt content
148
+ and trace ids stay in the span. OTel has no cache TTL split, so cache
149
+ verdicts read "cannot tell" rather than a guessed one. Non-LLM spans are
150
+ counted and skipped, said on stderr.
151
+
140
152
  ${bold('OPTIONS FOR from-claude-code')}
141
153
  --label <name> Stamp every record with one label.
142
154
  --label-from-project Label each record with its transcript's project
@@ -1613,6 +1625,17 @@ ${bold('EXAMPLES')}
1613
1625
  },
1614
1626
  },
1615
1627
 
1628
+ fromOtel: {
1629
+ noPath: () => 'from-otel needs an OTLP file or directory: trazum from-otel spans.json',
1630
+ notFound: (path) => `${path}: not found`,
1631
+ noExports: (path) => `${path}: no .json/.jsonl/.ndjson OTLP exports under it.`,
1632
+ summary: (files, llmSpans) => `${files} file(s), ${llmSpans} LLM span(s) priced.`,
1633
+ skipped: (otherSpans) => `${otherSpans} non-LLM span(s) skipped — the trace's other work, not a bill.`,
1634
+ noCache: (count) => `${count} span(s) carried no cache data. OpenTelemetry has not standardised the cache TTL split, so the cache verdicts read "cannot tell" on this log rather than a fabricated one.`,
1635
+ unparseable: (count) => `${count} line(s) did not parse as JSON.`,
1636
+ written: (file) => `Wrote ${file}.`,
1637
+ },
1638
+
1616
1639
  fromClaudeCode: {
1617
1640
  noPath: () => 'from-claude-code needs a transcript file or directory: trazum from-claude-code ~/.claude/projects',
1618
1641
  notFound: (path) => `${path}: not found`,
package/src/i18n/es.ts CHANGED
@@ -1612,6 +1612,17 @@ ${bold('EJEMPLOS')}
1612
1612
  },
1613
1613
  },
1614
1614
 
1615
+ fromOtel: {
1616
+ noPath: () => 'from-otel necesita un archivo o directorio OTLP: trazum from-otel spans.json',
1617
+ notFound: (path) => `${path}: no existe`,
1618
+ noExports: (path) => `${path}: no hay exports OTLP .json/.jsonl/.ndjson debajo.`,
1619
+ summary: (files, llmSpans) => `${files} archivo(s), ${llmSpans} span(s) LLM tasados.`,
1620
+ skipped: (otherSpans) => `${otherSpans} span(s) no-LLM omitidos — el resto del trabajo de la traza, no una factura.`,
1621
+ noCache: (count) => `${count} span(s) sin datos de caché. OpenTelemetry no ha estandarizado el reparto del TTL de caché, así que los veredictos de caché dicen «no se puede saber» en este log en vez de uno inventado.`,
1622
+ unparseable: (count) => `${count} línea(s) no se pudieron parsear como JSON.`,
1623
+ written: (file) => `Escrito ${file}.`,
1624
+ },
1625
+
1615
1626
  fromClaudeCode: {
1616
1627
  noPath: () => 'from-claude-code necesita un archivo o directorio de transcripts: trazum from-claude-code ~/.claude/projects',
1617
1628
  notFound: (path) => `${path}: no existe`,
package/src/i18n/types.ts CHANGED
@@ -523,6 +523,22 @@ export interface CliMessages {
523
523
  * the command's honesty: what was priced, what was collapsed (one API
524
524
  * call arrives as one line per content block), and what was passed over.
525
525
  */
526
+ /**
527
+ * `trazum from-otel` — OpenTelemetry GenAI spans as a usage log. The summary
528
+ * is the command's honesty: LLM spans converted, non-LLM spans skipped, and
529
+ * how many carried no cache data (OTel has no TTL split to give).
530
+ */
531
+ fromOtel: {
532
+ noPath(): string;
533
+ notFound(path: string): string;
534
+ noExports(path: string): string;
535
+ summary(files: number, llmSpans: number): string;
536
+ skipped(otherSpans: number): string;
537
+ noCache(count: number): string;
538
+ unparseable(count: number): string;
539
+ written(file: string): string;
540
+ };
541
+
526
542
  fromClaudeCode: {
527
543
  noPath(): string;
528
544
  notFound(path: string): string;
package/src/index.ts CHANGED
@@ -111,6 +111,7 @@ import {
111
111
  parseUsageLine,
112
112
  plannedCalls,
113
113
  claudeCodeRecords,
114
+ otelRecords,
114
115
  positionAt,
115
116
  positionReport,
116
117
  PRICING_LAST_REVIEWED,
@@ -670,6 +671,7 @@ const COMMAND_FLAGS: Record<string, string[]> = {
670
671
  rollup: ['json', 'html-out'],
671
672
  position: ['json', 'html-out', 'pricing', 'pricing-live'],
672
673
  'from-claude-code': ['label', 'label-from-project', 'out', 'o'],
674
+ 'from-otel': ['label-from-service', 'out', 'o'],
673
675
  pulse: ['json', 'max-stale-hours'],
674
676
  bench: ['workload', 'json', 'record', 'against', 'max-ratio'],
675
677
  write: ['answers', 'json', 'out', 'o', 'calls', 'avg-output'],
@@ -2635,6 +2637,69 @@ async function commandFromClaudeCode(args: Args, t: CliMessages): Promise<void>
2635
2637
  console.error(t.fromClaudeCode.skipped(otherLines, unparseable, withoutUsage));
2636
2638
  }
2637
2639
 
2640
+ /**
2641
+ * `trazum from-otel <file|dir>` — OpenTelemetry GenAI spans as a usage log.
2642
+ *
2643
+ * The 1.71 move: the same pure-converter pattern generalised to the standard
2644
+ * the ecosystem is converging on, so Trazum prices whatever telemetry a team
2645
+ * already emits. `otelRecords` in core does the reading; this is the walk and
2646
+ * the honesty — how many spans were LLM calls, how many were skipped as
2647
+ * non-LLM, how many carried no cache data (the OTel norm, since it has not
2648
+ * standardised the TTL split). Prompt content, trace ids and every other span
2649
+ * attribute stay in the span; a fixture greps the whole output to prove it.
2650
+ */
2651
+ async function commandFromOtel(args: Args, t: CliMessages): Promise<void> {
2652
+ const target = args.positional[0];
2653
+ if (target === undefined) throw new Error(t.fromOtel.noPath());
2654
+
2655
+ let info;
2656
+ try {
2657
+ info = await stat(target);
2658
+ } catch {
2659
+ throw new Error(t.fromOtel.notFound(target));
2660
+ }
2661
+ const files: string[] = [];
2662
+ if (info.isDirectory()) {
2663
+ const entries = await readdir(target, { recursive: true, withFileTypes: true });
2664
+ for (const entry of entries) {
2665
+ if (entry.isFile() && /\.(json|jsonl|ndjson)$/i.test(entry.name)) {
2666
+ files.push(join(entry.parentPath, entry.name));
2667
+ }
2668
+ }
2669
+ files.sort();
2670
+ if (files.length === 0) throw new Error(t.fromOtel.noExports(target));
2671
+ } else {
2672
+ files.push(target);
2673
+ }
2674
+
2675
+ const lines: string[] = [];
2676
+ let llmSpans = 0;
2677
+ let otherSpans = 0;
2678
+ let noCacheData = 0;
2679
+ let unparseable = 0;
2680
+ for (const file of files) {
2681
+ const conversion = otelRecords(await readFile(file, 'utf8'));
2682
+ for (const record of conversion.records) lines.push(JSON.stringify(record));
2683
+ llmSpans += conversion.llmSpans;
2684
+ otherSpans += conversion.otherSpans;
2685
+ noCacheData += conversion.noCacheData;
2686
+ unparseable += conversion.unparseable;
2687
+ }
2688
+
2689
+ const out = stringFlag(args, 'out') ?? stringFlag(args, 'o');
2690
+ if (out !== undefined) {
2691
+ await writeFile(out, lines.join('\n') + (lines.length > 0 ? '\n' : ''), 'utf8');
2692
+ console.error(t.fromOtel.written(out));
2693
+ } else {
2694
+ for (const line of lines) console.log(line);
2695
+ }
2696
+
2697
+ console.error(t.fromOtel.summary(files.length, llmSpans));
2698
+ if (otherSpans > 0) console.error(t.fromOtel.skipped(otherSpans));
2699
+ if (noCacheData > 0) console.error(t.fromOtel.noCache(noCacheData));
2700
+ if (unparseable > 0) console.error(t.fromOtel.unparseable(unparseable));
2701
+ }
2702
+
2638
2703
  /**
2639
2704
  * `trazum position <usage.jsonl>` — where the month stands, measured.
2640
2705
  *
@@ -11029,6 +11094,9 @@ async function main(): Promise<void> {
11029
11094
  case 'from-claude-code':
11030
11095
  await commandFromClaudeCode(args, t);
11031
11096
  break;
11097
+ case 'from-otel':
11098
+ await commandFromOtel(args, t);
11099
+ break;
11032
11100
  case 'pulse':
11033
11101
  await commandPulse(args, t);
11034
11102
  break;