Avoid implementing logging calls that could trigger recursive logging patterns, which can lead to infinite loops and program crashes. This is particularly important in logging handlers, exporters, and instrumentation code.
Avoid implementing logging calls that could trigger recursive logging patterns, which can lead to infinite loops and program crashes. This is particularly important in logging handlers, exporters, and instrumentation code.
Key guidelines:
Example of safe logging implementation:
# Do not add any logging.log statements to this function
# they can trigger recursive calls that crash the program
def emit(self, log_data):
try:
self._exporter.export((log_data,))
except Exception:
warnings.warn(f"Exception while exporting logs: {traceback.format_exc()}")
For logging handlers and processors, consider using suppression flags:
from opentelemetry.context import attach, set_value
def emit(self):
token = attach(set_value(_SUPPRESS_INSTRUMENTATION_KEY, True))
try:
# Logging code here
pass
finally:
detach(token)
Enter the URL of a public GitHub repository