Skip to main content

Automatic instrumentation for Python agent applications, monitored via WSO2 Agent Management Platform

Project description

WSO2 Agent Manager Instrumentation

Zero-code OpenTelemetry instrumentation for Python agents using the Traceloop SDK, with trace visibility in the WSO2 Agent Manager.

Overview

amp-instrumentation enables zero-code instrumentation for Python agents, automatically capturing traces for LLM calls, MCP requests, and other operations. It seamlessly wraps your agent’s execution with OpenTelemetry tracing powered by the Traceloop SDK.

For agents on a custom or non-frontier framework — or anywhere you want full control over the spans you emit — it also ships init_otel(), a one-line OpenTelemetry exporter setup so you can instrument the agent yourself against AMP's instrumentation contract. See Manual instrumentation.

Features

  • Zero Code Changes: Instrument existing applications without modifying code
  • Automatic Tracing: Traces LLM calls, MCP requests, database queries, and more
  • OpenTelemetry Compatible: Uses industry-standard OpenTelemetry protocol
  • Flexible Configuration: Configure via environment variables
  • Framework Agnostic: Works with any Python application built using a wide range of agent frameworks supported by the TraceLoop SDK
  • Manual path: init_otel() for agents that emit their own OpenTelemetry GenAI spans

Installation

pip install amp-instrumentation

Each release of amp-instrumentation pins a specific Traceloop SDK version, so a given amp-instrumentation version always installs a fully determined SDK. To use a different Traceloop SDK version, install a different amp-instrumentation version.

Quick Start

1. Register Your Agent

First, register your agent at the WSO2 Agent Manager to obtain your agent API key and configuration details.

2. Set Required Environment Variables

export AMP_OTEL_ENDPOINT="https://amp-otel-endpoint.com" # AMP OTEL endpoint
export AMP_AGENT_API_KEY="your-agent-api-key" # Agent-specific key generated after registration

Optional: prompt and completion content is captured by default. To suppress it, set TRACELOOP_TRACE_CONTENT=false.

3. Run Your Application

Use the amp-instrument command to wrap your application run command:

# Run a Python script
amp-instrument python my_script.py

# Run with uvicorn
amp-instrument uvicorn app:main --reload

# Run with any package manager
amp-instrument poetry run python script.py
amp-instrument uv run python script.py

That's it! Your application is now instrumented and sending traces to the WSO2 Agent Manager.

Manual instrumentation

If your agent uses a framework the Traceloop SDK doesn't cover — or you want to emit your own spans — instrument it yourself and send the spans to AMP. init_otel() configures the OpenTelemetry exporter (the same AMP_OTEL_ENDPOINT / AMP_AGENT_API_KEY environment variables as above); it does no instrumentation itself, so you control the spans:

import json
from opentelemetry import trace
from amp_instrumentation import init_otel

init_otel()  # reads AMP_OTEL_ENDPOINT and AMP_AGENT_API_KEY from the environment
tracer = trace.get_tracer("my-agent")

with tracer.start_as_current_span("chat") as span:
    span.set_attribute("gen_ai.operation.name", "chat")
    span.set_attribute("gen_ai.system", "openai")
    span.set_attribute("gen_ai.request.model", "gpt-4o-mini")
    span.set_attribute("gen_ai.input.messages", json.dumps(input_messages))
    response = call_model(...)
    span.set_attribute("gen_ai.response.model", response.model)
    span.set_attribute("gen_ai.output.messages", json.dumps(response.messages))
    span.set_attribute("gen_ai.usage.input_tokens", response.usage.input_tokens)
    span.set_attribute("gen_ai.usage.output_tokens", response.usage.output_tokens)

Spans that follow AMP's instrumentation contract — the OpenTelemetry GenAI semantic conventions — render with the full trace view in the Agent Manager and run through evaluators; spans that don't still appear, just without the rich view. The contract and the full supported-attribute reference are published in the WSO2 Agent Manager documentation (manual instrumentation guide).

init_otel() is idempotent and is roughly ten lines of vanilla OpenTelemetry SDK setup (TracerProvider + BatchSpanProcessor + an OTLP/HTTP exporter to <AMP_OTEL_ENDPOINT>/v1/traces with the x-amp-api-key header) — use it so you don't have to write that yourself.

Project details


Download files

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

Source Distribution

amp_instrumentation-0.2.0.tar.gz (15.1 kB view details)

Uploaded Source

Built Distribution

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

amp_instrumentation-0.2.0-py3-none-any.whl (16.0 kB view details)

Uploaded Python 3

File details

Details for the file amp_instrumentation-0.2.0.tar.gz.

File metadata

  • Download URL: amp_instrumentation-0.2.0.tar.gz
  • Upload date:
  • Size: 15.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.10.20

File hashes

Hashes for amp_instrumentation-0.2.0.tar.gz
Algorithm Hash digest
SHA256 d9f2cbd555ce56ac97c2930b6f2c513514cbccbf4ca9c60e72dfeebf7f0fa776
MD5 b45a27c0438aabb1818d6cb43da97d24
BLAKE2b-256 3f2e58f0eb0d1dbb1e65a2e75a8458c0c603541e4d5692e01e3855b7bf241f12

See more details on using hashes here.

File details

Details for the file amp_instrumentation-0.2.0-py3-none-any.whl.

File metadata

File hashes

Hashes for amp_instrumentation-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 83e70f2b3cce90f00efa2ec3327b9f8c6f33ceeb9217f3996ee3178b4d1df659
MD5 c0d63f5a413d82c3a6d3dc6bcf4d2389
BLAKE2b-256 3d9450be0df1ed5404765ad9c218b8b346c8d5112bc11c9ba8ad78c7a8fbd315

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