Repository navigation
Breaking change: Reject a trace sample rate outside 0.0 to 1.0 instead of keeping every trace - #2818
Merged
alexmojaki merged 2 commits intoNov 18, 2026
Conversation
…y trace A head sample rate of nan, inf or 1.5 skipped the sampler because the check `head < 1` is false for them, so every trace was exported. A negative rate reached OpenTelemetry's bare "Probability must be in range" error with no mention of the setting. Check the rate once in the Config constructor, so LOGFIRE_TRACE_SAMPLE_RATE, the pyproject setting and SamplingOptions(head=...) all raise a LogfireConfigError that names trace_sample_rate, like the not-a-number error from pydantic#2685.
Contributor
Coverage reportClick to see where and how coverage changed
This report was generated by python-coverage-comment-action |
||||||||||||||||||||||||
Yasser-Ameur
marked this pull request as ready for review
November 16, 2026 22:27
alexmojaki
reviewed
Nov 18, 2026
| ) | ||
| head = sampling.head | ||
| if isinstance(head, (int, float)) and not 0.0 <= head <= 1.0: | ||
| raise LogfireConfigError(f'Expected trace_sample_rate to be between 0.0 and 1.0, got {head!r}') |
Contributor
There was a problem hiding this comment.
Suggested change
| raise LogfireConfigError(f'Expected trace_sample_rate to be between 0.0 and 1.0, got {head!r}') | |
| raise LogfireConfigError(f'Expected sampling.head (LOGFIRE_TRACE_SAMPLE_RATE) to be between 0.0 and 1.0, got {head!r}') |
Contributor
There was a problem hiding this comment.
All reported issues were addressed across 2 files (changes from recent commits).
Reply with feedback, questions, or to request a fix.
View guided diff | Re-trigger cubic
alexmojaki
marked this pull request as draft
November 18, 2026 14:38
alexmojaki
marked this pull request as ready for review
November 18, 2026 14:54
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.
A head sample rate outside 0 to 1 is not reported.
LOGFIRE_TRACE_SAMPLE_RATE=1.5,nanorinfkeeps every trace, because the sampler is only installed whenhead < 1and that comparison is false for all three. A negative rate reaches OpenTelemetry and fails with a bare "Probability must be in range" that does not name the setting. #2685 gave the not a number case aLogfireConfigErrorand left ranges for later; this is that follow up.Change: the rate is checked once in the
Configconstructor, so the env var, thepyproject.tomlsetting andSamplingOptions(head=...)all raise aLogfireConfigErrorthat namestrace_sample_rate. The same kind of check already exists at_tail_sampling.py:132andmain.py:883.Behaviour to be aware of: values above 1 used to behave like 1.0 and now raise. For the env var and the pyproject setting the error surfaces at
import logfire, since the default config is built there;SamplingOptionsfails atconfigure(). If you would rather not break a deployment that has2set, I can change values above 1 to a warning that keeps every trace and raise only for negative,nanandinf.Tests: 12 new cases in
tests/test_configure.py(out of range values through each of the three inputs, and 0, 0.5 and 1 still accepted). 9 of them fail on main.