Skip to content

feat: add opt-in DBQueryTracer for per-request DB query tracing#471

Open
Youssef-SH wants to merge 2 commits intoNetflix:masterfrom
Youssef-SH:feat/db-query-tracing-execute-sql
Open

feat: add opt-in DBQueryTracer for per-request DB query tracing#471
Youssef-SH wants to merge 2 commits intoNetflix:masterfrom
Youssef-SH:feat/db-query-tracing-execute-sql

Conversation

@Youssef-SH
Copy link
Copy Markdown

Summary

Implements Issue #5 by adding opt-in per-request DB query tracing in execute_sql().

All DB access flows through this method. This introduces DBQueryTracer to record:

  • query count
  • rows returned
  • execution time

Tracing is scoped via ContextVar, ensuring isolation per async request.
When disabled, it is a no-op (single conditional check, no overhead).

Validation

Tested on the dev stack using real endpoints:

GET /flows/TestFlow/runs

  • query_count: 1
  • total_rows: 3

GET /flows/TestFlow/runs/3/steps/start/tasks

  • query_count: 2
  • total_rows: 2

The first endpoint executes a single DB query.
The second demonstrates query fan-out across multiple DB calls.

Notes

  • Fully orthogonal to API behavior and schema
  • Single instrumentation point (execute_sql())
  • Enables per-request DB cost visibility for agent workloads

execute_sql() is the single path for all database access. This adds an opt-in tracer
that records query count, rows returned, and execution time.

Tracing is context-local via ContextVar, ensuring isolation per async request and
avoiding global state. No overhead when tracing is disabled.
Comment thread services/data/postgres_async_db.py
Comment thread services/data/postgres_async_db.py
Comment thread services/data/postgres_async_db.py
Comment thread services/data/postgres_async_db.py
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.

2 participants