Skip to content

Using nodejs build-in fetch doesn't seem to work with the undici plugin #7958

Closed
@wirtsi

Description

@wirtsi

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.49.0

Framework Version

No response

Link to Sentry event

No response

SDK Setup

  Sentry.init({
    dsn: `<dsn>`,
    environment,
    integrations: [
      // enable HTTP calls tracing
      new Sentry.Integrations.Http({ tracing: true }),
      new Sentry.Integrations.Undici({
        shouldCreateSpanForRequest: (url) => {
          console.log(url);
          return true;
        },
      }),
    ],
    debug: true,
    // Set tracesSampleRate to 1.0 to capture 100%
    // of transactions for performance monitoring.
    // We recommend adjusting this value in production
    tracesSampleRate: 1,
  });

Steps to Reproduce

I have some custom written code that uses Node v19 fetch (so without undici). Code looks like this

const response = await fetch(endpoint, { method: 'POST', body: JSON.stringify({ query: print(document), variables }), headers: { 'Content-Type': 'application/json', ...headers }, });
I am also using the algoliasearch package which uses node's http.

Expected Result

I would expect that sentries creates a span for my fetchoperation.

Actual Result

First call is the one using algolia, second one fetch

Sentry Logger [log]: [Tracing] Starting 'http.client' span on transaction '/en-gb/c
ollections/women-dresses' (bd112c3d23c5805b).
Sentry Logger [log]: [Tracing] Adding sentry-trace header 924d5e8b06ea43fb8bef49de1
d763358-9e98a1ca69022d7c-1 to outgoing request to "https://5fgvyedx6g-1.algolianet.
com/":
Sentry Logger [log]: [Tracing] Finishing 'http.client' span on transaction '/en-gb/
collections/women-dresses' (bd112c3d23c5805b).
Sentry Logger [log]: [Tracing] Finishing 'http.client' span on transaction '/en-gb/
collections/women-dresses' (bd112c3d23c5805b).
Sentry Logger [log]: [Tracing] Finishing handle-request transaction: /en-gb/collect
ions/women-dresses.
Sentry Logger [log]: [Tracing] starting handle-request transaction - /en-gb/p/s14-o
nl-li-5656-black
Sentry Logger [log]: [Tracing] Finishing handle-request transaction: /en-gb/p/s14-o
nl-li-5656-black.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Package: nodeIssues related to the Sentry Node SDK

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions