Skip to content

Commit f8817c5

Browse files
solnicclaude
andcommitted
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) <noreply@anthropic.com>
1 parent 1e5ad01 commit f8817c5

1 file changed

Lines changed: 6 additions & 10 deletions

File tree

sentry-rails/spec/sentry/rails/tracing_spec.rb

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -52,11 +52,9 @@
5252
expect(second_span[:description]).to eq("SELECT \"posts\".* FROM \"posts\"")
5353
expect(second_span[:parent_span_id]).to eq(first_span[:span_id])
5454

55-
# this is to make sure we calculate the timestamp in the correct scale (second instead of millisecond)
56-
# Use more relaxed bounds for JRuby compatibility
57-
min_duration = 10.0 / 1_000_000 # 10 microseconds
58-
max_duration = RUBY_PLATFORM == "java" ? 50.0 / 1000 : 10.0 / 1000 # 50ms for JRuby, 10ms for others
59-
expect(second_span[:timestamp] - second_span[:start_timestamp]).to be_between(min_duration, max_duration)
55+
expect(second_span[:timestamp] - second_span[:start_timestamp]).to be > 0
56+
expect(second_span[:start_timestamp]).to be >= transaction[:start_timestamp]
57+
expect(second_span[:timestamp]).to be <= transaction[:timestamp]
6058
end
6159

6260
it "records transaction alone" do
@@ -91,11 +89,9 @@
9189
)
9290
expect(second_span[:parent_span_id]).to eq(first_span[:span_id])
9391

94-
# this is to make sure we calculate the timestamp in the correct scale (second instead of millisecond)
95-
# Use more relaxed bounds for JRuby compatibility
96-
min_duration = 10.0 / 1_000_000 # 10 microseconds
97-
max_duration = RUBY_PLATFORM == "java" ? 50.0 / 1000 : 10.0 / 1000 # 50ms for JRuby, 10ms for others
98-
expect(second_span[:timestamp] - second_span[:start_timestamp]).to be_between(min_duration, max_duration)
92+
expect(second_span[:timestamp] - second_span[:start_timestamp]).to be > 0
93+
expect(second_span[:start_timestamp]).to be >= transaction[:start_timestamp]
94+
expect(second_span[:timestamp]).to be <= transaction[:timestamp]
9995

10096
third_span = transaction[:spans][2]
10197
expect(third_span[:op]).to eq("template.render_template.action_view")

0 commit comments

Comments
 (0)