Skip to content

Add event sinks with OpenTelemetry and Sentry exporters - #5

Merged
javaquasar merged 1 commit into
mainfrom
claude/event-log
Dec 2, 2026
Merged

javaquasar merged 1 commit into
mainfrom
claude/event-log

Conversation

@javaquasar

Copy link
Copy Markdown
Owner

Summary

The mutation event log can now be sent to production monitoring, not only shown in devtools.

export const events = createMutationEventStore({
  limit: 200,
  sinks: [
    createOpenTelemetrySink({ tracer: trace.getTracer("app") }), // mutaflow/otel
    createSentrySink({ sentry: Sentry }),                         // mutaflow/sentry
  ],
});

Event log

  • Bounded store. createMutationEventStore now keeps the latest 1000 events by default (limit). It used to grow for the life of the page. limit: 0 keeps no events and only forwards them to sinks.
  • Sinks. A sink is any (event) => void and receives every event as it is emitted. If a sink throws, the flow is not affected and the error goes to onSinkError (default console.error).
  • durationMs. flow:success, flow:error and flow:cancelled events now carry durationMs.
  • serializeMutationEvent. Returns a JSON-safe event:
    • errors keep their name, message, stack, cause and own fields such as code;
    • circular references are replaced;
    • input and result are left out unless asked for.

Exporters

  • mutaflow/otel. Each flow run becomes one span.
    • The optimistic update, retries, rollback and reconcile are recorded as span events.
    • The span carries the status, attempts, duration, invalidations and consistency strategy.
    • A failed run gets the ERROR status and its exception recorded.
    • A run that fails in beforeRun, before flow:start, still gets a span.
  • mutaflow/sentry. Adds a breadcrumb per event and captures flow:error as an issue tagged with the flow name and stage.
    • Cancellations are not captured.
    • captureError can filter the remaining errors.

Neither SDK is a dependency. Both sinks accept objects shaped like an OpenTelemetry Tracer or the Sentry SDK. tests/types/observability.ts checks them against the real @opentelemetry/api and @sentry/core types, which are root devDependencies only. Neither sink sends input or result.

Devtools

  • Show the run duration.
  • The inspector shows real errors. It used to show {}, because JSON.stringify drops Error fields.
  • New "Export log" button: downloads the log as JSON, with input and result, since devtools run locally.
  • New "Clear" button.
  • serializeEventLog is exported.

Behaviour changes

  • The 1000-event default limit is new. It is noted under Changed in the CHANGELOG.

Not included

  • A browser-extension devtools. The devtools are still an in-app React panel.

Test plan

  • npm run typecheck from a clean build. This includes the SDK compatibility type tests.
  • npm test: 53/53. New tests cover:
    • the store limit and sinks;
    • durationMs;
    • the serializer;
    • the OTel spans;
    • the Sentry breadcrumbs and capture, including a check that input is not sent;
    • the devtools inspector.
  • examples/next-app: typecheck and next build.

🤖 Generated with Claude Code

createMutationEventStore now takes a limit (1000 by default, so the log
no longer grows without bound) and sinks that receive every event as it
is emitted. A failing sink does not affect the flow.

mutaflow/otel records each flow run as one span with its intermediate
events, status, attempts, duration and invalidations. mutaflow/sentry
adds breadcrumbs and captures failed runs as issues. Both accept objects
shaped like the SDKs, so neither is a dependency; type tests check them
against @opentelemetry/api and @sentry/core. Neither sends input or result.

serializeMutationEvent returns a JSON-safe event that keeps error
details. Terminal events carry durationMs. Devtools show the duration,
render errors instead of {}, and can export and clear the log.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@javaquasar
javaquasar merged commit bb4c311 into main Dec 2, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant