Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions .github/workflows/loongsuite_lint_0.yml
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,25 @@ jobs:
- name: Run tests
run: tox -c tox-loongsuite.ini -e lint-loongsuite-instrumentation-langgraph

lint-loongsuite-instrumentation-qwen-agent:
name: LoongSuite loongsuite-instrumentation-qwen-agent
runs-on: ubuntu-latest
timeout-minutes: 30
steps:
- name: Checkout repo @ SHA - ${{ github.sha }}
uses: actions/checkout@v4

- name: Set up Python 3.13
uses: actions/setup-python@v5
with:
python-version: "3.13"

- name: Install tox
run: pip install tox-uv

- name: Run tests
run: tox -c tox-loongsuite.ini -e lint-loongsuite-instrumentation-qwen-agent

lint-loongsuite-instrumentation-mem0:
name: LoongSuite loongsuite-instrumentation-mem0
runs-on: ubuntu-latest
Expand Down
190 changes: 190 additions & 0 deletions .github/workflows/loongsuite_test_0.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1096,6 +1096,196 @@ jobs:
- name: Run tests
run: tox -c tox-loongsuite.ini -e py313-test-loongsuite-instrumentation-langgraph-latest -- -ra

py39-test-loongsuite-instrumentation-qwen-agent-oldest_ubuntu-latest:
name: LoongSuite loongsuite-instrumentation-qwen-agent-oldest 3.9 Ubuntu
runs-on: ubuntu-latest
timeout-minutes: 30
steps:
- name: Checkout repo @ SHA - ${{ github.sha }}
uses: actions/checkout@v4

- name: Set up Python 3.9
uses: actions/setup-python@v5
with:
python-version: "3.9"

- name: Install tox
run: pip install tox-uv

- name: Run tests
run: tox -c tox-loongsuite.ini -e py39-test-loongsuite-instrumentation-qwen-agent-oldest -- -ra

py39-test-loongsuite-instrumentation-qwen-agent-latest_ubuntu-latest:
name: LoongSuite loongsuite-instrumentation-qwen-agent-latest 3.9 Ubuntu
runs-on: ubuntu-latest
timeout-minutes: 30
steps:
- name: Checkout repo @ SHA - ${{ github.sha }}
uses: actions/checkout@v4

- name: Set up Python 3.9
uses: actions/setup-python@v5
with:
python-version: "3.9"

- name: Install tox
run: pip install tox-uv

- name: Run tests
run: tox -c tox-loongsuite.ini -e py39-test-loongsuite-instrumentation-qwen-agent-latest -- -ra

py310-test-loongsuite-instrumentation-qwen-agent-oldest_ubuntu-latest:
name: LoongSuite loongsuite-instrumentation-qwen-agent-oldest 3.10 Ubuntu
runs-on: ubuntu-latest
timeout-minutes: 30
steps:
- name: Checkout repo @ SHA - ${{ github.sha }}
uses: actions/checkout@v4

- name: Set up Python 3.10
uses: actions/setup-python@v5
with:
python-version: "3.10"

- name: Install tox
run: pip install tox-uv

- name: Run tests
run: tox -c tox-loongsuite.ini -e py310-test-loongsuite-instrumentation-qwen-agent-oldest -- -ra

py310-test-loongsuite-instrumentation-qwen-agent-latest_ubuntu-latest:
name: LoongSuite loongsuite-instrumentation-qwen-agent-latest 3.10 Ubuntu
runs-on: ubuntu-latest
timeout-minutes: 30
steps:
- name: Checkout repo @ SHA - ${{ github.sha }}
uses: actions/checkout@v4

- name: Set up Python 3.10
uses: actions/setup-python@v5
with:
python-version: "3.10"

- name: Install tox
run: pip install tox-uv

- name: Run tests
run: tox -c tox-loongsuite.ini -e py310-test-loongsuite-instrumentation-qwen-agent-latest -- -ra

py311-test-loongsuite-instrumentation-qwen-agent-oldest_ubuntu-latest:
name: LoongSuite loongsuite-instrumentation-qwen-agent-oldest 3.11 Ubuntu
runs-on: ubuntu-latest
timeout-minutes: 30
steps:
- name: Checkout repo @ SHA - ${{ github.sha }}
uses: actions/checkout@v4

