Skip to content

feat: default CloudEvent source for emitted events (#776)#782

Open
anuragpaul602-netizen wants to merge 1 commit into
quarkiverse:mainfrom
anuragpaul602-netizen:issues/776-cloudevent-emit-default-source
Open

feat: default CloudEvent source for emitted events (#776)#782
anuragpaul602-netizen wants to merge 1 commit into
quarkiverse:mainfrom
anuragpaul602-netizen:issues/776-cloudevent-emit-default-source

Conversation

@anuragpaul602-netizen

Copy link
Copy Markdown

What & why

Fixes #776.

The emit DSL helpers only set type and data, so emitted CloudEvents had no source unless the user manually chained .source(...). The underlying SDK then fell back to the opaque reference-impl, giving no traceability.

This PR gives every emitted CloudEvent that does not declare its own source a traceable default, with zero configuration required.

How

The default is injected at WorkflowRegistrarService.register(Workflow) — the single runtime seam shared by both class-based flows (Flow.descriptor()) and YAML/JSON flows (WorkflowReader.readWorkflowFromClasspath). This is the only layer with the built workflow model and its identity in hand.

  • EmitEventSourceInjector — a recursive walker over the task tree that sets a source on every emit that has none. It descends into every container that can nest an emit: top-level do, DoTask.do, ForTask.do, ForkTask.fork.branches, TryTask.try + catch.do, and ListenTask.foreach.do. An explicit source (literal or runtime expression) is never overwritten.
  • Default value — the emitting workflow's identity, namespace:name:version (WorkflowDefinitionId.of(workflow).toString(":")).
  • FlowCloudEventsConfig (quarkus.flow.cloud-events):
    • source — a fixed global override applied to all emits.
    • derive-source-from-workflow (default true) — escape hatch to disable injection entirely.
  • Precedence: explicit per-emit source → configured source → identity-derived → SDK fallback.

Scope note: time

The event time default is intentionally not handled here. time is a per-execution value that cannot be baked into a definition, so it belongs in the SDK runtime — see open-workflow-specification/sdk-java#1554. This PR needs no SDK change and works against the current 7.25.1.Final; once that SDK change ships and the version is bumped, emitted events also get a default time.

Design

See adr/2026-07-23-cloudevent-emit-defaults-design.md for the full design, the layering principle (per-execution values in the SDK runtime; source ergonomics at the quarkus-flow registrar seam), and the alternatives considered.

Testing

  • EmitEventSourceInjectorTest — unit tests for each nesting container, explicit-source preservation, and null/blank no-ops (5 tests, passing).
  • Full core/runtime suite passes (219 tests).
  • CloudEventDefaultSourceTest (@QuarkusTest) — asserts a class-based emit flow with no source gets the identity-derived namespace:name:version on its registered definition. Compiles locally; relies on CI to run (needs Dev Services / Docker).
  • messaging.adoc documents the new default and config.

Docs

New "Default event source" section in messaging.adoc.

🤖 Generated with Claude Code

Fix quarkiverse#776

Emit tasks that do not declare a `source` now receive a traceable
default so produced CloudEvents are well-formed without manual
`.source(...)` chaining.

The default is injected at `WorkflowRegistrarService.register(Workflow)`,
the single runtime seam shared by both class-based (`Flow.descriptor()`)
and YAML/JSON flows. `EmitEventSourceInjector` walks the task tree
recursively (do, for, fork branches, try/catch, listen foreach) and sets
a source only where none is present; explicit per-emit sources are never
overwritten.

By default the injected value is the emitting workflow's identity,
`namespace:name:version`. New `FlowCloudEventsConfig`
(`quarkus.flow.cloud-events`) allows a fixed `source` override or
disabling identity derivation via `derive-source-from-workflow=false`.

The event `time` default is intentionally left to the SDK runtime
(open-workflow-specification/sdk-java#1554), since it is a per-execution
value and cannot be baked into a definition.

Design: adr/2026-07-23-cloudevent-emit-defaults-design.md

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@anuragpaul602-netizen
anuragpaul602-netizen requested a review from a team as a code owner July 23, 2026 13:03
@ricardozanini

Copy link
Copy Markdown
Member

I think we are overengineering here a bit, but I'll give some thoughts on it before closing it.

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.

Add smart CloudEvent defaults to FlowDSL emit helpers

2 participants