Skip to main content
Version: 1.3.1

Instrumentation

RubyEventStore and RailsEventStore ships with built-in instrumentation on which you can build additional features or benchmark event store performance in your app.

Enabling instrumentation​

RailsEventStore​

RailsEventStore is integrated with ActiveSupport::Notifications by default. You don't have to do anything else.

RubyEventStore​

Instrumentation is provided by InstrumentedRepository and InstrumentedDispatcher decorators. We don't force any particular instrumentation framework, as long as it has the same API as ActiveSupport::Notifications.

That having said, if you want to instrument your event store with ActiveSupport::Notifications, initialize your client with following repository and/or dispatcher:

repository = RailsEventStoreActiveRecord::EventRepository.new # or other repo you use
dispatcher = RubyEventStore::Dispatcher.new # or other dispatcher you use
RubyEventStore::Client.new(
repository: InstrumentedRepository.new(repository, ActiveSupport::Notifications),
dispatcher: InstrumentedDispatcher.new(dispatcher, ActiveSupport::Notifications),
)

Usage​

Subscribe to the hooks as Rails guides and manual recommend.

Example​

name = "append_to_stream.repository.rails_event_store"
ActiveSupport::Notifications.subscribe(name) do |name, start, finish, id, payload|
metric = ActiveSupport::Notifications::Event.new(name, start, finish, id, payload)
NewRelic::Agent.record_metric("Custom/RES/append_to_stream", metric.duration)
end

Hooks and their payloads​

append_to_stream.repository.rails_event_store​

KeyValue
:eventsArray of appended events
:streamName of stream we append events to
KeyValue
:event_idsArray of linked events' ids
:streamName of stream we link events to

delete_stream.repository.rails_event_store​

KeyValue
:streamName of stream deleted

read_event.repository.rails_event_store​

KeyValue
:event_idId of the read event

read.repository.rails_event_store​

KeyValue
:specificationSpecification of the query to event store

Queries specification is not documented, but you can read the source code of it.

call.dispatcher.rails_event_store​

KeyValue
:eventAn event which is being dispatched
:subscriberA subscriber to which event is dispatched to