Skip to content

fix(span_processor): skip span_formatter serialization when DEBUG is off - #1837

Open
kokhlo wants to merge 1 commit into
langfuse:mainfrom
kokhlo:fix/span-processor-lazy-debug
Open

fix(span_processor): skip span_formatter serialization when DEBUG is off#1837
kokhlo wants to merge 1 commit into
langfuse:mainfrom
kokhlo:fix/span-processor-lazy-debug

Conversation

@kokhlo

@kokhlo kokhlo commented Aug 26, 2026

Copy link
Copy Markdown

Summary

  • LangfuseSpanProcessor.on_end calls span_formatter(span) unconditionally inside an f-string passed to langfuse_logger.debug(...). Python evaluates f-strings eagerly, so every exported span pays full JSON serialization even when DEBUG is disabled — the common production case.
  • This guards the call behind langfuse_logger.isEnabledFor(logging.DEBUG), skipping the formatting entirely when the level is off.

Testing

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.

  • Adds the standard logging import.
  • Calls span_formatter only 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

@claude claude Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Claude Code Review

This pull request is from a fork — automated review is disabled. A repository maintainer can comment @claude review to run a one-time review.

@CLAassistant

CLAassistant commented Aug 26, 2026

Copy link
Copy Markdown

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

…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
kokhlo force-pushed the fix/span-processor-lazy-debug branch from a6e1ac3 to ffb4f34 Compare August 26, 2026 10:31
@kokhlo

kokhlo commented Aug 26, 2026

Copy link
Copy Markdown
Author

@cla-assistant check

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants