adding crew ai instrumentation - #363
Conversation
Pull request dashboard statusWaiting on the author · refreshed 2026-08-09 04:43 UTC Respond to 4 review items (e.g. link a commit, explain why not, ask a follow-up): Status above doesn't look right?
|
There was a problem hiding this comment.
Pull request overview
Adds first-pass OpenTelemetry GenAI instrumentation for CrewAI LLM inference by translating CrewAI LLM lifecycle events into opentelemetry-util-genai inference telemetry, along with unit + conformance scaffolding and docs/examples.
Changes:
- Introduces a
CrewAIInferenceEventListenerthat maps CrewAI LLM events toTelemetryHandler.inference()invocations. - Adds unit tests for inference event translation, completion hook wiring, and disabling CrewAI’s native telemetry while instrumented.
- Adds a CrewAI conformance scenario + tox wiring and expands the package README with configuration and completion hook docs.
Reviewed changes
Copilot reviewed 11 out of 11 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| tox.ini | Adds a CrewAI conformance tox env and updates CrewAI test commands to exclude conformance from non-conformance runs. |
| instrumentation/opentelemetry-instrumentation-genai-crewai/tests/test_instrumentor.py | Adds tests ensuring CrewAI native telemetry is disabled only when instrumentation sets the default. |
| instrumentation/opentelemetry-instrumentation-genai-crewai/tests/test_inference.py | Adds unit tests validating span attributes/status for completed/failed events and completion hook invocation. |
| instrumentation/opentelemetry-instrumentation-genai-crewai/tests/test_conformance.py | Adds conformance test entrypoint wiring for CrewAI scenarios. |
| instrumentation/opentelemetry-instrumentation-genai-crewai/tests/conftest.py | Ensures content_capture="SPAN_ONLY" for tests that assert content-related attributes exist. |
| instrumentation/opentelemetry-instrumentation-genai-crewai/tests/conformance/inference.py | Adds a minimal inference conformance scenario emitting CrewAI LLM start/completion events. |
| instrumentation/opentelemetry-instrumentation-genai-crewai/tests/conformance/init.py | Adds package marker for conformance scenarios. |
| instrumentation/opentelemetry-instrumentation-genai-crewai/src/opentelemetry/instrumentation/genai/crewai/event_listener.py | Implements event listener translating CrewAI LLM events into GenAI inference invocations. |
| instrumentation/opentelemetry-instrumentation-genai-crewai/src/opentelemetry/instrumentation/genai/crewai/init.py | Creates the listener during instrumentation and disables/restores CrewAI native telemetry via env var. |
| instrumentation/opentelemetry-instrumentation-genai-crewai/README.rst | Updates README to reflect inference spans/metrics and documents native telemetry disabling + completion hooks. |
| instrumentation/opentelemetry-instrumentation-genai-crewai/examples/custom_hook.py | Adds a minimal custom completion hook example. |
| ; instrumentation-genai-crewai | ||
| py3{10,11,12,13,14}-test-instrumentation-genai-crewai-latest | ||
| py310-test-instrumentation-genai-crewai-oldest | ||
| py313-test-instrumentation-genai-crewai-conformance | ||
| lint-instrumentation-genai-crewai |
Assisted-by: ChatGPT GPT-5
6b5e409 to
64b9fbe
Compare
Assisted-by: ChatGPT GPT-5
| ) | ||
| # CrewAI patching will be added in a follow-up change. | ||
| if self._disabled_crewai_telemetry: | ||
| os.environ[_CREWAI_DISABLE_TELEMETRY] = "true" |
There was a problem hiding this comment.
this is a side-effect we should not do. It's fragile and depends on us modifying env before crewai instrumentation starts. We also can't modify app env. Is there less invasive way?
| getattr(event, "temperature", None), | ||
| getattr(source, "temperature", None), |
There was a problem hiding this comment.
can we be more specific? do we need to read it from both? why getattr(event, "temperature", None) is we know event type?
|
|
||
|
|
||
| def _set_request_attributes( | ||
| invocation: InferenceInvocation, source: Any, event: LLMCallStartedEvent |
There was a problem hiding this comment.
is there more precise type than Any we can use here?
| provider = str(getattr(source, "provider", None) or "unknown") | ||
| model = getattr(event, "model", None) or getattr(source, "model", None) | ||
| server_address, server_port = _server(source) | ||
| invocation = self._telemetry_handler.inference( |
There was a problem hiding this comment.
there is no point in instrumenting inference calls inside crewai - crewai uses other llm clients to do inference and they are instrumented. if we emit inference spans here, we end up duplicating inference spans from crewai and from corresponding llm client. please remove them from crewai instrumentation.
the spans we should have are invoke_agent, invoke_workflow, tools and planning - https://github.com/open-telemetry/semantic-conventions-genai/blob/main/reference/scenarios/crewai/README.md.
Description
Description
opentelemetry-util-genai.CREWAI_DISABLE_TELEMETRY=false. Existing values are preserved and restored correctly. ref: #308 (comment)Type of change
Please delete options that are not relevant.
Future PR
In follow-up PRs, I plan to add CrewAI workflow, agent, and tool instrumentation using the
invoke_workflow,invoke_agent, andexecute_toolGenAI semantic conventions, along with proper context propagation and streaming support.