Skip to content

Commit c951628

Browse files
authored
Merge pull request #1759 from zvkemp/instrument-serialization
Instrument serialization and rendering as 'format_response.grape'
2 parents 786fbcc + 7f9e329 commit c951628

File tree

7 files changed

+21
-8
lines changed

7 files changed

+21
-8
lines changed

.travis.yml

-2
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,6 @@ matrix:
3333
gemfile: gemfiles/rack_edge.gemfile
3434
- rvm: 2.3.5
3535
gemfile: gemfiles/rack_1.5.2.gemfile
36-
- rvm: 2.3.5
37-
gemfile: gemfiles/rails_edge.gemfile
3836
- rvm: 2.3.5
3937
gemfile: gemfiles/rails_5.gemfile
4038
- rvm: 2.2.8

Appraisals

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ appraise 'rack-1.5.2' do
1616
end
1717

1818
appraise 'rails-edge' do
19-
gem 'arel', github: 'rails/arel'
19+
gem 'rails', github: 'rails/rails'
2020
end
2121

2222
appraise 'rack-edge' do

CHANGELOG.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,11 @@
22

33
#### Features
44

5-
* Your contribution here.
5+
* [#1759](https://github.com/ruby-grape/grape/pull/1759): Instrument serialization as `'format_response.grape'` - [@zvkemp](https://github.com/zvkemp).
66

77
#### Fixes
88

9+
* [#1759](https://github.com/ruby-grape/grape/pull/1759): Update appraisal for rails_edge - [@zvkemp](https://github.com/zvkemp).
910
* Your contribution here.
1011

1112
### 1.0.3 (4/23/2018)

README.md

+8
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,7 @@
129129
- [endpoint_render.grape](#endpoint_rendergrape)
130130
- [endpoint_run_filters.grape](#endpoint_run_filtersgrape)
131131
- [endpoint_run_validators.grape](#endpoint_run_validatorsgrape)
132+
- [format_response.grape](#format_responsegrape)
132133
- [Monitoring Products](#monitoring-products)
133134
- [Contributing to Grape](#contributing-to-grape)
134135
- [License](#license)
@@ -3484,6 +3485,13 @@ The execution of validators.
34843485
* *validators* - The validators being executed
34853486
* *request* - The request being validated
34863487

3488+
#### format_response.grape
3489+
3490+
Serialization or template rendering.
3491+
3492+
* *env* - The request environment
3493+
* *formatter* - The formatter object (e.g., `Grape::Formatter::Json`)
3494+
34873495
See the [ActiveSupport::Notifications documentation](http://api.rubyonrails.org/classes/ActiveSupport/Notifications.html) for information on how to subscribe to these events.
34883496

34893497
### Monitoring Products

gemfiles/rails_edge.gemfile

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
source 'https://rubygems.org'
44

5-
gem 'arel', github: 'rails/arel'
5+
gem 'rails', github: 'rails/rails'
66

77
group :development, :test do
88
gem 'bundler'

lib/grape/middleware/formatter.rb

+3-1
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,9 @@ def build_formatted_response(status, headers, bodies)
4141
else
4242
# Allow content-type to be explicitly overwritten
4343
formatter = fetch_formatter(headers, options)
44-
bodymap = bodies.collect { |body| formatter.call(body, env) }
44+
bodymap = ActiveSupport::Notifications.instrument('format_response.grape', formatter: formatter, env: env) do
45+
bodies.collect { |body| formatter.call(body, env) }
46+
end
4547
Rack::Response.new(bodymap, status, headers)
4648
end
4749
rescue Grape::Exceptions::InvalidFormatter => e

spec/grape/endpoint_spec.rb

+6-2
Original file line numberDiff line numberDiff line change
@@ -1493,7 +1493,9 @@ def memoized
14931493
filters: [],
14941494
type: :after }),
14951495
have_attributes(name: 'endpoint_run.grape', payload: { endpoint: a_kind_of(Grape::Endpoint),
1496-
env: an_instance_of(Hash) })
1496+
env: an_instance_of(Hash) }),
1497+
have_attributes(name: 'format_response.grape', payload: { env: an_instance_of(Hash),
1498+
formatter: a_kind_of(Module) })
14971499
)
14981500

14991501
# In order that events were initialized
@@ -1515,7 +1517,9 @@ def memoized
15151517
have_attributes(name: 'endpoint_render.grape', payload: { endpoint: a_kind_of(Grape::Endpoint) }),
15161518
have_attributes(name: 'endpoint_run_filters.grape', payload: { endpoint: a_kind_of(Grape::Endpoint),
15171519
filters: [],
1518-
type: :after })
1520+
type: :after }),
1521+
have_attributes(name: 'format_response.grape', payload: { env: an_instance_of(Hash),
1522+
formatter: a_kind_of(Module) })
15191523
)
15201524
end
15211525
end

0 commit comments

Comments
 (0)