Skip to content

Add OpenTelemetry instrumentation for CrewAI#87

Open
whoIam0987 wants to merge 13 commits intoalibaba:mainfrom
whoIam0987:mingzhi/crewai
Open

Add OpenTelemetry instrumentation for CrewAI#87
whoIam0987 wants to merge 13 commits intoalibaba:mainfrom
whoIam0987:mingzhi/crewai

Conversation

@whoIam0987
Copy link

@whoIam0987 whoIam0987 commented Dec 15, 2025

Description

Instrument CrewAI with genai util.

Fixes # (issue)

Type of change

Please delete options that are not relevant.

  • New feature (non-breaking change which adds functionality)

How Has This Been Tested?

Please describe the tests that you ran to verify your changes. Provide instructions so we can reproduce. Please also list any relevant details for your test configuration

  • Modify releated unit tests.

Does This PR Require a Core Repo Change?

  • 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

@CLAassistant
Copy link

CLAassistant commented Dec 15, 2025

CLA assistant check
All committers have signed the CLA.

@ralf0131
Copy link
Collaborator

Thanks for the contribution! Please fix the CI failure.

Copy link
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 pull request adds OpenTelemetry instrumentation for the CrewAI framework, enabling automatic tracing of Crew, Agent, Task, and Tool executions with GenAI semantic conventions.

Changes:

  • Implements OpenTelemetry instrumentation wrappers for CrewAI's core components (Crew, Flow, Agent, Task, and Tool)
  • Adds utility functions for JSON serialization and message conversion to GenAI format
  • Includes comprehensive test suite covering synchronous/streaming LLM calls, tool usage, error scenarios, and agent workflows

Reviewed changes

Copilot reviewed 15 out of 16 changed files in this pull request and generated 16 comments.

Show a summary per file
File Description
src/opentelemetry/instrumentation/crewai/__init__.py Main instrumentation module with wrapper classes for Crew.kickoff, Flow.kickoff_async, Agent.execute_task, Task.execute_sync, and ToolUsage._use
src/opentelemetry/instrumentation/crewai/utils.py Utility functions for JSON serialization, message conversion, and GenAI hook helpers
src/opentelemetry/instrumentation/crewai/package.py Package metadata defining instrumentation dependencies
src/opentelemetry/instrumentation/crewai/version.py Version information (0.1.0)
pyproject.toml Project configuration with dependencies and build settings
README.md Documentation with installation instructions and usage examples
test-requirements.txt Test dependencies including CrewAI >=0.80.0 and LiteLLM
tests/*.py Comprehensive test suite covering various CrewAI execution scenarios

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@whoIam0987 whoIam0987 changed the title [WIP] Add OpenTelemetry instrumentation for CrewAI Add OpenTelemetry instrumentation for CrewAI Feb 5, 2026
@@ -0,0 +1,9 @@
crewai>=0.70.0
Copy link
Collaborator

Choose a reason for hiding this comment

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

Could you please add these tests as github workflows?

Just refer to:

- 测试
- 添加新 instrumentation 时,请记住更新 `tox.ini`,在 `envlist``command_pre``commands` 部分添加适当的规则

## 本地运行测试
1. 转到您的 Python Agent 仓库目录。`git clone git@github.com:alibaba/loongsuite-python-agent.git && cd loongsuite-python-agent`
2. 确保您已安装 `tox``pip install tox`
3. 运行 `tox` 不带任何参数以运行所有包的测试。阅读更多关于 [tox](https://tox.readthedocs.io/en/latest/) 的信息。
由于执行依赖项安装的预步骤,某些测试可能很慢。为了帮助解决这个问题,您可以先运行一次 tox,然后使用 toxdir 中先前安装的依赖项运行测试,如下所示:
1. 首次运行(例如,opentelemetry-instrumentation-aiopg)
```console
tox -e py312-test-instrumentation-aiopg
```
2. 再次运行测试而不执行预步骤:
```console
.tox/py312-test-instrumentation-aiopg/bin/pytest instrumentation/opentelemetry-instrumentation-aiopg
```

Copy link
Author

Choose a reason for hiding this comment

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

These tests is added to github workflows

@github-actions github-actions bot requested a review from Cirilla-zmh February 24, 2026 08:15
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.

6 participants