feat(cloudflare): Instrument SQL API in sqlite durable objects#21656
feat(cloudflare): Instrument SQL API in sqlite durable objects#21656JPeer264 wants to merge 2 commits into
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 890e3ff. Configure here.
| span.setAttributes({ | ||
| 'cloudflare.durable_object.response.rows_read': cursor.rowsRead, | ||
| 'cloudflare.durable_object.response.rows_written': cursor.rowsWritten, | ||
| }); |
There was a problem hiding this comment.
Bug: cursor.rowsRead and cursor.rowsWritten are read before the cursor is iterated, causing SQL metrics to be incorrectly reported as 0.
Severity: MEDIUM
Suggested Fix
To fix this, the cursor's iteration methods (like next(), all(), etc.) should be wrapped. The rowsRead and rowsWritten properties should only be read and set on the span after these iteration methods have been called and the cursor has been at least partially consumed. This ensures the metrics reflect the actual state of the cursor after data access.
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: packages/cloudflare/src/instrumentations/instrumentSqlStorage.ts#L40-L43
Potential issue: The instrumentation for Cloudflare's `SqlStorageCursor` reads the
`cursor.rowsRead` and `cursor.rowsWritten` properties immediately after the cursor is
created. According to official documentation, the cursor is a lazy iterator, and these
values are only populated as the cursor is iterated over. Because the instrumentation
captures these metrics before returning the cursor to the caller for consumption, the
span attributes and breadcrumbs will always record `0` for
`cloudflare.durable_object.response.rows_read` and
`cloudflare.durable_object.response.rows_written`. This renders the row tracking metrics
non-functional, as they will consistently be inaccurate in any real-world usage.
Also affects:
packages/cloudflare/src/instrumentations/instrumentSqlStorage.ts:48~51
Did we get this right? 👍 / 👎 to inform future reviews.
size-limit report 📦
|

closes #20832
closes JS-2445
This instruments
sql.exec()for an SQLite DurableObject. It adds a span and a breadcrumb for theexecmethod.It was inspired by the postgres integration, that is why the
_INTERNAL_sanitizeSqlQueryhas been now exported fromcore. I wanted to also add the span attributedb.query.summary, but the functionality didn't exist and didn't want to make the PR bigger. I'll add another PR for that functionality.This PR can only be merged once getsentry/sentry-conventions#435 has been merged