Python
Collect HTTP server and CPython runtime metrics from your Python services and get curated dashboards and alerts for them with a single import.
Python apps instrumented with OpenTelemetry export their metrics over OTLP to your LeanSignal agent gateway (one per cluster or environment) — never to a remote or third-party endpoint. The gateway keeps full fidelity locally and forwards only the demanded subset to your central dataplane. This integration covers HTTP server request metrics (Flask/Django/FastAPI/WSGI/ASGI) plus CPython process/runtime metrics (memory, CPU, threads, GC).
Metric names follow the standard OTLP → Prometheus normalization (dots become
underscores, unit/_total suffixes are added), so http.server.request.duration
becomes http_server_request_duration_seconds and
process.runtime.cpython.memory becomes process_runtime_cpython_memory_bytes.
The demands below are built against those names.
Prerequisites
Section titled “Prerequisites”- A LeanSignal agent gateway deployed and connected — one per cluster or
environment. If you haven’t deployed it yet, follow
Install the agent (source:
LeanSignal/leansignal-agent). It should show as Connected under Agents in the LeanSignal app. - Network reachability to the gateway’s OTLP port —
4317(gRPC) or4318(HTTP). See Agent configuration. - Your Python app instrumented with the OpenTelemetry SDK, exporting metrics over OTLP to the gateway — configured in Setup.
- Editor or admin role in the LeanSignal app (importing a demand creates dashboards and alert rules).
Install the HTTP and system-metrics instrumentation plus the OTLP exporter, then
point the SDK at your LeanSignal agent gateway (OTLP gRPC :4317 / HTTP :4318)
— not a SaaS endpoint.
pip install opentelemetry-distro opentelemetry-exporter-otlp \ opentelemetry-instrumentation-system-metricsopentelemetry-bootstrap -a install # adds Flask/Django/FastAPI/WSGI/ASGI instrumentorsexport OTEL_SERVICE_NAME=my-python-appexport OTEL_EXPORTER_OTLP_ENDPOINT=http://<gateway-host>:4317 # :4318 for http/protobufexport OTEL_EXPORTER_OTLP_PROTOCOL=grpcexport OTEL_METRICS_EXPORTER=otlpexport OTEL_SEMCONV_STABILITY_OPT_IN=http # emit http.server.request.duration (seconds)Run with auto-instrumentation:
opentelemetry-instrument python app.pyEnable the process/runtime metrics once in code:
from opentelemetry.instrumentation.system_metrics import SystemMetricsInstrumentorSystemMetricsInstrumentor().instrument()Logs and traces
Section titled “Logs and traces”opentelemetry-instrument from Setup exports traces by default
once OTEL_EXPORTER_OTLP_ENDPOINT is set. Logs are one opt-in away — the
standard-library logging output is then captured and exported:
export OTEL_LOGS_EXPORTER="otlp"export OTEL_PYTHON_LOGGING_AUTO_INSTRUMENTATION_ENABLED="true"See the Python zero-code instrumentation docs.
Demands
Section titled “Demands”Python ships as a ready-made demand in three variants. You don’t copy any JSON — in the LeanSignal app go to Demands, press the ˅ arrow on the Add Demand button (the arrow opens the import menu), choose Import from catalog…, and pick the variant. Each variant below lists the slug that identifies its published bundle. See Integrations for the full import flow.
The variants are nested — Standard is a superset of Essential, Extended a superset of Standard. Pick whichever is closest to what you need and treat it as a starting point: after import everything is a normal, editable copy, so retune thresholds, add or drop panels, and adjust queries for your environment — your edits reshape the demand automatically. Start small and re-import a larger variant later if you outgrow it.
The golden signals. 1 dashboard · 4 panels · 3 alerts — traffic, errors, latency, and memory at a glance.
Import this variant from the catalog. Its demand slug:
python-otel-demand-essentialDashboard — Request rate, 5xx error rate, Request latency p95, and Process memory (RSS).
Alerts (3)
| Alert | Severity | Fires when |
|---|---|---|
| High HTTP 5xx error rate | critical | 5xx ratio > 5% for 5m |
| High request latency (p95) | warning | p95 latency > 1s for 5m |
| High process memory (RSS) | warning | RSS > 1 GiB for 10m |
Well-rounded coverage. 1 dashboard · 7 panels · 5 alerts — adds latency percentiles and per-route traffic. The recommended default.
Import this variant from the catalog. Its demand slug:
python-otel-demand-standardDashboard — everything in Essential, plus Request latency p50, Request latency p99, and Request rate by route.
Alerts (5)
| Alert | Severity | Fires when |
|---|---|---|
| High HTTP 5xx error rate | critical | 5xx ratio > 5% for 5m |
| High request latency (p95) | warning | p95 latency > 1s for 5m |
| High process memory (RSS) | warning | RSS > 1 GiB for 10m |
| Critical HTTP 5xx error rate | critical | 5xx ratio > 20% for 5m |
| High request latency (p99) | warning | p99 latency > 2.5s for 5m |
Deep runtime visibility. 1 dashboard · 14 panels · 9 alerts — CPU, threads, context switches, and GC generations for services you need to diagnose, not just watch.
Import this variant from the catalog. Its demand slug:
python-otel-demand-extendedDashboard — everything in Standard, plus In-flight requests, CPU time (cores), CPU utilization, Thread count, Context switches, Virtual memory (VMS), and GC collections by generation.
Alerts (9)
| Alert | Severity | Fires when |
|---|---|---|
| High HTTP 5xx error rate | critical | 5xx ratio > 5% for 5m |
| High request latency (p95) | warning | p95 latency > 1s for 5m |
| High process memory (RSS) | warning | RSS > 1 GiB for 10m |
| Critical HTTP 5xx error rate | critical | 5xx ratio > 20% for 5m |
| High request latency (p99) | warning | p99 latency > 2.5s for 5m |
| Thread count elevated | warning | > 300 threads for 10m |
| Frequent gen-2 garbage collection | warning | > 1 gen-2 GC/s for 10m |
| Involuntary context-switch storm | warning | > 1000 involuntary switches/s for 10m |
| No inbound traffic | warning | no requests for 15m |
Dashboards
Section titled “Dashboards”Each variant imports one Python dashboard, its panels grouped into
collapsible sections. Every dashboard carries an Instance filter (on the
instance label), so one import covers the whole fleet — view every instance
at once, or focus on one. Legends are sortable tables showing last/mean/max per
series, so the outlier instance stands out. Dashboards are demand-driven:
importing one tells your agents to forward exactly the timeseries its panels
query, and nothing else. Panels are ordinary Perses panels — edit queries, add
panels, or retune them after import, and your changes reshape the demand
automatically.
Alerts
Section titled “Alerts”Thresholds are conservative starting points — tune them to your workload.
Next steps
Section titled “Next steps”- Demand-driven observability — why importing a demand also shapes what your agents collect.
- Agent configuration — the full agent config surface.
Thanks for your feedback!
Report sent — thank you!