fix(http): keep client span open on the default agent socket timeout #11343
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
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.17 · 1 substantive comment(s)
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 35%
Bedrock Claude 3 · Risk Narration
(disconnected)
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
BridgeAR
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 atimeoutoption) work as before. They mark the span as an error and finish it.Motivation
Fixes #11331.
Since Node.js 19,
http.globalAgenthas 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 nohttp.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. Passingagent: http.globalAgentexplicitly 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 appsecssrf.spec.jsandssrf-redirects.spec.jsspecs pass too. I didn't run the ESM integration test since it needs a packed install.A request with
{ timeout }in its options and noreq.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.