-
Notifications
You must be signed in to change notification settings - Fork 150
AsyncPipeline
Creates Multiple Traces Instead of a Single Unified Trace in Langfuse
#1604
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
AsyncPipeline
Creates Multiple Traces Instead of a Single Unified Trace in Langfuse
hey @immortal3 thanks for raising this! To help with the debugging could you tell us specifically which Retriever and Generator you were using? It sounds like this could be related to this issue where the parent context is also not being passed down correctly when using the OpenTelemetry tracer when using AsyncPipeline. |
@immortal3 ahh okay good to know. In that case I'd like to confirm that your custom components don't have a So nothing like @component
class CustomComp:
@component.output_types()
def run(self, a):
...
@component.output_types()
async def run_async(self, a):
... |
Yes, no |
Hey @immortal3 I'm struggling to reproduce your issue. Here is the example script I've tried import asyncio
import logging
logging.basicConfig(format="%(levelname)s - %(name)s - %(message)s", level=logging.WARNING)
logging.getLogger("haystack").setLevel(logging.INFO)
import os
os.environ["OPENAI_API_KEY"] = ""
os.environ["LANGFUSE_SECRET_KEY"] = ""
os.environ["LANGFUSE_PUBLIC_KEY"] = ""
os.environ["HAYSTACK_CONTENT_TRACING_ENABLED"] = "true"
from haystack import AsyncPipeline
from haystack.components.builders import ChatPromptBuilder
from haystack.components.generators.chat import OpenAIChatGenerator
from haystack.dataclasses import ChatMessage
from haystack_integrations.components.connectors.langfuse import LangfuseConnector
pipe = AsyncPipeline()
pipe.add_component("tracer", LangfuseConnector("Async Pipeline Test"))
pipe.add_component("prompt_builder", ChatPromptBuilder())
pipe.add_component("llm", OpenAIChatGenerator())
pipe.connect("prompt_builder.prompt", "llm.messages")
messages = [
ChatMessage.from_system("Always respond in German even if some input data is in other languages."),
ChatMessage.from_user("Tell me about {{location}}"),
]
# use sync run
# response = pipe.run(
# data={
# "prompt_builder": {
# "template_variables": {"location": "Berlin"},
# "template": messages,
# },
# "tracer": {
# "invocation_context": {"some_key": "some_value"},
# },
# }
# )
# print(response["llm"]["replies"][0])
# print(response["tracer"]["trace_url"])
# use async run
async def run_async():
resp = await pipe.run_async(
data={
"prompt_builder": {
"template_variables": {"location": "Berlin"},
"template": messages,
},
"tracer": {
"invocation_context": {"some_key": "some_value"},
},
}
)
print(resp["llm"]["replies"][0])
print(resp["tracer"]["trace_url"])
asyncio.run(run_async()) and when running this I end up with the following trace ![]() so everything looks to be as expected. Could you provide a minimal working example that caused your issue? Is it possible your problem resulted from using components that were using sub-pipelines like you mentioned in your other issue? |
And to clarify this
was a false positive. The warning message shouldn't have been shown. This if statement if context.operation_name != _PIPELINE_RUN_KEY: needs to be updated to if context.operation_name not in [_PIPELINE_RUN_KEY, _ASYNC_PIPELINE_RUN_KEY]: |
@sjrl Can't reproduce on Single Pipeline and checked traces, it mainly creates new traces for Sub pipelines. This is helpful. |
@immortal3 thanks for the info! I'll focus on sub-pipelines then to see if the fix here is enough or if more needs to be done. |
Hey @immortal3 this has been merged now and is available in |
Describe the Bug:
When using the
AsyncPipeline
instead of the synchronousPipeline
, multiple trace entries are created in Langfuse for what should be a single execution of the pipeline. This behavior makes it difficult to get a unified view of the request flow.Additionally, the following warning is logged during execution:
This suggests that the trace context is not being properly propagated across async components or pipeline runs.
Code to Reproduce:
Observed Behavior:
Expected Behavior:
A single trace should be created and propagated throughout the entire async pipeline execution, just like in the synchronous
Pipeline
. This would ensure consistent observability and debugging in Langfuse.Describe your environment (please complete the following information):
The text was updated successfully, but these errors were encountered: