Skip to content

Commit 8cebde6

Browse files
authored
Add OpenTelemetry instrumentation for CrewAI (#87)
1 parent cee652e commit 8cebde6

33 files changed

Lines changed: 11421 additions & 1 deletion

.github/workflows/loongsuite_lint_0.yml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,3 +203,22 @@ jobs:
203203
- name: Run tests
204204
run: tox -c tox-loongsuite.ini -e lint-loongsuite-instrumentation-litellm
205205

206+
lint-loongsuite-instrumentation-crewai:
207+
name: LoongSuite loongsuite-instrumentation-crewai
208+
runs-on: ubuntu-latest
209+
timeout-minutes: 30
210+
steps:
211+
- name: Checkout repo @ SHA - ${{ github.sha }}
212+
uses: actions/checkout@v4
213+
214+
- name: Set up Python 3.13
215+
uses: actions/setup-python@v5
216+
with:
217+
python-version: "3.13"
218+
219+
- name: Install tox
220+
run: pip install tox-uv
221+
222+
- name: Run tests
223+
run: tox -c tox-loongsuite.ini -e lint-loongsuite-instrumentation-crewai
224+

.github/workflows/loongsuite_test_0.yml

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1457,3 +1457,79 @@ jobs:
14571457
- name: Run tests
14581458
run: tox -c tox-loongsuite.ini -e py313-test-loongsuite-instrumentation-litellm -- -ra
14591459

1460+
py310-test-loongsuite-instrumentation-crewai_ubuntu-latest:
1461+
name: LoongSuite loongsuite-instrumentation-crewai 3.10 Ubuntu
1462+
runs-on: ubuntu-latest
1463+
timeout-minutes: 30
1464+
steps:
1465+
- name: Checkout repo @ SHA - ${{ github.sha }}
1466+
uses: actions/checkout@v4
1467+
1468+
- name: Set up Python 3.10
1469+
uses: actions/setup-python@v5
1470+
with:
1471+
python-version: "3.10"
1472+
1473+
- name: Install tox
1474+
run: pip install tox-uv
1475+
1476+
- name: Run tests
1477+
run: tox -c tox-loongsuite.ini -e py310-test-loongsuite-instrumentation-crewai -- -ra
1478+
1479+
py311-test-loongsuite-instrumentation-crewai_ubuntu-latest:
1480+
name: LoongSuite loongsuite-instrumentation-crewai 3.11 Ubuntu
1481+
runs-on: ubuntu-latest
1482+
timeout-minutes: 30
1483+
steps:
1484+
- name: Checkout repo @ SHA - ${{ github.sha }}
1485+
uses: actions/checkout@v4
1486+
1487+
- name: Set up Python 3.11
1488+
uses: actions/setup-python@v5
1489+
with:
1490+
python-version: "3.11"
1491+
1492+
- name: Install tox
1493+
run: pip install tox-uv
1494+
1495+
- name: Run tests
1496+
run: tox -c tox-loongsuite.ini -e py311-test-loongsuite-instrumentation-crewai -- -ra
1497+
1498+
py312-test-loongsuite-instrumentation-crewai_ubuntu-latest:
1499+
name: LoongSuite loongsuite-instrumentation-crewai 3.12 Ubuntu
1500+
runs-on: ubuntu-latest
1501+
timeout-minutes: 30
1502+
steps:
1503+
- name: Checkout repo @ SHA - ${{ github.sha }}
1504+
uses: actions/checkout@v4
1505+
1506+
- name: Set up Python 3.12
1507+
uses: actions/setup-python@v5
1508+
with:
1509+
python-version: "3.12"
1510+
1511+
- name: Install tox
1512+
run: pip install tox-uv
1513+
1514+
- name: Run tests
1515+
run: tox -c tox-loongsuite.ini -e py312-test-loongsuite-instrumentation-crewai -- -ra
1516+
1517+
py313-test-loongsuite-instrumentation-crewai_ubuntu-latest:
1518+
name: LoongSuite loongsuite-instrumentation-crewai 3.13 Ubuntu
1519+
runs-on: ubuntu-latest
1520+
timeout-minutes: 30
1521+
steps:
1522+
- name: Checkout repo @ SHA - ${{ github.sha }}
1523+
uses: actions/checkout@v4
1524+
1525+
- name: Set up Python 3.13
1526+
uses: actions/setup-python@v5
1527+
with:
1528+
python-version: "3.13"
1529+
1530+
- name: Install tox
1531+
run: pip install tox-uv
1532+
1533+
- name: Run tests
1534+
run: tox -c tox-loongsuite.ini -e py313-test-loongsuite-instrumentation-crewai -- -ra
1535+
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# Changelog
2+
3+
All notable changes to this project will be documented in this file.
4+
5+
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
6+
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7+
8+
## Unreleased
9+
10+
### Added
11+
12+
- Initialize the instrumentation for CrewAI
13+
([#87](https://github.com/alibaba/loongsuite-python-agent/pull/87))
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
# LoongSuite CrewAI Instrumentation
2+
3+
This library provides automatic instrumentation for [CrewAI](https://www.crewai.com/), a framework for orchestrating role-playing, autonomous AI agents.
4+
5+
## Installation
6+
7+
```bash
8+
git clone https://github.com/alibaba/loongsuite-python-agent.git
9+
cd loongsuite-python-agent
10+
pip install ./instrumentation-loongsuite/loongsuite-instrumentation-crewai
11+
```
12+
13+
## Usage
14+
15+
```python
16+
from opentelemetry.instrumentation.crewai import CrewAIInstrumentor
17+
18+
# Instrument CrewAI
19+
CrewAIInstrumentor().instrument()
20+
21+
# Your CrewAI code here
22+
from crewai import Agent, Task, Crew
23+
24+
agent = Agent(
25+
role='Data Analyst',
26+
goal='Extract actionable insights',
27+
backstory='Expert in data analysis',
28+
verbose=True
29+
)
30+
31+
task = Task(
32+
description='Analyze the latest AI trends',
33+
agent=agent
34+
)
35+
36+
crew = Crew(
37+
agents=[agent],
38+
tasks=[task],
39+
verbose=True
40+
)
41+
42+
result = crew.kickoff()
43+
```
44+
45+
## Supported Versions
46+
47+
- CrewAI >= 0.80.0
48+
49+
## References
50+
51+
- [CrewAI Documentation](https://docs.crewai.com/)
52+
- [OpenTelemetry Python Documentation](https://opentelemetry-python.readthedocs.io/)
53+
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
[build-system]
2+
requires = ["hatchling"]
3+
build-backend = "hatchling.build"
4+
5+
[project]
6+
name = "loongsuite-instrumentation-crewai"
7+
dynamic = ["version"]
8+
description = "LoongSuite CrewAI instrumentation"
9+
readme = "README.md"
10+
license = "Apache-2.0"
11+
requires-python = ">=3.10,<4"
12+
authors = [
13+
{ name = "OpenTelemetry Authors", email = "cncf-opentelemetry-contributors@lists.cncf.io" },
14+
]
15+
classifiers = [
16+
"Development Status :: 4 - Beta",
17+
"Intended Audience :: Developers",
18+
"License :: OSI Approved :: Apache Software License",
19+
"Programming Language :: Python",
20+
"Programming Language :: Python :: 3.10",
21+
"Programming Language :: Python :: 3.11",
22+
"Programming Language :: Python :: 3.12",
23+
]
24+
dependencies = [
25+
"opentelemetry-api >= 1.37.0",
26+
"opentelemetry-instrumentation >= 0.58b0",
27+
"opentelemetry-semantic-conventions >= 0.58b0",
28+
"wrapt >= 1.0.0, < 2.0.0",
29+
"opentelemetry-util-genai >= 0.3b0.dev0",
30+
]
31+
32+
[project.optional-dependencies]
33+
instruments = [
34+
"crewai >= 0.80.0",
35+
]
36+
37+
[project.entry-points.opentelemetry_instrumentor]
38+
crewai = "opentelemetry.instrumentation.crewai:CrewAIInstrumentor"
39+
40+
[project.urls]
41+
Homepage = "https://github.com/alibaba/loongsuite-python-agent/tree/main/instrumentation-loongsuite/loongsuite-instrumentation-crewai"
42+
Repository = "https://github.com/alibaba/loongsuite-python-agent"
43+
44+
[tool.hatch.version]
45+
path = "src/opentelemetry/instrumentation/crewai/version.py"
46+
47+
[tool.hatch.build.targets.sdist]
48+
include = [
49+
"/src",
50+
"/tests",
51+
]
52+
53+
[tool.hatch.build.targets.wheel]
54+
packages = ["src/opentelemetry"]
55+

0 commit comments

Comments
 (0)