# Seeing every event of a journey

## What you want to do

The log stopped at Pat's charge, so no record says how Pat's journey ended. You want to see every event of a journey as it happens, without writing a reporter of your own.

## The code

The shop is [chapter 31](https://itinera-dev.org/book/kotlin/31-stopping-a-journey-when-its-log-fails.md)'s, with one more reporter. `DebugReporter`, from `org.itineradev.itinera.report`, comes with Itinera, and prints every event of a journey on a line of its own. The workflow lists it first:

Kotlin, from the program [`ch32_seeing_every_event_of_a_journey`](https://github.com/itinera-dev/book/blob/main/kotlin/examples/ch32_seeing_every_event_of_a_journey.kt)

```kotlin
@Workflow(
    name = "orders",
    reporters = [DebugReporter::class, Log::class, Desk::class],
    policies = [Notify::class],
)
```

Kotlin, the same in its asynchronous form, from the program [`ch32_seeing_every_event_of_a_journey_async`](https://github.com/itinera-dev/book/blob/main/kotlin/examples/ch32_seeing_every_event_of_a_journey_async.kt)

```kotlin
@Workflow(
    name = "orders",
    reporters = [AsyncDebugReporter::class, Log::class, Desk::class],
    policies = [Notify::class],
)
```

The log is [chapter 31](https://itinera-dev.org/book/kotlin/31-stopping-a-journey-when-its-log-fails.md)'s, the desk is [chapter 11](https://itinera-dev.org/book/kotlin/11-naming-a-journey.md)'s and `Notify` is [chapter 19](https://itinera-dev.org/book/kotlin/19-letting-policies-act-on-the-outside-world.md)'s. The rest of the workflow is as [chapter 23](https://itinera-dev.org/book/kotlin/23-undoing-a-charge-when-the-shipping-fails.md) declares it.

In the asynchronous form, the workflow lists `AsyncDebugReporter`, from `org.itineradev.itinera.report.async`, which prints the same lines as an `AsyncReporter`, since every reporter of an asynchronous workflow is one, as [chapter 26](https://itinera-dev.org/book/kotlin/26-running-async-journeys-while-others-wait.md) said. Its workflow is otherwise as chapter 26 shows it.

`main` runs Pat's order alone, as [chapter 31](https://itinera-dev.org/book/kotlin/31-stopping-a-journey-when-its-log-fails.md) runs it, and prints:

What `ch32_seeing_every_event_of_a_journey` prints, recorded in [`ch32_seeing_every_event_of_a_journey.txt`](https://github.com/itinera-dev/book/blob/main/kotlin/expected/ch32_seeing_every_event_of_a_journey.txt)

```text
Pat's order:
JourneyStarted(sequence=1, timestamp=2026-10-30T02:35:46.286248862Z, journeyId=A-15, workflow=orders, initialKeys=[order, customer, price, parcel, card, giftCard])
log orders A-15 #1 journey_started order, customer, price, parcel, card, giftCard
AttemptStarted(sequence=2, timestamp=2026-10-30T02:35:46.316041216Z, journeyId=A-15, workflow=orders, step=lookup, attempt=1)
log orders A-15 #2 attempt_started lookup, attempt 1
ServiceProvided(sequence=3, timestamp=2026-10-30T02:35:46.332045762Z, journeyId=A-15, workflow=orders, step=lookup, attempt=1, key=orderBook, provider=ledger, implementation=ch32_seeing_every_event_of_a_journey.Ledger, data=null)
log orders A-15 #3 service_provided lookup gets orderBook from ledger, a ch32_seeing_every_event_of_a_journey.Ledger
the order book has no order A-15 yet
StepSucceeded(sequence=4, timestamp=2026-10-30T02:35:46.347340651Z, journeyId=A-15, workflow=orders, step=lookup, attempt=1)
log orders A-15 #4 step_succeeded lookup
ContributionCommitted(sequence=5, timestamp=2026-10-30T02:35:46.349679958Z, journeyId=A-15, workflow=orders, key=completed, source=StepSource(step=lookup, attempt=1))
log orders A-15 #5 contribution_committed completed
StepHookCalled(sequence=6, timestamp=2026-10-30T02:35:46.357951201Z, journeyId=A-15, workflow=orders, source=StepHookSource(policy=alreadyCompleted, hook=on step success, step=lookup, attempt=1), lifecycle=null)
log orders A-15 #6 hook_called alreadyCompleted: on step success of lookup
AttemptStarted(sequence=7, timestamp=2026-10-30T02:35:46.363821540Z, journeyId=A-15, workflow=orders, step=price, attempt=1)
log orders A-15 #7 attempt_started price, attempt 1
OptionalInputAbsent(sequence=8, timestamp=2026-10-30T02:35:46.365134599Z, journeyId=A-15, workflow=orders, key=discount, requester=StepSource(step=price, attempt=1))
log orders A-15 #8 optional_input_absent discount
StepSucceeded(sequence=9, timestamp=2026-10-30T02:35:46.369498054Z, journeyId=A-15, workflow=orders, step=price, attempt=1)
log orders A-15 #9 step_succeeded price
ContributionCommitted(sequence=10, timestamp=2026-10-30T02:35:46.369743464Z, journeyId=A-15, workflow=orders, key=amount, source=StepSource(step=price, attempt=1))
log orders A-15 #10 contribution_committed amount
AttemptStarted(sequence=11, timestamp=2026-10-30T02:35:46.369885688Z, journeyId=A-15, workflow=orders, step=charge, attempt=1)
log orders A-15 #11 attempt_started charge, attempt 1
ServiceProvided(sequence=12, timestamp=2026-10-30T02:35:46.372353009Z, journeyId=A-15, workflow=orders, step=charge, attempt=1, key=payments, provider=bank, implementation=ch32_seeing_every_event_of_a_journey.Bank, data=null)
log orders A-15 #12 service_provided charge gets payments from bank, a ch32_seeing_every_event_of_a_journey.Bank
the bank charges 50 for order A-15
StepSucceeded(sequence=13, timestamp=2026-10-30T02:35:46.379707318Z, journeyId=A-15, workflow=orders, step=charge, attempt=1)
JourneyAborted(sequence=14, timestamp=2026-10-30T02:35:46.381314443Z, journeyId=A-15, workflow=orders, abort=ReporterFailed(step=charge, errorMessage=the logging service is down))
the journey was aborted (reporter failed: the logging service is down)
```

What the asynchronous form `ch32_seeing_every_event_of_a_journey_async` prints, recorded in [`ch32_seeing_every_event_of_a_journey_async.txt`](https://github.com/itinera-dev/book/blob/main/kotlin/expected/ch32_seeing_every_event_of_a_journey_async.txt)

```text
JourneyStarted(sequence=1, timestamp=2026-10-30T02:35:48.280677353Z, journeyId=A-15, workflow=orders, initialKeys=[order, customer, price, parcel, card, giftCard])
log orders A-15 #1 journey_started order, customer, price, parcel, card, giftCard
AttemptStarted(sequence=2, timestamp=2026-10-30T02:35:48.311022716Z, journeyId=A-15, workflow=orders, step=lookup, attempt=1)
log orders A-15 #2 attempt_started lookup, attempt 1
ServiceProvided(sequence=3, timestamp=2026-10-30T02:35:48.333464190Z, journeyId=A-15, workflow=orders, step=lookup, attempt=1, key=orderBook, provider=ledger, implementation=ch32_seeing_every_event_of_a_journey_async.Ledger, data=null)
log orders A-15 #3 service_provided lookup gets orderBook from ledger, a ch32_seeing_every_event_of_a_journey_async.Ledger
the order book has no order A-15 yet
StepSucceeded(sequence=4, timestamp=2026-10-30T02:35:48.347289905Z, journeyId=A-15, workflow=orders, step=lookup, attempt=1)
log orders A-15 #4 step_succeeded lookup
ContributionCommitted(sequence=5, timestamp=2026-10-30T02:35:48.349553506Z, journeyId=A-15, workflow=orders, key=completed, source=StepSource(step=lookup, attempt=1))
log orders A-15 #5 contribution_committed completed
StepHookCalled(sequence=6, timestamp=2026-10-30T02:35:48.358810109Z, journeyId=A-15, workflow=orders, source=StepHookSource(policy=alreadyCompleted, hook=on step success, step=lookup, attempt=1), lifecycle=null)
log orders A-15 #6 hook_called alreadyCompleted: on step success of lookup
AttemptStarted(sequence=7, timestamp=2026-10-30T02:35:48.365175558Z, journeyId=A-15, workflow=orders, step=price, attempt=1)
log orders A-15 #7 attempt_started price, attempt 1
OptionalInputAbsent(sequence=8, timestamp=2026-10-30T02:35:48.366698835Z, journeyId=A-15, workflow=orders, key=discount, requester=StepSource(step=price, attempt=1))
log orders A-15 #8 optional_input_absent discount
StepSucceeded(sequence=9, timestamp=2026-10-30T02:35:48.369632132Z, journeyId=A-15, workflow=orders, step=price, attempt=1)
log orders A-15 #9 step_succeeded price
ContributionCommitted(sequence=10, timestamp=2026-10-30T02:35:48.369884766Z, journeyId=A-15, workflow=orders, key=amount, source=StepSource(step=price, attempt=1))
log orders A-15 #10 contribution_committed amount
AttemptStarted(sequence=11, timestamp=2026-10-30T02:35:48.370149344Z, journeyId=A-15, workflow=orders, step=charge, attempt=1)
log orders A-15 #11 attempt_started charge, attempt 1
ServiceProvided(sequence=12, timestamp=2026-10-30T02:35:48.371842404Z, journeyId=A-15, workflow=orders, step=charge, attempt=1, key=payments, provider=bank, implementation=ch32_seeing_every_event_of_a_journey_async.Bank, data=null)
log orders A-15 #12 service_provided charge gets payments from bank, a ch32_seeing_every_event_of_a_journey_async.Bank
the bank charges 50 for order A-15
StepSucceeded(sequence=13, timestamp=2026-10-30T02:35:48.379860382Z, journeyId=A-15, workflow=orders, step=charge, attempt=1)
JourneyAborted(sequence=14, timestamp=2026-10-30T02:35:48.381684281Z, journeyId=A-15, workflow=orders, abort=ReporterFailed(step=charge, errorMessage=the logging service is down))
order A-15:
the journey was aborted (reporter failed: the logging service is down)
```

## How it works

1. **A ready-made reporter prints every event.** `DebugReporter` prints each event as its data class prints it: the class's name, then its sequence number, its timestamp, the journey's ID, the workflow and everything its kind carries. An event is plain data, so nothing is left out. It is a reporter like any other, a class implementing `Reporter`, so the workflow lists it by its class, as it does the log. It suits trying a workflow out, debugging one and watching a test run. A reporter for the shop's real log still formats its own lines, as the log does.
2. **It never fails.** It prints and returns, so `DebugReporter` never costs a journey, as [chapter 31](https://itinera-dev.org/book/kotlin/31-stopping-a-journey-when-its-log-fails.md) said every reporter should.
3. **Reporters receive each event in the order the workflow lists them,** as [chapter 10](https://itinera-dev.org/book/kotlin/10-more-than-one-reporter.md) showed. `DebugReporter` comes first, so it printed event 13, the charge's `StepSucceeded`, before the log failed on it.
4. **`journey_aborted` reaches every reporter but the one that failed.** Event 14, a `JourneyAborted`, reached `DebugReporter`, and the desk, which prints nothing for it, but not the log. Its `abort` is the `ReporterFailed` of [chapter 31](https://itinera-dev.org/book/kotlin/31-stopping-a-journey-when-its-log-fails.md), naming the step the journey was in, `charge`, and the message of the log's error.

Pat's journey is now on record to its end. But the shop still has to refund Pat, and no line holds the receipt the bank gave: the charge never got to commit it. Nor does any event name Pat: each names the journey, `A-15`.

## Outcomes

We have shown how a ready-made reporter shows every event of a journey, up to its end.

| The usual way                                                                       | With Itinera                                                                                     |
| ----------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------ |
| Seeing what a request did often means adding `println` calls, then taking them out. | A reporter that comes with Itinera prints every event, listed once on the workflow.              |
| A crash in one part of the logging often hides what happened next.                  | `journey_aborted` reaches every reporter but the one that failed, with the reason and the error. |
