Repository navigation
Conversation
A TailSampler runs in span.End and can mark a head-sampled span as unsampled, e.g. RootOrErrorSpans keeps process roots and failed spans. Tail-dropped spans are logged with span.is_sampled=0 (or skipped with SkipUnsampledLogs) and are not exported. Children still inherit the head decision. LogRequest now records panics before End so the sampler sees them. With TailSampler unset, behaviour and log output are unchanged. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
WithParentSpanID only says the parent is not in the context; it does not mean the parent is in another process. Replace HasRemoteParent with HasContextParent. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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
Adds an optional
TailSamplertologtracing: a sampling decision made when a span ends, next to the existing headSampler(made when it starts). This lets an app keep only the spans it needs, for example roots plus failed spans, while still seeing errors.Motivation: in kakuyasu (KGM-5741), child spans of batch jobs (per-query SQL, S3, KMS) are ~107M of ~427M Honeycomb events per month. Today there is no way to cut them:
LogSpanlogs every span whatever the sampling flag, and the head sampler only runs for roots.Changes
Config.TailSampler(type TailSampler func(*SpanData) bool, same shape asSampler), consulted in(*span).End(), only for head-sampled spans. It can drop a span, never re-sample one.RootOrErrorSpans(): keeps spans started without a parent span in their context, and spans that recorded an error or panic.SpanData.HasContextParent: whether the span was started under a parent span in its context. A span whose parent is given only by ID (WithParentSpanID, e.g. from atraceparentheader inserver.LogRequest) has a validParentSpanIDbut no context parent, soRootOrErrorSpanskeeps it.span.is_sampledand is not exported.atomic.Bool) from the head flag. Children keep inheriting the head decision, so a failed child of a dropped span is still kept, and there is no race with children started from other goroutines.server.LogRequest: panics are recorded beforespan.End(), so a tail sampler can see them.Compatibility
With
TailSamplerunset, behaviour and log output are unchanged.TestHeadUnsampledSpanLogOutputUnchangedcovers this: head-unsampled spans still have nospan.is_sampledkey.Other differences:
LogRequestlog lines:err/stackkeys now come beforerequest_us/status/user_agent. On panic, the stack capture now counts toward the span duration.ApplyConfigapplies non-zero fields only (existing behaviour, now documented), soTailSamplercannot be unset once applied.RootOrErrorSpansdoes not treat an HTTP 4xx/5xx response as an error; only a recordederror panic counts.Tests
logtracing/sampling_test.go:span.is_sampled, like head-unsampled ones; unchanged without a tail sampler);servertest: a panic is visible to the tail sampler. It fails without the reorder; checked.go vet ./logtracing/... ./server/...passes;go test -raceand a shuffled run of the new tests pass;go test ./...passes.Not run:
golangci-lint. It is not in CI, and my local build targets an older Go thango.mod.Unrelated, already on master:
TestTraceWithDefaultNeverSampler/TestChildrenAreSampledAsParentleaveNeverSampleset globally, soTestExportSpanfails under some-shuffleseeds. The new tests restore config viat.Cleanup.🤖 Generated with Claude Code