Repository navigation
fix(otel): widen the span queue when flush_at exceeds its default - #2086
Open
passionworkeer wants to merge 5 commits into
Open
passionworkeer wants to merge 5 commits into
passionworkeer wants to merge 5 commits into
Conversation
This branch has not been deployed
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?
LangfuseSpanProcessorforwardsflush_attoBatchSpanProcessorasmax_export_batch_sizeand never setsmax_queue_size. OpenTelemetry keeps its owndefault queue size and rejects any larger batch, so a
flush_atabove the queue sizefailed client construction with
The message never mentions
flush_at, which makes the failure hard to attribute to aLangfuse setting.
This passes
max_queue_size=max(flush_at, default_queue_size), wheredefault_queue_sizeis OpenTelemetry's own resolved default (
BatchSpanProcessor._default_max_queue_size(),which honours
OTEL_BSP_MAX_QUEUE_SIZE). A batch that already fits leaves the queueexactly as it is today; only a batch that does not fit widens it.
Fixes langfuse/langfuse#19539
Type of change
Verification
Regression tests in
tests/unit/test_flush_at_batch_size.py. On the unpatchedmain4 of the 5 fail or error with the
ValueErrorabove; all 5 pass with the fix:flush_at=5000constructs and flushesflush_at=5000OTEL_BSP_MAX_QUEUE_SIZE=1000+flush_at=1500OTEL_BSP_MAX_QUEUE_SIZE=5000+flush_at=3000keeps queue at 5000Queue capacity sweep (probe script, not committed — it reads OpenTelemetry internals):
OTEL_BSP_MAX_QUEUE_SIZEflush_atValueErrorValueErrorValueErrorValueErrorOther checks:
tests/unit/test_span_processor.py+test_resource_manager.py+test_otel.py:145 passed, 2 skipped.
tests/unit: 988 passed, 2 skipped. The remaining 2 failures and 18 errors are allin
tests/unit/test_prompt.py/test_prompt_atexit.pyand reproduce identically on theunpatched
mainin this environment (noLANGFUSE_PUBLIC_KEY, no literalpythononPATH); they are unrelated to this change.
ruff check .clean,ruff format --checkclean on both changed files,mypy langfuseclean.Note for reviewers
_default_max_queue_size()is an OpenTelemetry internal. It is used here because it iswhat determines the constraint being fixed, and because the queue default is configurable
through
OTEL_BSP_MAX_QUEUE_SIZE— hard-coding 2048 would both miss smaller configuredqueues and narrow larger ones. The declared range is
opentelemetry-sdk>=1.45.0,<2; thealternative would be duplicating OpenTelemetry's environment parsing.
An alternative fix would be to validate
flush_atand raise a clear error naming thesetting instead of widening the queue. Happy to switch if you prefer that — this PR picks
widening because it keeps every currently working configuration working.
Checklist
langfuse/api/The PR appears safe to merge, with a non-blocking test isolation issue.
Summary
Widens the span queue when
flush_atexceeds OpenTelemetry's configured queue size.flush_atsettings fit in the span queue.Reviews (1) · Last reviewed commit: "fix(otel): widen the span queue when flu..." · Reviewed by Greptile