Skip to content

Commit a6e1ac3

Browse files
author
Konstantin Khlopkov
committed
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: langfuse/langfuse#15339
1 parent 4c5b5e6 commit a6e1ac3

1 file changed

Lines changed: 5 additions & 3 deletions

File tree

langfuse/_client/span_processor.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
"""
1313

1414
import base64
15+
import logging
1516
import os
1617
import threading
1718
from typing import Callable, Dict, List, Optional, cast
@@ -218,9 +219,10 @@ def on_end(self, span: ReadableSpan) -> None:
218219
)
219220
return
220221

221-
langfuse_logger.debug(
222-
f"Trace: Processing span name='{span._name}' | Full details:\n{span_formatter(span)}"
223-
)
222+
if langfuse_logger.isEnabledFor(logging.DEBUG):
223+
langfuse_logger.debug(
224+
f"Trace: Processing span name='{span._name}' | Full details:\n{span_formatter(span)}"
225+
)
224226

225227
super().on_end(span)
226228
finally:

0 commit comments

Comments
 (0)