Skip to content

Observability

Observability

Gember Event Sourcing provides built-in logging through decorator classes that wrap the core components. These decorators use PSR-3 for logging, making them compatible with any framework.

Logging

Loggable decorators provide structured logging for the main execution paths:

Decorator Wraps Logs
LoggableEventStoreDecorator EventStore Event loading and appending
LoggableUseCaseCommandExecutorDecorator UseCaseCommandExecutor Command handling on use cases
LoggableSagaEventExecutorDecorator SagaEventExecutor Event handling on sagas
LoggableSnapshotStoreDecorator SnapshotStore Snapshot loading and saving (when snapshotting is enabled)

They log at INFO level using PSR-3's LoggerInterface, except failures of the snapshot store, which are logged at ERROR. Some components log problems that need attention at WARNING or ERROR: saga retries that gave up (below), snapshots that couldn't be loaded or saved (see Snapshotting), and outbox messages that failed or couldn't be deserialized (see Outbox).

What gets logged

Each decorator logs the start, completion, and failure of its wrapped operation:

Event store (load):

[EventStore] Started loading events          {domainTags: [...]}
[EventStore] Loaded event CourseCreatedEvent  {eventId: "...", appliedAt: "...", metadata: {...}, domainTags: [...]}
[EventStore] Ended loading events            {domainTags: [...], duration: 0.0042}

Command handling:

[UseCase] Started handling CreateCourseCommand by CreateCourse  {domainTags: [...]}
[UseCase] Finished handling CreateCourseCommand by CreateCourse {domainTags: [...], duration: 0.0051}

Saga event handling:

[Saga] Started handling OrderPlacedEvent by OrderFulfillmentSaga  {sagaIds: ["order-123"]}
[Saga] Finished handling OrderPlacedEvent by OrderFulfillmentSaga {sagaIds: ["order-123"], duration: 0.0023}

sagaIds lists the event's Saga ID values the saga was looked up by.

A saga changed concurrently is retried (see How it works - Saga concurrency): each failed attempt is logged as a failure with exceptionClass SagaConcurrencyException. When all attempts fail, RetryingSagaEventExecutorDecorator logs a WARNING:

[Saga] Gave up handling OrderPlacedEvent by OrderFulfillmentSaga after 5 attempt(s): saga was changed concurrently {sagaIds: ["order-123"], insideTransaction: false}

On failure, the log includes exception (message) and exceptionClass in the context. All durations are measured in seconds using microtime(true).

Symfony bundle configuration

When using the Symfony bundle, the logging decorators are always enabled. They automatically wrap the core components using Symfony's service decoration. No additional configuration is needed.

The logger service can be customized in gember_event_sourcing.yaml:

gember_event_sourcing:
    logging:
        logger: '@logger'  # default