Skip to content

feat: add SQL instrumentation through the extension#447

Open
Litarnus wants to merge 6 commits into
mainfrom
more-extension-instrumentation
Open

feat: add SQL instrumentation through the extension#447
Litarnus wants to merge 6 commits into
mainfrom
more-extension-instrumentation

Conversation

@Litarnus

@Litarnus Litarnus commented Jul 7, 2026

Copy link
Copy Markdown
Contributor

Replaces query logging with extension based query logging

@Litarnus Litarnus marked this pull request as ready for review July 7, 2026 15:58
@Litarnus Litarnus requested a review from a team as a code owner July 7, 2026 15:58
Comment thread config/sentry_instrumentation.php
Comment thread config/sentry_instrumentation.php Outdated
Comment thread config/bootstrap.php
Comment thread config/sentry_instrumentation.php Outdated
Comment thread config/sentry_instrumentation.php Outdated

@cursor cursor Bot left a comment

Copy link
Copy Markdown

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 1 potential issue.

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 af4d0d9. Configure here.

Comment thread config/sentry_instrumentation.php
Comment on lines +28 to +38
// Handle parenthesized statements like "(SELECT ...)" and capture the SQL operation.
$operation = preg_match('/^\(*(\w+)/', $query, $matches) === 1
? strtoupper($matches[1])
: 'QUERY';

return [
'description' => $query,
'db.operation' => $operation,
'db.query.text' => $query,
'db.query.parameter_count' => count($params ?? $statement->getBoundParams()),
];

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Bug: The preprocessing callback has an incorrect signature, causing a fatal TypeError when instrumented database methods are called because it receives a Driver object instead of a StatementInterface.
Severity: CRITICAL

Suggested Fix

Update the preprocessing callback signatures to accept the object instance as the first argument. For example, change static function (StatementInterface $statement, ?array $params = null) to static function (object $driver, StatementInterface $statement, ?array $params = null). This fix should be applied to all similar callbacks.

Prompt for AI Agent
Review the code at the location below. A potential bug has been identified by an AI
agent. Verify if this is a real issue. If it is, propose a fix; if not, explain why it's
not valid.

Location: config/sentry_instrumentation.php#L25-L38

Potential issue: The `preprocessing` callback defined for Sentry instrumentation has an
incorrect signature. The Sentry PHP extension's instrumentation pattern for instance
methods passes the object instance (`Driver`) as the first argument, but the callback is
defined as `static function (StatementInterface $statement, ?array $params = null)`.
This mismatch causes the `$statement` parameter to incorrectly hold the `Driver` object.
Consequently, the call to `$statement->queryString()` will trigger a fatal `TypeError`
because the `Driver` class does not have a `queryString()` method. This bug will crash
nearly all database operations, including calls to `Driver::executeStatement()` and
`Driver::exec()`.

Also affects:

  • config/sentry_instrumentation.php:50~63
  • config/sentry_instrumentation.php:65~76

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.

2 participants