feat(crewAI): add instrumentation for async API (akickoff)#4342
feat(crewAI): add instrumentation for async API (akickoff)#4342tsdaemon wants to merge 3 commits into
Conversation
📝 Walkthrough📝 Walkthrough🚥 Pre-merge checks | ✅ 2✅ Passed checks (2 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In
`@packages/opentelemetry-instrumentation-crewai/opentelemetry/instrumentation/crewai/instrumentation.py`:
- Around line 27-33: The LiteLLM prefix-to-OTel provider mapping in
instrumentation.py is incomplete for CrewAI model IDs. Update
_LITELLM_PREFIX_TO_OTEL_PROVIDER in the CrewAI instrumentation to normalize
bedrock/... to the AWS provider name and add the missing azure_ai/... mapping to
the Azure AI OpenAI provider name, so get_otel_provider_name (or the lookup path
used by CrewAI spans) returns the correct gen_ai.provider.name value.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: 3d2f6bd3-05ca-4427-81f6-8fccfc354c8a
⛔ Files ignored due to path filters (1)
packages/opentelemetry-instrumentation-crewai/uv.lockis excluded by!**/*.lock
📒 Files selected for processing (3)
packages/opentelemetry-instrumentation-crewai/opentelemetry/instrumentation/crewai/instrumentation.pypackages/opentelemetry-instrumentation-crewai/pyproject.tomlpackages/opentelemetry-instrumentation-crewai/tests/test_async_instrumentation.py
| _LITELLM_PREFIX_TO_OTEL_PROVIDER = { | ||
| "openai": GenAISystem.OPENAI.value, | ||
| "anthropic": GenAISystem.ANTHROPIC.value, | ||
| "gemini": GenAiSystemValues.GCP_GEMINI.value, | ||
| "vertex_ai": GenAiSystemValues.GCP_VERTEX_AI.value, | ||
| "gemini": GenAiProviderNameValues.GCP_GEMINI.value, | ||
| "vertex_ai": GenAiProviderNameValues.GCP_VERTEX_AI.value, | ||
| "bedrock": GenAISystem.AWS.value, | ||
| "azure": GenAiSystemValues.AZURE_AI_OPENAI.value, | ||
| "azure": GenAiProviderNameValues.AZURE_AI_OPENAI.value, |
There was a problem hiding this comment.
🗄️ Data Integrity & Integration | 🟠 Major | ⚡ Quick win
🧩 Analysis chain
🏁 Script executed:
#!/bin/bash
# Verify enum availability and cross-package provider expectations.
uv run python - <<'PY'
from opentelemetry.semconv._incubating.attributes.gen_ai_attributes import GenAiProviderNameValues
for name in ("AWS_BEDROCK", "AZURE_AI_INFERENCE"):
print(name, getattr(GenAiProviderNameValues, name).value)
PY
rg -n -C2 '("bedrock"|"azure_ai"|AWS_BEDROCK|AZURE_AI_INFERENCE)' \
packages/opentelemetry-instrumentation-litellm \
packages/opentelemetry-instrumentation-crewaiRepository: traceloop/openllmetry
Length of output: 3426
🏁 Script executed:
sed -n '1,160p' packages/opentelemetry-instrumentation-crewai/opentelemetry/instrumentation/crewai/instrumentation.py
printf '\n---\n'
rg -n -C3 'AWS_BEDROCK|AZURE_AI_INFERENCE|bedrock|azure_ai' packages/opentelemetry-instrumentation-crewaiRepository: traceloop/openllmetry
Length of output: 8219
Normalize Bedrock and Azure AI provider names. bedrock/... maps to AWS, and azure_ai/... has no entry, so CrewAI spans will emit incorrect or missing gen_ai.provider.name values for LiteLLM-style model IDs.
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In
`@packages/opentelemetry-instrumentation-crewai/opentelemetry/instrumentation/crewai/instrumentation.py`
around lines 27 - 33, The LiteLLM prefix-to-OTel provider mapping in
instrumentation.py is incomplete for CrewAI model IDs. Update
_LITELLM_PREFIX_TO_OTEL_PROVIDER in the CrewAI instrumentation to normalize
bedrock/... to the AWS provider name and add the missing azure_ai/... mapping to
the Azure AI OpenAI provider name, so get_otel_provider_name (or the lookup path
used by CrewAI spans) returns the correct gen_ai.provider.name value.
There was a problem hiding this comment.
Thanks — split into the two parts:
-
azure_ai/: good catch, added"azure_ai": GenAiProviderNameValues.AZURE_AI_INFERENCE.value(→azure.ai.inference). LiteLLM'sazure_ai/prefix targets Azure AI Foundry serverless deployments (Azure AI Inference API), which is distinct fromazure/→ Azure OpenAI (azure.ai.openai). Previouslyazure_ai/...fell through toNone. -
bedrock/: this one is already correct and needs no change. It maps toGenAISystem.AWS.value, whose value is"aws.bedrock"— identical toGenAiProviderNameValues.AWS_BEDROCK.value. So bedrock spans already emitgen_ai.provider.name = aws.bedrock. (The verification script above only inspectedGenAiProviderNameValues, not the actualGenAISystem.AWSvalue.)
There was a problem hiding this comment.
Oops, something went wrong! Please try again later. 🐰 💔
CrewAI has released an async interface
akickoffwhich is not covered in the current instrumentation. This adds instrumentation for the new execution path. This also removes deprecatedGenAiSystemValues.feat(instrumentation): ...orfix(instrumentation): ....Summary by CodeRabbit
New Features
Bug Fixes