Skip to content

Support for ActiveSupport::Notifications #550

@vojtad

Description

@vojtad

Rails and other gems provide lots of instrumentation data through ActiveSupport::Notifications subscriptions.

For now I am mainly interested in instrumenting ViewComponent which already has instrumentation built in and provides all the data using ActiveSupport::Notifications. The notifications from ViewComponent are documented here. Right now, when we use lots of components all their time is recorded under View without any granularity visible in Scout UI.

Basic code to consume notifications looks like this:

ActiveSupport::Notifications.subscribe("render.view_component") do |event| # or !render.view_component
  event.name    # => "render.view_component"
  event.duration      # => 10 (in milliseconds)
  event.allocations   # => 1826 (objects)
  event.payload # => { name: "MyComponent", identifier: "/Users/mona/project/app/components/my_component.rb" }
end

Look at ActiveSupport::Notifications::Event to find all information that is available.

It would be great if Scout agent would provide a way to easily ingest data from ActiveSupport::Notifications. It could probably even subscribe to some of them by default when gems are detected (like ViewComponent).

I would be happy to try to implement proof of concept with some guidance or try any testing version you would have.

From what I can tell and from discussion with @lancetarn on Discord I adding children ScoutApm::Layers under the View one as components are rendered could be possible. Is this the way to go or should I explore anything else?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions