← Back to Pull requests

semconv,sdk/log: unwrap single-error errors.Join wrappers in error type derivation #9466

Closed
unknown closed this pull request without merging on Nov 09, 2026 20:46 UTC
View on GitHub
unknown unknown commented on Nov 08, 2026 00:50 UTC
Author

Part of #9446

Summary

In Go, errors.Join is commonly used to accumulate optional errors across operations—for example, uploadErr = errors.Join(uploadErr, err) where uploadErr starts as nil. When only one non-nil error is passed (e.g., errors.Join(nil, err)), errors.Join still wraps that single error in an unexported errors.joinError implementing Unwrap() []error (not Unwrap() error).

When no error in the chain implements ErrorType() string, semconv.ErrorType and sdk/log fall back to reflection after unwrapping fmt.wrapError (#8133). Because errors.Unwrap returns nil for Unwrap() []error, single-error errors.Join wrappers were not unwrapped and caused instrumentation and SDK self-observability metrics to report the opaque error.type="errors.joinError" instead of the underlying error's concrete type.

Approach

  • Extend the reflection-fallback unwrapping helper in internal/tools/semconvkit/templates/error_type.go.tmpl, semconv/v1.44.0/error_type.go, and sdk/log/logger.go to iteratively unwrap both fmt.wrapError (fmt.Errorf with single %w) and single-error errors.joinError (errors.Join when len(u.Unwrap()) == 1).

  • Preserve existing behavior when errors.Join wraps multiple non-nil errors (len > 1 continues to report errors.joinError) and when custom user-defined error types implement Unwrap() []error (custom wrapper types continue to report their top-level concrete type, matching #8133 / #7975).
  • Alternatives Considered

  • Avoiding errors.Join at individual call sites inside opentelemetry-go: Only fixes internal call sites and leaves external instrumentation and callers using errors.Join(nil, err) reporting *errors.joinError. Handling single-error errors.Join alongside fmt.Errorf in semconv and sdk/log fixes this consistently across the ecosystem.

  • Unwrapping arbitrary Unwrap() []error implementations with len == 1: Rejected for the same reason #8133 / #7975 restricted single-error unwrapping to fmt.Errorf: user-defined domain error types implementing Unwrap() []error carry meaningful top-level type identity that should not be stripped.
  • Diff: 274 lines (+205 / -69) across 3 files Reviewer: pellared Review duration: 2636m
    All Vouch review confidence checks passed
    Residual risk 0.17 = Change Risk (0.40) × (1 − Review Confidence (0.57)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.40 · 274 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%
    56%
    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.336
    Shallow Review Depth shallow_review_depth
    0.289
    Real PR Conversation Timeline
    1 comments
    "Review active on #9466"
    general weight: 0.35
    Reviewers
    Assignees
    Unassigned
    Labels
    risk: low confidence: 56.8% 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.5% (MEDIUM) · Higher = larger blast radius
    39.5%
    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: 56.8% · Lower = rushed or shallow review
    56.8%
    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: 17.1% · Safe to merge
    17.1%