Skip to content

feat: add Google SQLCommenter support and ADK stale-session detection#408

Merged
cofin merged 11 commits intomainfrom
feat/sqlcommenter
Apr 7, 2026
Merged

feat: add Google SQLCommenter support and ADK stale-session detection#408
cofin merged 11 commits intomainfrom
feat/sqlcommenter

Conversation

@cofin
Copy link
Copy Markdown
Member

@cofin cofin commented Apr 6, 2026

Summary

  • Add spec-compliant Google SQLCommenter support using sqlglot AST-level comment injection
  • Comments are added via expression.add_comments() on the parsed expression tree, coexisting with existing SQL comments and optimizer hints (/*+ ... */)
  • Integrates as a statement_transformer (AST-level), not output_transformer (string-level)
  • ADK: implement stale-session detection

cofin and others added 11 commits April 6, 2026 21:42
Implements Google SQLCommenter spec: URL-encoded key-value pairs
in lexicographically sorted SQL comments for query attribution.
Includes generate_comment(), append_comment(), and parse_comment()
with full round-trip fidelity.
Follows the existing extension pattern (otel, prometheus, etc.)
rather than living at the top level.
- create_sqlcommenter_transformer() factory with static attr caching
- StatementConfig gains enable_sqlcommenter, sqlcommenter_attributes,
  and sqlcommenter_enable_traceparent flags
- Auto-constructs output_transformer with chaining support
- W3C traceparent auto-population from OpenTelemetry span context
- Move tests to extensions/test_sqlcommenter/
- SQLCommenterContext for request-scoped attribute storage
- Litestar SQLCommenterMiddleware extracts route/controller/action
- Starlette/FastAPI SQLCommenterMiddleware extracts route/action
- Transformer enable_context flag reads from SQLCommenterContext
- StatementConfig gains sqlcommenter_enable_context flag
- Move from sqlspec/extensions/sqlcommenter/ to sqlspec/core/sqlcommenter.py
- Replace string-based comment manipulation with sqlglot AST
  (expression.add_comments) so sqlcommenter coexists with existing
  comments and optimizer hints
- Change from output_transformer to statement_transformer (AST-level)
- StatementConfig appends sqlcommenter transformer to statement_transformers
  instead of wrapping output_transformer
- Included in mypyc compilation via existing core/**/*.py glob
Oracle fixed their packaging — 9.6.0 ships cp312, cp313, and cp314
wheels. The exclude-newer-package constraint is no longer needed.
- Introduced configuration options for enabling SQLCommenter middleware in SQLSpecConfigState.
- Updated SQLSpecPlugin to manage SQLCommenter middleware initialization based on configuration.
- Implemented SQLCommenterMiddleware to capture SQL comments with correlation IDs.
- Enhanced unit tests to cover SQLCommenter functionality and correlation ID integration.
- Updated dependencies in lock file for compatibility with Python versions.
@cofin cofin merged commit 8961725 into main Apr 7, 2026
16 checks passed
@cofin cofin deleted the feat/sqlcommenter branch April 7, 2026 15:34
@cofin cofin linked an issue Apr 7, 2026 that may be closed by this pull request
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.

feat: Add Google SQLCommenter support for automatic query attribution

1 participant