Skip to content

feat(observability): add wire-level sqlcommenter, zero-RTT Oracle trace piggybacking, and DuckDB statement profiling - #851

Merged
cofin merged 1 commit into
mainfrom
feat/observability-and-profiling
Oct 22, 2026
Merged

cofin merged 1 commit into
mainfrom
feat/observability-and-profiling

Conversation

@cofin

@cofin cofin commented Oct 21, 2026

Copy link
Copy Markdown
Member

Summary

Decouples wire-level sqlcommenter injection from statement AST transformers so compilation caching remains active, adds zero-RTT Oracle session trace piggybacking (MODULE, ACTION, CLIENT_IDENTIFIER, and ECID), and adds opt-in DuckDB statement profiling and per-statement execute_script observability events across duckdb and adbc.

Closes #848
Closes #810

Key Changes

Wire-Level SQLCommenter & Correlation Context (sqlspec/core/, sqlspec/driver/, sqlspec/adapters/psqlpy/)

  • Add append_wire_sqlcomment(...) in sqlspec/core/sqlcommenter.py bridging CorrelationContext.get() as a fallback for correlation_id and merging SQLCommenterContext.get() attributes without mutating the SQL object or enabling _has_transformers, preserving _stmt_cache_enabled = True when enable_sqlcommenter=True.
  • Add _wire_sqlcomment_enabled(...) and _format_wire_sql(...) in CommonDriverAttributesMixin (sqlspec/driver/_common.py) and apply wire-level comment appending in SyncDriverAdapterBase._prepare_driver_statement and AsyncDriverAdapterBase._prepare_driver_statement.
  • Compute _dml_count_query(clean_sql) before appending dynamic wire comments in PsqlpyDriver (sqlspec/adapters/psqlpy/driver.py) so @lru_cache(maxsize=512) hits remain stable across dynamic trace contexts.

Zero-RTT Oracle Session Tracing (sqlspec/adapters/oracledb/)

  • Add enable_session_tracing in driver_features and apply_oracle_session_tracing(...) in sqlspec/adapters/oracledb/core.py to stage connection.module, connection.action, connection.client_identifier, and connection.econtext_id (ECID, when supported by the python-oracledb mode) directly on the connection object before the next cursor execution round-trip with dirty-state deduplication via _sqlspec_trace_state.

DuckDB Statement Profiling & Script Observability (sqlspec/observability/, sqlspec/builder/, sqlspec/adapters/{duckdb,adbc}/)

  • Extend StatementEvent (__slots__) and ObservabilityRuntime with profile: dict[str, Any] | None, script_ordinal: int | None, and script_statement_count: int | None.
  • Fix build_duckdb_explain(...) (sqlspec/builder/_explain.py) to emit parenthesized EXPLAIN (ANALYZE, FORMAT JSON) <sql> options.
  • Add opt-in enable_statement_profiling (PRAGMA enable_profiling = 'json', PRAGMA profiling_output = '<temp_file>') and per-statement StatementEvent emission (script_ordinal, script_statement_count, and parsed JSON profile payload) in dispatch_execute_script across DuckDBConfig/DuckDBDriver and DuckDB-backed AdbcConfig/AdbcDriver.

@codecov-commenter

codecov-commenter commented Oct 21, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 78.02691% with 98 lines in your changes missing coverage. Please review.
✅ Project coverage is 81.35%. Comparing base (6d283b6) to head (a734092).
⚠️ Report is 2 commits behind head on main.

Files with missing lines Patch % Lines
sqlspec/adapters/duckdb/driver.py 68.62% 11 Missing and 5 partials ⚠️
sqlspec/adapters/adbc/driver.py 71.69% 12 Missing and 3 partials ⚠️
sqlspec/adapters/duckdb/core.py 65.11% 9 Missing and 6 partials ⚠️
sqlspec/core/sqlcommenter.py 77.77% 8 Missing and 4 partials ⚠️
sqlspec/driver/_async.py 33.33% 12 Missing ⚠️
sqlspec/adapters/oracledb/core.py 80.95% 3 Missing and 5 partials ⚠️
sqlspec/driver/_sync.py 63.15% 5 Missing and 2 partials ⚠️
sqlspec/adapters/duckdb/pool.py 84.61% 2 Missing and 2 partials ⚠️
sqlspec/adapters/oracledb/driver.py 87.50% 2 Missing and 2 partials ⚠️
sqlspec/observability/_observer.py 80.00% 2 Missing and 1 partial ⚠️
... and 1 more
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #851      +/-   ##
==========================================
- Coverage   81.36%   81.35%   -0.02%     
==========================================
  Files         527      527              
  Lines       87836    88239     +403     
  Branches    16370    16435      +65     
