Prerequisites
What are you trying to do that currently feels hard or impossible?
Summary
Introduce a centralized SQLCommenter integration that automatically appends
metadata (action, controller, db_driver, traceparent) to every
database request (SQL statements and BigQuery job labels). This will give
operators full trace correlation between AI‑driven tool calls and the
underlying database activity.
Motivation
- Unified observability – no longer need to sprinkle manual comment logic
in each tool implementation.
- Trace correlation – the OpenTelemetry
traceparent tag lets Cloud
Monitoring link the AI request to the database query.
- Zero runtime overhead – only a string concatenation before the query is
executed.
- Future‑proof – new database sources automatically inherit the behavior.
Suggested Solution(s)
Proposed Design (high‑level)
- Core helper –
internal/sqlcommenter/commenter.go will expose
AppendComment(ctx, sql) that reads the request context for:
toolName (the tool being executed)
controller (the agent name, from TOOLBOX_AGENT_NAME)
db_driver (derived from the source type)
traceparent (from the current OpenTelemetry span, if any)
- Context injection – modify
internal/server/api.go (and the MCP
method files) to store toolName and controller in the request context
before the tool handler runs.
- Source updates – each source’s
RunSQL method calls
sqlcommenter.AppendComment before executing the query.
This includes Postgres, MySQL, BigQuery, SQLite, MSSQL, CockroachDB,
AlloyDB, SingleStore, etc.
- BigQuery job labels – the same tags are added to
JobLabels so they
appear in Cloud Logging.
- OpenTelemetry – add the
traceparent tag to enable end‑to‑end tracing.
- Tests – add unit tests (
internal/sqlcommenter/commenter_test.go) that
verify the generated comment contains all fields when the context is set.
- Documentation – add a design note in
docs/sqlcommenter_design.md
Alternatives Considered
No response
Additional Details
No response
Prerequisites
What are you trying to do that currently feels hard or impossible?
Summary
Introduce a centralized SQLCommenter integration that automatically appends
metadata (
action,controller,db_driver,traceparent) to everydatabase request (SQL statements and BigQuery job labels). This will give
operators full trace correlation between AI‑driven tool calls and the
underlying database activity.
Motivation
in each tool implementation.
traceparenttag lets CloudMonitoring link the AI request to the database query.
executed.
Suggested Solution(s)
Proposed Design (high‑level)
internal/sqlcommenter/commenter.gowill exposeAppendComment(ctx, sql)that reads the requestcontextfor:toolName(the tool being executed)controller(the agent name, fromTOOLBOX_AGENT_NAME)db_driver(derived from the source type)traceparent(from the current OpenTelemetry span, if any)internal/server/api.go(and the MCPmethod files) to store
toolNameandcontrollerin the request contextbefore the tool handler runs.
RunSQLmethod callssqlcommenter.AppendCommentbefore executing the query.This includes Postgres, MySQL, BigQuery, SQLite, MSSQL, CockroachDB,
AlloyDB, SingleStore, etc.
JobLabelsso theyappear in Cloud Logging.
traceparenttag to enable end‑to‑end tracing.internal/sqlcommenter/commenter_test.go) thatverify the generated comment contains all fields when the context is set.
docs/sqlcommenter_design.mdAlternatives Considered
No response
Additional Details
No response