Open
Description
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:
- 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));
- 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