corvix.observability¶
Observability for Corvix: structured logging, Prometheus metrics, OTel tracing.
Structured JSON logging via
configure_logging()(always available).Prometheus metrics via the
corvix.observability.metricsmodule and the/metricsweb endpoint.Optional OpenTelemetry tracing via
setup_tracing()andspan()(requires theotelextra andCORVIX_OTEL_ENABLED).
Submodules¶
Functions¶
|
Merge fields into the current logging context and return the previous one. |
|
Install the structured logging handler on the root logger. |
|
Restore a logging context previously returned by |
|
Return whether tracing has been successfully configured. |
|
Configure the global tracer provider when tracing is requested. |
|
Start a span as the current context, or no-op when tracing is disabled. |
Package Contents¶
- corvix.observability.bind_log_context(**fields: object) dict[str, object] | None[source][source]¶
Merge fields into the current logging context and return the previous one.
The returned value should be passed to
reset_log_context()to restore the prior state (typically in afinallyblock).
- corvix.observability.configure_logging(level: str | None = None, log_format: str | None = None) None[source][source]¶
Install the structured logging handler on the root logger.
leveldefaults toCORVIX_LOG_LEVEL(thenINFO) andlog_formattoCORVIX_LOG_FORMAT(thenjson;consoleselects a human-readable formatter for local development). Safe to call multiple times — the Corvix handler is only installed once.
- corvix.observability.reset_log_context(previous: dict[str, object] | None) None[source][source]¶
Restore a logging context previously returned by
bind_log_context().
- corvix.observability.is_enabled() bool[source][source]¶
Return whether tracing has been successfully configured.
- corvix.observability.setup_tracing(service_name: str | None = None) bool[source][source]¶
Configure the global tracer provider when tracing is requested.
Returns
Truewhen tracing is active afterwards. A no-op (returningFalse) whenCORVIX_OTEL_ENABLEDis not truthy or theotelextra is not installed. Safe to call multiple times.
- corvix.observability.span(name: str, attributes: collections.abc.Mapping[str, Any] | None = None) collections.abc.Iterator[Any][source][source]¶
Start a span as the current context, or no-op when tracing is disabled.
Yields the active span (or
Nonewhen disabled). Exceptions raised in the block are recorded on the span and re-raised.