← Back to Pull requests

fix(http): keep client span open on the default agent socket timeout #11343

Closed
unknown closed this pull request without merging on Nov 20, 2026 18:12 UTC
View on GitHub
unknown unknown commented on Nov 20, 2026 01:09 UTC
Author

What does this PR do?

The http client instrumentation no longer finishes the span on a 'timeout' event from the default agent. The span now ends when the response ends, or on 'error' or 'close', like any other request.

Timeouts the app sets itself (req.setTimeout(), or an agent with a timeout option) work as before. They mark the span as an error and finish it.

Motivation

Fixes #11331.

Since Node.js 19, http.globalAgent has a 5s socket timeout. Node.js only emits 'timeout' for it and the request keeps going. The instrumentation treated that event as the end of the request, so any call slower than 5s got a span of about 5s with no http.status_code. The plugin already skips the error tag for this timeout, but the span was still finished at that point.

The repro from the issue, run against this branch's checkout. Before:

span finished at 5010 ms, response: none
response ended at 7015 ms: 200

After:

span finished at 7014 ms, response: 200
response ended at 7015 ms: 200

Additional Notes

The existing default agent test now also checks for the 200 status code. Before this change it failed with undefined !== '200'. I also added a test where the app destroys the request on the default timeout. Before this change that span ended with no error, and now it gets the destroy error. Passing agent: http.globalAgent explicitly now counts as the default agent too, since its 5s timeout still comes from Node.js, and there's a test for that.

Ran on Node 22.23.2:

node --expose-gc ./node_modules/mocha/bin/mocha.js packages/datadog-plugin-http/test/client.spec.js --grep imeout

24 passing (12 passing and 12 failing before the fix, the 12 being the three changed or new tests across http, https, node:http and node:https). The rest of packages/datadog-plugin-http/test, packages/datadog-instrumentations/test/http.spec.js, http-client-options.spec.js, and the appsec ssrf.spec.js and ssrf-redirects.spec.js specs pass too. I didn't run the ESM integration test since it needs a packed install.

A request with { timeout } in its options and no req.setTimeout() call goes down the same path as the default agent, which matches the plugin's existing error check. Its span now also waits for the response or the error instead of ending at the timeout.

Diff: 291 lines (+218 / -73) across 3 files Reviewer: BridgeAR Review duration: 1022m
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 · 291 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.340
Shallow Review Depth shallow_review_depth
0.289
Real PR Conversation Timeline
1 comments
"Review active on #11343"
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.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: 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.2% · Safe to merge
17.2%