CrewAI Multi Tool Usage Single Trace Problem #3090
Replies: 2 comments
-
|
The multiple traces issue is common with OpenTelemetry-style tracing. Here's how to consolidate: Solution 1: Single Span ContextEnsure all operations share the same trace context: from langfuse import Langfuse
from opentelemetry import trace
langfuse = Langfuse()
# Create a single parent trace
with langfuse.trace(name="Analysis Workflow") as trace:
# Pass trace context to all operations
result = crew.kickoff(
inputs={"task": task},
callbacks=[LangfuseCallback(trace_id=trace.trace_id)]
)Solution 2: Manual Span Hierarchywith langfuse.trace(name="crew_execution") as parent:
for agent in crew.agents:
with langfuse.span(name=f"agent_{agent.name}", parent=parent):
# Agent operations here
passSolution 3: State-Based TracingInstead of relying on auto-instrumentation: state = {
"trace_id": str(uuid.uuid4()),
"spans": [],
"events": []
}
def log_event(name, data):
state["events"].append({
"trace_id": state["trace_id"],
"name": name,
"timestamp": time.time(),
"data": data
})
# After execution, send all events as single trace
langfuse.trace(
trace_id=state["trace_id"],
events=state["events"]
)Root CauseOpenLIT creates new traces for each tool call because it doesn't share context. Disable OpenLIT auto-tracing and manually instrument to maintain hierarchy. |
Beta Was this translation helpful? Give feedback.
-
|
I think the key issue here is trace context propagation. Your outer Langfuse span creates a parent span in your application code, but the CrewAI/tool/model calls will only attach to it if the same OpenTelemetry context stays active inside the CrewAI execution path. When tools/generations show up as separate traces, it usually means one of these is happening:
The trace shape you probably want is: |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
I want to integrate langfuse to crewai. There is one crew having an agent that use multiple custom tools. After a single execution, i expect to create single trace by Langfuse. But it creates multiple trace entities for tools, generations, etc as seen in the images. I already tried the methods discussed in https://github.com/orgs/langfuse/discussions/6291. Also check the related documents, but i could not to create single trace.
Beta Was this translation helpful? Give feedback.
All reactions