Diagnostic utils¶
This appendix documents two helpers for debugging protocol traffic. Normal client and worker code does not need them.
format_msg() renders a protocol message as one
line for log output. Pass field names as suppress to replace the value
of a text or binary field with its length. Use this for large fields and
for fields whose content must not reach the log:
from momotor.rpc.utils import format_msg
logger.debug('request: %s', format_msg(request, suppress=['chunk']))
Naming a field that the message does not have raises ValueError.
setup_h2_logging() routes the debug output of
the HTTP/2 layer under gRPC to the h2 Python logger. Call it on a
channel when a connection problem needs transport-level detail.
Client connection recovery describes one such case.
API reference¶
- momotor.rpc.utils.format_msg(msg, *, suppress=None)¶
Format a protobuf Message as one line for use in logs
- Parameters:
msg (
Message) – The message to formatsuppress (
Collection[str] |None) – Names of text or binary fields whose value is replaced by its length. Use this for large fields and for fields whose content must not reach the log.
- Return type:
- Returns:
The formatted message
- Raises:
ValueError – When a name in suppress is not a field of the message