Interface Reporter

Receives the events and the global metadata of a journey, and decides on its own what to do with each: filter it, map it, forward it, keep it or ignore it. A workflow lists its reporters, and a workflow instance may add more; itinera builds them for every journey.

Either operation may be synchronous or asynchronous: itinera waits for what it returns before it goes on, so a slow reporter slows the journey.

A reporter handles its own trouble. One that cannot report an event should deal with that itself, by logging it, dropping the event or keeping it to retry later, and return normally, so that the reporters after it still receive the event. A failure that escapes a reporter, a throw or a rejected promise, aborts the journey with reporter failed, and the event goes no further.

import type { Event } from "itinera/event";
import type { Reporter } from "itinera/report";
import type { PlainValue } from "itinera/value";

export class Audit implements Reporter {
readonly #metadata = new Map<string, PlainValue>();

receiveGlobalMetadata(key: string, value: PlainValue): void {
this.#metadata.set(key, value);
}

report(event: Event): void {
const tenant = JSON.stringify(this.#metadata.get("tenant"));
console.log(`${event.journeyId} ${event.kind} for ${tenant}`);
}
}
interface Reporter {
    receiveGlobalMetadata?(
        key: string,
        value: PlainValue,
    ): void | Promise<void>;
    report(event: Event): void | Promise<void>;
}

Implemented by

Index

  • Receives one entry of the journey's global metadata: a key, and a value captured when it was set. The journey ID comes first, under journey_id; setting a key again replaces its value. A reporter without this operation accepts every entry and does nothing with it.

    Parameters

    Returns void | Promise<void>

  • Receives one event of the journey.

    Parameters

    Returns void | Promise<void>