fix(span_processor): skip span_formatter serialization when DEBUG is off - #1837
Open
kokhlo wants to merge 1 commit into
Open
fix(span_processor): skip span_formatter serialization when DEBUG is off#1837kokhlo wants to merge 1 commit into
kokhlo wants to merge 1 commit into
Conversation
|
|
…For 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
kokhlo
force-pushed
the
fix/span-processor-lazy-debug
branch
from
August 26, 2026 10:31
a6e1ac3 to
ffb4f34
Compare
Author
|
@cla-assistant check |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
LangfuseSpanProcessor.on_endcallsspan_formatter(span)unconditionally inside an f-string passed tolangfuse_logger.debug(...). Python evaluates f-strings eagerly, so every exported span pays full JSON serialization even when DEBUG is disabled — the common production case.langfuse_logger.isEnabledFor(logging.DEBUG), skipping the formatting entirely when the level is off.Testing
pytest tests/unit/test_span_processor.py -q— all green (42 passed, same suite as perf(span-processor): defer span_formatter serialization behind DEBUG guard #1779).Note: I see #1779 proposes the same guard and has been open since July 23 — happy to close this in its favour if that one lands, or to help get it over the line (its test coverage is equivalent). Opening this mainly to surface that the perf cost is real in tracing-heavy production setups.
Greptile Summary
Guards detailed span formatting behind the logger’s DEBUG-level check, avoiding unnecessary serialization in normal production logging while preserving span export behavior.
loggingimport.span_formatteronly when DEBUG logging is enabled.Confidence Score: 5/5
The PR appears safe to merge with no actionable correctness or security issues identified.
The guard uses the same effective-level predicate as the standard logger’s debug method, and accepted spans still reach the batch processor unconditionally.
Reviews (1): Last reviewed commit: "fix(span_processor): guard span_formatte..." | Re-trigger Greptile