Introducing: Tagged Events!
-
This adds a new
tagged: true
option tojournal_attributes
, andJournaled.tagged
/Journaled.tag!
helpers that allow events to be tagged with contextual metadata (useful for audit logs and tracing):class MyEvent include Journaled::Event journal_attributes :attr_1, :attr_2, tagged: true end Journaled.tagged(foo: 'bar') do # events emitted in this scope will have a `tags` attribute with contents `{ "foo": "bar" }` end # events emitted in this scope will have a `tags` attribute with contents `{}`
All "tagged" events will be given a
tags
attribute, but it can be empty. Consuming apps with strict schema enforcement ("additionalProperties": false
) will need to include the "tags" field in any relevant event schemas. While this feature is not a breaking change for existing events, we have incremented the gem by a full minor version (to4.1.0
). -
Under the hood, this removes
RequestStore
in favor ofActiveSupport::CurrentAttributes
. This is the new convention for Rails apps (available in 5.2+), so in theory consuming apps shouldn't be impacted by this, but it is another reason to increment a full minor version at the least. -
The README now includes two standard usage examples:
class ApplicationController < ActionController::Base
before_action do
Journaled.tag!(request_id: request.request_id, current_user_id: current_user&.id)
end
end
class ApplicationJob < ActiveJob::Base
around_perform do |job, perform|
Journaled.tagged(job_id: job.job_id, &perform)
end
end