Skip to content

feat(crewai): add GenAI util instrumentation#198

Open
sipercai wants to merge 1 commit into
mainfrom
feat/crewai-genai-util
Open

feat(crewai): add GenAI util instrumentation#198
sipercai wants to merge 1 commit into
mainfrom
feat/crewai-genai-util

Conversation

@sipercai
Copy link
Copy Markdown
Collaborator

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

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update

How Has This Been Tested?

  • uvx tox -e precommit
  • uvx tox -c tox-loongsuite.ini -e lint-loongsuite-instrumentation-crewai
  • uvx tox -c tox-loongsuite.ini -e py312-test-loongsuite-instrumentation-crewai

Does This PR Require a Core Repo Change?

  • Yes. - Link to PR:
  • No.

Checklist:

See contributing.md for styleguide, changelog guidelines, and more.

  • Followed the style guidelines of this project
  • Changelogs have been updated
  • Unit tests have been added
  • Documentation has been updated

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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, plus gen_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,
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants