fix: pin owned tracer provider to alwaysOn sampler - #13
Merged
Conversation
LangfuseOtel builds and owns a dedicated SdkTracerProvider, but never set a Sampler on it. The SDK default is parentBased(alwaysOn), so whenever an application already runs the OpenTelemetry Java agent or the Micrometer tracing bridge, every Langfuse span inherits that upstream sampling decision. An app head-sampling HTTP traces at 10% therefore loses 90% of its LLM observability, silently. Set Sampler.alwaysOn() explicitly. The provider exports only to Langfuse, so sampling it independently costs no volume on any other backend, and LLM spans are low-volume/high-value enough that 100% is the only sensible default. Add ExternalTraceLinkageTest covering the surrounding-trace behaviour: context propagation across the two providers, survival of an upstream sampling drop, and root-trace creation without ambient context.
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.
Fixes #12.
What
LangfuseOtel.Builder.build()creates its ownSdkTracerProviderwithout setting a sampler, so it falls back to the SDK defaultparentBased(alwaysOn)and inherits the sampling decision of whatever span happens to be current. With an OpenTelemetry Java agent or the Micrometer bridge in the same application, LLM spans disappear along with any head-sampled HTTP trace — silently.This sets
Sampler.alwaysOn()explicitly:The provider exports only to Langfuse, so sampling it independently adds no volume to any other backend. No public API changes, no new configuration.
Tests
New
ExternalTraceLinkageTestpins down how Langfuse spans behave next to an externally created parent span:langfuseSpansJoinTheSurroundingTracetraceIdand correct parent chain across the two providers; each exporter sees only its own halflangfuseSpansSurviveAnUpstreamSamplingDropbuiltProviderSamplesIndependentlyOfAnUnsampledParentLangfuseOtel.builder()wiring, not a stand-inlangfuseStartsItsOwnTraceWithoutSurroundingContextVerified the tests fail on the pre-fix code (
builtProviderSamplesIndependentlyOfAnUnsampledParent, 1 failure) and pass with it. Full suite: 193 tests, 0 failures across core and starter.The
builtProvider...test points at an unroutable host and deliberately leaves its span unended — the sampling decision happens atstartSpan(), and ending the span would queue a delivery that can only fail slowly. Keeping it out of the export queue holds the class at ~0.25s instead of ~7.4s.Out of scope
With an agent present the surrounding HTTP/JDBC spans and the LLM spans still land in different backends, so neither holds the complete trace. That needs a duplicate/fan-out exporter and is tracked separately in the notes on #12.