Skip to content

Commit 575bed3

Browse files
committed
agentgrep(feat[logging]): Add agentic logs
why: Local OTel traces showed sparse Loki coverage, leaving agentic debug loops without searchable status records for engine, TUI, MCP, and benchmark boundaries. The logs need to remain trace-linked and content-free. what: - Emit structured start, completion, and failure logs for search, find, TUI, MCP request, and benchmark boundaries. - Redact env, override, and config path warning extras before log records leave the call site. - Cover trace linkage, redaction, and non-tool MCP request logs in telemetry tests.
1 parent 80c3da2 commit 575bed3

9 files changed

Lines changed: 594 additions & 53 deletions

File tree

scripts/benchmark.py

Lines changed: 65 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
import dataclasses
3636
import io
3737
import json
38+
import logging
3839
import math
3940
import pathlib
4041
import shlex
@@ -76,6 +77,8 @@
7677
type CommandContext = dict[str, str]
7778
type ProfilePayload = dict[str, object]
7879

80+
logger = logging.getLogger("agentgrep.benchmark")
81+
7982

8083
def _telemetry_api() -> t.Any | None:
8184
"""Return the optional project telemetry API when available."""
@@ -1570,24 +1573,74 @@ def _run_one_commit(
15701573
prefer_hyperfine=prefer_hyperfine,
15711574
notify=notify,
15721575
)
1576+
started_at = time.monotonic()
15731577
with telemetry.span(
15741578
"agentgrep.benchmark.run",
15751579
agentgrep_surface="benchmark",
15761580
agentgrep_benchmark_commit=commit.short_sha,
1581+
agentgrep_benchmark_count=len(bench_names),
15771582
):
1578-
return _run_one_commit_inner(
1579-
commit=commit,
1580-
config=config,
1581-
bench_names=bench_names,
1582-
query_overrides=query_overrides,
1583-
runs=runs,
1584-
warmup=warmup,
1585-
no_sync=no_sync,
1586-
dry_run=dry_run,
1587-
repo=repo,
1588-
prefer_hyperfine=prefer_hyperfine,
1589-
notify=notify,
1583+
logger.info(
1584+
"benchmark run started",
1585+
extra={
1586+
"agentgrep_surface": "benchmark",
1587+
"agentgrep_operation": "benchmark.run",
1588+
"agentgrep_benchmark_commit": commit.short_sha,
1589+
"agentgrep_benchmark_count": len(bench_names),
1590+
"agentgrep_run_count": runs,
1591+
"agentgrep_warmup_count": warmup,
1592+
"agentgrep_dry_run": dry_run,
1593+
},
1594+
)
1595+
try:
1596+
measurements = _run_one_commit_inner(
1597+
commit=commit,
1598+
config=config,
1599+
bench_names=bench_names,
1600+
query_overrides=query_overrides,
1601+
runs=runs,
1602+
warmup=warmup,
1603+
no_sync=no_sync,
1604+
dry_run=dry_run,
1605+
repo=repo,
1606+
prefer_hyperfine=prefer_hyperfine,
1607+
notify=notify,
1608+
)
1609+
except Exception as exc:
1610+
duration_ms = (time.monotonic() - started_at) * 1000.0
1611+
telemetry.set_span_attribute("agentgrep_outcome", "error")
1612+
telemetry.set_span_attribute("agentgrep_error_type", type(exc).__name__)
1613+
telemetry.set_span_attribute("agentgrep_duration_ms", duration_ms)
1614+
logger.info(
1615+
"benchmark run failed",
1616+
extra={
1617+
"agentgrep_surface": "benchmark",
1618+
"agentgrep_operation": "benchmark.run",
1619+
"agentgrep_benchmark_commit": commit.short_sha,
1620+
"agentgrep_benchmark_count": len(bench_names),
1621+
"agentgrep_outcome": "error",
1622+
"agentgrep_error_type": type(exc).__name__,
1623+
"agentgrep_duration_ms": duration_ms,
1624+
},
1625+
)
1626+
raise
1627+
duration_ms = (time.monotonic() - started_at) * 1000.0
1628+
telemetry.set_span_attribute("agentgrep_outcome", "ok")
1629+
telemetry.set_span_attribute("agentgrep_duration_ms", duration_ms)
1630+
telemetry.set_span_attribute("agentgrep_measurement_count", len(measurements))
1631+
logger.info(
1632+
"benchmark run completed",
1633+
extra={
1634+
"agentgrep_surface": "benchmark",
1635+
"agentgrep_operation": "benchmark.run",
1636+
"agentgrep_benchmark_commit": commit.short_sha,
1637+
"agentgrep_benchmark_count": len(bench_names),
1638+
"agentgrep_measurement_count": len(measurements),
1639+
"agentgrep_outcome": "ok",
1640+
"agentgrep_duration_ms": duration_ms,
1641+
},
15901642
)
1643+
return measurements
15911644

15921645

15931646
def _run_one_commit_inner(

scripts/otel_smoke.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,11 @@ def main() -> int:
3434
):
3535
logger.info(
3636
"otel smoke started",
37-
extra={"agentgrep_surface": "otel", "agentgrep_run_id": args.run_id},
37+
extra={
38+
"agentgrep_surface": "otel",
39+
"agentgrep_operation": "otel.smoke",
40+
"agentgrep_run_id": args.run_id,
41+
},
3842
)
3943
with _telemetry.span("agentgrep.otel.smoke.sqlite", agentgrep_surface="otel"):
4044
connection = sqlite3.connect(
@@ -71,7 +75,11 @@ def main() -> int:
7175
_telemetry.set_span_attribute("agentgrep_cpu_accumulator", accumulator)
7276
logger.info(
7377
"otel smoke completed",
74-
extra={"agentgrep_surface": "otel", "agentgrep_run_id": args.run_id},
78+
extra={
79+
"agentgrep_surface": "otel",
80+
"agentgrep_operation": "otel.smoke",
81+
"agentgrep_run_id": args.run_id,
82+
},
7583
)
7684
finally:
7785
telemetry.shutdown()

scripts/profile_engine.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -656,6 +656,7 @@ def main(argv: list[str] | None = None) -> int:
656656
"profile engine completed",
657657
extra={
658658
"agentgrep_surface": "profile_engine",
659+
"agentgrep_operation": "profile_engine.run",
659660
"agentgrep_outcome": outcome,
660661
"agentgrep_exit_code": exit_code,
661662
},
@@ -666,7 +667,10 @@ def main(argv: list[str] | None = None) -> int:
666667
assert args is not None
667668
logger.info(
668669
"profile engine started",
669-
extra={"agentgrep_surface": "profile_engine"},
670+
extra={
671+
"agentgrep_surface": "profile_engine",
672+
"agentgrep_operation": "profile_engine.run",
673+
},
670674
)
671675
try:
672676
with _telemetry.span(
@@ -680,6 +684,7 @@ def main(argv: list[str] | None = None) -> int:
680684
"profile engine failed",
681685
extra={
682686
"agentgrep_surface": "profile_engine",
687+
"agentgrep_operation": "profile_engine.run",
683688
"agentgrep_outcome": "parse_error",
684689
},
685690
)
@@ -704,6 +709,7 @@ def main(argv: list[str] | None = None) -> int:
704709
"profile engine failed",
705710
extra={
706711
"agentgrep_surface": "profile_engine",
712+
"agentgrep_operation": "profile_engine.run",
707713
"agentgrep_outcome": "parse_error",
708714
},
709715
)
@@ -716,6 +722,7 @@ def main(argv: list[str] | None = None) -> int:
716722
"profile engine completed",
717723
extra={
718724
"agentgrep_surface": "profile_engine",
725+
"agentgrep_operation": "profile_engine.run",
719726
"agentgrep_outcome": "ok",
720727
"agentgrep_exit_code": 0,
721728
},

0 commit comments

Comments
 (0)