Skip to main content

LoongSuite AgentScope Instrumentation

Project description

LoongSuite AgentScope Instrumentation

LoongSuite instrumentation for AgentScope framework.

Features

  • Traces: Distributed tracing for agents, LLMs, tools, and formatters
  • Metrics: Performance metrics following OpenTelemetry GenAI semantic conventions
    • gen_ai.client.operation.duration: Operation duration in seconds
    • gen_ai.client.token.usage: Token usage for input and output
  • Events: Detailed event logging for messages and choices

Installation

# Step 1: install LoongSuite distro
pip install loongsuite-distro

# Step 2 (Option C): install this instrumentation from PyPI
pip install loongsuite-instrumentation-agentscope

# Optional app dependency
pip install agentscope

Usage

Auto-instrumentation

loongsuite-instrument \
    --traces_exporter console \
    --metrics_exporter console \
    python your_agentscope_app.py

Manual instrumentation

from opentelemetry.instrumentation.agentscope import AgentScopeInstrumentor
from agentscope.models import DashScopeChatModel
import agentscope

AgentScopeInstrumentor().instrument()

agentscope.init(project="my_project")
model = DashScopeChatModel(model_name="qwen-max")
result = await model(messages)

AgentScopeInstrumentor().uninstrument()

Configuration

Export to OTLP Backend

export OTEL_SERVICE_NAME=my-agentscope-app
export OTEL_EXPORTER_OTLP_PROTOCOL=http/protobuf
export OTEL_EXPORTER_OTLP_TRACES_ENDPOINT=<trace_endpoint>
export OTEL_EXPORTER_OTLP_METRICS_ENDPOINT=<metrics_endpoint>

loongsuite-instrument python your_app.py

Content Capture

Control message content capture using environment variables:

# Enable experimental GenAI semantic conventions
export OTEL_SEMCONV_STABILITY_OPT_IN=gen_ai_latest_experimental

# Capture content in spans only
export OTEL_INSTRUMENTATION_GENAI_CAPTURE_MESSAGE_CONTENT=SPAN_ONLY

# Capture content in events only
export OTEL_INSTRUMENTATION_GENAI_CAPTURE_MESSAGE_CONTENT=EVENT_ONLY

# Capture in both spans and events
export OTEL_INSTRUMENTATION_GENAI_CAPTURE_MESSAGE_CONTENT=SPAN_AND_EVENT

# Disable content capture (default)
export OTEL_INSTRUMENTATION_GENAI_CAPTURE_MESSAGE_CONTENT=NO_CONTENT

Supported Components

  • Models: ChatModelBase and all subclasses (nested __call__ / proxy chains emit a single LLM span per logical invocation)
  • Agents: AgentBase and all subclasses (same for stacked AgentBase.__call__)
  • ReAct Steps: Per-iteration react step spans for ReActAgent (via instance hooks); nested overrides that call super()._reasoning / super()._acting still produce one step per logical iteration
  • Tools: Toolkit.call_tool_function
  • Formatters: TruncatedFormatterBase.format

Concurrency (agents)

ReAct step tracing stores temporary state on the agent instance for the duration of each AgentBase.__call__. AgentScope itself models a single in-flight reply per instance (see AgentBase._reply_task / _reply_id in agentscope): concurrent overlapping await agent(...) on the same instance is unsupported and can corrupt traces, hook state, and interrupt behavior. Use one instance per concurrent conversation, or serialize calls with a lock or queue.

Visualization

Export telemetry data to:

Examples

See the main README for complete usage examples.

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

File metadata

File hashes

Hashes for loongsuite_instrumentation_agentscope-0.4.0-py3-none-any.whl
Algorithm Hash digest
SHA256 ddcbf1a892545c816436fc545c3eb16c3692f31f9ebbfb3e180ba1658ec466b7
MD5 33e93bc5c0bb12dc248c8bc55fb1fa81
BLAKE2b-256 d5f2eaaff1652c6bffea1b6df5777c3c932c14ff0ec263e55cfef7ca9084cffc

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