Skip to content

Log every HotCell call to the Rails log by default - #78

Merged
flavorjones merged 2 commits into
masterfrom
issue-10-log-subscriber
Sep 30, 2026
Merged

flavorjones merged 2 commits into
masterfrom
issue-10-log-subscriber

Conversation

@flavorjones

@flavorjones flavorjones commented Sep 28, 2026 •

Copy link
Copy Markdown
Member

Motivation

The client publishes the perform.hot_cell Active Support notification on every call, success or failure (client.rb). Its payload carries the cell, the operation, the failure code and cause, the tool's stderr, the byte counts, and the time the cell measured (publish).

Nothing in the gem turns that event into a log line. An application that wanted one line per call had to write its own subscriber, and each application that adopted HotCell wrote the same one.

Details

  • HotCell::LogSubscriber is an ActiveSupport::LogSubscriber. It writes one info line per call:

    HotCell (41.2ms) {"cell":"images","operation":"active_storage.transformers.image.vips","code":"ok","perform_ms":38,"duration_ms":41.2,"bytes_in":20480,"bytes_out":8192}
    

    A failed call adds cause and stderr when it has them. A call that an exception interrupts, such as the application's own request timeout, logs the exception's class in place of the code. stderr is text a tool wrote while reading an untrusted file. It goes only inside the JSON, which is ASCII-only, so neither a newline nor a Unicode line separator in it can forge a log line.

  • The railtie attaches the subscriber at boot, so a Rails application logs to Rails.logger with no setup. An application turns it off with HotCell::LogSubscriber.detach_from :hot_cell. Without Rails, an application requires hot_cell/log_subscriber, calls attach_to :hot_cell, and sets ActiveSupport::LogSubscriber.logger.

  • An application that already logs this event should delete its own subscriber, or it will log each call twice. The CHANGELOG says so under "Upgrading".

Fixes #10

Each application that wanted a log line per call had to write its own
`perform.hot_cell` subscriber. Add `HotCell::LogSubscriber`, which the
railtie attaches, and describe its line in the README.

[Fix #10]
Copilot AI balanced review requested due to automatic review settings September 28, 2026 21:30

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

When an exception escaped the call, such as the application's
own request timeout, `HotCell::LogSubscriber` logged the call as
`"code":"ok"` with no cell and no operation. Put the cell and the
operation on the event before the call, and log the exception's class
in place of the code.
@flavorjones
flavorjones merged commit 2ce0274 into master Sep 30, 2026
16 checks passed
@flavorjones
flavorjones deleted the issue-10-log-subscriber branch September 30, 2026 18:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Ship default logging via a LogSubscriber

2 participants