Repository navigation
feat: fi.sampling.ratio on spans kept by head sampling across the traceAI SDKs - #713
Merged
Merged
Conversation
nik13
marked this pull request as ready for review
November 17, 2026 22:52
This was referenced Nov 18, 2026
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.
Adds
fi.sampling.ratio, so Future AGI can estimate true counts and cost from head-sampled traces. It applies wherever a traceAI SDK or agent creates its own tracer provider, in all six SDKs.Behaviour
FI_SAMPLE_RATE,OTEL_TRACES_SAMPLER=traceidratio|parentbased_traceidratio, or the Java/C# register sampler option built by traceAI's own factory), every kept span carriesfi.sampling.ratio(a double in (0, 1)). The rate is also written to the W3C tracestate asfi=r:<rate>.fientry. This holds even when its own root rate is 1, so every kept span of a trace carries the same value across services.always_on/always_off;fientry;Languages
Python (
fi_instrumentation.auto), TypeScript (@traceai/auto), Java (core + agent), Go (go/auto), C# (FIInstrumentation + auto), Ruby (traceai-auto). Each language has tests, then the implementation, then docs.Known limits
fientry, there is no room to add one. The kept span still carriesfi.sampling.ratio, but descendants in other processes count as 1.0.typescript/packages/traceai_auto/src/agent-context.ts). This is unrelated to this change and is tracked separately.Also fixes a regression already on
devThe zero-code Node agent read its sampler settings through
getStringFromEnvfrom@opentelemetry/core. Hosts that resolve the older@opentelemetry/core1.30.1 (for example the Vercel AI SDK packages' install) lack that helper, so the agent failed to initialize there. This came in with the sampler work in #711. The agent now builds its sampler from public constructors that work across OpenTelemetry versions.How it was tested
verifypassed (967 tests, including 188 child-JVM end-to-end tests); Go passed under-race.FI_SAMPLE_RATE=0.5calling a Node service with default settings) exportsfi.sampling.ratio=0.5on all three spans of a kept trace, with correct parentage.