Comments (14)
I will update this issue once the next release happens
from datadog-api-client-typescript.
Thanks for the report. I don't know much about wrangler, I tried a basic module and it failed with XMLHttpRequest is not defined
. Is there something else I'm missing in the basic setup? Can you provide the small reproducing worker code?
from datadog-api-client-typescript.
I got this working by doing the following making a copy of https://github.com/DataDog/datadog-api-client-typescript/blob/master/packages/datadog-api-client-v1/http/isomorphic-fetch.ts in my project and using it as my own httpApi.
import datadoghttp from './datadog-poly'
import { v1 } from '@datadog/datadog-api-client'
const configuration = v1.createConfiguration({
httpApi: new datadoghttp()
});
Haven't fully tested it but I got a nice 403 from Datadog. What this does specifically is remove the cross-fetch
import in favor of the default fetch api.
from datadog-api-client-typescript.
@therve Thankfully it just got a lot easier to setup & run a worker.
I'm going to update description to show how to use these on a brand new project. The error changed (it now fails because of the node-specific Actually, after setting up the repro example, there's a few issues at work, so I'm just going to leave some notes here and leave it up to you want to deal with this ticket.os
) but the issue / request is the same (don't crash on non-node
runtimes if possible)
Working workers example
npx wrangler init some-workers-example-repo -y
cd some-workers-example-repo
npx wrangler dev src/index.ts
⛅️ wrangler 2.0.1 ------------------- ⬣ Listening at http://localhost:8787 12:05:21 PM GET / 200 Script modified; context reset. 12:05:21 PM GET /favicon.ico 200 ╭────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╮ │ [b] open a browser, [d] open Devtools, [l] turn on local mode, [c] clear console, [x] to exit │ ╰────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯
- press
b
or otherwise visit http://localhost:8787 and observe "Hello world" response
Crashes with @datadog/datadog-api-client
npm add @datadog/datadog-api-client
- Setup client instance, e.g.
diff --git a/src/index.ts b/src/index.ts index 0ddd687..3ba0f21 100644 --- a/src/index.ts +++ b/src/index.ts @@ -8,6 +8,11 @@ * Learn more at https://developers.cloudflare.com/workers/ */ +import { v1 } from '@datadog/datadog-api-client'; + +const configuration = v1.createConfiguration(); +const apiInstance = new v1.LogsApi(configuration); + export default { async fetch(request: Request): Promise<Response> { return new Response("Hello World!");
- run
npx wrangler dev src/index.ts
again - observe error message
✘ [ERROR] Could not resolve "os"
node_modules/@datadog/datadog-api-client/dist/userAgent.js:23:30:
23 │ var os = __importStar(require("os"));
╵ ~~~~
The package "os" wasn't found on the file system but is built into node. Are you trying to bundle
for node? You can use "platform: 'node'" to do that, which will remove this error.
My attempts to resolve
I a few iterations of "run wrangler, patch the error, repeat" which was mainly prefacing all process
access with typeof process !== 'undefined'
. There's no checks in userAgent
and a few other places (packages/*v1/configuration
?) do process !== undefined
which fails with a ReferenceError
.
After patching those I hit the XMLHttpRequest is not defined
error you mentioned. I believe that's due to lquixada/cross-fetch#78. Here it is failing with the same error in a Chrome extension (also a worker context)
So it seems there are two areas at work
- Node specific vars like
process
or built ins likeos
in@datadog/datadog-api-client
library code - lquixada/cross-fetch#78
I think you can work around (1) an isNode
guard of some type, like:
const isNode = () =>
typeof process !== "undefined" &&
process.versions != null &&
process.versions.node != null;
In the case of userAgent
is seems reasonable to have things still work even if we're not in node
. The behavior won't change. Perhaps other places aren't as obvious when we not in node.
For (2), I was going to suggest replacing cross-fetch
with something like node-fetch
but I see you just recently did the reverse :) #498
Regardless, at least now you should be able to easily create a worker environment and have confidence when you're testing ideas / changes.
from datadog-api-client-typescript.
Any progress on this?
from datadog-api-client-typescript.
Thanks for your contribution!
This issue has been automatically marked as stale because it has not had activity in the last 30 days. Note that the issue will not be automatically closed, but this notification will remind us to investigate why there's been inactivity. Thank you for participating in the Datadog open source community.
If you would like this issue to remain open:
-
Verify that you can still reproduce the issue in the latest version of this project.
-
Comment that the issue is still reproducible and include updated details requested in the issue template.
from datadog-api-client-typescript.
I can't even use this in the browser due to this. This is caused by some modules importing userAgent.ts
which does this process check unconditionally at import time.
from datadog-api-client-typescript.
Thanks for your contribution!
This issue has been automatically marked as stale because it has not had activity in the last 30 days. Note that the issue will not be automatically closed, but this notification will remind us to investigate why there's been inactivity. Thank you for participating in the Datadog open source community.
If you would like this issue to remain open:
-
Verify that you can still reproduce the issue in the latest version of this project.
-
Comment that the issue is still reproducible and include updated details requested in the issue template.
from datadog-api-client-typescript.
This is still relevant :)
from datadog-api-client-typescript.
👋 hello, we just merged #899
Runtimes where XHR is not available, users will need to supply their own implementation of HttpLibrary. See example implementation with proxy here: https://github.com/DataDog/datadog-api-client-typescript#configure-proxy. This is due to cross-fetch assuming XHR is always present lquixada/cross-fetch#78.
Otherwise, you can add polyfils. Looks like node_compat = true
in the wrangler settings should do the trick.
from datadog-api-client-typescript.
users will need to supply their own implementation of HttpLibrary ...
Otherwise, you can add polyfils
ok, thank you. I won't do either of those but I appreciate the update
from datadog-api-client-typescript.
Another follow up. We just merged #900. This should use native fetch method on non-node environments, omitting the requirement of custom HttpLibrary implementation in environments where XHR is not available. Thanks
from datadog-api-client-typescript.
This should use native fetch method on non-node environments
Oh, this sounds perfect. Will this ticket or #900 get updated when there's a release ready with the fix?
from datadog-api-client-typescript.
Hi all, quick update we just released v1.6.0
from datadog-api-client-typescript.
Related Issues (20)
- HostsApi method listHosts results in a deserialization error HOT 5
- apiInstance.queryScalarData does not support Percentile as Aggregator HOT 1
- List logs from Historical index HOT 1
- dateToRFC3339String produces invalid dates
- Package size HOT 3
- Allow multiple clients to different site (don't rely on global state) HOT 3
- DataScalarColumn.values should be Array<number | null> HOT 1
- Uncatched API Exception in TeamsApi if StatusCode 403 HOT 3
- Typing Inconsistency for "v1.SearchSLOResponse" on GET /api/v1/slo endpoints HOT 5
- Request returns empty 429 HOT 1
- Documentation: add missing word in "Unstable Endpoints" section to add clarity
- Expose domain and endpoint list HOT 1
- criticalRecovery and warningRecovery always fail for `createMonitor` HOT 3
- How do you specify an eu server when using the v2.LogsAPI methods? HOT 4
- Intermittent error querying metrics HOT 2
- v1.searchSLO SearchSLOResponse does not match actual API response HOT 2
- FetchError: client socket disconnected before secure TLS connection is established HOT 9
- Log Aggregate API doesn't support Integer facets on group_by expression HOT 5
- How to change the Datadog host? HOT 2
- APIException HTTP-code: 429 HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from datadog-api-client-typescript.