Skip to content

Commit

Permalink
fix: bug on tracing where components are in a loop in a pipeline (#8576)
Browse files Browse the repository at this point in the history
* Fix to tracing parent spans on loops

* Fix linting

* Add release notes

---------

Co-authored-by: Silvano Cerza <silvanocerza@gmail.com>
  • Loading branch information
ttamg and silvanocerza authored Nov 25, 2024
1 parent ab84035 commit e3b73e0
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
6 changes: 4 additions & 2 deletions haystack/core/pipeline/pipeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,9 @@ def _run_subgraph( # noqa: PLR0915
cycle: List[str],
component_name: str,
components_inputs: Dict[str, Dict[str, Any]],
*,
include_outputs_from: Optional[Set[str]] = None,
parent_span: Optional[tracing.Span] = None,
) -> Tuple[Dict[str, Any], Dict[str, Any]]:
"""
Runs a `cycle` in the Pipeline starting from `component_name`.
Expand Down Expand Up @@ -162,7 +164,7 @@ def _run_subgraph( # noqa: PLR0915
msg = f"Maximum run count {self._max_runs_per_component} reached for component '{name}'"
raise PipelineMaxComponentRuns(msg)

res: Dict[str, Any] = self._run_component(name, components_inputs[name])
res: Dict[str, Any] = self._run_component(name, components_inputs[name], parent_span=parent_span)

# Delete the inputs that were consumed by the Component and are not received from
# the user or from Components that are part of this cycle
Expand Down Expand Up @@ -439,7 +441,7 @@ def run( # noqa: PLR0915, PLR0912
# are run doesn't make a different whether we pick the first or any of the others a
# Component is part of.
subgraph_output, subgraph_extra_output = self._run_subgraph(
cycles[0], name, components_inputs, include_outputs_from
cycles[0], name, components_inputs, include_outputs_from=include_outputs_from, parent_span=span
)

# After a cycle is run the previous run_queue can't be correct anymore cause it's
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
---
fixes:
- |
Fix tracing `Pipeline` with cycles to correctly track components execution

0 comments on commit e3b73e0

Please sign in to comment.