Repository navigation
Keep the upstream sampling decision for a propagated trace - #264
Merged
Merged
Conversation
createSpan0 checked len(ds.Refs) and ran the local sampler before it applied the core options, so the upstream sw8 ref was not attached yet and every entry span that starts a tracing context was sampled locally. With agent.sampler below 1, a downstream service dropped traces that the upstream service had already sampled. Reported in apache/skywalking#14201. - Apply the core options before the sampling decision. A valid sw8 context forces sampling, as in the Java agent. The sampler gets the real operation name, and the propagated so11y counter counts again. - Accept a sw8 header only when every required field is set, like the Java agent's ContextCarrier#isValid, so a header such as 1---0---- no longer forces sampling or creates a segment with an empty trace ID. - Add regression tests. - Document the sampling policy for agent.sampler, and fix its environment key, which is SW_AGENT_SAMPLE, not SW_AGENT_SAMPLER. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The /propagated and /ignored.html entry spans carry a valid sw8 ref from /so11y, so sw_go_created_tracing_context_counter now counts them as created_by=propagated (2) instead of created_by=sampler, which keeps the /health and /so11y entry spans and the two exit spans (4). The scenario expected 0 propagated contexts because of the bug this change fixes. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
mrproliu
approved these changes
Nov 7, 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.
Summary
Fixes the sampling bug reported in apache/skywalking#14201.
createSpan0checkedlen(ds.Refs) > 0and ran the local sampler before it applied the core options, so the upstreamsw8ref fromwithRefwas not attached yet. Every entry span that starts a tracing context was sampled locally, even with a valid upstream context. Withagent.samplerbelow 1, a downstream Go service dropped traces that the upstream service had already sampled. It then sent nosw8header onward, so its own downstream services could start unrelated traces. The order changed in #27, so every release since v0.1.0 is affected.sw8context forces sampling, as in the Java agent (ContextManager#createEntrySpan). The sampler now receives the operation name (it received an empty one), andsw_go_created_tracing_context_counter{created_by="propagated"}counts again.sw8header only when every required field is set, like the Java agent'sContextCarrier#isValid. A header such as1---0----used to be accepted and created a segment with an empty trace ID. With the reorder alone, it would also have bypassed sampling. It is now ignored, and the request starts a new trace through the local sampler. Headers written by the Go agent always carry every field, because the plugin API rejects empty operation names and peers.agent.samplerrow ofdocs/en/agent/tracing-metrics-logging.md, and fix its environment key: the agent readsSW_AGENT_SAMPLE, notSW_AGENT_SAMPLER.The Sample flag in
sw8is still not checked, which matches the other SkyWalking agents. apache/skywalking#14204 documents that convention in the protocol doc, including the#samplinganchor that theagent.samplerrow links to.Tests
TestPropagatedContextIsNotResampled,TestSamplerReceivesOperationName, andTestIncompletePropagatedContextIsIgnored. Each fails onmainand passes with this change.plugins/core,go test ./..., the race tests,go vet, and golangci-lint v2.15.0 with the repository config pass.