perf(span-processor): skip span_formatter when debug logging is off - #1845
Open
DavidTraina wants to merge 1 commit into
Open
perf(span-processor): skip span_formatter when debug logging is off#1845DavidTraina wants to merge 1 commit into
DavidTraina wants to merge 1 commit into
Conversation
DavidTraina
force-pushed
the
perf/lazy-span-formatter-debug-log
branch
from
August 28, 2026 00:57
6d8faa4 to
8d402a8
Compare
11 tasks
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.
What does this PR do?
Fixes langfuse/langfuse#15339
LangfuseSpanProcessor.on_endbuilt its debug message with an f-string:f-strings are evaluated before
debug()is called, sospan_formatter(span)-- ajson.dumps(indent=2)of the span's attributes, events, links, resource and scope -- ran on every span end even though thelangfuselogger defaults toWARNINGand the string was then discarded.on_endruns on the thread that ends the span, the event loop in async apps, so this was a per-span CPU cost proportional to span throughput that no log-level setting could switch off.Measured locally,
span_formattercosts 28 us on a small span and 167 us on a 100 KB one; the linked issue reports ~0.27 ms/span. TheisEnabledForcheck costs 0.02 us.This guards the call so the serialization only runs when the record would be emitted, and passes the message as lazy
%-style args. Output at DEBUG is unchanged.Adds a parametrized unit test that drives a real span through the processor and asserts
span_formatteris not called atWARNINGand is called once atDEBUG. TheWARNINGcase fails onmain.Related: #1846 converts the SDK's remaining f-string log calls to lazy formatting and enables ruff
G004. It touches this same call to make it lazy but does not add the guard, so whichever merges second needs a trivial rebase here.Type of change
Verification
e2e / live_provider were not run: unit-testable change, no network behavior touched.
Checklist
code_review.md..env.templateif needed. (n/a, internal-only change)