-
Notifications
You must be signed in to change notification settings - Fork 116
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add response status code to transaction metadata #183
Comments
We can get the status code from the @app.call(env).tap do |status, _, __|
transaction.set_metadata("status", status)
end This would work for any Rack application since they are required to return the response triplet: status code, headers, and body (in that order). So we can add it for Rack, Sinatra and Grape too. Is this what you had in mind, @matsimitsu ? |
Sounds good! 👍 |
@tombruijn so this is implemented for the elexir client but not in the ruby version? |
This would be very helpful. I was hoping to see throughput and response time graphs by HTTP response code out-of-the box with AppSignal. |
Rework the Rails instrumentation to use the Rack::Events module to start and complete the transaction at the very start and end of the request. A new middleware is added at the very top of the middleware stack to start and complete the transaction. This allows us to instrument more of the request's duration, as we're now at the very start and end of the request handling. We will now report the time the request has spend handling any other middleware. This will be visible with a new `process_request.rack` event. To make sure we always close the transaction, listen for the `on_finish` event, but also register a last resort "after_reply" callback. This callback is supported by web servers like Puma and Unicorn. If it's called when a transaction is active, it will close it, preventing transactions to span multiple requests. If no transaction is active, it will do nothing. Moving forward, I'd like to update our Rack, Sinatra, Padrino, Grape, etc. instrumentations to use this EventHandler middleware too, which will be a bit more work, because some require users to manually add middleware. When they all use the same EventHandler, we have one place to start and complete transactions, and issues like #289 cannot happen again in the future. Previously, our only Rails instrumentation was positioned after the DebugExceptions middleware, just in time to catch any errors before the Rails error middleware showed a nice error/debug page. This wouldn't show the complete picture in request duration. The original Rails instrumentation middleware will remain to report errors and Rails specific metadata. This cannot be part of the EventHandler, without overloading it with responsibilities, and for Rails error reporting we need to be right after the DebugExceptions middleware before errors are no longer bubbled up in the stack. TODO: SPLIT COMMIT: We can now report the response status as a `response_status` tag and metric. Previously, due to the position of the Rails middleware, this was unreliable and wouldn't always report the real status code if other middleware in the stack returned another status. This is part of issue #183, but only implements it now for Rails apps and apps using the `Appsignal::Rack::EventHandler` manually. We'll need to update other instrumentations for Rack, Sinatra, Padrino, Grape, etc. to use this new EventHandler, so they can also benefit from this new response status tag and metric. TODO: - How to report the request_id? Can't overwrite the tag - Remove the `request_id2` tag
We can now report the response status as a `response_status` tag and metric. Previously, due to the position of the Rails middleware, this was unreliable and wouldn't always report the real status code if other middleware in the stack that are run after ours returned another status. This is part of issue #183, but only implements it now for Rails apps and apps using the `Appsignal::Rack::EventHandler` manually. We'll need to update other instrumentations for Rack, Sinatra, Padrino, Grape, etc. to use this new EventHandler, so they can also benefit from this new response status tag and metric.
We can now report the response status as a `response_status` tag and metric. Previously, due to the position of the Rails middleware, this was unreliable and wouldn't always report the real status code if other middleware in the stack that are run after ours returned another status. This is part of issue #183, but only implements it now for Rails apps and apps using the `Appsignal::Rack::EventHandler` manually. We'll need to update other instrumentations for Rack, Sinatra, Padrino, Grape, etc. to use this new EventHandler, so they can also benefit from this new response status tag and metric.
We can now report the response status as a `response_status` tag and metric. Previously, due to the position of the Rails middleware, this was unreliable and wouldn't always report the real status code if other middleware in the stack that are run after ours returned another status. This is part of issue #183, but only implements it now for Rails apps and apps using the `Appsignal::Rack::EventHandler` manually. We'll need to update other instrumentations for Rack, Sinatra, Padrino, Grape, etc. to use this new EventHandler, so they can also benefit from this new response status tag and metric.
Requested in this Intercom conversation (2024-05-28). Working on this in PR #1090 |
We can now report the response status as a `response_status` tag and metric. Previously, due to the position of the Rails middleware, this was unreliable and wouldn't always report the real status code if other middleware in the stack that are run after ours returned another status. This is part of issue #183, but only implements it now for Rails apps and apps using the `Appsignal::Rack::EventHandler` manually. We'll need to update other instrumentations for Rack, Sinatra, Padrino, Grape, etc. to use this new EventHandler, so they can also benefit from this new response status tag and metric.
We can now report the response status as a `response_status` tag and metric. Previously, due to the position of the Rails middleware, this was unreliable and wouldn't always report the real status code if other middleware in the stack that are run after ours returned another status. This is part of issue #183, but only implements it now for Rails apps and apps using the `Appsignal::Rack::EventHandler` manually. We'll need to update other instrumentations for Rack, Sinatra, Padrino, Grape, etc. to use this new EventHandler, so they can also benefit from this new response status tag and metric.
We can now report the response status as a `response_status` tag and metric. Previously, due to the position of the Rails middleware, this was unreliable and wouldn't always report the real status code if other middleware in the stack that are run after ours returned another status. This is part of issue #183, but only implements it now for Rails apps and apps using the `Appsignal::Rack::EventHandler` manually. We'll need to update other instrumentations for Rack, Sinatra, Padrino, Grape, etc. to use this new EventHandler, so they can also benefit from this new response status tag and metric.
We report the |
💋 |
Hm, I'm not able to create a dashboard with metrics from |
You should be able to make a graph like this: If the tag is set on samples, the metric is sent as well. These things are set right after one another. |
ah, i was missing the namespace part 👍 |
This has been released in several recent Ruby gems, with the last libraries supported in Ruby gem 3.10. |
Response status codes (200,202 etc.) could help debug performance issues. e.g. short-returning a 404-not found could have a different impact on your app then returning a 200 with a body. While it might be clear from the event timeline, I think it's nice to have as additional metadata.
Blocked by #329
Instrumentations
Response status reporting will be supported in #1090 through the Rack EventHandler. This will only work for Rails first, as it's the first instrumentation to use that. As we port other instrumentations over to use Rack EventHandler, more libraries will be supported.
Webmachine?Not doing thisThe text was updated successfully, but these errors were encountered: