From ffb4f3452b3e76663f50830fa18457149f9144d2 Mon Sep 17 00:00:00 2001 From: Konstantin Khlopkov Date: Wed, 26 Aug 2026 13:31:09 +0300 Subject: [PATCH] fix(span_processor): guard span_formatter debug call behind isEnabledFor check The method evaluates inside an f-string passed to , which causes full span serialization on every span end, regardless of the effective log level. This is a measurable per-span CPU cost. Because Python f-strings are evaluated before being handed to the logger, the formatting runs unconditionally even when DEBUG logging is disabled. Guard the debug call with so the expensive only runs when DEBUG level is actually enabled. Resolves: https://github.com/langfuse/langfuse/issues/15339 --- langfuse/_client/span_processor.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/langfuse/_client/span_processor.py b/langfuse/_client/span_processor.py index f01b081c2..a426975a3 100644 --- a/langfuse/_client/span_processor.py +++ b/langfuse/_client/span_processor.py @@ -12,6 +12,7 @@ """ import base64 +import logging import os import threading from typing import Callable, Dict, List, Optional, cast @@ -218,9 +219,10 @@ def on_end(self, span: ReadableSpan) -> None: ) return - langfuse_logger.debug( - f"Trace: Processing span name='{span._name}' | Full details:\n{span_formatter(span)}" - ) + if langfuse_logger.isEnabledFor(logging.DEBUG): + langfuse_logger.debug( + f"Trace: Processing span name='{span._name}' | Full details:\n{span_formatter(span)}" + ) super().on_end(span) finally: