-
Notifications
You must be signed in to change notification settings - Fork 58
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Consider dropping @datadog/datadog-api-client
?
#132
Comments
Related note: I think one reason If we make this change, it would be good to ensure there’s a nice way to set up proxying (in the worst case, someone can still provide a custom reporter, but it would be nice if they didn’t have to). |
I think a first implementation of this should replace In a second release, we can update to Node.js 18+ and use the built-in |
Some additional notes here:
Ideally, we’d be able to use the fetch built-ins for all environments and just supply proxy info in the relevant format for that environment (still a bit of a pain), but Node.js just doesn’t support it with fetch at all, and also doesn’t have built-in proxy support of any kind (you can get an agent via the Another option is to choose a userland module (which we kind of need anyway if we are going to stay compatible with Node.js v14), most of which have a way to do proxies.
Honestly the straightforward option maybe be to either not worry about this option (someone can supply their own reporter) or make it possible to provide a custom import metrics from 'datadog-metrics';
import { HttpsProxyAgent } from 'https-proxy-agent';
import fetch as nodeFetch from 'node-fetch';
const agent = new HttpsProxyAgent('http://my-proxy-url.com:1234');
metrics.init({
fetch (url, options) {
return nodeFetch(url, { ...options, agent });
}
}); Or: import metrics from 'datadog-metrics';
import { HttpsProxyAgent } from 'https-proxy-agent';
import fetch as nodeFetch from 'node-fetch';
const agent = new HttpsProxyAgent('http://my-proxy-url.com:1234');
const reporter = new metrics.DatadogReporter({
fetch (url, options) {
return nodeFetch(url, { ...options, agent });
}
});
metrics.init({ reporter }); Or: import metrics from 'datadog-metrics';
import { HttpsProxyAgent } from 'https-proxy-agent';
import fetch as nodeFetch from 'node-fetch';
class ProxyReporter extends metrics.DatadogReporter {
constructor (options) {
super(options);
this.agent = new HttpsProxyAgent('http://my-proxy-url.com:1234');
}
fetch (url, options) {
return nodeFetch(url, { ...options, agent: this.agent });
}
}
metrics.init({ reporter: new ProxyReporter() }); The last one is a bit of a bear, but they are all pretty easy to make possible and document. The first two feel pretty do-able for most users that have this need. |
And another reason to do this besides dependency weight or complexity: in current versions of Node.js, |
One thing I’ve been thinking about is dropping our dependency on the official
@datadog/datadog-api-client
package. Folks value and use this package over that official one because of simplicity, and it is a pretty heavy-weight dependency for us to bring in. We don’t actually use much of its functionality or features, and it mostly serves as an HTTP client for us.Would it be worth dropping this dependency and using the HTTP API directly? I currently plan to make a major, breaking release in January 2025 (see #131), and that might be a good time to upgrade the minimum Node.js version to 18, where
fetch
is built-in and we wouldn’t need to replace the Datadog client with anything at all.This might not be worthwhile! It adds (a little) maintenance burden (mainly auth and error handling), and keeping a minimal dependency tree is probably not critical to most of our users here (if it is to you, please comment!).
The text was updated successfully, but these errors were encountered: