Skip to main content

OpenTelemetry Qwen-Agent Instrumentation

OpenTelemetry instrumentation for the Qwen-Agent framework.

Installation

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

pip install "qwen-agent >= 0.0.20"

pip install ./util/opentelemetry-util-genai

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

Published package name:

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.

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

Manual instrumentation

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

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

# 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:

License

Apache License 2.0

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

File details

Details for the file loongsuite_instrumentation_qwen_agent-0.8.0-py3-none-any.whl.

File metadata

File hashes

Hashes for loongsuite_instrumentation_qwen_agent-0.8.0-py3-none-any.whl
Algorithm Hash digest
SHA256 4620b3a4a754c4c7d9c49bfc953f79f508975fd9f40f3c33a72e4bb9bc790368
MD5 b28f97e4847b56448aa530751469ea4b
BLAKE2b-256 50718167eb46f75ff06bdb9286a02d0129228017670f21a98decae8cecbd7f63

See more details on using hashes here.

Release history Release notifications | RSS feed

0.9.0

1 file

This release

0.8.0 This release

1 file

0.7.0

1 file

0.6.0

1 file

0.5.0

1 file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page