Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions sentry-rails/lib/sentry/rails/capture_exceptions.rb
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,12 @@ def start_transaction(env, scope)
origin: SPAN_ORIGIN
}

if @assets_regexp && scope.transaction_name.match?(@assets_regexp)
options.merge!(sampled: false)
end
options.merge!(sampled: false) if @assets_regexp && scope.transaction_name.match?(@assets_regexp)

transaction = Sentry.continue_trace(env, **options)
Sentry.start_transaction(transaction: transaction, custom_sampling_context: { env: env }, **options)
transaction = Sentry.start_transaction(transaction: transaction, custom_sampling_context: { env: env }, **options)
attach_queue_time(transaction, env)
transaction
end

def show_exceptions?(exception, env)
Expand Down
27 changes: 27 additions & 0 deletions sentry-rails/spec/sentry/rails/tracing_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,33 @@

expect(transport.events.count).to eq(1)
end

context "with X-Request-Start header" do
it "attaches queue time to the Rails transaction" do
p = Post.create!
timestamp = Time.now.to_f - 0.05 # 50ms ago

get "/posts/#{p.id}", headers: { "X-Request-Start" => "t=#{timestamp}" }

expect(response).to have_http_status(:ok)
transaction = transport.events.last
queue_time = transaction.contexts.dig(:trace, :data, "http.server.request.time_in_queue")
expect(queue_time).not_to be_nil
expect(queue_time).to be >= 0
end

it "does not attach queue time when capture_queue_time is disabled" do
p = Post.create!
timestamp = Time.now.to_f - 0.05

Sentry.configuration.capture_queue_time = false
get "/posts/#{p.id}", headers: { "X-Request-Start" => "t=#{timestamp}" }

transaction = transport.events.last
queue_time = transaction.contexts.dig(:trace, :data, "http.server.request.time_in_queue")
expect(queue_time).to be_nil
end
end
end

context "with report_rescued_exceptions and public error pages" do
Expand Down
12 changes: 7 additions & 5 deletions sentry-ruby/lib/sentry/rack/capture_exceptions.rb
Original file line number Diff line number Diff line change
Expand Up @@ -73,13 +73,15 @@ def start_transaction(env, scope)

transaction = Sentry.continue_trace(env, **options)
transaction = Sentry.start_transaction(transaction: transaction, custom_sampling_context: { env: env }, **options)
attach_queue_time(transaction, env)
transaction
end

# attach queue time if available
if transaction && (queue_time = extract_queue_time(env))
transaction.set_data(Span::DataConventions::HTTP_QUEUE_TIME_MS, queue_time)
end
def attach_queue_time(transaction, env)
return unless transaction
return unless (queue_time = extract_queue_time(env))

transaction
transaction.set_data(Span::DataConventions::HTTP_QUEUE_TIME_MS, queue_time)
end


Expand Down
Loading