Skip to content

Event querying with Cratis CLI

The events commands let you query events from an event sequence and retrieve the highest used sequence number. Use these commands to verify that events were appended, inspect their content, and understand the current state of an event log.

Retrieves events from an event sequence, with optional filtering by range, event source, and event type.

Terminal window
cratis chronicle events get
Flag Description
-e, --event-store <NAME> Event store to query. Defaults to the active context’s event store, then default.
-n, --namespace <NAME> Namespace to query. Defaults to the active context’s namespace, then Default.
--sequence <NAME> Event sequence to query. Defaults to the event log.
--from <SEQUENCE_NUMBER> Start of the sequence range (inclusive, 0-based). Defaults to 0.
--to <SEQUENCE_NUMBER> End of the sequence range (inclusive). Omit to read to the current tail.
--event-source-id <ID> Filter events to a single event source.
--event-type <TYPES> Comma-separated event type identifiers. Filtering uses only identifiers; a +<generation> suffix is accepted but does not restrict generation.

Use --output plain when processing events in scripts.

Get all events from the event log:

Terminal window
cratis chronicle events get

Get events from sequence number 100 to 200:

Terminal window
cratis chronicle events get --from 100 --to 200

Get all events for a specific event source:

Terminal window
cratis chronicle events get --event-source-id "user-42"

Filter to a single event type:

Terminal window
cratis chronicle events get --event-type UserRegistered

Adding +2 still filters only by the UserRegistered identifier, not by generation:

Terminal window
cratis chronicle events get --event-type UserRegistered+2

Filter to multiple event types:

Terminal window
cratis chronicle events get --event-type UserRegistered,UserEmailChanged

Combine filters for targeted inspection:

Terminal window
cratis chronicle events get --event-source-id "user-42" --event-type UserRegistered --output json

Gets the highest used sequence number in an event sequence. This is the tail of the log — the sequence number of the last appended event. It is not a count of events: gaps may exist in the sequence if events were redacted or sequences were not used contiguously.

Terminal window
cratis chronicle events tail
Flag Description
-e, --event-store <NAME> Event store to query. Defaults to the active context’s event store, then default.
-n, --namespace <NAME> Namespace to query. Defaults to the active context’s namespace, then Default.
--sequence <NAME> Event sequence to query. Defaults to the event log.
--event-type <TYPE> Return the tail sequence number for a specific event type.
--event-source-id <ID> Return the tail sequence number for a specific event source.

With --output plain, the command prints a TailSequenceNumber header line followed by the number. Use -q (--quiet) to get only the number on one line, making it easy to capture in a script:

Terminal window
TAIL=$(cratis chronicle events tail -q)

Get the tail sequence number of the event log:

Terminal window
cratis chronicle events tail

Get the tail for a specific event source:

Terminal window
cratis chronicle events tail --event-source-id "user-42"

Get the tail for a specific event type:

Terminal window
cratis chronicle events tail --event-type UserRegistered

Capture the tail number in a script:

Terminal window
TAIL=$(cratis chronicle events tail -e myapp -q)
echo "Current tail: $TAIL"