Skip to content

Latest commit

 

History

History
40 lines (29 loc) · 1001 Bytes

instrumentation.md

File metadata and controls

40 lines (29 loc) · 1001 Bytes

Back to Guides

Instrumentation

ActiveModelSerializers uses the ActiveSupport::Notification API, which allows for subscribing to events, such as for logging.

Events

Name:

render.active_model_serializers

Payload (example):

{
  serializer: PostSerializer,
  adapter: ActiveModelSerializers::Adapter::Attributes
}

Subscribing:

ActiveSupport::Notifications.subscribe 'render.active_model_serializers' do |name, started, finished, unique_id, data|
  # whatever
end
ActiveSupport::Notifications.subscribe 'render.active_model_serializers' do |*args|
  event = ActiveSupport::Notifications::Event.new(*args)
  # event.payload
  # whatever
end

ActiveModelSerializers includes an ActiveModelSerializers::LogSubscriber that attaches to render.active_model_serializers.