You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Describe the bug
I'm currently using the datadog api client within my cloudflare worker and I recently updated the client from version 1.24 to 1.27. I ran into this error since the update:
"TypeError: Illegal invocation: function called with incorrect `this` reference. See https://developers.cloudflare.com/workers/observability/errors/#illegal-invocation-errors for details."
I took a look at the changes across the different versions and found this PR: #1646
It looks like that might be that change that caused the error I started observing. I was able to resolve my problem by downgrading back to 1.24.
To Reproduce
Steps to reproduce the behavior:
Try calling a datadog api client within a CF worker context. It's tail logs describe the error I shared.
(I can provide a repo which can be used to test if that's desired)
Expected behavior
I would like to expect that the latest datadog client continues to send requests in my cloudflare worker.
Screenshots
n/a
Environment and Versions (please complete the following information):
A clear and precise description of your setup:
handler: ExportedHandler = {
fetch(request) {
const logItems: HTTPLogItem[] = new Array<HTTPLogItem>();
const conf = client.createConfiguration({
authMethods: {
apiKeyAuth: env?.["DD_API_KEY_SECRET"],
appKeyAuth: env?.["DD_APP_KEY_SECRET"],
},
});
const logsApi = new v2.LogsApi(conf);
const params: v2.LogsApiSubmitLogRequest = {
ddtags: "env:" + env?.["APP_ENV"],
body: logItems,
};
// This line throws
// vvvvvvvvvvvvvvvvvvvvv
await logsApi.submitLog(params).catch((e) => {
// This log is recorded 100% of the time
console.error("Error submitting logs to datadog", e);
});
// ^^^^^^^^^^^^^^^^^^
return new Response("OK");
},
}
version for this project in use.
1.27 (but it looks like any version that is 1.26 or later)
services, libraries, languages and tools list and versions.
package.json:
Additional context
I am guessing this has to do with the CF runtime releasing the this reference in the PR when the client attempts to make the fetch request call.
I have been running into the same issues on CF pages functions. I passed in a custom http client (fetch as an option didn't work) with .bind as per the help page, and it seems to be working.
// I'm not sure if this is the best way to import this...
import { IsomorphicFetchHttpLibrary } from '@datadog/datadog-api-client/dist/packages/datadog-api-client-common'
import { client } from '@datadog/datadog-api-client'
...
const httpApi = new IsomorphicFetchHttpLibrary({ fetch: fetch.bind(this) })
const config = client.createConfiguration({ httpApi })
const apiInstance = new v2.LogsApi(config)
...
Describe the bug
I'm currently using the datadog api client within my cloudflare worker and I recently updated the client from version 1.24 to 1.27. I ran into this error since the update:
I took a look at the changes across the different versions and found this PR:
#1646
It looks like that might be that change that caused the error I started observing. I was able to resolve my problem by downgrading back to 1.24.
To Reproduce
Steps to reproduce the behavior:
Try calling a datadog api client within a CF worker context. It's tail logs describe the error I shared.
(I can provide a repo which can be used to test if that's desired)
Expected behavior
I would like to expect that the latest datadog client continues to send requests in my cloudflare worker.
Screenshots
n/a
Environment and Versions (please complete the following information):
A clear and precise description of your setup:
version for this project in use.
1.27 (but it looks like any version that is 1.26 or later)
services, libraries, languages and tools list and versions.
package.json:
Additional context
I am guessing this has to do with the CF runtime releasing the
this
reference in the PR when the client attempts to make the fetch request call.cc @linnea-moment
The text was updated successfully, but these errors were encountered: