Repository navigation
Apply the ignore rules to every request that starts a trace - #265
Conversation
|
@mrproliu, could you check whether this mechanism change fits the design of the tracing context? It changes the code that #237 touched.
A design question: the root cause is that a finished trace leaves its context in the goroutine. The Java agent removes both the tracing context and the runtime context when a trace finishes ( |
A goroutine keeps its tracing context after a trace ends, and createNoop treated any existing context as being inside a trace, so it skipped the ignore rules (agent.ignore_suffix, agent.trace_ignore_path) and the disconnected-reporter check. On a goroutine that serves several requests, such as an HTTP/1 keep-alive connection, only the first request was checked. The so11y scenario expected /ignored.html to be traced because of this. - Return early in createNoop only when the context has an active span, and run the checks otherwise. Store the noop span of an ignored request as the active span, as for a request the sampler drops, so the spans under it are ignored instead of each starting its own trace. - Give each ContinueContext of a noop snapshot its own noop span, so goroutines continuing one captured context don't share its nesting count. - gin, goframe: pass the span to the after-hook before collecting the request headers, and treat a header_length_threshold of 0 or less as no limit. A negative value panicked after the span was created, so the span was never ended. - Restore the so11y expected counters to what the scenario intends.
cbc7d32 to
f332792
Compare
mrproliu
left a comment
There was a problem hiding this comment.
LGTM. Treating "no active span" as the start of a trace keeps the #237 intent and fixes the reused-goroutine case.
One possible problem: the noop span of the ignore and disconnected-reporter paths is now stored as the active span. If a plugin creates a root span and never ends it (for example, BeforeInvoke fails before SetContext), every later request on that goroutine, such as an HTTP/1 keep-alive connection, is silently ignored. This PR fixes gin and goframe, but other plugins could still hit it.
I'll submit a follow-up PR that handles this in the interceptor templates, so plugins don't need to get it right themselves.
Summary
Found while checking the
so11yexpected data changed in #264. The/ignored.htmlhandler should be ignored, because.htmlis in the defaultignore_suffix, but the scenario expected it to be traced.Problems on
main:Endonly resets the active span.createNooptreated any existing context as being inside a trace, so it skippedignore_suffix,trace_ignore_path, and the init/disconnected-reporter check. On a goroutine that serves several requests, such as an HTTP/1 keep-alive connection, every request after the first was traced even when it should be ignored, and was traced while the reporter was disconnected. Fix wrong tracing context switch when trace ignore plugin activated #237 (in v0.7.0) introduced this when it moved the checks below that return, so that they don't apply inside a trace. Inso11y,/ignored.htmlreuses the connection that served/propagated.sw8downstream. The sampler's noop path stores its span, so a sampled-out request doesn't have this problem.ContinueContextgave every continuation the same noop object, so goroutines continuing one captured context, such as the send and receive goroutines of a gRPC stream, shared an unsynchronized nesting count.header_length_thresholdafter creating the entry span and beforeSetContext, so the span was never ended. With the fix for (2), the stuck noop span of an ignored request would have suppressed every later request on that goroutine.Changes:
createNoopreturns early only when the context has an active span. Otherwise it runs the checks, reusing the goroutine's context. A noop span from the checks is stored as the active span, as the sampler path does. Spans inside a trace still skip the checks, which keeps the Fix wrong tracing context switch when trace ignore plugin activated #237 behavior.ContinueContextgives each continuation of a noop snapshot its own noop span.SetContextruns right after the span is created, soAfterInvokealways ends the span. Aheader_length_thresholdof 0 or less now means no limit, as forredis.max_args_bytes;collect_request_headersalready decides whether headers are collected. The doc rows are updated.so11yexpected counters: propagated 1, sampler 4, created-ignored 1, finished-tracing 5, finished-ignored 1. They no longer depend on HTTP connection reuse.Not changed here, because they already exist on
mainand need their own design:sw8header.Tests
plugins/core/tracer_ignore_test.go:TestIgnoreRulesApplyAfterFinishedTrace,TestDisconnectedReporterAppliesAfterFinishedTrace,TestSpansUnderIgnoredEntryAreIgnored, andTestContinuedNoopSnapshotsAreIndependentfail onmain.TestIgnoreRulesDoNotApplyInsideTrace(the Fix wrong tracing context switch when trace ignore plugin activated #237 case) passes on both.TestCollectHeadersWithoutLimitin gin and goframe (thresholds 0 and -1) fails onmain.make test, the race tests,go vet, and golangci-lint v2.15.0 pass. Theso11yscenario passed locally in all three cases, and the collector received exactly the new counters.