Skip to content

feat(sql): add base sql/driver wrappers#1281

Open
giortzisg wants to merge 2 commits into
masterfrom
feat/sql
Open

feat(sql): add base sql/driver wrappers#1281
giortzisg wants to merge 2 commits into
masterfrom
feat/sql

Conversation

@giortzisg
Copy link
Copy Markdown
Contributor

@giortzisg giortzisg commented Apr 24, 2026

Description

This PR adds the base passthrough wrappers for database/sql/driver and the public API . Instrumentation will be added in a follow-up PR.

The core design is for sentryConn to always expose context-aware interfaces. Then each method delegates to the underlying driver implementation. For legacy drivers the wrapper falls back to the non-context methods. This way we can correctly instrument the legacy drivers as well with the correct context.

Issues

Changelog Entry Instructions

To add a custom changelog entry, uncomment the section above. Supports:

  • Single entry: just write text
  • Multiple entries: use bullet points
  • Nested bullets: indent 4+ spaces

For more details: custom changelog entries

Reminders

@giortzisg giortzisg self-assigned this Apr 24, 2026
@linear-code
Copy link
Copy Markdown

linear-code Bot commented Apr 24, 2026

Copy link
Copy Markdown

@cursor cursor Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes and found 2 potential issues.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit 3f8f67c. Configure here.

Comment thread sql/stmt.go
return ch.CheckNamedValue(nv)
}
return driver.ErrSkip
}
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Stmt wrapper bypasses conn-level NamedValueChecker

Medium Severity

sentryStmt unconditionally implements driver.NamedValueChecker. The Go stdlib's driverArgsConnLocked checks the stmt for this interface first, then falls back to the conn. Because sentryStmt always claims to implement it, the conn-level NamedValueChecker is never consulted for prepared statements. When the underlying stmt lacks NamedValueChecker but the underlying conn has one (common in drivers like lib/pq for custom types like pq.Array), the wrapper returns ErrSkip and the stdlib falls through to DefaultParameterConverter instead of using the conn's checker — breaking custom type handling.

Additional Locations (1)
Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit 3f8f67c. Configure here.

Comment thread sql/conn.go
case <-ctx.Done():
return nil, errors.Join(ctx.Err(), tx.Rollback())
}
return tx, nil
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

BeginTx legacy fallback checks context after Begin

Medium Severity

In the legacy BeginTx fallback path, c.Begin() is called before checking ctx.Done(). The Go stdlib's ctxDriverBegin checks context cancellation before calling ci.Begin(). This means the wrapper starts a transaction on the database even when the context is already cancelled, then immediately rolls it back — causing unnecessary database round-trips and a different error shape (errors.Join of context error and potential rollback error).

Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit 3f8f67c. Configure here.

Comment thread sql/conn.go
Comment on lines +63 to +67
select {
default:
case <-ctx.Done():
return nil, ctx.Err()
}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Honestly this is useless, it just guards whenever the cancel is called before we call the ex.Exec(). If it's already passed, then it won't be canceled at all.

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(sql): implement sentrysql sub-module with passthrough driver wrappers

2 participants