← Back to Pull requests

fix(otlp-http): record one terminal ExporterMetrics outcome per export #1347

Open
unknown opened this pull request with 332 lines diff across 4 files
View on GitHub
unknown unknown commented on Dec 02, 2026 23:29 UTC
Author

Summary

Fixes #1212.

When an OTLP/HTTP export or flush timed out, the waiting caller called exporterMetrics?.addFailed(value:) and returned .failure. If the HTTP client invoked its completion handler later, the callback called addSuccess or addFailed again for the same attempt, producing double-counted outcomes (failed=2, or failed=1 and success=1).

This adds a shared OtlpHttpExporterBase.send(_:timeout:metrics:count:onSuccess:onFailure:) helper and updates export and flush across OtlpHttpTraceExporter, OtlpHttpLogExporter, and OtlpHttpMetricExporter to use it:

  • Only the waiting caller records the terminal ExporterMetrics outcome (addSuccess if the request finishes before the timeout and succeeds, addFailed otherwise).

  • Late HTTP callbacks still run queue updates (requeue on export failure, dropFlushed on flush success) and error feedback without recording a second metric outcome.
  • Testing

    Ran locally on macOS (Swift 6.4.2):

    swift test --enable-all-traits
    # 20 XCTest bundles passed: 1817 executed, 64 skipped, 0 failures
    
    OTEL_CONCURRENCY_TESTS=1 swift test --enable-all-traits --sanitize=thread --filter "ExporterMetricsCoverageTests|OtlpHttp"
    # OpenTelemetryProtocolExporterTests: 95 executed, 0 failures
    

    Added ExporterMetricsCoverageTests.testLateHTTPCompletionsDoNotRecordAnotherOutcome, covering timed-out export with a late failure and timed-out flush with a late 200 response across OtlpHttpTraceExporter, OtlpHttpLogExporter, and OtlpHttpMetricExporter (asserting 6 failed outcomes and 0 success outcomes total).

    Limitations

  • Keeps the existing public ExporterMetrics API (addSeen, addSuccess, addFailed) unchanged for source compatibility and enforces single-outcome recording in OtlpHttpExporterBase.send.

  • Late responses after timeout still update the pending queue (requeue / dropFlushed) to keep existing retry behavior intact.
  • Checklist

  • swift test --enable-all-traits passes locally

  • Unit tests added or updated for the change

  • Instrumentation and event changes only: the integration tests in

  • Tests/IntegrationTests are updated. Anything that adds, removes or
    renames a span, log record, event name, or attribute emitted by an
    instrumentation (Sources/Instrumentation/**) must be exercised by
    IntegrationTestScenario in Examples/HackerNewsDemo and asserted on
    in Tests/IntegrationTests/Assertions. Run make integ-tests-ios to
    verify, and see Tests/IntegrationTests/README.md.
  • Documentation updated (README, doc comments) where behavior changed
  • Diff: 332 lines (+249 / -83) across 4 files Reviewer: aranhave Review duration: 3355m
    All Vouch review confidence checks passed
    Residual risk 0.24 = Change Risk (0.42) × (1 − Review Confidence (0.43)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.42 · 332 lines diff across 4 files
    0.42
    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%
    42%
    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.347
    Shallow Review Depth shallow_review_depth
    0.344
    Real PR Conversation Timeline
    1 comments
    "Review active on #1347"
    general weight: 0.35
    Reviewers
    Assignees
    Unassigned
    Labels
    risk: low confidence: 43.0% 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: 42.1% (MEDIUM) · Higher = larger blast radius
    42.1%
    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: 43.0% · Lower = rushed or shallow review
    43.0%
    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: 24% · Safe to merge
    24%