feat(crewai): add GenAI util instrumentation#198
Open
sipercai wants to merge 1 commit into
Open
Conversation
13 tasks
Contributor
There was a problem hiding this comment.
Pull request overview
This PR migrates the LoongSuite CrewAI instrumentation to build GenAI telemetry using opentelemetry-util-genai’s ExtendedTelemetryHandler, aligning spans/attributes with the extended GenAI semantic conventions and adding a real-world smoke example plus updated docs/changelog.
Changes:
- Replace legacy direct-span GenAI hooks with util-genai invocations/handlers for Crew/Flow entry spans, task/agent invoke spans, and tool execute spans (including usage + content-capture gating).
- Update CrewAI instrumentation tests to the new span kinds/attribute keys (
gen_ai.provider.name,gen_ai.operation.name=enter|invoke_agent|execute_tool, plusgen_ai.crewai.*). - Add a runnable CrewAI smoke example for sync/stream/concurrent runs and refresh the README + changelog.
Reviewed changes
Copilot reviewed 13 out of 13 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| instrumentation-loongsuite/loongsuite-instrumentation-crewai/src/opentelemetry/instrumentation/crewai/init.py | Core migration to util-genai handler + wrapper logic for entry/task/agent/tool spans and safety guards. |
| instrumentation-loongsuite/loongsuite-instrumentation-crewai/src/opentelemetry/instrumentation/crewai/utils.py | New helpers to build util-genai invocations and map CrewAI objects/usage/content into standardized attributes. |
| instrumentation-loongsuite/loongsuite-instrumentation-crewai/tests/test_tool_calls.py | Update assertions for tool spans/attributes and content-capture env vars. |
| instrumentation-loongsuite/loongsuite-instrumentation-crewai/tests/test_sync_llm_calls.py | Update span selection/hierarchy expectations to util-genai semantics and new attribute names. |
| instrumentation-loongsuite/loongsuite-instrumentation-crewai/tests/test_streaming_llm_calls.py | Update streaming test expectations to util-genai entry/task spans and provider attribute. |
| instrumentation-loongsuite/loongsuite-instrumentation-crewai/tests/test_prompt_and_memory.py | Update task span filtering to gen_ai.crewai.operation. |
| instrumentation-loongsuite/loongsuite-instrumentation-crewai/tests/test_flow_kickoff.py | Expand wrapper-focused coverage (entry nesting guards, token usage mapping, capture gating, tool-call parsing behavior). |
| instrumentation-loongsuite/loongsuite-instrumentation-crewai/tests/test_error_scenarios.py | Update error-path assertions to new CrewAI operation attribute key. |
| instrumentation-loongsuite/loongsuite-instrumentation-crewai/tests/test_agent_workflow.py | Update workflow assertions to new entry semantics and CrewAI operation keying. |
| instrumentation-loongsuite/loongsuite-instrumentation-crewai/examples/crewai_smoke.py | Add real smoke runner for sync/stream/concurrent runs and optional OTLP export setup. |
| instrumentation-loongsuite/loongsuite-instrumentation-crewai/README.md | Document util-genai span model, content capture env vars, and smoke example usage. |
| instrumentation-loongsuite/loongsuite-instrumentation-crewai/pyproject.toml | Update Python support metadata and dependency declaration for util-genai. |
| instrumentation-loongsuite/loongsuite-instrumentation-crewai/CHANGELOG.md | Record breaking semantic-convention alignment + new example and behavior changes. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
45
to
54
| @@ -53,319 +50,795 @@ | |||
| import crewai.tools.tool_usage | |||
|
|
|||
| _CREWAI_LOADED = True | |||
| except (ImportError, Exception): | |||
| except ImportError: | |||
| _CREWAI_LOADED = False | |||
Comment on lines
+28
to
+31
| from opentelemetry import trace | ||
| from opentelemetry.exporter.otlp.proto.http.trace_exporter import ( | ||
| OTLPSpanExporter, | ||
| ) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
This PR updates the LoongSuite CrewAI instrumentation to build GenAI telemetry through
opentelemetry-util-genai, including Crew/Flow entry spans, agent/task/tool spans, token usage, streaming behavior, and safe instrumentation failure handling. It also adds a real CrewAI smoke example for sync, streaming, and concurrent runs, and refreshes the README and changelog.Fixes # (N/A)
Type of change
How Has This Been Tested?
uvx tox -e precommituvx tox -c tox-loongsuite.ini -e lint-loongsuite-instrumentation-crewaiuvx tox -c tox-loongsuite.ini -e py312-test-loongsuite-instrumentation-crewaiDoes This PR Require a Core Repo Change?
Checklist:
See contributing.md for styleguide, changelog guidelines, and more.