Add `perf` as the 12th skinny package with full OpenTelemetry instrumentation for pipeline traces, Prometheus metrics, and Loki-correlated logs. - src/perf/: TracerProvider, MeterProvider, LoggerProvider bridge, PipelineCollector, psutil system metrics, FileExporter fallback, FastAPI middleware, auto-file Gitea issues on step/test failure - infra/otel/: OTel Collector fan-out (traces→Jaeger, metrics→Prometheus, logs→Loki), all services migrated from jaeger:4317 to collector - infra/grafana/dashboards/: 8-panel pipeline performance dashboard - Pipeline runner auto-instruments all 189 steps with zero-cost MockTracer/MockSpan no-ops when telemetry is disabled - 82 new tests, 12,055 total passing Closes #203, closes #204, closes #205, closes #206, closes #207, closes #208, closes #209, closes #210, closes #211, closes #212, closes #213
63 lines
1.7 KiB
Python
63 lines
1.7 KiB
Python
"""CLI subcommand for pipeline telemetry utilities."""
|
|
|
|
from __future__ import annotations
|
|
|
|
import json
|
|
from pathlib import Path
|
|
|
|
import typer
|
|
|
|
app = typer.Typer(no_args_is_help=True)
|
|
|
|
|
|
@app.command()
|
|
def show(
|
|
path: str = typer.Option(
|
|
"traces/spans.jsonl",
|
|
help="Path to JSONL span file.",
|
|
),
|
|
last: int = typer.Option(
|
|
20,
|
|
help="Show last N spans.",
|
|
),
|
|
) -> None:
|
|
"""Pretty-print spans from the local JSONL trace file."""
|
|
p = Path(path)
|
|
if not p.exists():
|
|
typer.echo(f"No trace file at {p}")
|
|
raise typer.Exit(1)
|
|
|
|
lines = p.read_text().strip().split("\n")
|
|
spans = [json.loads(line) for line in lines[-last:]]
|
|
|
|
if not spans:
|
|
typer.echo("No spans found.")
|
|
raise typer.Exit(0)
|
|
|
|
for span in spans:
|
|
trace_id = span.get("trace_id", "?")[:12]
|
|
name = span.get("name", "?")
|
|
attrs = span.get("attributes", {})
|
|
status = span.get("status", {}).get("status_code", "?")
|
|
|
|
# Duration
|
|
start = span.get("start_time", 0)
|
|
end = span.get("end_time", 0)
|
|
if start and end:
|
|
dur_ms = (end - start) / 1_000_000
|
|
dur_str = f"{dur_ms:.1f}ms"
|
|
else:
|
|
dur_str = "?"
|
|
|
|
# Key attributes
|
|
parts = []
|
|
if "rows.out" in attrs:
|
|
parts.append(f"rows={attrs['rows.out']}")
|
|
if "cache.hit" in attrs:
|
|
parts.append("cache=HIT" if attrs["cache.hit"] else "cache=MISS")
|
|
if "memory.delta_mb" in attrs:
|
|
parts.append(f"mem={attrs['memory.delta_mb']:+.1f}MB")
|
|
attr_str = " ".join(parts)
|
|
|
|
typer.echo(f" {trace_id} {name:<40} {dur_str:>10} {status:<4} {attr_str}")
|