sentry-java icon indicating copy to clipboard operation
sentry-java copied to clipboard

Select queries are not instrumented correctly

Open stefanosiano opened this issue 1 year ago • 0 comments

Description

In Android select queries return a Cursor, and the query is actually executed when the Cursor is read. Our instrumentation wraps the query method, which is always fast. Here is an example of a transaction with a slow query select * from storeitem where first_name regexp '.*.*.*.*1'. The Dao span is correct, but the db.sql.query span is 1ms long, which is wrong. The related profile gives some more insight. This affects only select queries, as updates don't return a cursor. We should wrap the cursor with a custom wrapper and override the correct methods. Some challenges:

  • getCount() fills the data only the first time, so we should account for that
  • onMove() is not available in Cursor, but only in SQLiteCursor. But we get a Cursor and we should return a Cursor
  • accessing private fields in SQLiteCursor with reflection failed

stefanosiano avatar Dec 01 '23 16:12 stefanosiano