Skip to content

Allow unsubscribing from events #39

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 6 commits into
base: ac-structured-events
Choose a base branch
from

Conversation

zzak
Copy link

@zzak zzak commented Jul 20, 2025

Some minor API changes around subscriptions, partly taken from ErrorReporter.

  • We don't want to publicize the readers for @subscribers or @raise_on_error.
  • Publicize raise_on_error= with docs
  • Remove uniqueness for subscribe(already_included_subscriber)

Some of these we didn't do with ErrorReporter (mainly attr_*) but I think it's a cleaner API, for example ErrorReporter#logger doesn't need a reader but now that it's public technically removing it should be deprecated. So just being stricter about what we publicize makes maintenance / change easier later.

I also debated whether to add EventReporter#disable(&block) for disabling subscriptions because I couldn't think of a use-case but it could always be added later.

/cc @adrianna-chang-shopify

Ref: rails#50452

This adds a Structured Event Reporter to Rails, accessible via `Rails.event`.
It allows you to report events to a subscriber, and provides mechanisms for adding tags and context to events.

Events encompass "structured logs", but also "business events", as well as telemetry events such as metrics
and logs. The Event Reporter is designed to be a single interface for producing any kind of event in a Rails
application.

We separate the emission of events from how these events reach end consumers; applications are expected to
define their own subscribers, and the Event Reporter is responsible for emitting events to these subscribers.
Add JSON and MessagePack encoders to ActiveSupport::EventReporter.
This allows applications to serialize events to common formats without
needing to implement their own serialization logic in subscribers.
@zzak zzak force-pushed the event-reporter-subscribers branch from 9dbd456 to 6a2a397 Compare July 26, 2025 07:24
@adrianna-chang-shopify adrianna-chang-shopify force-pushed the ac-structured-events branch 3 times, most recently from ebd42e3 to 2e8ae57 Compare August 5, 2025 18:32
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.

2 participants