==========================================
+ Hits        71471    71783     +312     
- Misses      12001    12062      +61     
- Partials     4364     4394      +30     
Flag Coverage Δ
integration 60.02% <35.65%> (-0.13%) ⬇️
py3.11 79.78% <77.80%> (-0.01%) ⬇️
py3.12 79.77% <77.80%> (-0.01%) ⬇️
py3.13 79.78% <77.80%> (-0.01%) ⬇️
py3.14 80.71% <77.65%> (-0.03%) ⬇️
unit 73.51% <77.35%> (+0.05%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
sqlspec/adapters/adbc/config.py 94.49% <100.00%> (+0.52%) ⬆️
sqlspec/adapters/adbc/core.py 84.28% <100.00%> (+0.18%) ⬆️
sqlspec/adapters/duckdb/config.py 95.20% <100.00%> (+0.02%) ⬆️
sqlspec/adapters/oracledb/_typing.py 96.15% <100.00%> (+0.23%) ⬆️
sqlspec/adapters/oracledb/config.py 88.69% <100.00%> (+0.02%) ⬆️
sqlspec/adapters/psqlpy/driver.py 85.78% <100.00%> (+0.20%) ⬆️
sqlspec/builder/_explain.py 95.15% <100.00%> (+0.04%) ⬆️
sqlspec/core/statement.py 86.76% <100.00%> (+0.02%) ⬆️
sqlspec/observability/_runtime.py 82.42% <100.00%> (+0.13%) ⬆️
sqlspec/driver/_common.py 83.12% <92.00%> (+0.13%) ⬆️
... and 10 more

... and 2 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@cofin
cofin force-pushed the feat/observability-and-profiling branch 4 times, most recently from 67dfe90 to 73b8965 Compare October 22, 2026 03:57
…ce piggybacking, and DuckDB statement profiling
@cofin
cofin force-pushed the feat/observability-and-profiling branch from 73b8965 to a734092 Compare October 22, 2026 05:21
@cofin
cofin merged commit 24cc153 into main Oct 22, 2026
11 checks passed
@cofin
cofin deleted the feat/observability-and-profiling branch October 22, 2026 05:25
cofin added a commit that referenced this pull request Oct 22, 2026
## Summary

Prepares the `v0.68.0` release of SQLSpec, updates the changelog with
comprehensive release notes covering Oracle enterprise topology and 26ai
capabilities, PostgreSQL pooler modes, Google ADK v2 parity, wire-level
SQLCommenter injection, and DuckDB statement profiling, upgrades
pre-commit tools and lockfile dependencies, and resolves DuckDB Arrow
result typing.

## Key Changes

### Documentation (`docs/`)
- Add comprehensive `v0.68.0` release notes in `docs/changelog.rst`
documenting new features, changes, and fixes across PRs #840, #849,
#850, #851, and #852.

### Package & Tooling (`pyproject.toml`, `.pre-commit-config.yaml`,
`uv.lock`)
- Bump package `version` and bumpversion `current_version` to `0.68.0`
in `pyproject.toml`.
- Bump `ruff-pre-commit` hook from `v0.16.10` to `v0.17.0` in
`.pre-commit-config.yaml`.
- Update `uv.lock` with bumped `sqlspec` package version and refreshed
dependencies.

### Database Adapters (`sqlspec/adapters/duckdb/`)
- Ensure `DuckDBDriver.select_to_arrow` verifies
`cursor.to_arrow_table()` is not `None` before passing to
`build_arrow_result_from_table`, satisfying strict type checking under
updated DuckDB stubs.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

2 participants