← Back to Pull requests

fix(zpages): release stored span state on SpanProcessor.Shutdown #10416

Merged
dashpole merged 5 files (575 lines) on Dec 01, 2026 15:15 UTC
View on GitHub
dashpole dashpole commented on Nov 25, 2026 17:05 UTC
Author

Fixes #10396

Summary

SpanProcessor.Shutdown was previously a no-op. If a TracerProvider shut down while spans were still active, the SDK removed its processors before those spans ended, so their later End() calls never reached zpages. Any tracez handler that outlived the provider retained those span references indefinitely and kept reporting active spans as still running.

This change updates SpanProcessor.Shutdown to stop processing further span lifecycle events and release all stored span state:

  • Store activeSpansStore and spanSampleStores in an internal spanState struct held by atomic.Pointer[spanState], lazily initialized via CompareAndSwap so zero-value &SpanProcessor{} remains usable.

  • On Shutdown, atomically swap in a stoppedState sentinel and clear both maps on the previous state. Subsequent Shutdown calls are no-ops, and calls to OnStart and OnEnd after Shutdown return immediately via a single atomic pointer load.

  • Add lifecycle tests covering spans active across TracerProvider.Shutdown (including tracez HTTP rendering), direct SpanProcessor.Shutdown with subsequent OnStart/OnEnd/ForceFlush/Shutdown calls, zero-value SpanProcessor, TracerProvider.UnregisterSpanProcessor, and concurrent OnStart/OnEnd/HTTP handler reads/Shutdown.

  • Add BenchmarkSpanProcessorOnStartOnEnd (Serial and Parallel) to cover the OnStart/OnEnd hot path. Both Serial and Parallel are statistically indistinguishable from main with no additional allocations.
  • Benchmarks

    goos: linux
    goarch: amd64
    pkg: go.opentelemetry.io/contrib/zpages
    cpu: Intel(R) Xeon(R) CPU @ 2.20GHz
                                          │  base.txt   │             head.txt              │
                                          │   sec/op    │   sec/op     vs base              │
    SpanProcessorOnStartOnEnd/Serial-24     415.8n ± 6%   420.8n ± 9%       ~ (p=0.818 n=6)
    SpanProcessorOnStartOnEnd/Parallel-24   479.3n ± 6%   483.3n ± 3%       ~ (p=0.589 n=6)
    geomean                                 446.4n        451.0n       +1.02%
    
                                          │  base.txt  │              head.txt              │
                                          │    B/op    │    B/op     vs base                │
    SpanProcessorOnStartOnEnd/Serial-24     72.00 ± 0%   72.00 ± 0%       ~ (p=1.000 n=6) ¹
    SpanProcessorOnStartOnEnd/Parallel-24   76.00 ± 1%   75.00 ± 1%       ~ (p=0.242 n=6)
    geomean                                 73.97        73.48       -0.66%
    ¹ all samples are equal
    
                                          │  base.txt  │              head.txt              │
                                          │ allocs/op  │ allocs/op   vs base                │
    SpanProcessorOnStartOnEnd/Serial-24     2.000 ± 0%   2.000 ± 0%       ~ (p=1.000 n=6) ¹
    SpanProcessorOnStartOnEnd/Parallel-24   2.000 ± 0%   2.000 ± 0%       ~ (p=1.000 n=6) ¹
    geomean                                 2.000        2.000       +0.00%
    ¹ all samples are equal
    

    Alternatives Considered

  • Retain spanSampleStores after Shutdown: Keeping completed span samples would allow post-shutdown inspection of historical latency and error samples when an HTTP server outlives the TracerProvider, at the cost of pinning completed span attributes and events in memory indefinitely whenever a handler remains registered. Clearing both stores matches sdktrace.SpanProcessor.Shutdown ("release of resources held by the processor") and avoids retaining stale diagnostics after shutdown.

  • Guard OnStart/OnEnd/Shutdown with sync.RWMutex: Taking RLock/RUnlock on every OnStart and OnEnd synchronously drains in-flight calls on Shutdown, but introduces shared reader-count atomic contention (+10% Serial, +13% Parallel in BenchmarkSpanProcessorOnStartOnEnd). Swapping an atomic.Pointer[spanState] to a stoppedState sentinel avoids hot-path contention while detaching the old state immediately so any concurrent in-flight call finishes on the unreachable struct and is collected on return.
  • Diff: 575 lines (+545 / -30) across 5 files Reviewer: MrAlias Review duration: 8530m
    All Vouch review confidence checks passed
    Residual risk 0.06 = Change Risk (0.47) × (1 − Review Confidence (0.87)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.47 · 575 lines diff across 5 files
    0.47
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.83 · 5 substantive comment(s)
    0.83
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 50%
    87%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    Groq Risk Narration
    AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
    Model 1 · Change Risk Attribution
    SHAP Weights
    Diff Size diff_size
    0.380
    Real PR Conversation Timeline
    17 items
    copilot-pull-request-reviewer[bot] copilot-pull-request-reviewer[bot] commented on Nov 25, 2026 17:05 UTC
    Reviewer

    Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

    opentelemetry-pr-dashboard[bot] opentelemetry-pr-dashboard[bot] commented on Nov 25, 2026 17:05 UTC
    Bot

    <!-- pull-request-dashboard-status -->
    <!-- pull-request-dashboard-status-revision:25 -->

    Pull request dashboard status

    Merged · refreshed 2026-12-01 15:16 UTC

    <details>
    <summary>Status above doesn't look right?</summary>

    <br>

  • Anything look wrong? Report it with what you expected; it helps us improve the dashboard.
  • </details>

    codecov[bot] codecov[bot] commented on Nov 25, 2026 17:13 UTC
    Bot

    Codecov Report


    :x: Patch coverage is 97.67442% with 1 line in your changes missing coverage. Please review.
    :white_check_mark: Project coverage is 90.7%. Comparing base (1903d1a) to head (c64961e).

    | Files with missing lines | Patch % | Lines |
    |---|---|---|
    | zpages/spanprocessor.go | 97.6% | 1 Missing :warning: |

    <details><summary>Additional details and impacted files</summary>

    ![Impacted file tree graph](https://app.codecov.io/gh/open-telemetry/opentelemetry-go-contrib/pull/10416?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=open-telemetry)

    @@          Coverage Diff           @@
    ##            main   #10416   +/-   ##
    ======================================
      Coverage   90.7%    90.7%           
    ======================================
      Files        232      232           
      Lines      16793    16827   +34     
    ======================================
    + Hits       15242    15275   +33     
    - Misses      1551     1552    +1     
    

    | Files with missing lines | Coverage Δ | |
    |---|---|---|
    | zpages/spanprocessor.go | 99.1% <97.6%> (-0.9%) | :arrow_down: |
    </details>
    <details><summary> :rocket: New features to boost your workflow: </summary>

  • :snowflake: Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

  • </details>

    copilot-pull-request-reviewer[bot] copilot-pull-request-reviewer[bot] commented on Nov 25, 2026 17:32 UTC
    Reviewer

    <!-- ccr-overview-v2 -->

    🟢 Approval recommended

    The review identified no issues requiring action, although tests were not run.

    No open issues 🎉

    <sub>Review effort: Balanced</sub>

    dmathieu dmathieu commented on code on Nov 26, 2026 10:43 UTC
    Code Review
    zpages/spanprocessor.go:1
    @@ -52,15 +55,27 @@ func NewSpanProcessor() *SpanProcessor {
     }
     
     // OnStart adds span as active and reports it with zpages.
    +// Calls after Shutdown are ignored.
     func (ssm *SpanProcessor) OnStart(_ context.Context, span sdktrace.ReadWriteSpan) {
    +	ssm.mu.RLock()

    OnStart and OnEnd now take mu.RLock() on every call. The lock is what closes the race with Shutdown, so I think it's the right approach. I'm wondering about contention, though, because the reader count is a shared atomic and parallel callers will all hit it. Could you add benchstat output for BenchmarkSpanProcessorOnStartOnEnd (Serial and Parallel) against main to the PR description? If Parallel shows a meaningful regression, we should look at a cheaper guard.

    dmathieu dmathieu commented on code on Nov 26, 2026 10:43 UTC
    Code Review
    zpages/spanprocessor_test.go:1
    @@ -19,10 +23,317 @@ import (
     	"go.opentelemetry.io/otel/trace"
     )
     
    -func TestSpanProcessorDoNothing(t *testing.T) {
    +func TestSpanProcessorForceFlush(t *testing.T) {
     	zsp := NewSpanProcessor()
     	assert.NoError(t, zsp.ForceFlush(t.Context()))
     	assert.NoError(t, zsp.Shutdown(t.Context()))
    +	assert.NoError(t, zsp.ForceFlush(t.Context()))
    +}
    +
    +func activeStoreLen(zsp *SpanProcessor) int {

    Nit: activeStoreLen and sampleStoreLen differ only in which sync.Map they range over. A single mapLen(m *sync.Map) int would cover both.

    dmathieu dmathieu commented on code on Nov 26, 2026 10:43 UTC
    Code Review
    zpages/spanprocessor_test.go:1
    @@ -19,10 +23,317 @@ import (
     	"go.opentelemetry.io/otel/trace"
     )
     
    -func TestSpanProcessorDoNothing(t *testing.T) {
    +func TestSpanProcessorForceFlush(t *testing.T) {
     	zsp := NewSpanProcessor()
     	assert.NoError(t, zsp.ForceFlush(t.Context()))
     	assert.NoError(t, zsp.Shutdown(t.Context()))
    +	assert.NoError(t, zsp.ForceFlush(t.Context()))
    +}
    +
    +func activeStoreLen(zsp *SpanProcessor) int {
    +	count := 0
    +	zsp.activeSpansStore.Range(func(_, _ any) bool {
    +		count++
    +		return true
    +	})
    +	return count
    +}
    +
    +func sampleStoreLen(zsp *SpanProcessor) int {
    +	count := 0
    +	zsp.spanSampleStores.Range(func(_, _ any) bool {
    +		count++
    +		return true
    +	})
    +	return count
    +}
    +
    +func totalLatencySamples(zsp *SpanProcessor, name string) int {
    +	total := 0
    +	for i := range defaultBoundaries.numBuckets() {
    +		total += len(zsp.spansByLatency(name, i))
    +	}
    +	return total
    +}
    +
    +func TestSpanProcessorShutdownAcrossTracerProviderShutdown(t *testing.T) {
    +	zsp := NewSpanProcessor()
    +	tp := sdktrace.NewTracerProvider(
    +		sdktrace.WithSampler(sdktrace.AlwaysSample()),
    +		sdktrace.WithSpanProcessor(zsp),
    +	)
    +	tracer := tp.Tracer("test")
    +	ctx := t.Context()
    +
    +	_, completedLatency := tracer.Start(ctx, "mixed")
    +	completedLatency.End()
    +
    +	_, completedErr := tracer.Start(ctx, "error-only")
    +	completedErr.SetStatus(codes.Error, "failed")
    +	completedErr.End()
    +
    +	_, activeOnly := tracer.Start(ctx, "active-only")
    +	_, activeMixed := tracer.Start(ctx, "mixed")
    +
    +	require.Equal(t, 2, activeStoreLen(zsp))
    +	require.Equal(t, 2, sampleStoreLen(zsp))
    +	require.Len(t, zsp.activeSpans("active-only"), 1)
    +	require.Len(t, zsp.activeSpans("mixed"), 1)
    +	require.Equal(t, 1, totalLatencySamples(zsp, "mixed"))
    +	require.Len(t, zsp.errorSpans("error-only"), 1)
    +
    +	require.NoError(t, tp.Shutdown(ctx))
    +
    +	// Both active and completed span state must be released on Shutdown.
    +	assert.Zero(t, activeStoreLen(zsp))
    +	assert.Zero(t, sampleStoreLen(zsp))
    +	assert.Empty(t, zsp.activeSpans("active-only"))
    +	assert.Empty(t, zsp.activeSpans("mixed"))
    +	assert.Zero(t, totalLatencySamples(zsp, "mixed"))
    +	assert.Empty(t, zsp.errorSpans("error-only"))
    +	assert.Empty(t, zsp.spansPerMethod())
    +
    +	// Ending spans that were active across provider shutdown must not
    +	// resurrect active or completed state.
    +	activeOnly.End()
    +	activeMixed.End()
    +
    +	assert.Zero(t, activeStoreLen(zsp))
    +	assert.Zero(t, sampleStoreLen(zsp))
    +	assert.Empty(t, zsp.activeSpans("active-only"))
    +	assert.Empty(t, zsp.activeSpans("mixed"))
    +	assert.Empty(t, zsp.spansPerMethod())
    +}
    +
    +func TestSpanProcessorShutdownIgnoresSubsequentCalls(t *testing.T) {
    +	zsp := NewSpanProcessor()
    +	tp := sdktrace.NewTracerProvider(
    +		sdktrace.WithSampler(sdktrace.AlwaysSample()),
    +		sdktrace.WithSpanProcessor(zsp),
    +	)
    +	defer func() {
    +		require.NoError(t, tp.Shutdown(t.Context()))
    +	}()
    +
    +	tracer := tp.Tracer("test")
    +	ctx := t.Context()
    +
    +	_, beforeCompleted := tracer.Start(ctx, "before-shutdown")
    +	beforeCompleted.End()
    +
    +	_, beforeActive := tracer.Start(ctx, "active-before-shutdown")
    +	require.Equal(t, 1, activeStoreLen(zsp))
    +	require.Equal(t, 1, sampleStoreLen(zsp))
    +
    +	// Shut down the SpanProcessor directly while the TracerProvider is still active
    +	// so subsequent span lifecycle hooks still invoke OnStart and OnEnd on zsp.
    +	require.NoError(t, zsp.Shutdown(ctx))
    +	// Subsequent Shutdown calls are no-ops.
    +	require.NoError(t, zsp.Shutdown(ctx))
    +
    +	assert.Zero(t, activeStoreLen(zsp))
    +	assert.Zero(t, sampleStoreLen(zsp))
    +	assert.Empty(t, zsp.activeSpans("active-before-shutdown"))
    +	assert.Empty(t, zsp.spansPerMethod())
    +
    +	// Ending the previously active span triggers zsp.OnEnd and must be ignored.
    +	beforeActive.End()
    +
    +	// Starting and ending new spans (both new names and prior names) must be ignored.
    +	_, afterActive := tracer.Start(ctx, "after-shutdown-active")
    +	defer afterActive.End()
    +
    +	_, afterCompleted := tracer.Start(ctx, "after-shutdown-completed")
    +	afterCompleted.End()
    +
    +	_, afterPriorNameErr := tracer.Start(ctx, "before-shutdown")
    +	afterPriorNameErr.SetStatus(codes.Error, "post-shutdown error")
    +	afterPriorNameErr.End()
    +
    +	assert.Zero(t, activeStoreLen(zsp))
    +	assert.Zero(t, sampleStoreLen(zsp))
    +	assert.Empty(t, zsp.activeSpans("after-shutdown-active"))
    +	assert.Empty(t, zsp.errorSpans("before-shutdown"))
    +	assert.Empty(t, zsp.spansPerMethod())
    +}
    +
    +func TestSpanProcessorShutdownOnUnregister(t *testing.T) {
    +	zsp := NewSpanProcessor()
    +	tp := sdktrace.NewTracerProvider(
    +		sdktrace.WithSampler(sdktrace.AlwaysSample()),
    +		sdktrace.WithSpanProcessor(zsp),
    +	)
    +	defer func() {
    +		require.NoError(t, tp.Shutdown(t.Context()))
    +	}()
    +
    +	tracer := tp.Tracer("test")
    +	ctx := t.Context()
    +
    +	_, doneSpan := tracer.Start(ctx, "done")
    +	doneSpan.End()
    +
    +	_, activeSpan := tracer.Start(ctx, "in-flight")
    +	require.Equal(t, 1, activeStoreLen(zsp))
    +	require.Equal(t, 1, sampleStoreLen(zsp))
    +
    +	tp.UnregisterSpanProcessor(zsp)
    +
    +	assert.Zero(t, activeStoreLen(zsp))
    +	assert.Zero(t, sampleStoreLen(zsp))
    +	assert.Empty(t, zsp.activeSpans("in-flight"))
    +	assert.Empty(t, zsp.spansPerMethod())
    +
    +	activeSpan.End()
    +	assert.Zero(t, activeStoreLen(zsp))
    +	assert.Zero(t, sampleStoreLen(zsp))
    +	assert.Empty(t, zsp.spansPerMethod())
    +}
    +
    +func TestSpanProcessorShutdownConcurrentSafe(t *testing.T) {

    Whether Shutdown lands mid-flight here depends on scheduling, so on a fast run the producers may finish before it starts, and the test then covers only the post-shutdown path. Could we make the overlap deterministic? For example, run the producers until a channel closes and call Shutdown once a producer has signalled it's inside its loop. It would also help to confirm the test fails with the stopped check removed, using -race -count=100, so we know it guards the regression.

    dmathieu dmathieu commented on code on Nov 26, 2026 10:43 UTC
    Code Review
    zpages/tracez_test.go:1
    @@ -359,6 +359,73 @@ func TestTracezHandler_ActiveOnlySpan(t *testing.T) {
     	assert.Contains(t, body, `<a href="tracez?zspanname=active-only-span&ztype=2&zlatencybucket=0">0</a></td>`)
     }
     
    +func TestTracezHandler_AfterTracerProviderShutdown(t *testing.T) {

    The store-level state here is already covered by TestSpanProcessorShutdownAcrossTracerProviderShutdown. I think this test is most useful when it checks only what the handler adds: the summary omits the span names, and the active and error detail views show "0 Requests". Could you trim the setup and assertions to that?

    dashpole dashpole commented on code on Nov 30, 2026 16:52 UTC
    Code Review
    zpages/spanprocessor.go:1
    @@ -52,15 +55,27 @@ func NewSpanProcessor() *SpanProcessor {
     }
     
     // OnStart adds span as active and reports it with zpages.
    +// Calls after Shutdown are ignored.
     func (ssm *SpanProcessor) OnStart(_ context.Context, span sdktrace.ReadWriteSpan) {
    +	ssm.mu.RLock()

    addressed in c69a6cb5a. The previous sync.RWMutex guard regressed Parallel by ~13%, so I switched to an atomic.Pointer[spanState] with a stopped sentinel and updated the benchstat output in the PR description (now statistically indistinguishable from main in both Serial and Parallel).

    dashpole dashpole commented on code on Nov 30, 2026 16:52 UTC
    Code Review
    zpages/spanprocessor_test.go:1
    @@ -19,10 +23,317 @@ import (
     	"go.opentelemetry.io/otel/trace"
     )
     
    -func TestSpanProcessorDoNothing(t *testing.T) {
    +func TestSpanProcessorForceFlush(t *testing.T) {
     	zsp := NewSpanProcessor()
     	assert.NoError(t, zsp.ForceFlush(t.Context()))
     	assert.NoError(t, zsp.Shutdown(t.Context()))
    +	assert.NoError(t, zsp.ForceFlush(t.Context()))
    +}
    +
    +func activeStoreLen(zsp *SpanProcessor) int {

    addressed in 13900f72c

    dashpole dashpole commented on code on Nov 30, 2026 16:52 UTC
    Code Review
    zpages/spanprocessor_test.go:1
    @@ -19,10 +23,317 @@ import (
     	"go.opentelemetry.io/otel/trace"
     )
     
    -func TestSpanProcessorDoNothing(t *testing.T) {
    +func TestSpanProcessorForceFlush(t *testing.T) {
     	zsp := NewSpanProcessor()
     	assert.NoError(t, zsp.ForceFlush(t.Context()))
     	assert.NoError(t, zsp.Shutdown(t.Context()))
    +	assert.NoError(t, zsp.ForceFlush(t.Context()))
    +}
    +
    +func activeStoreLen(zsp *SpanProcessor) int {
    +	count := 0
    +	zsp.activeSpansStore.Range(func(_, _ any) bool {
    +		count++
    +		return true
    +	})
    +	return count
    +}
    +
    +func sampleStoreLen(zsp *SpanProcessor) int {
    +	count := 0
    +	zsp.spanSampleStores.Range(func(_, _ any) bool {
    +		count++
    +		return true
    +	})
    +	return count
    +}
    +
    +func totalLatencySamples(zsp *SpanProcessor, name string) int {
    +	total := 0
    +	for i := range defaultBoundaries.numBuckets() {
    +		total += len(zsp.spansByLatency(name, i))
    +	}
    +	return total
    +}
    +
    +func TestSpanProcessorShutdownAcrossTracerProviderShutdown(t *testing.T) {
    +	zsp := NewSpanProcessor()
    +	tp := sdktrace.NewTracerProvider(
    +		sdktrace.WithSampler(sdktrace.AlwaysSample()),
    +		sdktrace.WithSpanProcessor(zsp),
    +	)
    +	tracer := tp.Tracer("test")
    +	ctx := t.Context()
    +
    +	_, completedLatency := tracer.Start(ctx, "mixed")
    +	completedLatency.End()
    +
    +	_, completedErr := tracer.Start(ctx, "error-only")
    +	completedErr.SetStatus(codes.Error, "failed")
    +	completedErr.End()
    +
    +	_, activeOnly := tracer.Start(ctx, "active-only")
    +	_, activeMixed := tracer.Start(ctx, "mixed")
    +
    +	require.Equal(t, 2, activeStoreLen(zsp))
    +	require.Equal(t, 2, sampleStoreLen(zsp))
    +	require.Len(t, zsp.activeSpans("active-only"), 1)
    +	require.Len(t, zsp.activeSpans("mixed"), 1)
    +	require.Equal(t, 1, totalLatencySamples(zsp, "mixed"))
    +	require.Len(t, zsp.errorSpans("error-only"), 1)
    +
    +	require.NoError(t, tp.Shutdown(ctx))
    +
    +	// Both active and completed span state must be released on Shutdown.
    +	assert.Zero(t, activeStoreLen(zsp))
    +	assert.Zero(t, sampleStoreLen(zsp))
    +	assert.Empty(t, zsp.activeSpans("active-only"))
    +	assert.Empty(t, zsp.activeSpans("mixed"))
    +	assert.Zero(t, totalLatencySamples(zsp, "mixed"))
    +	assert.Empty(t, zsp.errorSpans("error-only"))
    +	assert.Empty(t, zsp.spansPerMethod())
    +
    +	// Ending spans that were active across provider shutdown must not
    +	// resurrect active or completed state.
    +	activeOnly.End()
    +	activeMixed.End()
    +
    +	assert.Zero(t, activeStoreLen(zsp))
    +	assert.Zero(t, sampleStoreLen(zsp))
    +	assert.Empty(t, zsp.activeSpans("active-only"))
    +	assert.Empty(t, zsp.activeSpans("mixed"))
    +	assert.Empty(t, zsp.spansPerMethod())
    +}
    +
    +func TestSpanProcessorShutdownIgnoresSubsequentCalls(t *testing.T) {
    +	zsp := NewSpanProcessor()
    +	tp := sdktrace.NewTracerProvider(
    +		sdktrace.WithSampler(sdktrace.AlwaysSample()),
    +		sdktrace.WithSpanProcessor(zsp),
    +	)
    +	defer func() {
    +		require.NoError(t, tp.Shutdown(t.Context()))
    +	}()
    +
    +	tracer := tp.Tracer("test")
    +	ctx := t.Context()
    +
    +	_, beforeCompleted := tracer.Start(ctx, "before-shutdown")
    +	beforeCompleted.End()
    +
    +	_, beforeActive := tracer.Start(ctx, "active-before-shutdown")
    +	require.Equal(t, 1, activeStoreLen(zsp))
    +	require.Equal(t, 1, sampleStoreLen(zsp))
    +
    +	// Shut down the SpanProcessor directly while the TracerProvider is still active
    +	// so subsequent span lifecycle hooks still invoke OnStart and OnEnd on zsp.
    +	require.NoError(t, zsp.Shutdown(ctx))
    +	// Subsequent Shutdown calls are no-ops.
    +	require.NoError(t, zsp.Shutdown(ctx))
    +
    +	assert.Zero(t, activeStoreLen(zsp))
    +	assert.Zero(t, sampleStoreLen(zsp))
    +	assert.Empty(t, zsp.activeSpans("active-before-shutdown"))
    +	assert.Empty(t, zsp.spansPerMethod())
    +
    +	// Ending the previously active span triggers zsp.OnEnd and must be ignored.
    +	beforeActive.End()
    +
    +	// Starting and ending new spans (both new names and prior names) must be ignored.
    +	_, afterActive := tracer.Start(ctx, "after-shutdown-active")
    +	defer afterActive.End()
    +
    +	_, afterCompleted := tracer.Start(ctx, "after-shutdown-completed")
    +	afterCompleted.End()
    +
    +	_, afterPriorNameErr := tracer.Start(ctx, "before-shutdown")
    +	afterPriorNameErr.SetStatus(codes.Error, "post-shutdown error")
    +	afterPriorNameErr.End()
    +
    +	assert.Zero(t, activeStoreLen(zsp))
    +	assert.Zero(t, sampleStoreLen(zsp))
    +	assert.Empty(t, zsp.activeSpans("after-shutdown-active"))
    +	assert.Empty(t, zsp.errorSpans("before-shutdown"))
    +	assert.Empty(t, zsp.spansPerMethod())
    +}
    +
    +func TestSpanProcessorShutdownOnUnregister(t *testing.T) {
    +	zsp := NewSpanProcessor()
    +	tp := sdktrace.NewTracerProvider(
    +		sdktrace.WithSampler(sdktrace.AlwaysSample()),
    +		sdktrace.WithSpanProcessor(zsp),
    +	)
    +	defer func() {
    +		require.NoError(t, tp.Shutdown(t.Context()))
    +	}()
    +
    +	tracer := tp.Tracer("test")
    +	ctx := t.Context()
    +
    +	_, doneSpan := tracer.Start(ctx, "done")
    +	doneSpan.End()
    +
    +	_, activeSpan := tracer.Start(ctx, "in-flight")
    +	require.Equal(t, 1, activeStoreLen(zsp))
    +	require.Equal(t, 1, sampleStoreLen(zsp))
    +
    +	tp.UnregisterSpanProcessor(zsp)
    +
    +	assert.Zero(t, activeStoreLen(zsp))
    +	assert.Zero(t, sampleStoreLen(zsp))
    +	assert.Empty(t, zsp.activeSpans("in-flight"))
    +	assert.Empty(t, zsp.spansPerMethod())
    +
    +	activeSpan.End()
    +	assert.Zero(t, activeStoreLen(zsp))
    +	assert.Zero(t, sampleStoreLen(zsp))
    +	assert.Empty(t, zsp.spansPerMethod())
    +}
    +
    +func TestSpanProcessorShutdownConcurrentSafe(t *testing.T) {

    addressed in 645d9d85c. Confirmed with -race -count=100 that the test passes 100/100 times as written and fails 100/100 times with the stopped check removed.

    dashpole dashpole commented on code on Nov 30, 2026 16:52 UTC
    Code Review
    zpages/tracez_test.go:1
    @@ -359,6 +359,73 @@ func TestTracezHandler_ActiveOnlySpan(t *testing.T) {
     	assert.Contains(t, body, `<a href="tracez?zspanname=active-only-span&ztype=2&zlatencybucket=0">0</a></td>`)
     }
     
    +func TestTracezHandler_AfterTracerProviderShutdown(t *testing.T) {

    addressed in 0127d8ece

    copilot-pull-request-reviewer[bot] copilot-pull-request-reviewer[bot] commented on Nov 30, 2026 16:55 UTC
    Reviewer

    <!-- ccr-overview-v2 -->

    🟢 Approval recommended

    No active review findings were reported, although tests were not run during this review.

    No open issues 🎉

    <sub>Review effort: Balanced</sub>

    MrAlias MrAlias approved these changes on Nov 30, 2026 21:12 UTC
    Approved Reviewer

    Approved these changes.

    dmathieu dmathieu approved these changes on Dec 01, 2026 09:19 UTC
    Approved Reviewer

    Approved these changes.

    copilot-pull-request-reviewer[bot] copilot-pull-request-reviewer[bot] commented on Dec 01, 2026 14:53 UTC
    Reviewer

    <!-- ccr-overview-v2 -->

    🟢 Approval recommended

    There are no active review issues for the change that releases zpages span state on shutdown.

    No open issues 🎉

    <sub>Review effort: Balanced</sub>

    Reviewers
    Assignees
    dashpole dashpole
    Labels
    risk: low confidence: 87.1% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 46.9% (MEDIUM) · Higher = larger blast radius
    46.9%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 87.1% · Lower = rushed or shallow review
    87.1%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 6.1% · Safe to merge
    6.1%