Skip to content

Commit 4d64142

Browse files
logaretmclaude
andcommitted
fix(node): Guard against null httpVersion in outgoing request span attributes
On Node 22+ with Next.js 15, the bundled `@mswjs/interceptors` emits a synthetic `response` event on request timeout/abort whose `IncomingMessage` has `httpVersion === null`. `_getOutgoingRequestEndedSpanData` called `httpVersion.toUpperCase()` unguarded, which crashed the process with an unhandled rejection. The sibling server-side code in `httpServerSpansIntegration` already optional-chains this attribute; this brings the client path in line. Fixes #20415 Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent 617fede commit 4d64142

1 file changed

Lines changed: 4 additions & 1 deletion

File tree

packages/node-core/src/integrations/http/SentryHttpInstrumentation.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -459,7 +459,10 @@ function _getOutgoingRequestSpanData(request: http.ClientRequest): [string, Span
459459
function _getOutgoingRequestEndedSpanData(response: http.IncomingMessage): SpanAttributes {
460460
const { statusCode, statusMessage, httpVersion, socket } = response;
461461

462-
const transport = httpVersion.toUpperCase() !== 'QUIC' ? 'ip_tcp' : 'ip_udp';
462+
// httpVersion can be undefined in some cases and we seem to hav encountered this before:
463+
// https://github.com/getsentry/sentry-javascript/blob/ec8c8c64cde6001123db0199a8ca017b8863eac8/packages/node-core/src/integrations/http/httpServerSpansIntegration.ts#L158
464+
// see: #20415
465+
const transport = httpVersion?.toUpperCase() !== 'QUIC' ? 'ip_tcp' : 'ip_udp';
463466

464467
const additionalAttributes: SpanAttributes = {
465468
[ATTR_HTTP_RESPONSE_STATUS_CODE]: statusCode,

0 commit comments

Comments
 (0)