Skip to content

Commit

Permalink
feat: Trace pipeline run input/output data (#7590)
Browse files Browse the repository at this point in the history
* Trace pipeline run

* Add reno note

* Update tracing tests to check input_data and output_data

* empty

---------

Co-authored-by: anakin87 <stefanofiorucci@gmail.com>
Co-authored-by: Silvano Cerza <3314350+silvanocerza@users.noreply.github.com>
  • Loading branch information
3 people committed Apr 29, 2024
1 parent 451fae8 commit 8cb3cec
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 3 deletions.
8 changes: 5 additions & 3 deletions haystack/core/pipeline/pipeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -796,17 +796,19 @@ def run(self, word: str):

include_outputs_from = set() if include_outputs_from is None else include_outputs_from

# This is what we'll return at the end
final_outputs: Dict[Any, Any] = {}

with tracing.tracer.trace(
"haystack.pipeline.run",
tags={
"haystack.pipeline.input_data": data,
"haystack.pipeline.output_data": final_outputs,
"haystack.pipeline.debug": debug,
"haystack.pipeline.metadata": self.metadata,
"haystack.pipeline.max_loops_allowed": self.max_loops_allowed,
},
):
# This is what we'll return at the end
final_outputs: Dict[Any, Any] = {}

# Cache for extra outputs, if enabled.
extra_outputs: Dict[Any, Any] = {}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
---
enhancements:
- |
Improved pipeline run tracing to include pipeline input/output data.
4 changes: 4 additions & 0 deletions test/core/pipeline/test_tracing.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ def test_with_enabled_tracing(self, pipeline: Pipeline, spying_tracer: SpyingTra
SpyingSpan(
operation_name="haystack.pipeline.run",
tags={
"haystack.pipeline.input_data": {"hello": {"word": "world"}},
"haystack.pipeline.output_data": {"hello2": {"output": "Hello, Hello, world!!"}},
"haystack.pipeline.debug": False,
"haystack.pipeline.metadata": {},
"haystack.pipeline.max_loops_allowed": 100,
Expand Down Expand Up @@ -97,6 +99,8 @@ def test_with_enabled_content_tracing(
"haystack.pipeline.debug": False,
"haystack.pipeline.metadata": {},
"haystack.pipeline.max_loops_allowed": 100,
"haystack.pipeline.input_data": {"hello": {"word": "world"}},
"haystack.pipeline.output_data": {"hello2": {"output": "Hello, Hello, world!!"}},
},
trace_id=ANY,
span_id=ANY,
Expand Down

0 comments on commit 8cb3cec

Please sign in to comment.