Event-driven observability for qortex: metrics, traces, logs, and alerts.
Project description
qortex-observe
Event-driven observability for qortex: metrics, traces, logs, and alerts.
Install
pip install qortex-observe
With OpenTelemetry exporters:
pip install "qortex-observe[otel]"
Quick Start
from qortex.observe import configure, emit
from qortex.observe.events import QueryCompleted
# Zero-config: structured logging to stderr
configure()
# Emit typed events — subscribers handle metrics, traces, logs
emit(QueryCompleted(
query_id="q-1",
latency_ms=142.5,
seed_count=12,
result_count=8,
mode="hybrid",
))
What It Does
qortex-observe decouples event emission from observation. Application code emits typed events; pluggable subscribers route them to metrics, traces, logs, and alerts — without modules knowing about any of those concerns.
Metrics (48 instruments)
Single source of truth via the METRICS schema tuple. Counters, histograms, and gauges covering:
| Domain | Metrics | Examples |
|---|---|---|
| Query lifecycle | 4 | qortex_queries, qortex_query_duration_seconds |
| PPR convergence | 2 | qortex_ppr_started, qortex_ppr_iterations |
| Teleportation factors | 4 | qortex_factor_updates, qortex_factor_entropy |
| Edge promotion | 5 | qortex_edges_promoted, qortex_kg_coverage |
| Vector search | 8 | qortex_vec_search_duration_seconds, qortex_vec_index_size |
| Online indexing | 4 | qortex_messages_ingested, qortex_message_ingest_duration_seconds |
| Learning (bandit) | 7 | qortex_learning_selections, qortex_learning_posterior_mean |
| Enrichment | 3 | qortex_enrichment, qortex_enrichment_duration_seconds |
| Credit propagation | 4 | qortex_credit_propagations, qortex_credit_alpha_delta |
| Carbon | 4 | qortex_carbon_co2_grams, qortex_carbon_tokens |
Traces
The @traced decorator creates OpenTelemetry spans with overhead timing (wall time minus external I/O). SelectiveSpanProcessor exports only error spans, slow spans, or sampled spans — keeping telemetry volume manageable.
from qortex.observe import traced
@traced("retrieval.query")
def retrieve(query: str) -> list[dict]:
results = vec_search(query) # external call tracked separately
return rerank(results) # compute overhead measured
MCP Trace Propagation
Distributed tracing across the Python server ↔ TypeScript client boundary via W3C traceparent in MCP _meta:
from qortex.observe.mcp import mcp_trace_middleware
result = mcp_trace_middleware("retrieve", params, handler)
# Creates span "mcp.tool.retrieve" linked to client's trace context
Logging (Swappable Formatter x Destination)
Structured logging with a strategy pattern: pick a formatter (structlog or stdlib) and a destination (stderr, VictoriaLogs, JSONL file). All combinations work.
Carbon Accounting
Per-inference CO2 and water tracking with regulatory export formats:
from qortex.observe.carbon import calculate_carbon, calculate_equivalents
calc = calculate_carbon(input_tokens=1000, output_tokens=500, provider="anthropic", model="claude-sonnet")
equiv = calculate_equivalents(calc.total_co2_grams)
# GHG Protocol, CDP, TCFD, ISO 14064-1 exports available
Configuration
All settings are environment-variable driven with safe defaults:
| Env Var | Default | Purpose |
|---|---|---|
QORTEX_LOG_FORMATTER |
structlog |
structlog or stdlib |
QORTEX_LOG_DESTINATION |
stderr |
stderr, victorialogs, jsonl |
QORTEX_LOG_LEVEL |
INFO |
Python logging level |
QORTEX_LOG_FORMAT |
json |
json or console |
QORTEX_OTEL_ENABLED |
false |
Enable OTLP metric/trace push |
OTEL_EXPORTER_OTLP_ENDPOINT |
http://localhost:4317 |
OTLP collector endpoint |
OTEL_EXPORTER_OTLP_PROTOCOL |
grpc |
grpc or http/protobuf |
QORTEX_PROMETHEUS_ENABLED |
false |
Enable Prometheus /metrics |
QORTEX_PROMETHEUS_PORT |
9464 |
Prometheus scrape port |
QORTEX_OTEL_TRACE_SAMPLE_RATE |
0.1 |
Non-error/slow span sample rate |
QORTEX_OTEL_TRACE_LATENCY_THRESHOLD_MS |
100 |
Always export slower spans |
QORTEX_ALERTS_ENABLED |
false |
Enable alert rule evaluation |
40+ Typed Events
All events are frozen dataclasses grouped by domain:
- Query:
QueryStarted,QueryCompleted,QueryFailed - PPR:
PPRStarted,PPRConverged,PPRDiverged - Factors:
FactorUpdated,FactorsPersisted,FactorsLoaded,FactorDriftSnapshot - Edges:
OnlineEdgeRecorded,EdgePromoted,BufferFlushed - Retrieval:
VecSearchCompleted,OnlineEdgesGenerated,FeedbackReceived - Online Indexing:
MessageIngested,ToolResultIngested - Learning:
LearningSelectionMade,LearningObservationRecorded,LearningPosteriorUpdated - Carbon:
CarbonTracked
Requirements
- Python 3.11+
- pyventus (event bus)
- structlog (structured logging)
- OpenTelemetry SDK (optional, for metrics/traces export)
License
MIT
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 qortex_observe-0.1.0.tar.gz.
File metadata
- Download URL: qortex_observe-0.1.0.tar.gz
- Upload date:
- Size: 31.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
348e9e4711d0298d393a9fec622c70fdde7ec0aa56610aa296fdc75fd7f27bef
|
|
| MD5 |
e7c42c2d185e24fdf6848e7ec4b9d2d6
|
|
| BLAKE2b-256 |
ebcb0dc1789d4fed0e000258fd4257ebc0ef10bbd611c5131c5bf22e3cbfddca
|
Provenance
The following attestation bundles were made for qortex_observe-0.1.0.tar.gz:
Publisher:
publish-observe.yml on Peleke/qortex
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
qortex_observe-0.1.0.tar.gz -
Subject digest:
348e9e4711d0298d393a9fec622c70fdde7ec0aa56610aa296fdc75fd7f27bef - Sigstore transparency entry: 953556358
- Sigstore integration time:
-
Permalink:
Peleke/qortex@8640a68a84cde653c35103fb723609ff05ed107d -
Branch / Tag:
refs/tags/observe-v0.1.0 - Owner: https://github.com/Peleke
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish-observe.yml@8640a68a84cde653c35103fb723609ff05ed107d -
Trigger Event:
push
-
Statement type:
File details
Details for the file qortex_observe-0.1.0-py3-none-any.whl.
File metadata
- Download URL: qortex_observe-0.1.0-py3-none-any.whl
- Upload date:
- Size: 43.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
39e1b22ed6354dc6ce195a7317f2c9f1a9d25599170285043c7cd7ea44924c48
|
|
| MD5 |
e74490c77bfa125bdd6ec060a6d23a5e
|
|
| BLAKE2b-256 |
94c36ce3081e77fd9d45d8b4112886ba20c3e560f619528a305f0534817d63cf
|
Provenance
The following attestation bundles were made for qortex_observe-0.1.0-py3-none-any.whl:
Publisher:
publish-observe.yml on Peleke/qortex
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
qortex_observe-0.1.0-py3-none-any.whl -
Subject digest:
39e1b22ed6354dc6ce195a7317f2c9f1a9d25599170285043c7cd7ea44924c48 - Sigstore transparency entry: 953556359
- Sigstore integration time:
-
Permalink:
Peleke/qortex@8640a68a84cde653c35103fb723609ff05ed107d -
Branch / Tag:
refs/tags/observe-v0.1.0 - Owner: https://github.com/Peleke
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish-observe.yml@8640a68a84cde653c35103fb723609ff05ed107d -
Trigger Event:
push
-
Statement type: