← Back to Pull requests

fix(trace): resolve parent from active context in Tracer.startSpan #164

Closed
unknown closed this pull request without merging on Nov 04, 2026 18:41 UTC
View on GitHub
unknown unknown commented on Nov 04, 2026 08:42 UTC
Author

Description

Per the OpenTelemetry Trace API Specification: Span Creation:

"When starting a Span, the API MUST allow passing an explicit Context to be used as parent. If no parent context is provided, the current active Context MUST be used as the parent. The API MAY also provide an option to explicitly create a span without a parent (as a root span)."

Previously, Tracer.startSpan in opentelemetry-sdk/src/sdk/trace/provider.zig only inspected options.parent_context. When options.parent_context was null (the default in StartOptions), it completely bypassed context.getCurrentContext(), generating a new trace_id and setting parent_span_id = null. This caused child spans created within an active context (e.g. attached via context.attachContext or trace.setCurrentSpan) to become disconnected root spans rather than children of the active span.

Additionally, SpanProcessor.onStart was always receiving an empty Context.init() when options.parent_context was null, rather than the resolved parent context as mandated by the SpanProcessor specification.

Changes

1. Active Context Fallback:
In Tracer.startSpan, resolve parent context as:

   const parent_context = if (options.root)
       context.Context.init()
   else
       options.parent_context orelse context.getCurrentContext();
   

2. Root Span Option:
Added root: bool = false to TracerImpl.StartOptions allowing callers to explicitly start a root span even when an active context is present on the thread-local context stack.
3. SpanProcessor Propagation:
Pass the resolved parent_context to self.provider.onSpanStart(&span, parent_context).
4. Unit Tests:
- Tracer inherits parent from current Context when parent_context is null: verifies child inherits trace_id, trace_flags, and sets parent_span_id to active parent's span_id.
- Tracer.startSpan honors root: true even when a parent Context is active: verifies root: true breaks away from active context to create an independent root trace.
- Tracer passes resolved current Context to SpanProcessor.onStart: verifies that SpanProcessor.onStart receives the active parent context.

All 480 SDK tests pass cleanly with 0 memory leaks.

Close #163

Diff: 293 lines (+219 / -74) across 3 files Reviewer: agagniere Review duration: 599m
All Vouch review confidence checks passed
Residual risk 0.16 = Change Risk (0.40) × (1 − Review Confidence (0.60)). Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.40 · 293 lines diff across 3 files
0.40
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.17 · 1 substantive comment(s)
0.17
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 35%
60%
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.340
Shallow Review Depth shallow_review_depth
0.289
Real PR Conversation Timeline
1 comments
"Review active on #164"
general weight: 0.35
Reviewers
Assignees
Unassigned
Labels
risk: low confidence: 60.5% 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: 39.9% (MEDIUM) · Higher = larger blast radius
39.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: 60.5% · Lower = rushed or shallow review
60.5%
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: 15.8% · Safe to merge
15.8%