Skip to main content

LoongSuite Qwen-Agent Instrumentation

Project description

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

Project details


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.6.0-py3-none-any.whl.

File metadata

File hashes

Hashes for loongsuite_instrumentation_qwen_agent-0.6.0-py3-none-any.whl
Algorithm Hash digest
SHA256 f542f55491df38c5a9ca13ee050cb82dc904038af9f222daab2ada6433cefdb9
MD5 7a40da88244553cfa1b38cf76c00633b
BLAKE2b-256 b8f24c1f5a2497bf8cd316a6e8acd19d2e5aeb49e2b7ac4475bdff8d1ef5f0d5

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page