Skip to content

fix(rails): record spans for events reported through Instrumenter#build_handle - #3241

Open
benaitcheson wants to merge 1 commit into
getsentry:masterfrom
benaitcheson:fix/rails-build-handle-start-timestamp
Open

benaitcheson wants to merge 1 commit into
getsentry:masterfrom
benaitcheson:fix/rails-build-handle-start-timestamp

Conversation

@benaitcheson

Copy link
Copy Markdown

Description

On Rails main, Active Record reports queries through ActiveSupport::Notifications::Instrumenter#build_handle instead of #instrument. The SDK only sets sentry_start_timestamp in #instrument, so every query that reaches the database lost its span, and only query cache hits were recorded.

This sets the start time in #build_handle as well (Rails 7.1+). #instrument calls #build_handle on those versions, so ||= keeps the timestamp #instrument already set and skips a second clock read.

Tested locally:

  • Rails 8.1: sentry-rails specs pass (the solid_queue specs weren't run). The new spec fails without the fix.
  • Rails main (rails/rails@c60254e): the ActiveRecordSubscriber specs pass; 5 of 6 failed before. The dummy app needs a local workaround to boot repeatedly on main, which now freezes inflections after initialisation, so that workaround isn't part of this PR. ActiveStorageSubscriber "records the upload event" also fails on main, with or without this change.

resolves: #3240

🤖 Generated with Claude Code

@benaitcheson
benaitcheson requested review from a team and solnic as code owners November 24, 2026 22:42
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.

sentry-rails drops sql.active_record spans on Rails main (8.2.0.alpha)

1 participant