Skip to content

[on-hold] 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

…ld_handle

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@benaitcheson
benaitcheson requested review from a team and solnic as code owners November 24, 2026 22:42
@solnic

solnic commented Dec 4, 2026

Copy link
Copy Markdown
Collaborator

Thanks for tackling this. We're gonna hold off with merging this though until we can at least have a beta version of Rails 8.2 released to run the test suite against. In general we want to avoid having code in released sentry gems that is dealing with 3rd-parties that are not yet released 😄

@solnic solnic changed the title fix(rails): record spans for events reported through Instrumenter#build_handle [on-hold] fix(rails): record spans for events reported through Instrumenter#build_handle Dec 4, 2026
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)

2 participants