feat: default CloudEvent source for emitted events (#776)#782
Open
anuragpaul602-netizen wants to merge 1 commit into
Open
Conversation
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>
Member
|
I think we are overengineering here a bit, but I'll give some thoughts on it before closing it. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What & why
Fixes #776.
The
emitDSL helpers only settypeanddata, so emitted CloudEvents had nosourceunless the user manually chained.source(...). The underlying SDK then fell back to the opaquereference-impl, giving no traceability.This PR gives every emitted CloudEvent that does not declare its own
sourcea 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 asourceon everyemitthat has none. It descends into every container that can nest an emit: top-leveldo,DoTask.do,ForTask.do,ForkTask.fork.branches,TryTask.try+catch.do, andListenTask.foreach.do. An explicit source (literal or runtime expression) is never overwritten.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(defaulttrue) — escape hatch to disable injection entirely.source→ configuredsource→ identity-derived → SDK fallback.Scope note:
timeThe event
timedefault is intentionally not handled here.timeis 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 current7.25.1.Final; once that SDK change ships and the version is bumped, emitted events also get a defaulttime.Design
See
adr/2026-07-23-cloudevent-emit-defaults-design.mdfor the full design, the layering principle (per-execution values in the SDK runtime;sourceergonomics 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).core/runtimesuite passes (219 tests).CloudEventDefaultSourceTest(@QuarkusTest) — asserts a class-based emit flow with no source gets the identity-derivednamespace:name:versionon its registered definition. Compiles locally; relies on CI to run (needs Dev Services / Docker).messaging.adocdocuments the new default and config.Docs
New "Default event
source" section inmessaging.adoc.🤖 Generated with Claude Code