feat: add SQLCommenter observability to database drivers (fixes #2899)#2913
feat: add SQLCommenter observability to database drivers (fixes #2899)#2913tanujbolisetty wants to merge 5 commits intogoogleapis:mainfrom
Conversation
|
Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA). View this failed invocation of the CLA check for more information. For the most up to date status, view the checks section at the bottom of the pull request. |
There was a problem hiding this comment.
Code Review
This pull request implements the SQLCommenter observability layer across all SQL-capable database drivers, enabling query tracking by tool name, agent identity, and trace metadata. It introduces the internal/sqlcommenter package and updates the MCP server to persist agent names across sessions. Feedback identifies a memory leak in the session name map, suggests refactoring duplicated RunSQL logic in the CockroachDB source, and recommends using %20 for space encoding to ensure strict adherence to the SQLCommenter specification.
8f3c9c0 to
9836bd1
Compare
9836bd1 to
b24f64f
Compare
…bstraction drivers
🚀 Overview
This PR introduces SQLCommenter observability across all supported database drivers in the GenAI Toolbox. It automatically injects rich contextual metadata (tool name, framework, agent controller, database driver, and OpenTelemetry traceparent) into every query executed by the toolbox.
By standardizing this telemetry pattern, downstream database administrators and cloud monitoring tools (like Cloud SQL Insights) can seamlessly map database loads back to specific AI agents and MCP tools without any manual parsing.
🛠 Features & Modifications
1. Comprehensive Driver Coverage
We have instrumented the
RunSQLmethod on 100% of SQL-capable database sources.The metadata is injected safely as a block comment (
/* ... */) before the trailing semicolon (where applicable) to preserve syntax parsing.alloydbpg,clickhouse,cockroachdb,cloudsqlmssql,cloudsqlmysql,cloudsqlpg,firebird,mindsdb,mssql,mysql,oceanbase,oracle,postgres,singlestore,snowflake,spanner,sqlite,tidb,trino,yugabytedb.cassandra(CQL) andcouchbase(N1QL). For Couchbase, the SourceRunSQLsignature and corresponding Tool wrapperInvokeinterface were refactored to explicitly acceptcontext.Contextto enable propagation.bigqueryis instrumented via native BigQuery Job Labels instead of SQL Comments, leveraging the same contextual map.mongodb,firestore,redis,bigtable,dgraph) were explicitly skipped as they do not support standard SQL comment blocks, preventing catastrophic parsing crashes.2. Context Injection Pipeline
Created
internal/sqlcommenter/commenter.goto handle context reading, deterministic key sorting, formatting (RFC 3986 URL encoding), and OpenTelemetry span extraction.MCP Auto-Context Pipeline:
internal/server/server.gowas updated to trap theclientInfo.namepayload from the MCPinitializehandshake in a concurrentmcpClientNamessync map.api.goextracts this dynamically during tool invocation to populate thecontrollerfield automatically (e.g. associating queries directly with "Mosa" or "Claude Desktop").Fallback configurations
TOOLBOX_APP_NAMEandTOOLBOX_AGENT_NAMEwere established to manually override the context if needed.3. Core Framework & Build Architecture Upgrades
These changes resolve significant localized testing and binary compilation blockers encountered during development:
internal/server/server.goconfiguration booting logic so that passing the--uiconfig implicitly turns on the REST API endpoints (if cfg.EnableAPI || cfg.UI).oci_cgo.goandoci_pure.go). By leveraging Go build tags (//go:build cgo), the toolbox now dynamically compiles using the lightweightgo-ora/v2Pure Go driver by default, entirely sidestepping notoriously complexgodrorC compiler dependencies native to Oracle cross-compilation.🧪 Verification
go test ./internal/sqlcommenter/....WithDBDriverandWithToolNamecontext decorators directly, avoiding the need for live mocked database instances in CI.go build ./...successfully compiles across pure GO targets natively.📝 Documentation
Overhauled
docs/SQLCOMMENTER_README.mdand explicitly mapped out the full driver support matrix, environment overrides, and NoSQL exclusions.Recommendation: Ensure
DEVELOPER.mdor the primaryREADME.mdis updated to highlight that the default codebase cross-compiles with Oracle's PureGo driver to unblock new developers!