Skip to main content

CrewAI

The CrewAI instrumentation traces the crew, its tasks and its agents; the OpenAI instrumentation traces the model calls under them.

New to Oodle?

Oodle is a managed observability platform for metrics, logs, traces and agent traces. It ingests OpenTelemetry natively, so the snippet on this page is the complete setup.

Each trace shows the full transcript, the token counts and cost of every call, the agent structure (runs, steps and tool calls) and Signals: labels for loops, rate limits, refusals and tool failures, detected as the trace arrives.

Sign up for free to get an instance ID and an API key, or see the Agent Observability overview first.

You will need:

  • OODLE_INSTANCE: your Oodle instance ID (ap1, us1)
  • OODLE_API_KEY: an Oodle API key (ap1, us1)
  • OTLP_ENDPOINT: your OTLP collector domain, shown on the tile

Open the CrewAI tile on the ap1, us1 page to get these filled in for you, or let an agent do the setup with /oodle-onboarding set up the llm_observability_crewai integration.

Install

Install CrewAI with the CrewAI and OpenAI OTel instrumentations:

pip install crewai \
opentelemetry-instrumentation-crewai \
opentelemetry-instrumentation-openai \
opentelemetry-exporter-otlp-proto-http \
opentelemetry-sdk

Instrument

Initialize OpenTelemetry and activate both instrumentors. The CrewAI one traces the crew, its tasks and agents; the OpenAI one traces the model calls underneath them:

from crewai import Agent, Crew, Task
from opentelemetry.exporter.otlp.proto.http.trace_exporter import OTLPSpanExporter
from opentelemetry.instrumentation.crewai import CrewAIInstrumentor
from opentelemetry.instrumentation.openai import OpenAIInstrumentor
from opentelemetry.sdk.resources import Resource
from opentelemetry.sdk.trace import TracerProvider
from opentelemetry.sdk.trace.export import BatchSpanProcessor
from opentelemetry.trace import set_tracer_provider


def setup_opentelemetry():
resource = Resource.create({"service.name": "my-llm-app"})

tracer_provider = TracerProvider(resource=resource)
tracer_provider.add_span_processor(
BatchSpanProcessor(OTLPSpanExporter())
)
set_tracer_provider(tracer_provider)


setup_opentelemetry()

# The CrewAI instrumentor traces the crew, tasks and agents.
# The OpenAI instrumentor traces the model calls under them:
# without it the run arrives with no generations.
CrewAIInstrumentor().instrument()
OpenAIInstrumentor().instrument()

researcher = Agent(
role="Researcher",
goal="Answer the question in one sentence",
backstory="You answer briefly.",
llm="openai/gpt-4o-mini",
)
task = Task(
description="What is the capital of France?",
expected_output="One sentence.",
agent=researcher,
)
crew = Crew(agents=[researcher], tasks=[task])
print(crew.kickoff().raw)

Environment

Point the application at Oodle:

# OTLP endpoint (points straight at Oodle)
export OTEL_EXPORTER_OTLP_ENDPOINT=https://<OTLP_ENDPOINT>

export OTEL_EXPORTER_OTLP_HEADERS="X-API-KEY=<OODLE_API_KEY>,X-OODLE-INSTANCE=<OODLE_INSTANCE>"

# Compress the export: prompt payloads are large
export OTEL_EXPORTER_OTLP_COMPRESSION=gzip

# Optional: disable prompt/response capture
# export TRACELOOP_TRACE_CONTENT=false

Verify

Run your application, then open ap1, us1. Spans carry gen_ai.* attributes: the model, token counts, and the prompt and response content. Click a trace for the Transcript, the waterfall, and the cost breakdown.

Trace detail showing the Transcript tab with system, user, and assistant messages

If nothing arrives, check that the exporter can reach https://<OTLP_ENDPOINT> and that the instance and key are set: the OTLP gateway answers 401 without them.


Support

If you need assistance or have any questions, please reach out to us through: