GenServer for storing and querying tracer events.
The EventStore provides persistent storage for tracer events with support for:
- Storing events with optional callbacks
- Filtering by event type, time range, and custom functions
- Querying the last N events
- Clearing all events
Examples
# Start the event store
{:ok, pid} = EventStore.start_link([])
# Store an event
event = %TracerEvent{...}
:ok = EventStore.store(pid, event)
# Get all events
events = EventStore.get_events(pid)
# Get events by type
llm_events = EventStore.get_events(pid, event_type: LLMCallTracerEvent)
# Get events by time range
events = EventStore.get_events(pid,
start_time: start_timestamp,
end_time: end_timestamp
)
# Get last N events
recent = EventStore.get_last_n_events(pid, 10)
# Clear all events
:ok = EventStore.clear(pid)
Summary
Functions
Returns a specification to start this module under a supervisor.
Clears all events from the store.
Retrieves events from the store with optional filtering.
Gets the last N events, optionally filtered by type.
Starts the EventStore GenServer.
Stores an event in the event store.
Types
Functions
Returns a specification to start this module under a supervisor.
See Supervisor.
@spec clear(GenServer.server()) :: :ok
Clears all events from the store.
Examples
:ok = EventStore.clear(pid)
@spec get_events( GenServer.server(), keyword() ) :: [Mojentic.Tracer.TracerEvents.TracerEvent.t()]
Retrieves events from the store with optional filtering.
Options
:event_type- Filter by specific event type (module):start_time- Include events with timestamp >= start_time:end_time- Include events with timestamp <= end_time:filter_func- Custom filter function that returns true for events to include
Examples
# Get all events
events = EventStore.get_events(pid)
# Filter by type
llm_calls = EventStore.get_events(pid, event_type: LLMCallTracerEvent)
# Filter by time range
recent = EventStore.get_events(pid,
start_time: start_timestamp,
end_time: end_timestamp
)
# Custom filter
events = EventStore.get_events(pid,
filter_func: fn event -> event.correlation_id == "abc-123" end
)
@spec get_last_n_events(GenServer.server(), non_neg_integer(), keyword()) :: [ Mojentic.Tracer.TracerEvents.TracerEvent.t() ]
Gets the last N events, optionally filtered by type.
Examples
# Get last 10 events
recent = EventStore.get_last_n_events(pid, 10)
# Get last 5 LLM call events
recent_calls = EventStore.get_last_n_events(pid, 5,
event_type: LLMCallTracerEvent
)
Starts the EventStore GenServer.
Options
:on_store_callback- Function called whenever an event is stored:name- Name to register the GenServer under
Examples
{:ok, pid} = EventStore.start_link([])
{:ok, pid} = EventStore.start_link(name: :my_event_store)
{:ok, pid} = EventStore.start_link(on_store_callback: &IO.inspect/1)
@spec store(GenServer.server(), Mojentic.Tracer.TracerEvents.TracerEvent.t()) :: :ok
Stores an event in the event store.
If an on_store_callback was provided during initialization, it will be called
with the stored event.
Examples
event = %TracerEvent{...}
:ok = EventStore.store(pid, event)