Skip to content

Undici 6.7.0 changes to request headers breaking Sentry code #10936

Closed
@jessezhang91

Description

@jessezhang91

Is there an existing issue for this?

How do you use Sentry?

Sentry Saas (sentry.io)

Which SDK are you using?

@sentry/node

SDK Version

7.105.0

Framework Version

No response

Link to Sentry event

No response

SDK Setup

No response

Steps to Reproduce

I can't figure out how to reproduce it locally but the issue occurs immediately on our staging and production servers for some reason.

I think it's related to [email protected] changes:
nodejs/undici#2708
nodejs/undici#2879

and this line of code here:

const headerLines = request.headers.split('\r\n');

Since the headers can now be arrays and iterables, this might not be properly accounting for that when attempting to call .split().

Pinning to [email protected] does not exhibit this behavior.

Expected Result

No errors

Actual Result

TypeError: request.headers.split is not a function
  File "/var/app/node_modules/@sentry/node/cjs/integrations/undici/index.js", line 266, col 39, in setHeadersOnRequest
    const headerLines = request.headers.split('\r\n');
  File "/var/app/node_modules/@sentry/node/cjs/integrations/undici/index.js", line 177, col 7, in _onRequestCreate
    setHeadersOnRequest(request, sentryTraceHeader, sentryBaggageHeader);
  File "node:diagnostics_channel", line 142, col 9, in Channel.publish
  File "/var/app/node_modules/undici/lib/core/request.js", line 189, col 23, in new Request
    channels.create.publish({ request: this })
  File "/var/app/node_modules/undici/lib/dispatcher/client.js", line 294, col 21, in [dispatch]
    const request = new Request(origin, opts, handler)
  File "/var/app/node_modules/undici/lib/interceptor/redirect-interceptor.js", line 11, col 16, in Intercept
    return dispatch(opts, handler)
  File "/var/app/node_modules/undici/lib/dispatcher/dispatcher-base.js", line 158, col 12, in [Intercepted Dispatch]
    return dispatch(opts, handler)
  File "/var/app/node_modules/undici/lib/dispatcher/dispatcher-base.js", line 179, col 40, in Client.dispatch
    return this[kInterceptedDispatch](opts, handler)
  File "/var/app/node_modules/undici/lib/dispatcher/pool-base.js", line 143, col 28, in [dispatch]
    } else if (!dispatcher.dispatch(opts, handler)) {
  File "/var/app/node_modules/undici/lib/dispatcher/dispatcher-base.js", line 150, col 29, in [Intercepted Dispatch]
    return this[kDispatch](opts, handler)
  File "/var/app/node_modules/undici/lib/dispatcher/dispatcher-base.js", line 179, col 40, in Pool.dispatch
    return this[kInterceptedDispatch](opts, handler)
  File "/var/app/node_modules/undici/lib/dispatcher/agent.js", line 105, col 23, in [dispatch]
    return dispatcher.dispatch(opts, handler)
  File "/var/app/node_modules/undici/lib/interceptor/redirect-interceptor.js", line 11, col 16, in Intercept
    return dispatch(opts, handler)
  File "/var/app/node_modules/undici/lib/dispatcher/dispatcher-base.js", line 158, col 12, in [Intercepted Dispatch]
    return dispatch(opts, handler)
  File "/var/app/node_modules/undici/lib/dispatcher/dispatcher-base.js", line 179, col 40, in Agent.dispatch
    return this[kInterceptedDispatch](opts, handler)
  File "node:internal/deps/undici/undici", line 10929, col 55, in <anonymous>

Metadata

Metadata

Assignees

No one assigned

    Labels

    Package: nodeIssues related to the Sentry Node SDK

    Type

    Projects

    Status

    No status

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions