Skip to content

LogsApi failing in Cloudflare Pages - XMLHttpRequest is not defined #2073

Open
@filipStoklasa23

Description

@filipStoklasa23

Describe the bug
When attempting to use the @datadog/datadog-api-client library within a Cloudflare Pages Function to send logs, the request fails with the following error:

ReferenceError: XMLHttpRequest is not defined
This error occurs because the client library uses cross-fetch internally, which relies on XMLHttpRequest. However, XMLHttpRequest is not available in the Cloudflare Workers environment where Pages Functions run.

To Reproduce
Steps to reproduce the behavior:

  1. Create Logs api instance and submit log in middleware of Nextjs app.
const clientApi = new HttpLibraryWithProxy();

    const configuration = client.createConfiguration({
      authMethods: { apiKeyAuth: DATADOG_API_KEY },
    });

    apiInstance = new v2.LogsApi(configuration);

...

.submitLog({ body: logItems })
    .then(() => console.log('Datadog logItems uploaded:', logItems))
    .catch((error) => console.error('Datadog logItems upload failed:', error, logItems));
  1. Visit Cloudflare realtime logs and see the error
"message": [
        "Datadog logItems upload failed:",
        "ReferenceError: XMLHttpRequest is not defined",
...

Expected behavior
Logs are successfully sent to Datadog.

Environment and Versions:
next: 14.x.x
@cloudflare/next-on-pages: 1.13.8
vercel: 41.2.2

Activity

changed the title v2 Client failing in Cloudflare Pages - XMLHttpRequest is not defined LogsApi failing in Cloudflare Pages - XMLHttpRequest is not defined on Feb 26, 2025
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

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

      Participants

      @filipStoklasa23

      Issue actions

        LogsApi failing in Cloudflare Pages - XMLHttpRequest is not defined · Issue #2073 · DataDog/datadog-api-client-typescript