Skip to content

feat(collector): minimal FastAPI trace collector#4

Merged
Svaag merged 1 commit into
mainfrom
feat/collector-service
Jun 29, 2026
Merged

feat(collector): minimal FastAPI trace collector#4
Svaag merged 1 commit into
mainfrom
feat/collector-service

Conversation

@Svaag

@Svaag Svaag commented Jun 29, 2026

Copy link
Copy Markdown
Contributor

The C2 piece of the trace pipeline: a minimal service that ingests agent-core TraceEvents.

  • agent_core/collector/app.py — FastAPI: POST /v1/trace, POST /v1/trace/batch
    (both validated by the shared TraceEvent contract → 422 on bad input), GET /v1/trace
    (recent / by run_id), GET /healthz.
  • agent_core/collector/db.py — async SQLAlchemy trace_events (sqlite for tests, Postgres
    via HYRULE_COLLECTOR_DATABASE_URL); flattens cost/labels into columns + keeps the full
    event JSON.
  • python -m agent_core.collector to run. Lives behind the optional collector extra,
    so import agent_core.contracts stays dependency-light (no-heavy-imports test still green).

ruff + mypy clean; 36 tests pass (+4 collector). Next: C3 deploy (Postgres + ansible),
C4 point producers at it.

🤖 Generated with Claude Code

POST /v1/trace + /v1/trace/batch (validated by the TraceEvent contract), GET /v1/trace, /healthz; async SQLAlchemy store (sqlite for tests, Postgres via HYRULE_COLLECTOR_DATABASE_URL in prod). Optional 'collector' extra so core contracts stay dependency-light; run with 'python -m agent_core.collector'. ruff + mypy clean; 36 tests pass.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@Svaag Svaag merged commit 9daf2ef into main Jun 29, 2026
1 check passed
@Svaag Svaag deleted the feat/collector-service branch June 29, 2026 11:09

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 2535bf41dc

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread pyproject.toml

[project.optional-dependencies]
dev = ["pytest>=8", "pyyaml>=6", "ruff>=0.5", "mypy>=1.8", "types-PyYAML"]
collector = ["fastapi>=0.110", "uvicorn>=0.29", "sqlalchemy>=2", "asyncpg>=0.29"]

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Add aiosqlite to the collector extra

When a user installs agent-core[collector] and runs the documented default collector without HYRULE_COLLECTOR_DATABASE_URL, the app falls back to sqlite+aiosqlite:///./collector.db in collector/db.py, but this extra installs asyncpg and not aiosqlite. In that default path SQLAlchemy cannot load the SQLite async driver, so python -m agent_core.collector fails before serving; include aiosqlite in the collector extra or avoid a SQLite default.

Useful? React with 👍 / 👎.


@app.get("/v1/trace")
async def recent(run_id: str | None = None, limit: int = 50) -> list[dict[str, Any]]:
stmt = select(TraceEventRow).order_by(TraceEventRow.id.desc()).limit(min(limit, 500))

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Reject negative trace limits

When clients call /v1/trace?limit=-1 against the default SQLite store, min(limit, 500) passes the negative value through; SQLite treats a negative LIMIT as unbounded, so this bypasses the apparent 500-row cap and can load every stored trace JSON into memory. Add lower-bound validation or clamp the value before applying it.

Useful? React with 👍 / 👎.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant