Shared metrics + dashboard for Demystify services (Python mirror): canonical RED metric names, a prometheus-client registry with RED helpers, a framework-neutral /metrics handler, an offline HTML dashboard, and a span->metrics bridge.
Project description
platform-observability — shared metrics + dashboard
@demystify/platform-observability (TS) · demystify-platform-observability (Py) · v0.2.0 · MIT
What it is / when to use it
The single source of truth for RED metrics across all six Demystify services.
Canonical dmstfy_* metric names, a metrics registry with RED helpers, a
framework-neutral /metrics handler, an offline HTML dashboard, and a bridge that
turns a module's existing span instrumentation into duration metrics for free.
Leaf package: depends only on prom-client (TS) / prometheus-client (Py). Zero
dependency on any module. Keyless, offline, deterministic.
Install standalone
pnpm add @demystify/platform-observability # TS
uv add demystify-platform-observability # Py
Canonical metric names
Defined once, shared by both languages (METRIC_NAMES / fixture-locked):
| name | type | labels |
|---|---|---|
dmstfy_http_requests_total |
counter | method, route, status, tenant |
dmstfy_http_request_duration_seconds |
histogram | method, route, status, tenant |
dmstfy_provider_calls_total |
counter | provider, model, status |
dmstfy_provider_call_duration_seconds |
histogram | provider, model, status |
dmstfy_provider_cost_micro_usd_total |
counter | provider, model |
dmstfy_queue_depth |
gauge | queue |
dmstfy_span_duration_seconds |
histogram | span, module |
Durations are seconds; cost is integer µUSD (CONVENTIONS.md §2). Buckets:
[0.005, 0.01, 0.025, 0.05, 0.1, 0.25, 0.5, 1, 2.5, 5, 10].
SDK usage
import {
createMetrics, mountMetricsHono, renderDashboardHtml, spanExporterToMetrics,
} from "@demystify/platform-observability";
const metrics = createMetrics();
metrics.httpRequest("GET", "/v1/chat", 200, tenantId, 12.4); // RED helper
metrics.providerCall("openai", "gpt-4o", "ok", 210, 1500); // count+dur+cost
metrics.queueDepth("gateway", 7);
mountMetricsHono(app, metrics); // GET /metrics (Prometheus text)
setSpanExporter(spanExporterToMetrics(metrics)); // spans -> duration histogram
const html = renderDashboardHtml(metrics.snapshot());
from demystify_platform_observability import (
create_metrics, mount_metrics_fastapi, render_dashboard_html, span_exporter_to_metrics,
)
metrics = create_metrics()
metrics.http_request("GET", "/v1/chat", 200, tenant_id, 12.4)
metrics.provider_call("openai", "gpt-4o", "ok", 210, 1500)
metrics.queue_depth("gateway", 7)
mount_metrics_fastapi(app, metrics) # GET /metrics
set_span_exporter(span_exporter_to_metrics(metrics))
html = render_dashboard_html(metrics.snapshot())
Mounting /metrics
- Hono:
mountMetricsHono(app, metrics, "/metrics"). - FastAPI:
mount_metrics_fastapi(app, metrics, "/metrics"). - Anything else:
metricsHandler(metrics)/metrics_handler(metrics)returns{status, contentType, body}— wire it to your framework.
Span → metrics bridge
spanExporterToMetrics(metrics) returns an object matching the Wave-7
SpanExporter shape (export(span) in TS; a Callable[[Span], None] in Py). Pass
it to a module's setSpanExporter(...) / set_span_exporter(...) and every
finished span becomes an observation on dmstfy_span_duration_seconds. Off by
default (no exporter registered = zero cost), exactly like §14.3.
Architecture & ports/adapters
| seam | implementation | notes |
|---|---|---|
| metric store | private prom-client / prometheus-client registry per Metrics |
isolated; no global default registry |
| snapshot | deterministic in-memory tally | ordering-stable; powers dashboard + parity |
| exposition | metricsText() / metrics_text() |
Prometheus v0.0.4 text |
Testing
make -C packages/platform-observability setup lint test build. Unit tests only
(offline). Parity: TS and Py replay the same fixtures/snapshot.json and must
produce byte-identical snapshots; metric names locked to fixtures/metric-names.json.
v1 scope
RED + cost + queue-depth + span-duration. No exemplars, no push-gateway, no histogram-quantile helpers (scrape + PromQL do that). Real Prometheus scrape is the standard opt-in path; nothing here requires it to run.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file demystify_platform_observability-0.3.0.tar.gz.
File metadata
- Download URL: demystify_platform_observability-0.3.0.tar.gz
- Upload date:
- Size: 67.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a446b46839f9efff7b3b5306265ca47519fec757756c1d719f78ef7554620137
|
|
| MD5 |
1484067894f7963e48f450424dd61ea0
|
|
| BLAKE2b-256 |
db7153be96ba3661f0d1fb9ee182cac0872d508e4d3f527992e3724eb6d35e80
|
Provenance
The following attestation bundles were made for demystify_platform_observability-0.3.0.tar.gz:
Publisher:
publish-pypi.yml on demystify-systems/ai-services-tools
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
demystify_platform_observability-0.3.0.tar.gz -
Subject digest:
a446b46839f9efff7b3b5306265ca47519fec757756c1d719f78ef7554620137 - Sigstore transparency entry: 2188359193
- Sigstore integration time:
-
Permalink:
demystify-systems/ai-services-tools@8a03d52d29b940de704d971b9c437493879613a4 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/demystify-systems
-
Access:
private
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish-pypi.yml@8a03d52d29b940de704d971b9c437493879613a4 -
Trigger Event:
workflow_dispatch
-
Statement type:
File details
Details for the file demystify_platform_observability-0.3.0-py3-none-any.whl.
File metadata
- Download URL: demystify_platform_observability-0.3.0-py3-none-any.whl
- Upload date:
- Size: 13.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
35cb014c3074e88c99c1c9f35abb647dd4eb4159ab76148ba73d9523c71e7f4a
|
|
| MD5 |
44168a0de15c5665bd80e9ba92964fa8
|
|
| BLAKE2b-256 |
f8ec78eeeff802db982998a83d1fff9109c66b93acee8e4b161a94bb663ab751
|
Provenance
The following attestation bundles were made for demystify_platform_observability-0.3.0-py3-none-any.whl:
Publisher:
publish-pypi.yml on demystify-systems/ai-services-tools
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
demystify_platform_observability-0.3.0-py3-none-any.whl -
Subject digest:
35cb014c3074e88c99c1c9f35abb647dd4eb4159ab76148ba73d9523c71e7f4a - Sigstore transparency entry: 2188359215
- Sigstore integration time:
-
Permalink:
demystify-systems/ai-services-tools@8a03d52d29b940de704d971b9c437493879613a4 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/demystify-systems
-
Access:
private
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish-pypi.yml@8a03d52d29b940de704d971b9c437493879613a4 -
Trigger Event:
workflow_dispatch
-
Statement type: