py_research.telemetry module#

Utilities for monitoring long-running functions via logging, tracing and metrics.

class TqdmHandler(*args, **kwargs)[source]#

Bases: StreamHandler

A handler class which allows the cursor to stay on one line.

tqdm: tqdm | None = None#
emit(record)[source]#

Emit a record.

If a formatter is specified, it is used to format the record. The record is then written to the stream with a trailing newline. If exception information is present, it is formatted using traceback.print_exception and appended to the stream. If the stream has an ‘encoding’ attribute, it is used to determine how to do the output to the stream.

configure_logging(purpose='status')[source]#

Auto-configure structlog based on logging purpose.

Parameters:

purpose (Literal['status', 'report', 'log']) –

Which purpose the default global logger is supposed to fulfill. Can be any of:

  • status:

    Inform about the current status of long-running functions via a single, changing console line.

  • report:

    Record important steps / intermediate values / logical branches of large functions to the console.

  • log:

    Produce a common log stream in JSON format.

Return type:

None