File: instrumentation.md

package info (click to toggle)
ruby-active-model-serializers 0.10.10-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 1,704 kB
  • sloc: ruby: 13,103; sh: 53; makefile: 10
file content (40 lines) | stat: -rw-r--r-- 1,001 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
[Back to Guides](../README.md)

# Instrumentation

ActiveModelSerializers uses the
[ActiveSupport::Notification API](http://guides.rubyonrails.org/active_support_instrumentation.html#subscribing-to-an-event),
which allows for subscribing to events, such as for logging.

## Events

Name:

`render.active_model_serializers`

Payload (example):

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

Subscribing:

```ruby
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
```

## [LogSubscriber](http://api.rubyonrails.org/classes/ActiveSupport/LogSubscriber.html)

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