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's, with one more reporter. DebugReporter, from itinera/report, comes with itinera, and prints every event of a journey on a line of its own. The workflow lists it first:
@workflow({
name: "orders",
reporters: [DebugReporter, Log, Desk],
policies: [Notify],
})The log is chapter 31's, the desk is chapter 11's and Notify is chapter 26's. The rest of the workflow is as chapter 23 declares it, with the role implementations of chapter 26.
The program runs Pat's order alone, as chapter 31 runs it, and prints:
Pat's order:
{"kind":"journey_started","initialKeys":["order","customer","price","parcel","card","giftCard"],"sequence":1,"timestamp":"2026-10-21T05:55:58.260Z","journeyId":"A-15","workflow":"orders"}
log orders A-15 #1 journey_started order, customer, price, parcel, card, giftCard
{"kind":"attempt_started","step":"lookup","attempt":1,"sequence":2,"timestamp":"2026-10-21T05:55:58.261Z","journeyId":"A-15","workflow":"orders"}
log orders A-15 #2 attempt_started lookup, attempt 1
{"kind":"service_provided","step":"lookup","attempt":1,"key":"orderBook","provider":"ledger","implementation":"Ledger","sequence":3,"timestamp":"2026-10-21T05:55:58.262Z","journeyId":"A-15","workflow":"orders"}
log orders A-15 #3 service_provided lookup gets orderBook from ledger, a Ledger
the order book has no order A-15 yet
{"kind":"step_succeeded","step":"lookup","attempt":1,"sequence":4,"timestamp":"2026-10-21T05:55:58.263Z","journeyId":"A-15","workflow":"orders"}
log orders A-15 #4 step_succeeded lookup
{"kind":"contribution_committed","key":"completed","source":{"kind":"step","step":"lookup","attempt":1},"sequence":5,"timestamp":"2026-10-21T05:55:58.264Z","journeyId":"A-15","workflow":"orders"}
log orders A-15 #5 contribution_committed completed
{"kind":"hook_called","source":{"kind":"step hook","policy":"alreadyCompleted","hook":"on step success","step":"lookup","attempt":1},"sequence":6,"timestamp":"2026-10-21T05:55:58.265Z","journeyId":"A-15","workflow":"orders"}
log orders A-15 #6 hook_called alreadyCompleted: on step success of lookup
{"kind":"attempt_started","step":"price","attempt":1,"sequence":7,"timestamp":"2026-10-21T05:55:58.265Z","journeyId":"A-15","workflow":"orders"}
log orders A-15 #7 attempt_started price, attempt 1
{"kind":"optional_input_absent","key":"discount","requester":{"kind":"step","step":"price","attempt":1},"sequence":8,"timestamp":"2026-10-21T05:55:58.265Z","journeyId":"A-15","workflow":"orders"}
log orders A-15 #8 optional_input_absent discount
{"kind":"step_succeeded","step":"price","attempt":1,"sequence":9,"timestamp":"2026-10-21T05:55:58.266Z","journeyId":"A-15","workflow":"orders"}
log orders A-15 #9 step_succeeded price
{"kind":"contribution_committed","key":"amount","source":{"kind":"step","step":"price","attempt":1},"sequence":10,"timestamp":"2026-10-21T05:55:58.266Z","journeyId":"A-15","workflow":"orders"}
log orders A-15 #10 contribution_committed amount
{"kind":"attempt_started","step":"charge","attempt":1,"sequence":11,"timestamp":"2026-10-21T05:55:58.266Z","journeyId":"A-15","workflow":"orders"}
log orders A-15 #11 attempt_started charge, attempt 1
{"kind":"service_provided","step":"charge","attempt":1,"key":"payments","provider":"bank","implementation":"Bank","sequence":12,"timestamp":"2026-10-21T05:55:58.267Z","journeyId":"A-15","workflow":"orders"}
log orders A-15 #12 service_provided charge gets payments from bank, a Bank
the bank charges 50 for order A-15
{"kind":"step_succeeded","step":"charge","attempt":1,"sequence":13,"timestamp":"2026-10-21T05:55:58.267Z","journeyId":"A-15","workflow":"orders"}
{"kind":"journey_aborted","abort":{"reason":"reporter failed","step":"charge","errorMessage":"the logging service is down"},"sequence":14,"timestamp":"2026-10-21T05:55:58.267Z","journeyId":"A-15","workflow":"orders"}
the journey was aborted (reporter failed: the logging service is down)How it works
- A ready-made reporter prints every event.
DebugReporterprints each event as one line of JSON, asJSON.stringifywrites it: itskind, everything that kind carries, then its sequence number, its timestamp, the journey's ID and the workflow's name. An event is plain data, so nothing is left out. It is a reporter like any other, a class implementingReporter, 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. - It never fails. It prints and returns, so
DebugReporternever costs a journey, as chapter 31 said every reporter should. - Reporters receive each event in the order the workflow lists them, as chapter 10 showed.
DebugReportercomes first, so it printed event 13, the charge'sstep_succeeded, before the log failed on it. journey_abortedreaches every reporter but the one that failed. Event 14 reachedDebugReporter, and the desk, which prints nothing for it, but not the log. Itsabortnames the abort's reason,reporter failed, 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 console.log 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. |