Skip to content

Commit f47e0c8

Browse files
authored
Add tracing documentation and enable tracing feature in CrewAI
- Introduced a new documentation page for CrewAI Tracing, detailing setup and usage. - Updated the main documentation to include the new tracing page in the observability section. - Added example code snippets for enabling tracing in both Crews and Flows. - Included instructions for global tracing configuration via environment variables. - Added a new image for the CrewAI Tracing interface.
1 parent eabced3 commit f47e0c8

File tree

4 files changed

+214
-0
lines changed

4 files changed

+214
-0
lines changed

docs/docs.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -246,6 +246,7 @@
246246
{
247247
"group": "Observability",
248248
"pages": [
249+
"en/observability/tracing",
249250
"en/observability/overview",
250251
"en/observability/arize-phoenix",
251252
"en/observability/braintrust",

docs/en/observability/tracing.mdx

Lines changed: 213 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,213 @@
1+
---
2+
title: CrewAI Tracing
3+
description: Built-in tracing for CrewAI Crews and Flows with the CrewAI AMP platform
4+
icon: magnifying-glass-chart
5+
mode: "wide"
6+
---
7+
8+
# CrewAI Built-in Tracing
9+
10+
CrewAI provides built-in tracing capabilities that allow you to monitor and debug your Crews and Flows in real-time. This guide demonstrates how to enable tracing for both **Crews** and **Flows** using CrewAI's integrated observability platform.
11+
12+
> **What is CrewAI Tracing?** CrewAI's built-in tracing provides comprehensive observability for your AI agents, including agent decisions, task execution timelines, tool usage, and LLM calls - all accessible through the [CrewAI AMP platform](https://app.crewai.com).
13+
14+
![CrewAI Tracing Interface](/images/crewai-tracing.png)
15+
16+
## Prerequisites
17+
18+
Before you can use CrewAI tracing, you need:
19+
20+
1. **CrewAI AMP Account**: Sign up for a free account at [app.crewai.com](https://app.crewai.com)
21+
2. **CLI Authentication**: Use the CrewAI CLI to authenticate your local environment
22+
23+
```bash
24+
crewai login
25+
```
26+
27+
## Setup Instructions
28+
29+
### Step 1: Create Your CrewAI AMP Account
30+
31+
Visit [app.crewai.com](https://app.crewai.com) and create your free account. This will give you access to the CrewAI AMP platform where you can view traces, metrics, and manage your crews.
32+
33+
### Step 2: Install CrewAI CLI and Authenticate
34+
35+
If you haven't already, install CrewAI with the CLI tools:
36+
37+
```bash
38+
uv add crewai[tools]
39+
```
40+
41+
Then authenticate your CLI with your CrewAI AMP account:
42+
43+
```bash
44+
crewai login
45+
```
46+
47+
This command will:
48+
1. Open your browser to the authentication page
49+
2. Prompt you to enter a device code
50+
3. Authenticate your local environment with your CrewAI AMP account
51+
4. Enable tracing capabilities for your local development
52+
53+
### Step 3: Enable Tracing in Your Crew
54+
55+
You can enable tracing for your Crew by setting the `tracing` parameter to `True`:
56+
57+
```python
58+
from crewai import Agent, Crew, Process, Task
59+
from crewai_tools import SerperDevTool
60+
61+
# Define your agents
62+
researcher = Agent(
63+
role="Senior Research Analyst",
64+
goal="Uncover cutting-edge developments in AI and data science",
65+
backstory="""You work at a leading tech think tank.
66+
Your expertise lies in identifying emerging trends.
67+
You have a knack for dissecting complex data and presenting actionable insights.""",
68+
verbose=True,
69+
tools=[SerperDevTool()],
70+
)
71+
72+
writer = Agent(
73+
role="Tech Content Strategist",
74+
goal="Craft compelling content on tech advancements",
75+
backstory="""You are a renowned Content Strategist, known for your insightful and engaging articles.
76+
You transform complex concepts into compelling narratives.""",
77+
verbose=True,
78+
)
79+
80+
# Create tasks for your agents
81+
research_task = Task(
82+
description="""Conduct a comprehensive analysis of the latest advancements in AI in 2024.
83+
Identify key trends, breakthrough technologies, and potential industry impacts.""",
84+
expected_output="Full analysis report in bullet points",
85+
agent=researcher,
86+
)
87+
88+
writing_task = Task(
89+
description="""Using the insights provided, develop an engaging blog
90+
post that highlights the most significant AI advancements.
91+
Your post should be informative yet accessible, catering to a tech-savvy audience.""",
92+
expected_output="Full blog post of at least 4 paragraphs",
93+
agent=writer,
94+
)
95+
96+
# Enable tracing in your crew
97+
crew = Crew(
98+
agents=[researcher, writer],
99+
tasks=[research_task, writing_task],
100+
process=Process.sequential,
101+
tracing=True, # Enable built-in tracing
102+
verbose=True
103+
)
104+
105+
# Execute your crew
106+
result = crew.kickoff()
107+
```
108+
109+
### Step 4: Enable Tracing in Your Flow
110+
111+
Similarly, you can enable tracing for CrewAI Flows:
112+
113+
```python
114+
from crewai.flow.flow import Flow, listen, start
115+
from pydantic import BaseModel
116+
117+
class ExampleState(BaseModel):
118+
counter: int = 0
119+
message: str = ""
120+
121+
class ExampleFlow(Flow[ExampleState]):
122+
def __init__(self):
123+
super().__init__(tracing=True) # Enable tracing for the flow
124+
125+
@start()
126+
def first_method(self):
127+
print("Starting the flow")
128+
self.state.counter = 1
129+
self.state.message = "Flow started"
130+
return "continue"
131+
132+
@listen("continue")
133+
def second_method(self):
134+
print("Continuing the flow")
135+
self.state.counter += 1
136+
self.state.message = "Flow continued"
137+
return "finish"
138+
139+
@listen("finish")
140+
def final_method(self):
141+
print("Finishing the flow")
142+
self.state.counter += 1
143+
self.state.message = "Flow completed"
144+
145+
# Create and run the flow with tracing enabled
146+
flow = ExampleFlow(tracing=True)
147+
result = flow.kickoff()
148+
```
149+
150+
### Step 5: View Traces in the CrewAI AMP Dashboard
151+
152+
After running the crew or flow, you can view the traces generated by your CrewAI application in the CrewAI AMP dashboard. You should see detailed steps of the agent interactions, tool usages, and LLM calls.
153+
Just click on the link below to view the traces or head over to the traces tab in the dashboard [here](https://app.crewai.com/crewai_plus/trace_batches)
154+
![CrewAI Tracing Interface](/images/view-traces.png)
155+
156+
157+
### Alternative: Environment Variable Configuration
158+
159+
You can also enable tracing globally by setting an environment variable:
160+
161+
```bash
162+
export CREWAI_TRACING_ENABLED=true
163+
```
164+
165+
Or add it to your `.env` file:
166+
167+
```env
168+
CREWAI_TRACING_ENABLED=true
169+
```
170+
171+
When this environment variable is set, all Crews and Flows will automatically have tracing enabled, even without explicitly setting `tracing=True`.
172+
173+
## Viewing Your Traces
174+
175+
### Access the CrewAI AMP Dashboard
176+
177+
1. Visit [app.crewai.com](https://app.crewai.com) and log in to your account
178+
2. Navigate to your project dashboard
179+
3. Click on the **Traces** tab to view execution details
180+
181+
### What You'll See in Traces
182+
183+
CrewAI tracing provides comprehensive visibility into:
184+
185+
- **Agent Decisions**: See how agents reason through tasks and make decisions
186+
- **Task Execution Timeline**: Visual representation of task sequences and dependencies
187+
- **Tool Usage**: Monitor which tools are called and their results
188+
- **LLM Calls**: Track all language model interactions, including prompts and responses
189+
- **Performance Metrics**: Execution times, token usage, and costs
190+
- **Error Tracking**: Detailed error information and stack traces
191+
192+
### Trace Features
193+
- **Execution Timeline**: Click through different stages of execution
194+
- **Detailed Logs**: Access comprehensive logs for debugging
195+
- **Performance Analytics**: Analyze execution patterns and optimize performance
196+
- **Export Capabilities**: Download traces for further analysis
197+
198+
### Authentication Issues
199+
200+
If you encounter authentication problems:
201+
202+
1. Ensure you're logged in: `crewai login`
203+
2. Check your internet connection
204+
3. Verify your account at [app.crewai.com](https://app.crewai.com)
205+
206+
### Traces Not Appearing
207+
208+
If traces aren't showing up in the dashboard:
209+
210+
1. Confirm `tracing=True` is set in your Crew/Flow
211+
2. Check that `CREWAI_TRACING_ENABLED=true` if using environment variables
212+
3. Ensure you're authenticated with `crewai login`
213+
4. Verify your crew/flow is actually executing

docs/images/crewai-tracing.png

479 KB
Loading

docs/images/view-traces.png

53 KB
Loading

0 commit comments

Comments
 (0)