You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@@ -4125,35 +4127,38 @@ See [StackOverflow #3282655](http://stackoverflow.com/questions/3282655/ruby-on-
4125
4127
4126
4128
Grape has built-in support for [ActiveSupport::Notifications](http://api.rubyonrails.org/classes/ActiveSupport/Notifications.html) which provides simple hook points to instrument key parts of your application.
4127
4129
4128
-
The following are currently supported:
4129
4130
4130
-
#### endpoint_run.grape
4131
+
#### Hook Points
4132
+
4133
+
The following hook points are currently supported:
4134
+
4135
+
##### endpoint_run.grape
4131
4136
4132
4137
The main execution of an endpoint, includes filters and rendering.
4133
4138
4134
4139
**endpoint* - The endpoint instance
4135
4140
4136
-
#### endpoint_render.grape
4141
+
#####endpoint_render.grape
4137
4142
4138
4143
The execution of the main content block of the endpoint.
4139
4144
4140
4145
**endpoint* - The endpoint instance
4141
4146
4142
-
#### endpoint_run_filters.grape
4147
+
#####endpoint_run_filters.grape
4143
4148
4144
4149
**endpoint* - The endpoint instance
4145
4150
**filters* - The filters being executed
4146
4151
**type* - The type of filters (before, before_validation, after_validation, after)
4147
4152
4148
-
#### endpoint_run_validators.grape
4153
+
#####endpoint_run_validators.grape
4149
4154
4150
4155
The execution of validators.
4151
4156
4152
4157
**endpoint* - The endpoint instance
4153
4158
**validators* - The validators being executed
4154
4159
**request* - The request being validated
4155
4160
4156
-
#### format_response.grape
4161
+
#####format_response.grape
4157
4162
4158
4163
Serialization or template rendering.
4159
4164
@@ -4162,12 +4167,44 @@ Serialization or template rendering.
4162
4167
4163
4168
See the [ActiveSupport::Notifications documentation](http://api.rubyonrails.org/classes/ActiveSupport/Notifications.html) for information on how to subscribe to these events.
4164
4169
4170
+
#### Subscribe to Hooks
4171
+
4172
+
Once subscribed to the instrumentation, you can intercept the events reported above.
4173
+
4174
+
```ruby
4175
+
ActiveSupport::Notifications.subscribe(/<api_path>/) do |name, start, finish, id, payload|
4176
+
# your code to intercept the notification
4177
+
end
4178
+
```
4179
+
4180
+
The request data, the API’s internal data, and the response can be retrieved from the payload.
4181
+
4182
+
You can use `payload.fetch(:endpoint)` or directly `payload[:endpoint]`.
4183
+
4184
+
The `:endpoint` contains the data currently being processed, and access to attributes such as `body`, `request`, `params`, `headers`, `cookies` and `response_cookies`
4185
+
4186
+
For example, `payload[:endpoint].body` provides the current state of the response.
4187
+
4188
+
```ruby
4189
+
ActiveSupport::Notifications.subscribe(/v1/) do |name, start, finish, id, payload|
Grape integrates with following third-party tools:
4168
4204
4169
4205
***New Relic** - [built-in support](https://docs.newrelic.com/docs/agents/ruby-agent/frameworks/grape-instrumentation) from v3.10.0 of the official [newrelic_rpm](https://github.com/newrelic/rpm) gem, also [newrelic-grape](https://github.com/xinminlabs/newrelic-grape) gem
0 commit comments