Skip to content

fix: propagate OTel context through fan-out branches and emit per-branch spans - #11

Merged
lostbean merged 1 commit into
lostbean:mainfrom
Munksgaard:fix/fan-out-otel-context-propagation
Jun 16, 2026
Merged

lostbean merged 1 commit into
lostbean:mainfrom
Munksgaard:fix/fan-out-otel-context-propagation

Conversation

@Munksgaard

Copy link
Copy Markdown
Contributor

Three issues caused broken traces for workflows using MapNode/FanOutBranch:

  1. Task.async_stream in execute_fan_out_branches (dsl.ex) and MapNode.run spawned child tasks without propagating the current OTel context. Child spans were disconnected from the parent trace. Fixed by capturing the context before spawning and re-attaching via OtelCtx.with_parent_context in each task — the same pattern already used by SpawnAgent.

  2. execute_fan_out_branch ran the child node without creating a span, so individual branch executions were invisible to tracing. Now wraps each branch in a TOOL span with the child node name.

  3. maybe_complete_fan_out in the workflow strategy transitioned to the next node without finishing the current node span. This left the fan-out node's span open, causing subsequent nodes to incorrectly nest under it instead of being siblings. Added finish_node_span before the transition.

…nch spans

Three issues caused broken traces for workflows using MapNode/FanOutBranch:

1. Task.async_stream in execute_fan_out_branches (dsl.ex) and MapNode.run
   spawned child tasks without propagating the current OTel context. Child
   spans were disconnected from the parent trace. Fixed by capturing the
   context before spawning and re-attaching via OtelCtx.with_parent_context
   in each task — the same pattern already used by SpawnAgent.

2. execute_fan_out_branch ran the child node without creating a span, so
   individual branch executions were invisible to tracing. Now wraps each
   branch in a TOOL span with the child node name.

3. maybe_complete_fan_out in the workflow strategy transitioned to the next
   node without finishing the current node span. This left the fan-out
   node's span open, causing subsequent nodes to incorrectly nest under it
   instead of being siblings. Added finish_node_span before the transition.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@lostbean

Copy link
Copy Markdown
Owner

Thanks @Munksgaard! LGTM, merging it

@lostbean
lostbean merged commit 077bc4a into lostbean:main Jun 16, 2026
1 check 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.

2 participants