OTel tracing, Prometheus metrics, structured JSON logging, and trace ContextVars
Project description
nodus-observability
OpenTelemetry bootstrap, Prometheus registry, structured JSON logging, and async-safe trace ContextVars. Zero required dependencies beyond python-json-logger — OTel and Prometheus are optional extras.
Install
pip install nodus-observability # core only
pip install "nodus-observability[metrics]" # + prometheus-client
pip install "nodus-observability[otel]" # + opentelemetry stack
pip install "nodus-observability[all]" # everything
Trace context
from nodus_observability import set_trace_id, get_trace_id, reset_trace_id, ensure_trace_id
tok = set_trace_id("req-abc-123")
print(get_trace_id()) # "req-abc-123"
reset_trace_id(tok)
Structured logging
from nodus_observability import configure_logging, get_trace_id
configure_logging(
env="production",
log_level="INFO",
get_trace_id_fn=get_trace_id, # inject trace_id from ContextVar
)
OTel tracing
from nodus_observability import init_otel, get_tracer
init_otel(service_name="my-service") # reads OTEL_EXPORTER_OTLP_ENDPOINT
tracer = get_tracer("my-module")
with tracer.start_as_current_span("my-operation") as span:
span.set_status("ok")
Prometheus metrics
from nodus_observability import create_registry, Counter
REGISTRY = create_registry() # never use the default global registry
requests_total = Counter(
"myapp_requests_total",
"Total requests",
["method", "status"],
registry=REGISTRY,
)
requests_total.labels(method="GET", status="200").inc()
Extracted from
AINDY/platform_layer/trace_context.py, otel.py, metrics.py, and log_config.py in the A.I.N.D.Y. runtime.
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 nodus_observability-0.1.0.tar.gz.
File metadata
- Download URL: nodus_observability-0.1.0.tar.gz
- Upload date:
- Size: 10.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e2cd4b336bbc812db994c1f3c83336af8df865d21c47f32027ce752ebde3aa41
|
|
| MD5 |
0245d86103520952d8545f27ee9ed184
|
|
| BLAKE2b-256 |
d56f7209f37600daec9b488069edec8623c4489d3232345032565af8f8c0cada
|
File details
Details for the file nodus_observability-0.1.0-py3-none-any.whl.
File metadata
- Download URL: nodus_observability-0.1.0-py3-none-any.whl
- Upload date:
- Size: 9.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
96f5c25bd0e7081a03253bdf940f9acb7d3809a5ab03a03010c99a4b6ad5b58b
|
|
| MD5 |
09631d45ad116c0717c302ca8fbeee6c
|
|
| BLAKE2b-256 |
0afe623e7f716d099b0071603aac5986108bc3a96972cdc77c4943bc4cc97cd7
|