Skip to content

agardnerIT/opamp-server-py

Repository files navigation

OpAMP Server

Warning: Entirely vibecoded

OpenTelemetry OpAMP server in Python with FastAPI + Streamlit UI. Optional integration with Open Policy Agent.

This server also lets you:

  • Filter collectors by metadata (such as environment: production)
  • Build minimal OTel Collectors (server generates a new manifest.yaml which you build with the OpenTelemetry Collector Builder [OCB])
  • Validate connected collectors against OPA compliance policies

Architecture

┌─────────────────────────┐        ┌─────────────────┐        ┌──────────────┐
│  OTel Collector         │───────▶│  OpAMP Server   │────────│  UI (:8501)  │
│  (OpAMP Extension)      │        │  (:4320)        │        │              │
└─────────────────────────┘        └─────────────────┘        └──────────────┘
                                           │
                                  ┌────────┴──────────────┐
                                  │   Open Policy Agent   │ (optional)
                                  │  (:8181)              │
                                  └───────────────────────┘

Quick Start

Server

python -m venv ./venv
source venv/bin/activate
pip install -r requirements.txt
uvicorn server.main:app --port 4320

UI

pip install -r requirements-ui.txt
streamlit run ui/app.py

Connect Agent

Modify collector YAML by adding the opamp extension:

extensions:
  opamp:
    server:
      http:
        endpoint: http://127.0.0.1:4320/v1/opamp

Environment Variables

Variable Default Description
SERVER_HTTP_SCHEME http HTTP scheme
SERVER_ADDRESS localhost Server bind address
SERVER_PORT 4320 Server port
AGENT_TIMEOUT_SECONDS 60 Seconds before stale agent removed
DATA_DIR data SQLite database directory

Alerts (Webhook)

Configure via UI at /alerts endpoint. Webhook sends JSON with event_type and message.

event_type Trigger
new_agent New agent connects
agent_disconnected Agent becomes stale
compliance_violation OPA policy fails

⚠️ Warning: Enable alerts will cause alert spam until issue #27 is resolved.

OPA (Optional)

Run OPA server, then set OPA_ENABLED=true.

Variable Default Description
OPA_ENABLED false Enable OPA compliance
OPA_URL http://localhost:8181 OPA server URL
POLICIES_DIR policies/tags Policies directory

Policies

docker run --rm -it -p 8181:8181 -v $(pwd)/policies:/policies \
  openpolicyagent/opa run --server --bundle /policies --watch

Add package opamp.agent.compliance.<name> policies to policies/tags/.

Endpoints

Endpoint Method Description
/v1/opamp POST OpAMP connection
/metrics GET Prometheus metrics
/agents GET List agents
/agent/{id} GET Agent details
/health GET Health check

Development

pip install -r requirements.txt
pip install -r requirements-ui.txt
pytest tests/ -v

Project Structure

opamp-server-py/
├── server/          # FastAPI server
├── ui/              # Streamlit dashboard
├── proto/           # Protobuf definitions
├── tests/           # Tests
├── collector/       # Sample configs
└── data/           # SQLite DB

About

An OpenTelemetry OpAMP server in Python

Topics

Resources

Stars

Watchers

Forks

Contributors