feat: add SQL instrumentation through the extension#447
Conversation
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
❌ 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.
| // 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()), | ||
| ]; |
There was a problem hiding this comment.
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~63config/sentry_instrumentation.php:65~76

Replaces query logging with extension based query logging