Skip to content

Add native ActiveSupport::Notifications hook for transitions - #154

Open
serradura wants to merge 1 commit into
mainfrom
feature/active-support-notifications
Open

serradura wants to merge 1 commit into
mainfrom
feature/active-support-notifications

Conversation

@serradura

@serradura serradura commented May 27, 2026 •

Copy link
Copy Markdown
Member

Summary

  • New opt-in Micro::Case::Result::Notifications module that publishes one transition.micro_case ActiveSupport::Notifications event per transition, when both transitions and the new config.notifications flag are enabled. Payload exposes :use_case_class, :attributes, :result_type, :result_kind (:success | :failure), :result_data, and :accessible_attributes — plain Ruby values, safe for JSON-encoding subscribers (OTEL, structured logs, StatsD, Rack::MiniProfiler, etc.).
  • activesupport stays out of runtime deps. The module probes defined?(::ActiveSupport::Notifications) at require time and redefines publish to a no-op when unavailable, so the transition hot path stays branch-free. Setting notifications = true while AS::Notifications is not loaded raises the new Micro::Case::Error::NotificationsUnavailable (fail-fast at boot rather than silently dropping events). Default is off — existing callers get no behavior change.
  • Additive only per the no-breaking-changes policy: Transitions::MapEverything, result.transitions, and Result.new(custom_mapper) are unchanged. CHANGELOG entry under [Unreleased]; both READMEs (EN + pt-BR) gain a top-level Observability section with the Rack::MiniProfiler-step and Rails.logger subscriber recipes, plus the synchronous-subscriber cost warning.

Test plan

  • bundle exec rake test — 811 runs, 0 failures (default bundle, AS::Notifications absent → unavailable-path tests run, happy-path tests skip)
  • BUNDLE_GEMFILE=gemfiles/rails_8_1.gemfile bundle exec rake test — 1058 runs, 0 failures (AS::Notifications loaded → full happy-path tests run, unavailable-path tests skip)
  • ENABLE_TRANSITIONS=false bundle exec rake test — 0 failures (transitions off → no events fire even with config flag on)
  • ENABLE_TRANSITIONS=false BUNDLE_GEMFILE=gemfiles/rails_8_1.gemfile bundle exec rake test — 0 failures
  • Full bundle exec rake matrix across the Ruby × Rails × ENABLE_TRANSITIONS axes in CI

🤖 Generated with Claude Code

Emits one `transition.micro_case` event per transition when the new
`config.notifications` flag is on AND transitions are enabled. Payload
exposes use_case_class, attributes, result_type, result_kind,
result_data, and accessible_attributes — plain Ruby values, no Result
instance, safe for JSON-encoding subscribers.

`activesupport` stays out of runtime deps. The new
`Micro::Case::Result::Notifications` module probes
`defined?(::ActiveSupport::Notifications)` at require time and
redefines `publish` to a no-op when unavailable, so the transition hot
path stays branch-free. Setting `config.notifications = true` while
AS::Notifications is not loaded raises the new
`Micro::Case::Error::NotificationsUnavailable` (fail-fast at boot
rather than silently dropping events). Default is off — existing
callers get no behavior change.

Additive only: Transitions::MapEverything, result.transitions, and
Result.new(custom_mapper) are unchanged. CHANGELOG entry under
[Unreleased]; both READMEs gain a top-level Observability section with
subscriber recipes and the synchronous-subscriber cost warning.

Closes #5.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@serradura serradura self-assigned this May 27, 2026
@serradura serradura added this to the 5.x milestone May 27, 2026
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.

1 participant