Skip to content
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

@opentelemetry/exporter-prometheus does not work with create-react-app (bundling with Webpack V5) #40

Closed
brettimus opened this issue Apr 19, 2023 · 3 comments

Comments

@brettimus
Copy link
Collaborator

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

@brettimus
Copy link
Collaborator Author

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

@keturiosakys
Copy link
Member

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.

@arendjr
Copy link
Collaborator

arendjr commented Oct 23, 2023

I think this issue got resolved by splitting the packages we did for 0.7.

@arendjr arendjr closed this as completed Oct 23, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants