CrewAI Multi Tool Usage Single Trace Problem #3090
Unanswered
OnurYigitArpali
asked this question in
Q&A
Replies: 1 comment
-
|
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.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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