Skip to content

Commit 02f4885

Browse files
authored
Add ActiveSupport::Notifications instrumentation. (#41)
1 parent 0d513ca commit 02f4885

File tree

2 files changed

+14
-6
lines changed

2 files changed

+14
-6
lines changed

lib/jsonapi/rails/controller.rb

+9-5
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,15 @@ def deserializable_resource(key, options = {}, &block)
3333

3434
before_action(options) do |controller|
3535
hash = controller.params[:_jsonapi].to_unsafe_hash
36-
JSONAPI::Parser::Resource.parse!(hash)
37-
resource = klass.new(hash[:data])
38-
controller.request.env[JSONAPI_POINTERS_KEY] =
39-
resource.reverse_mapping
40-
controller.params[key.to_sym] = resource.to_hash
36+
ActiveSupport::Notifications.instrument('parse.jsonapi',
37+
payload: hash,
38+
class: klass) do
39+
JSONAPI::Parser::Resource.parse!(hash)
40+
resource = klass.new(hash[:data])
41+
controller.request.env[JSONAPI_POINTERS_KEY] =
42+
resource.reverse_mapping
43+
controller.params[key.to_sym] = resource.to_hash
44+
end
4145
end
4246
end
4347
end

lib/jsonapi/rails/railtie.rb

+5-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,11 @@ class Railtie < ::Rails::Railtie
3838
# Renderer proc is evaluated in the controller context.
3939
self.content_type ||= Mime[:jsonapi]
4040

41-
renderer.render(resources, options, self).to_json
41+
ActiveSupport::Notifications.instrument('render.jsonapi',
42+
resources: resources,
43+
options: options) do
44+
renderer.render(resources, options, self).to_json
45+
end
4246
end
4347
end
4448
end

0 commit comments

Comments
 (0)