- name: Set up Python 3.11
uses: actions/setup-python@v5
with:
python-version: "3.11"

- name: Install tox
run: pip install tox-uv

- name: Run tests
run: tox -c tox-loongsuite.ini -e py311-test-loongsuite-instrumentation-qwen-agent-oldest -- -ra

py311-test-loongsuite-instrumentation-qwen-agent-latest_ubuntu-latest:
name: LoongSuite loongsuite-instrumentation-qwen-agent-latest 3.11 Ubuntu
runs-on: ubuntu-latest
timeout-minutes: 30
steps:
- name: Checkout repo @ SHA - ${{ github.sha }}
uses: actions/checkout@v4

- name: Set up Python 3.11
uses: actions/setup-python@v5
with:
python-version: "3.11"

- name: Install tox
run: pip install tox-uv

- name: Run tests
run: tox -c tox-loongsuite.ini -e py311-test-loongsuite-instrumentation-qwen-agent-latest -- -ra

py312-test-loongsuite-instrumentation-qwen-agent-oldest_ubuntu-latest:
name: LoongSuite loongsuite-instrumentation-qwen-agent-oldest 3.12 Ubuntu
runs-on: ubuntu-latest
timeout-minutes: 30
steps:
- name: Checkout repo @ SHA - ${{ github.sha }}
uses: actions/checkout@v4

- name: Set up Python 3.12
uses: actions/setup-python@v5
with:
python-version: "3.12"

- name: Install tox
run: pip install tox-uv

- name: Run tests
run: tox -c tox-loongsuite.ini -e py312-test-loongsuite-instrumentation-qwen-agent-oldest -- -ra

py312-test-loongsuite-instrumentation-qwen-agent-latest_ubuntu-latest:
name: LoongSuite loongsuite-instrumentation-qwen-agent-latest 3.12 Ubuntu
runs-on: ubuntu-latest
timeout-minutes: 30
steps:
- name: Checkout repo @ SHA - ${{ github.sha }}
uses: actions/checkout@v4

- name: Set up Python 3.12
uses: actions/setup-python@v5
with:
python-version: "3.12"

- name: Install tox
run: pip install tox-uv

- name: Run tests
run: tox -c tox-loongsuite.ini -e py312-test-loongsuite-instrumentation-qwen-agent-latest -- -ra

py313-test-loongsuite-instrumentation-qwen-agent-oldest_ubuntu-latest:
name: LoongSuite loongsuite-instrumentation-qwen-agent-oldest 3.13 Ubuntu
runs-on: ubuntu-latest
timeout-minutes: 30
steps:
- name: Checkout repo @ SHA - ${{ github.sha }}
uses: actions/checkout@v4

- name: Set up Python 3.13
uses: actions/setup-python@v5
with:
python-version: "3.13"

- name: Install tox
run: pip install tox-uv

- name: Run tests
run: tox -c tox-loongsuite.ini -e py313-test-loongsuite-instrumentation-qwen-agent-oldest -- -ra

py313-test-loongsuite-instrumentation-qwen-agent-latest_ubuntu-latest:
name: LoongSuite loongsuite-instrumentation-qwen-agent-latest 3.13 Ubuntu
runs-on: ubuntu-latest
timeout-minutes: 30
steps:
- name: Checkout repo @ SHA - ${{ github.sha }}
uses: actions/checkout@v4

- name: Set up Python 3.13
uses: actions/setup-python@v5
with:
python-version: "3.13"

- name: Install tox
run: pip install tox-uv

- name: Run tests
run: tox -c tox-loongsuite.ini -e py313-test-loongsuite-instrumentation-qwen-agent-latest -- -ra

py310-test-loongsuite-instrumentation-mem0-oldest_ubuntu-latest:
name: LoongSuite loongsuite-instrumentation-mem0-oldest 3.10 Ubuntu
runs-on: ubuntu-latest
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Changelog

## Unreleased

### Added

- Initial release of `loongsuite-instrumentation-qwen-agent`
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

The format of the changelog file should follow the established conventions. Please refer to:
https://github.com/alibaba/loongsuite-python-agent/blob/main/instrumentation-loongsuite/loongsuite-instrumentation-dashscope/CHANGELOG.md

