Skip to content

Undici 6.7.0 changes to request headers breaking Sentry code #10936

Closed

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 undici@6.7.0 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 undici@6.6.2 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>

Activity

  1. moved this to Waiting for: Product Owner in GitHub Issues with 👀 2on Mar 5, 2024
  2. changed the title [-]Undici changes to request headers breaking Sentry code[/-] [+]Undici 6.7.0 changes to request headers breaking Sentry code[/+] on Mar 5, 2024
  3. AbhiPrasad commented on Mar 5, 2024

    @AbhiPrasad
    Contributor

    Good catch @jessezhang91 - would you be open to opening a PR to fix this? Otherwise we have to backlog in the time being until someone else can get to it.

  4. moved this from Waiting for: Product Owner to No status in GitHub Issues with 👀 2on Mar 5, 2024
  5. jessezhang91 commented on Mar 5, 2024

    @jessezhang91
    ContributorAuthor

    I traced down the change to here:
    https://github.com/nodejs/undici/pull/2874/files#diff-7d30f7ef62c49f60ef5b01576ca8898402aa790a09c623b13f9e0ea090fba7e6R151

    but it seems like the docs haven't been updated to reflect that change:
    https://github.com/nodejs/undici/blob/main/docs/docs/api/DiagnosticsChannel.md

    so I'm unsure if it's intentional? I'll double check there and apply the updated changes via a PR here when given confirmation.

  6. moved this to Waiting for: Product Owner in GitHub Issues with 👀 2on Mar 5, 2024
  7. jessezhang91 commented on Mar 5, 2024

    @jessezhang91
    ContributorAuthor

    Here's my rough attempt at a PR: #10938

    I don't have an easy way to test my changes beyond editing the node_modules files via patch-package but I did test that in my codebase and confirmed that it did work properly.

  8. added a commit that references this issue on Mar 5, 2024
  9. mydea commented on Mar 7, 2024

    @mydea
    Member

    Thank you, we'll take a look at the PR in the next days! 🎉

  10. moved this from Waiting for: Product Owner to No status in GitHub Issues with 👀 2on Mar 7, 2024
  11. AbhiPrasad commented on Mar 8, 2024

    @AbhiPrasad
    Contributor
  12. added a commit that references this issue on May 30, 2024
  13. added a commit that references this issue on Jul 30, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions