diff --git a/.changesets/report-response-status-for-rails-requests.md b/.changesets/report-response-status-for-rails-requests.md new file mode 100644 index 000000000..ecb46c9cc --- /dev/null +++ b/.changesets/report-response-status-for-rails-requests.md @@ -0,0 +1,8 @@ +--- +bump: patch +type: add +--- + +Report the response status for Rails requests as the `response_status` tag on samples, e.g. 200, 301, 500. This tag is visible on the sample detail page. + +The response status is also reported as the `response_status` metric. diff --git a/lib/appsignal/rack/event_handler.rb b/lib/appsignal/rack/event_handler.rb index c1048883a..93cd7a833 100644 --- a/lib/appsignal/rack/event_handler.rb +++ b/lib/appsignal/rack/event_handler.rb @@ -53,8 +53,16 @@ def on_finish(request, _response) transaction.finish_event("process_request.rack", "", "") transaction.set_action_if_nil("#{request.request_method} #{request.path}") + transaction.set_tags(:response_status => response.status) transaction.set_http_or_background_queue_start + Appsignal.increment_counter( + :response_status, + 1, + :status => response.status, + :namespace => format_namespace(transaction.namespace) + ) + # Make sure the current transaction is always closed when the request # is finished Appsignal::Transaction.complete_current! diff --git a/spec/lib/appsignal/rack/event_handler_spec.rb b/spec/lib/appsignal/rack/event_handler_spec.rb index b3b9f0d61..5bc29dd92 100644 --- a/spec/lib/appsignal/rack/event_handler_spec.rb +++ b/spec/lib/appsignal/rack/event_handler_spec.rb @@ -160,6 +160,25 @@ def on_finish ) end + it "sets the response status as a tag" do + on_start + on_finish + + expect(last_transaction.to_h).to include( + "sample_data" => hash_including( + "tags" => { "response_status" => 200 } + ) + ) + end + + it "increments the response status counter for response status" do + expect(Appsignal).to receive(:increment_counter) + .with(:response_status, 1, :status => 200, :namespace => :web) + + on_start + on_finish + end + it "logs an error in case of an error" do expect(Appsignal::Transaction) .to receive(:complete_current!).and_raise(ExampleStandardError, "oh no")