- Instrumentation for `Agent.run()` (invoke_agent spans; `run_nonstream()` is covered via its internal `run()` call — no duplicate span)
- Instrumentation for `BaseChatModel.chat()` (LLM spans)
- Instrumentation for `Agent._call_tool()` (execute_tool spans)
- Support for streaming and non-streaming LLM responses
- Message conversion from qwen-agent types to GenAI semantic conventions
- Provider detection for DashScope, OpenAI, and Azure backends
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
# OpenTelemetry Qwen-Agent Instrumentation

OpenTelemetry instrumentation for the [Qwen-Agent](https://github.com/QwenLM/Qwen-Agent) framework.

## Installation

```bash
pip install opentelemetry-distro opentelemetry-exporter-otlp
opentelemetry-bootstrap -a install

pip install "qwen-agent >= 0.0.20"

# Install this instrumentation (from the LoongSuite repo)
pip install ./instrumentation-loongsuite/loongsuite-instrumentation-qwen-agent

# Required: GenAI utilities used by the instrumentation
pip install ./util/opentelemetry-util-genai
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

This should be done before install loongsuite-instrumentation-qwen-agent.

```

Published package name:

```bash
pip install loongsuite-instrumentation-qwen-agent
```

## Usage

### Auto-instrumentation

With `loongsuite-instrumentation-qwen-agent` installed, the `opentelemetry_instrumentor` entry point `qwen_agent` is registered for use with the OpenTelemetry distro.

```bash
opentelemetry-instrument \
--traces_exporter console \
python your_qwen_agent_app.py
```

### Manual instrumentation

```python
from opentelemetry.instrumentation.qwen_agent import QwenAgentInstrumentor
from opentelemetry.sdk.trace import TracerProvider
from opentelemetry.sdk.trace.export import ConsoleSpanExporter, SimpleSpanProcessor
from qwen_agent.agents import Assistant

provider = TracerProvider()
provider.add_span_processor(SimpleSpanProcessor(ConsoleSpanExporter()))

QwenAgentInstrumentor().instrument(tracer_provider=provider)

bot = Assistant(
llm={"model": "qwen-max", "model_type": "qwen_dashscope"},
name="my-assistant",
)
for _ in bot.run([{"role": "user", "content": "Hello!"}]):
pass

QwenAgentInstrumentor().uninstrument()
```

## Configuration

### Export to an OTLP backend

```bash
export OTEL_SERVICE_NAME=my-qwen-agent-app
export OTEL_EXPORTER_OTLP_PROTOCOL=http/protobuf
export OTEL_EXPORTER_OTLP_TRACES_ENDPOINT=<trace_endpoint>
# Optional: metrics / logs if you configure exporters globally
export OTEL_EXPORTER_OTLP_METRICS_ENDPOINT=<metrics_endpoint>

opentelemetry-instrument python your_app.py
```

### GenAI semantic conventions and content capture

```bash
# Enable experimental GenAI semantic conventions (recommended for this instrumentation)
export OTEL_SEMCONV_STABILITY_OPT_IN=gen_ai_latest_experimental

# Message content capture (same env vars as other GenAI instrumentations in this repo)
export OTEL_INSTRUMENTATION_GENAI_CAPTURE_MESSAGE_CONTENT=SPAN_ONLY
# EVENT_ONLY | SPAN_AND_EVENT | NO_CONTENT
```

## Supported components

| Area | Instrumented API | Span / operation |
|------|------------------|------------------|
| Agent | `Agent.run` | `invoke_agent` |
| LLM | `BaseChatModel.chat` | `chat` |
| ReAct | `Agent._call_llm` | `react step` (agents with tools) |
| Tools | `Agent._call_tool` | `execute_tool` |

`Agent.run_nonstream()` is not wrapped separately; it calls `run()` internally, so you still get a single `invoke_agent` span per run.

**Model backends** (inferred from `model_type` / class name): DashScope, OpenAI-compatible APIs, Azure OpenAI, and other Qwen-Agent–supported backends.

## Visualization

Export telemetry to:

- [Alibaba Cloud ARMS / Managed Service for OpenTelemetry](https://www.aliyun.com/product/xtrace)
- [AgentScope Studio](https://github.com/agentscope-ai/agentscope-studio) or any OTLP-compatible collector
- Any OpenTelemetry-compatible backend (Jaeger, Zipkin, etc.)

## License

Apache License 2.0
Loading
Loading