reckon_db_causation (reckon_db v1.2.6)
View SourceCausation and correlation tracking for reckon-db
Provides functionality to trace event lineage: - Causation ID: Links an event to its direct cause - Correlation ID: Groups related events in a business process/saga - Actor ID: Identifies who/what triggered the event
Standard metadata fields (convention):
#{
causation_id => binary(), %% ID of event/command that caused this
correlation_id => binary(), %% Business process/saga ID
actor_id => binary() %% Who/what triggered this
}Use cases: - Debugging distributed event flows - Audit trails - Saga/process manager state reconstruction - Dependency analysis
Summary
Functions
Build a causation graph for visualization.
Get the event that caused the given event.
Get the full causation chain from root to the given event.
Get all events sharing the same correlation ID.
Get all events caused by the given event.
Export a causation graph as DOT format for Graphviz.
Types
-type event() :: #event{event_id :: binary(), event_type :: binary(), stream_id :: binary(), version :: non_neg_integer(), data :: map() | binary(), metadata :: map(), tags :: [binary()] | undefined, timestamp :: integer(), epoch_us :: integer(), data_content_type :: binary(), metadata_content_type :: binary()}.
Functions
-spec build_graph(atom(), binary()) -> {ok, causation_graph()} | {error, term()}.
Build a causation graph for visualization.
Accepts either an event_id (builds graph from that event) or a correlation_id (builds graph from all correlated events). Returns nodes and edges suitable for graph rendering.
Get the event that caused the given event.
Finds the event whose event_id matches this event's causation_id.
Get the full causation chain from root to the given event.
Walks backward through causation_id links until reaching an event with no cause. Returns events in order from root to target.
Get all events caused by the given event.
Returns events whose causation_id matches the given event_id.
-spec to_dot(causation_graph()) -> binary().
Export a causation graph as DOT format for Graphviz.
Usage: dot -Tpng -o graph.png with the output.