Observability Module API Reference¶
This section documents the internals of the observability
module in Bijux CLI.
bijux_cli.infra.observability ¶
Provides the concrete implementation of the observability and logging service.
This module defines the Observability
class, which implements the ObservabilityProtocol
. It serves as the primary interface for structured logging throughout the application, using structlog
as its underlying engine. It can also be configured to forward log entries to a telemetry backend, unifying logging and event tracking.
Observability ¶
Bases: ObservabilityProtocol
A structured logging service integrating structlog
and telemetry.
This class wraps a structlog
logger to produce structured log entries. If configured with a telemetry backend, it also forwards these events for analytics and monitoring.
Attributes:
-
_logger
(FilteringBoundLogger
) –The underlying
structlog
logger instance. -
_telemetry
(TelemetryProtocol
) –The telemetry service for event forwarding. Defaults to a
NullTelemetry
instance that does nothing.
Initializes the observability service.
Parameters:
-
debug
(bool
, default:False
) –If True, configures the service for debug-level logging.
Source code in src/bijux_cli/infra/observability.py
bind ¶
Binds context key-value pairs to all subsequent log entries.
Parameters:
-
**kwargs
(Any
, default:{}
) –Context values to include in each log entry.
Returns:
-
Self
(Self
) –The service instance, allowing for method chaining.
Source code in src/bijux_cli/infra/observability.py
close ¶
Logs the shutdown of the observability service.
Note
In this implementation, this method only logs a debug message and does not perform resource cleanup like flushing. Flushing is handled by the telemetry service's own lifecycle methods.
Source code in src/bijux_cli/infra/observability.py
get_logger ¶
Retrieves the underlying structlog
logger instance.
Returns:
-
FilteringBoundLogger
(FilteringBoundLogger
) –The
structlog
logger, which can be used directly if needed.
log ¶
Logs a structured message and emits a corresponding telemetry event.
Parameters:
-
level
(str
) –The severity level of the log (e.g., 'debug', 'info', 'warning', 'error', 'critical').
-
msg
(str
) –The log message.
-
extra
(dict[str, Any] | None
, default:None
) –Additional context to include in the log entry.
Returns:
-
Self
(Self
) –The service instance, allowing for method chaining.
Raises:
-
ServiceError
–If
level
is not a valid log level name.
Source code in src/bijux_cli/infra/observability.py
set_telemetry ¶
set_telemetry(telemetry: TelemetryProtocol) -> Self
Attaches a telemetry backend for forwarding log events.
This allows the service to be "upgraded" from a simple logger to a full observability tool after its initial creation.
Parameters:
-
telemetry
(TelemetryProtocol
) –The telemetry service to receive events.
Returns:
-
Self
(Self
) –The service instance, allowing for method chaining.
Source code in src/bijux_cli/infra/observability.py
setup classmethod
¶
Instantiates and configures an Observability
service.
Parameters:
-
debug
(bool
, default:False
) –If True, enables debug-level logging.
Returns:
-
Self
(Self
) –A new, configured
Observability
instance.