Add the instrumentation middleware
To integrate AppSignal in a Rack application, we first need to load, configure, and start AppSignal. Then, instrument the Rack app by adding our RackEventMiddleware and InstrumentationMiddleware to the middleware stack.
This documentation explains how to do this in your application’s config.ru file.
EventMiddleware and InstrumentationMiddleware are registered in the application middleware stack as early as possible. The earlier these middleware are registered, the more request runtime the middleware will instrument. If other middleware are registered beforehand, our middleware will not instrument these other middleware.
After adding the EventMiddleware and InstrumentationMiddleware to your app’s middleware stack, the action needs to be set for each route in your app in AppSignal. Without an action name to group requests, the event middleware will not report request information.
For more insights into the operation of your Rack application, we recommend adding additional instrumentation to the application’s endpoints.
The Rack event middleware
We recommend adding our Rack event middleware to all Rack applications. This middleware will ensure we track The AppSignal Rack event middleware has the following features:- Instrumentation of the request and recording a
process_request.rackevent. - Reporting Exceptions that occur in the app and middleware.
- Tracking the response status code as the
response_statustag on the trace. - Tracking the response status code as the
response_statusmetric, with thenamespaceandstatustags.
The Rack instrumentation middleware
We recommend that in addition to theAppsignal::Rack::EventMiddleware, the AppSignal::Rack::InstrumentationMiddleware is added to the app. This middleware supplements the event middleware’s instrumentation by adding tags for the request path and request method, as well as tracking response body handling and response body closing operations.
The instrumentation middleware has the following features:
- Instrumentation of the request and recording a
process_request.rackevent. - Reporting Exceptions that occur in the app.
- Tracking the request path and request method as tags on the trace.
- Instrumentation of the response body handling and recording a
process_response_body.rackevent for this operation. - Instrumentation of the response body closing and recording a
close_response_body.rackevent for this operation.
Using the legacy instrumentation middleware
To integrate AppSignal in a Rack application, we first need to load, configure, and start AppSignal. Then, instrument the Rack app by adding our RackGenericInstrumentation middleware to the middleware stack.
This documentation explains how to do this in your application’s config.ru file.
EventMiddleware and InstrumentationMiddleware are registered in the application middleware stack as early as possible. The earlier these middleware are registered, the more request runtime the middleware will instrument. If other middleware are registered beforehand, our middleware will not instrument these other middleware.
After adding the EventMiddleware and InstrumentationMiddleware to your app’s middleware stack, the action needs to be set for each route in your app in AppSignal. Without an action name to group requests, the event middleware will not report request information.
For more insights into the operation of your Rack application, we recommend adding additional instrumentation to the application’s endpoints.
Setting the action name
Set an action name on the AppSignal transaction for a request so we can group endpoints in our issues and metrics. We recommend using a static action name per endpoint, likeGET /blog, POST /users, PUT /users/:id, etc.
To set an action name for a request, call the Appsignal.set_action helper from the app.
Span attributes
Collector mode only: this applies when AppSignal for Ruby runs in collector mode. It has no effect otherwise.
http.request.method— the request method.url.scheme,url.path, andurl.query— the address that was requested.http.response.status_code— the status your application responded with.
error.type, the class of the error.
Distributed tracing
Collector mode only: this applies when AppSignal for Ruby runs in collector mode. It has no effect otherwise.
traceparent request header continues the trace it names.
The request appears inside the calling service’s trace, under the request that caused it. You can follow a slow request from that service into this application without switching traces.
The HTTP clients AppSignal supports start the trace. A request without the header starts a new one.