nemo_evaluator.logging.context#

Request context utilities for logging and tracing.

Module Contents#

Functions#

bind_request_id

Bind a request ID to the current logging context.

get_bound_logger

Get a logger with the request ID bound to it.

get_current_request_id

Get the current request ID from the context variables.

request_context

Context manager for binding and clearing request context.

API#

nemo_evaluator.logging.context.bind_request_id(request_id: str | None = None) str[source]#

Bind a request ID to the current logging context.

Args: request_id: Optional request ID. If None, a new UUID will be generated.

Returns: The request ID that was bound to the context.

nemo_evaluator.logging.context.get_bound_logger(
request_id: str | None = None,
logger_name: str = None,
)[source]#

Get a logger with the request ID bound to it.

Args: request_id: Optional request ID. If None, a new UUID will be generated. logger_name: Optional logger name. If None, uses the calling module.

Returns: A structlog logger with the request ID bound to it.

nemo_evaluator.logging.context.get_current_request_id() str | None[source]#

Get the current request ID from the context variables.

Returns: The current request ID if set, None otherwise.

nemo_evaluator.logging.context.request_context(request_id: str | None = None)[source]#

Context manager for binding and clearing request context.

Args: request_id: Optional request ID. If None, a new UUID will be generated.

Yields: The request ID that was bound to the context.