Skip to content

Commit 2a60a25

Browse files
authored
fix!: Make sure to JSON serialize objects before setting content tags (#1627)
* Coerce values when setting input and output tags for pipelines and components respectively * Update README and pyproject
1 parent 03386d7 commit 2a60a25

File tree

3 files changed

+13
-11
lines changed

3 files changed

+13
-11
lines changed

integrations/langfuse/README.md

+4-4
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,8 @@ Here's the correct way to set up your script:
3535
import os
3636

3737
# Set environment variables first
38-
os.environ["LANGFUSE_HOST"] = "https://cloud.langfuse.com"
39-
os.environ["TOKENIZERS_PARALLELISM"] = "false"
38+
os.environ["LANGFUSE_SECRET_KEY"] = "" # Your Langfuse secret key
39+
os.environ["LANGFUSE_PUBLIC_KEY"] = "" # Your Langfuse public key
4040
os.environ["HAYSTACK_CONTENT_TRACING_ENABLED"] = "true"
4141

4242
# Then import Haystack components
@@ -58,8 +58,8 @@ Here's a full example:
5858
```python
5959
import os
6060

61-
os.environ["LANGFUSE_HOST"] = "https://cloud.langfuse.com"
62-
os.environ["TOKENIZERS_PARALLELISM"] = "false"
61+
os.environ["LANGFUSE_SECRET_KEY"] = "" # Your Langfuse secret key
62+
os.environ["LANGFUSE_PUBLIC_KEY"] = "" # Your Langfuse public key
6363
os.environ["HAYSTACK_CONTENT_TRACING_ENABLED"] = "true"
6464

6565
from haystack.components.builders import ChatPromptBuilder

integrations/langfuse/pyproject.toml

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ build-backend = "hatchling.build"
55
[project]
66
name = "langfuse-haystack"
77
dynamic = ["version"]
8-
description = ''
8+
description = "Langfuse integration for Haystack"
99
readme = "README.md"
1010
requires-python = ">=3.9"
1111
license = "Apache-2.0"
@@ -22,7 +22,7 @@ classifiers = [
2222
"Programming Language :: Python :: Implementation :: CPython",
2323
"Programming Language :: Python :: Implementation :: PyPy",
2424
]
25-
dependencies = ["haystack-ai>=2.9.0", "langfuse"]
25+
dependencies = ["haystack-ai>=2.12.1", "langfuse"]
2626

2727
[project.urls]
2828
Documentation = "https://github.com/deepset-ai/haystack-core-integrations/tree/main/integrations/langfuse#readme"

integrations/langfuse/src/haystack_integrations/tracing/langfuse/tracer.py

+7-5
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,8 @@ def set_content_tag(self, key: str, value: Any) -> None:
101101
messages = [m.to_openai_dict_format() for m in value["messages"]]
102102
self._span.update(input=messages)
103103
else:
104-
self._span.update(input=value)
104+
coerced_value = tracing_utils.coerce_tag_value(value)
105+
self._span.update(input=coerced_value)
105106
elif key.endswith(".output"):
106107
if "replies" in value:
107108
if all(isinstance(r, ChatMessage) for r in value["replies"]):
@@ -110,7 +111,8 @@ def set_content_tag(self, key: str, value: Any) -> None:
110111
replies = value["replies"]
111112
self._span.update(output=replies)
112113
else:
113-
self._span.update(output=value)
114+
coerced_value = tracing_utils.coerce_tag_value(value)
115+
self._span.update(output=coerced_value)
114116

115117
self._data[key] = value
116118

@@ -286,9 +288,9 @@ def handle(self, span: LangfuseSpan, component_type: Optional[str]) -> None:
286288
# If the span is at the pipeline level, we add input and output keys to the span
287289
at_pipeline_level = span.get_data().get(_PIPELINE_INPUT_KEY) is not None
288290
if at_pipeline_level:
289-
span.raw_span().update(
290-
input=span.get_data().get(_PIPELINE_INPUT_KEY), output=span.get_data().get(_PIPELINE_OUTPUT_KEY)
291-
)
291+
coerced_input = tracing_utils.coerce_tag_value(span.get_data().get(_PIPELINE_INPUT_KEY))
292+
coerced_output = tracing_utils.coerce_tag_value(span.get_data().get(_PIPELINE_OUTPUT_KEY))
293+
span.raw_span().update(input=coerced_input, output=coerced_output)
292294

293295
if component_type in _SUPPORTED_GENERATORS:
294296
meta = span.get_data().get(_COMPONENT_OUTPUT_KEY, {}).get("meta")

0 commit comments

Comments
 (0)