From ec8f7cad460b7bc617927928d105282abcfb1136 Mon Sep 17 00:00:00 2001 From: Yury Gribkov Date: Mon, 6 Jan 2025 15:56:12 -0800 Subject: [PATCH] Fix format --- ddtrace/internal/logger.py | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/ddtrace/internal/logger.py b/ddtrace/internal/logger.py index 81b88060738..3d08bd8f28a 100644 --- a/ddtrace/internal/logger.py +++ b/ddtrace/internal/logger.py @@ -194,6 +194,7 @@ def handle(self, record): def _report_telemetry_log(self, record): # type: (logging.LogRecord) -> None from ddtrace.internal.telemetry.constants import TELEMETRY_LOG_LEVEL + key = (record.name, record.levelno, record.pathname, record.lineno) current_bucket = int(record.created / _TelemetryConfig.TELEMETRY_HEARTBEAT_INTERVAL) key_bucket = self.telemetry_log_buckets[key] @@ -202,11 +203,14 @@ def _report_telemetry_log(self, record): else: self.telemetry_log_buckets[key] = DDLogger.LoggingBucket(current_bucket, 0) level = ( - TELEMETRY_LOG_LEVEL.ERROR if record.levelno >= logging.ERROR - else TELEMETRY_LOG_LEVEL.WARNING if record.levelno == logging.WARNING + TELEMETRY_LOG_LEVEL.ERROR + if record.levelno >= logging.ERROR + else TELEMETRY_LOG_LEVEL.WARNING + if record.levelno == logging.WARNING else TELEMETRY_LOG_LEVEL.DEBUG ) from ddtrace.internal import telemetry + tags = { "lib_language": "python", } @@ -214,16 +218,19 @@ def _report_telemetry_log(self, record): if record.exc_info: _, _, traceback_object = record.exc_info if traceback_object: - stack_trace = ''.join(traceback.format_tb(traceback_object)) + stack_trace = "".join(traceback.format_tb(traceback_object)) # TODO redact absolute file paths and unknown packages if record.levelno >= logging.ERROR or stack_trace is not None: # Report only an error or an exception with a stack trace - telemetry.telemetry_writer.add_log(level, record.msg, tags=tags, stack_trace=stack_trace, count=key_bucket.skipped + 1) + telemetry.telemetry_writer.add_log( + level, record.msg, tags=tags, stack_trace=stack_trace, count=key_bucket.skipped + 1 + ) class _TelemetryConfig: TELEMETRY_ENABLED = os.getenv("DD_INSTRUMENTATION_TELEMETRY_ENABLED", "true").lower() in ("true", "1") - LOG_COLLECTION_ENABLED = TELEMETRY_ENABLED and os.getenv("DD_TELEMETRY_LOG_COLLECTION_ENABLED", "true").lower() in ("true", "1") + LOG_COLLECTION_ENABLED = TELEMETRY_ENABLED and os.getenv("DD_TELEMETRY_LOG_COLLECTION_ENABLED", "true").lower() in ( + "true", + "1", + ) TELEMETRY_HEARTBEAT_INTERVAL = float(os.getenv("DD_TELEMETRY_HEARTBEAT_INTERVAL", "60")) - -