CrewAI
Trace CrewAI agent and model spans with OpenLIT and standard OTLP/HTTP.
OpenLIT instruments CrewAI with OpenTelemetry. Initialize it once and point its OTLP/HTTP exporter at telemetry.dev to trace each crew run, with its agents, tasks, tools, and model calls, without changing your agents or tasks.
This guide was checked with crewai 1.15.28 and openlit 1.45.0. OpenLIT’s CrewAI instrumentation supports CrewAI 1.10.0 and later.
Install
CrewAI needs Python 3.10 to 3.13. Install CrewAI and OpenLIT in a virtual environment:
python3 -m venv .venv
. .venv/bin/activate
python -m pip install crewai openlit
Set the API key and exporter
Get a project API key from telemetry.dev. Then configure the OpenTelemetry exporter that OpenLIT uses:
export TELEMETRY_DEV_API_KEY="td_live_..."
export OTEL_EXPORTER_OTLP_ENDPOINT="https://api.telemetry.dev"
export OTEL_EXPORTER_OTLP_HEADERS="Authorization=Bearer%20$TELEMETRY_DEV_API_KEY"
export OTEL_SERVICE_NAME="your-crewai-service"
export OTEL_RESOURCE_ATTRIBUTES="deployment.environment.name=production"
OpenLIT sends traces to https://api.telemetry.dev/v1/traces, plus logs and metrics to /v1/logs and /v1/metrics. Without OTEL_EXPORTER_OTLP_ENDPOINT, OpenLIT prints spans to the console instead of sending them.
Trace a crew
Call openlit.init() before you create the crew. This example uses an OpenAI model, so set OPENAI_API_KEY as well; OpenAI charges apply.
import openlit
openlit.init(disable_batch=True)
from crewai import Agent, Crew, Task
researcher = Agent(
role="Researcher",
goal="Explain observability terms",
backstory="You write short, accurate definitions.",
llm="gpt-4o-mini",
)
task = Task(
description="Define OTLP in one sentence.",
expected_output="One sentence.",
agent=researcher,
)
print(Crew(agents=[researcher], tasks=[task]).kickoff())
disable_batch=True sends each span as it ends, so a short script does not exit before its spans are sent. In a long-running app, call openlit.init() without it.
Check the trace
Run the script and open Traces in your project. A crew run contains:
- An
invoke_workflow crewspan for the crew run - A
create_agentspan and aninvoke_agentspan for each agent, plusinvoke_agentspans for CrewAI’s internal steps - An
execute_toolspan for each tool run - A model span, such as
chat gpt-4o-mini, for each LLM call, with the model, token usage, and cost
OpenLIT calculates cost on model spans from its own price list and records it in gen_ai.usage.cost. telemetry.dev uses that value as-is. For a model that is not in OpenLIT’s price list, OpenLIT records a cost of 0, and telemetry.dev keeps that 0 rather than computing its own estimate. For model spans without gen_ai.usage.cost, telemetry.dev computes cost from the token counts and the model’s price.
Trace totals count tokens twice
OpenLIT copies the crew’s total token usage onto the invoke_workflow crew span, while the model spans under it report the same usage. telemetry.dev adds up usage across every span in a trace, so a crew trace’s token totals count the crew’s usage twice. The crew span also names the model, so telemetry.dev prices its copy of the tokens and the trace’s cost total is counted twice too.
Per-span data on model spans is correct. When you compare spend across crews, use the model spans rather than trace totals.
Control captured content
By default, OpenLIT exports agent backstories, task descriptions, tool arguments and results, and full model requests and responses, with no length limit. To capture less, pass one of these options to openlit.init():
openlit.init(capture_message_content=False)
# or cap the length of captured content instead:
openlit.init(max_content_length=2000)
Both options are partial:
capture_message_content=Falseleaves out backstories, task and model messages, tool payloads, and summaries. Agent roles, goals, and tool definitions and descriptions are still exported.max_content_lengthtruncates only some content attributes. It does not limit every attribute.
You can also set them with the OTEL_INSTRUMENTATION_GENAI_CAPTURE_MESSAGE_CONTENT and OPENLIT_MAX_CONTENT_LENGTH environment variables.
What telemetry.dev reads
OpenLIT emits OpenTelemetry GenAI attributes, which telemetry.dev reads directly:
- Tokens from
gen_ai.usage.input_tokens,gen_ai.usage.output_tokens, and the cache token attributes - Cost from
gen_ai.usage.cost - Model and provider from
gen_ai.request.model,gen_ai.response.model, andgen_ai.provider.name - The environment from
deployment.environment.name. OpenLIT also setsdeployment.environment(todefaultunless you setOTEL_DEPLOYMENT_ENVIRONMENT); telemetry.dev usesdeployment.environment.namefirst.
CrewAI orchestration spans carry gen_ai.provider.name: crewai, and model spans carry the model provider, such as openai.
Troubleshooting
- Spans print to the terminal.
OTEL_EXPORTER_OTLP_ENDPOINTis not set in the process. - No trace appears. Check that
OTEL_EXPORTER_OTLP_HEADERScontains your key, and thatopenlit.init()runs before the crew starts. A short script withoutdisable_batch=Truecan exit before its spans are sent. - Trace totals look doubled. See trace totals count tokens twice.