← Back to Pull requests

fix(otelhttp): set http.route on server spans when http.ServeMux populates Pattern #10417

Open
unknown opened this pull request with 248 lines diff across 3 files
View on GitHub
unknown unknown commented on Nov 25, 2026 19:41 UTC
Author

Description

Set the http.route attribute on server spans in otelhttp when http.Request.Pattern is populated or updated during next.ServeHTTP (such as when otelhttp.NewHandler wraps an http.ServeMux directly).

Previously, middleware.serveHTTP called RequestTraceAttrs before next.ServeHTTP (when r.Pattern is empty). After next.ServeHTTP returned, it updated the span name and passed rCtx to RecordMetrics (so server metrics included http.route), but never added http.route to the server span. Per the HTTP span semantic conventions, when http.route becomes available after span start, instrumentation must populate it before the span ends.

The route update also runs during panic unwinding in the request defer (matching RouteMiddleware behavior) so matched routes that panic retain their span name and http.route attribute.

Part of #8415

Key Design Decisions

  • Preserve WithSpanOptions overrides when r.Pattern was already populated: RequestTraceAttrs already sets http.route from r.Pattern before applying WithSpanOptions. Comparing rCtx.Pattern != origReq.Pattern skips redundant SetAttributes calls and avoids overwriting an explicit http.route attribute passed via WithSpanOptions when Pattern did not change.

  • Respect RouteMiddleware precedence: Only falls back to rCtx.Pattern when capturedRoute == "", so an inner RouteMiddleware match still wins over a coarser outer ServeMux pattern.

  • No http.route on empty or slash-less patterns: Uses semconv.HTTPRoute(rCtx.Pattern) and skips setting http.route if empty.
  • Alternatives Considered

  • Calling span.SetAttributes unconditionally whenever rCtx.Pattern != "": Simpler, but adds an unnecessary SetAttributes call on pre-routed handlers and would overwrite an http.route attribute provided through WithSpanOptions.
  • Diff: 248 lines (+186 / -62) across 3 files Reviewer: dashpole Review duration: 10329m
    All Vouch review confidence checks passed
    Residual risk 0.21 = Change Risk (0.39) × (1 − Review Confidence (0.47)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.39 · 248 lines diff across 3 files
    0.39
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.02 · 1 substantive comment(s)
    0.02
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 35%
    46%
    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
    Shallow Review Depth shallow_review_depth
    0.344
    Diff Size diff_size
    0.330
    Real PR Conversation Timeline
    1 comments
    "Review active on #10417"
    general weight: 0.35
    Reviewers
    Assignees
    Unassigned
    Labels
    risk: low confidence: 46.7% 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: 38.9% (MEDIUM) · Higher = larger blast radius
    38.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: 46.7% · Lower = rushed or shallow review
    46.7%
    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: 20.8% · Safe to merge
    20.8%