@opentelemetry/exporter-prometheus does not work with create-react-app (bundling with Webpack V5)
brettimus opened this issue · 3 comments
When trying to add autometrics with a push gateway to a create-react-app project, I get the following error:
ERROR in ./node_modules/@opentelemetry/exporter-prometheus/build/src/PrometheusExporter.js 28:14-28
Module not found: Error: Can't resolve 'url' in '/Users/brettbeutell/fiber/aplos-app/node_modules/@opentelemetry/exporter-prometheus/build/src'
BREAKING CHANGE: webpack < 5 used to include polyfills for node.js core modules by default.
This is no longer the case. Verify if you need this module and configure a polyfill for it.
If you want to include a polyfill, you need to:
- add a fallback 'resolve.fallback: { "url": require.resolve("url/") }'
- install 'url'
If you don't want to include a polyfill, you can use an empty module like this:
resolve.fallback: { "url": false }
webpack compiled with 2 errors
No issues found.
The issue appears to be that we need polyfills for node.js core modules.
Maybe it'd be good to have a client-side tailored package of autometrics? Since for browser-based apps we might not need all of the open telemetry deps
I was able to get an example running by adding node.js polyfills.
I needed to install the following
npm install --save url buffer
Then add this to my dependencies in package.json:
"http": "npm:stream-http@^3.2.0",
Got help from this comment
So this is happening because by default, with no other configuration, autometrics
currently uses the @opentelemetry/exporter-prometheus
package even on the client-side which uses some Node-specific APIs.
I think the shorter-term solution is throwing a better error for the user that explains they need to use the init
function whenever attempting to use the autometrics
in the client or figuring out a better default setting.
I think this issue got resolved by splitting the packages we did for 0.7.