From f8817c540057cfc34ca7fc8b77865177e84ce10b Mon Sep 17 00:00:00 2001 From: Peter Solnica Date: Tue, 19 May 2026 13:12:56 +0000 Subject: [PATCH 1/2] fix(rails): make db span scale assertion flake-proof Replace the flaky timing window with the span-containment invariant: a child span cannot outlast its enclosing transaction. Catches a seconds vs milliseconds scale regression without depending on CI query timing. Co-Authored-By: Claude Opus 4.7 (1M context) --- sentry-rails/spec/sentry/rails/tracing_spec.rb | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/sentry-rails/spec/sentry/rails/tracing_spec.rb b/sentry-rails/spec/sentry/rails/tracing_spec.rb index 1adf2d7fb..65988bc88 100644 --- a/sentry-rails/spec/sentry/rails/tracing_spec.rb +++ b/sentry-rails/spec/sentry/rails/tracing_spec.rb @@ -52,11 +52,9 @@ expect(second_span[:description]).to eq("SELECT \"posts\".* FROM \"posts\"") expect(second_span[:parent_span_id]).to eq(first_span[:span_id]) - # this is to make sure we calculate the timestamp in the correct scale (second instead of millisecond) - # Use more relaxed bounds for JRuby compatibility - min_duration = 10.0 / 1_000_000 # 10 microseconds - max_duration = RUBY_PLATFORM == "java" ? 50.0 / 1000 : 10.0 / 1000 # 50ms for JRuby, 10ms for others - expect(second_span[:timestamp] - second_span[:start_timestamp]).to be_between(min_duration, max_duration) + expect(second_span[:timestamp] - second_span[:start_timestamp]).to be > 0 + expect(second_span[:start_timestamp]).to be >= transaction[:start_timestamp] + expect(second_span[:timestamp]).to be <= transaction[:timestamp] end it "records transaction alone" do @@ -91,11 +89,9 @@ ) expect(second_span[:parent_span_id]).to eq(first_span[:span_id]) - # this is to make sure we calculate the timestamp in the correct scale (second instead of millisecond) - # Use more relaxed bounds for JRuby compatibility - min_duration = 10.0 / 1_000_000 # 10 microseconds - max_duration = RUBY_PLATFORM == "java" ? 50.0 / 1000 : 10.0 / 1000 # 50ms for JRuby, 10ms for others - expect(second_span[:timestamp] - second_span[:start_timestamp]).to be_between(min_duration, max_duration) + expect(second_span[:timestamp] - second_span[:start_timestamp]).to be > 0 + expect(second_span[:start_timestamp]).to be >= transaction[:start_timestamp] + expect(second_span[:timestamp]).to be <= transaction[:timestamp] third_span = transaction[:spans][2] expect(third_span[:op]).to eq("template.render_template.action_view") From 8c76258a93115ab3ed33341767b7d8720afe542e Mon Sep 17 00:00:00 2001 From: Peter Solnica Date: Wed, 20 May 2026 10:32:54 +0000 Subject: [PATCH 2/2] chore(rails): skip unstable active storage spec on jruby --- .../sentry/rails/tracing/active_storage_subscriber_spec.rb | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/sentry-rails/spec/sentry/rails/tracing/active_storage_subscriber_spec.rb b/sentry-rails/spec/sentry/rails/tracing/active_storage_subscriber_spec.rb index 54b4eda9c..f41b379e1 100644 --- a/sentry-rails/spec/sentry/rails/tracing/active_storage_subscriber_spec.rb +++ b/sentry-rails/spec/sentry/rails/tracing/active_storage_subscriber_spec.rb @@ -2,7 +2,9 @@ require "spec_helper" -RSpec.describe Sentry::Rails::Tracing::ActiveStorageSubscriber, :subscriber, type: :request, skip: Rails.version.to_f <= 5.2 do +# Skipped on JRuby because it's very flaky there due to shelling out to use imagemagick CLI +RSpec.describe Sentry::Rails::Tracing::ActiveStorageSubscriber, :subscriber, type: :request, + skip: Rails.version.to_f <= 5.2 || RUBY_PLATFORM == "java" do let(:transport) do Sentry.get_current_client.transport end