Rails 7: Instrument ActiveStorage analyzers


ActiveSupport Instrumentation is an API that allows developers to provide hooks that other developers may hook into. It can be used inside an application to measure specific actions that occur within Ruby code, such as inside a Rails application or the framework itself. With this API, developers can choose to notify when certain events occur inside their application or another piece of Ruby code.

Before

ActiveStorage provides the following instrumentation APIs,

However, there are no APIs for ActiveStorage’s analyzer methods. After a file is attached, it’s queued for what is known as analyzing. There are many inbuilt analyzers such as ImageAnalyzer, VideoAnalyzer and more.

When using ActiveStorage instrumentation APIs, one would often see a jump between time spans when a file gets uploaded and stored. That jump is due to a missing Analyzer instrumentation API.

After

Thanks to this PR, the API now publishes events when running ActiveStorage analyzers. The name of the new instrumentation event is analyze.active_storage that returns the analyzer used to extract meta information from an ActiveStorage blog.

Key Value
:analyzer Name of analyzer e.g., ffprobe