refactor: replace try-except blocks with contextlib.suppress for cleaner exception handling (#24284)

This commit is contained in:
Guangdong Liu
2025-08-21 18:18:49 +08:00
committed by GitHub
parent ad8e82ee1d
commit 1abf1240b2
16 changed files with 52 additions and 88 deletions

View File

@@ -1,4 +1,5 @@
import atexit
import contextlib
import logging
import os
import platform
@@ -106,7 +107,7 @@ def init_app(app: DifyApp):
"""Custom logging handler that creates spans for logging.exception() calls"""
def emit(self, record: logging.LogRecord):
try:
with contextlib.suppress(Exception):
if record.exc_info:
tracer = get_tracer_provider().get_tracer("dify.exception.logging")
with tracer.start_as_current_span(
@@ -126,9 +127,6 @@ def init_app(app: DifyApp):
if record.exc_info[0]:
span.set_attribute("exception.type", record.exc_info[0].__name__)
except Exception:
pass
from opentelemetry import trace
from opentelemetry.exporter.otlp.proto.grpc.metric_exporter import OTLPMetricExporter as GRPCMetricExporter
from opentelemetry.exporter.otlp.proto.grpc.trace_exporter import OTLPSpanExporter as GRPCSpanExporter