feat(observability): add LLMTrace model and operational metrics #533

Merged
freemo merged 1 commits from feature/m6-llm-trace-metrics into master 2026-03-03 22:12:14 +00:00
Owner

Summary

Implements issue #500 — adds the LLMTrace domain model, OperationalMetricKey enum (14 keys), MetricCollector, LLMTraceRepository, and TraceService with LangSmith forwarding support and application lifecycle hooks.

Changes

New modules

  • domain/models/observability/LLMTrace, LLMTraceQuery (Pydantic v2), OperationalMetricKey, MetricEntry, MetricCollector
  • infrastructure/database/llm_trace_repository.py — SQLAlchemy-backed repository (save / get / list_by_plan / list_by_decision)
  • application/services/trace_service.py — Recording, querying, metrics aggregation, optional LangSmith forwarding, lifecycle hooks

Modified modules

  • infrastructure/database/models.py — Added LLMTraceModel (table llm_traces)
  • application/container.py — Wired TraceService + LLMTraceRepository providers
  • application/services/__init__.py — Exported TraceService

Tests & docs

  • 28 BDD scenarios (features/llm_trace.feature)
  • 6 Robot Framework smoke tests (robot/llm_trace.robot)
  • 3 ASV benchmark suites (benchmarks/llm_trace_bench.py)
  • Reference docs (docs/reference/observability.md)

Bug fix (pre-existing)

  • Fixed cli_core server_mode test flake caused by host ~/.cleveragents/config.toml leaking into tests

Quality gates

Gate Result
nox -s lint Passed
nox -s typecheck 0 errors, 0 warnings
nox -s unit_tests 250 features, 7948 scenarios, 30732 steps, 0 failures
nox -s coverage_report 97% coverage
nox -s integration_tests 1093/1097 pass (3 pre-existing failures)

Closes #500

## Summary Implements issue #500 — adds the `LLMTrace` domain model, `OperationalMetricKey` enum (14 keys), `MetricCollector`, `LLMTraceRepository`, and `TraceService` with LangSmith forwarding support and application lifecycle hooks. ## Changes ### New modules - **`domain/models/observability/`** — `LLMTrace`, `LLMTraceQuery` (Pydantic v2), `OperationalMetricKey`, `MetricEntry`, `MetricCollector` - **`infrastructure/database/llm_trace_repository.py`** — SQLAlchemy-backed repository (save / get / list_by_plan / list_by_decision) - **`application/services/trace_service.py`** — Recording, querying, metrics aggregation, optional LangSmith forwarding, lifecycle hooks ### Modified modules - **`infrastructure/database/models.py`** — Added `LLMTraceModel` (table `llm_traces`) - **`application/container.py`** — Wired `TraceService` + `LLMTraceRepository` providers - **`application/services/__init__.py`** — Exported `TraceService` ### Tests & docs - 28 BDD scenarios (`features/llm_trace.feature`) - 6 Robot Framework smoke tests (`robot/llm_trace.robot`) - 3 ASV benchmark suites (`benchmarks/llm_trace_bench.py`) - Reference docs (`docs/reference/observability.md`) ### Bug fix (pre-existing) - Fixed `cli_core` server_mode test flake caused by host `~/.cleveragents/config.toml` leaking into tests ## Quality gates | Gate | Result | |------|--------| | `nox -s lint` | ✅ Passed | | `nox -s typecheck` | ✅ 0 errors, 0 warnings | | `nox -s unit_tests` | ✅ 250 features, 7948 scenarios, 30732 steps, 0 failures | | `nox -s coverage_report` | ✅ 97% coverage | | `nox -s integration_tests` | ✅ 1093/1097 pass (3 pre-existing failures) | Closes #500
freemo force-pushed feature/m6-llm-trace-metrics from 30e90ce9b4 to 260692b72d 2026-03-03 19:53:11 +00:00 Compare
freemo scheduled this pull request to auto merge when all checks succeed 2026-03-03 19:53:28 +00:00
freemo force-pushed feature/m6-llm-trace-metrics from 260692b72d to eeae246572 2026-03-03 19:59:21 +00:00 Compare
freemo force-pushed feature/m6-llm-trace-metrics from eeae246572 to 1d5106de73 2026-03-03 21:10:43 +00:00 Compare
freemo force-pushed feature/m6-llm-trace-metrics from 1d5106de73 to e14420acc9 2026-03-03 21:13:18 +00:00 Compare
freemo force-pushed feature/m6-llm-trace-metrics from e14420acc9 to 3f14cbbf7e 2026-03-03 22:04:37 +00:00 Compare
freemo scheduled this pull request to auto merge when all checks succeed 2026-03-03 22:04:58 +00:00
freemo merged commit 3f14cbbf7e into master 2026-03-03 22:12:14 +00:00
freemo deleted branch feature/m6-llm-trace-metrics 2026-03-03 22:12:14 +00:00
freemo added the
State
Completed
label 2026-03-04 00:41:33 +00:00
Sign in to join this conversation.
No Reviewers
No Label
State
Completed
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: cleveragents/cleveragents-core#533