-
Notifications
You must be signed in to change notification settings - Fork 230
log correlation + webpack may not work #2844
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
Comments
can we build a "native" solution for bundlers? you could hook when the webpack is compiling a given package like |
we can have a list of packages that needs to be external to make elastic apm instrumentation to work |
can elastic-apm-node |
@sibelius Hi. A native solution for bundlers will likely require a separate package/plugin/something for each bundler (e.g. one for webpack, one for esbuild, etc.), assuming the given bundler supports customization like that. I believe doing so is possible, yes, but it will take some investigation and prioritizing doing that. It is on my radar, but nothing is currently planned.
The best such list in here: apm-agent-nodejs/lib/instrumentation/index.js Lines 37 to 86 in 5c372b6
These are all the modules that the APM agent will possible instrument.
It often does log at "debug" level when it is instrumenting a particular part of a module, e.g.: agent.logger.debug('shimming generic-pool.Pool')
agent.logger.debug('shimming koa-router prototype.match function')
agent.logger.debug('wrapping fastify build function') However, it does not currently do so consistently. |
I would like to see logs that packages that should be instrumented but were not instrumented like we tried to instrument but I think this won't be easy or even possible |
The issue in a bundler is that the hook the APM agent puts on |
here is an article https://dev.to/woovi/using-webpack-to-slim-your-docker-image-1b1n of how we are using elastic apm with webpack (bundling), and enabling instrumentation we move all required packages that need instrumentation outside bundling, as externals and install them in the docker afterwards |
(I'm splitting out one of the listed issues on #1967 (comment) to this new issue.)
Scenario:
@elastic/ecs-winston-format
for ECS logging formatting.Is there a way to configure and use webpack so that (a) the APM agent works and (b) log correlation works?
See coming docs from #2837 about using the agent with webpack. Those docs should potentially be updated if there are changes required to get the above to work.
Using 'externals' in webpack.config.js like this:
naively works to get instrumentation of core node modules only, e.g. the
http
module. It may work for adding other modules as well:However, it does not work for log correlation via:
because I found that the built "dist/app.js" replaces the
require('elastic-apm-node')
in ecs-winston-format with the__webpack_require__
, breaking the sniffing. Solutions:Something about the more complete 'webpack-node-externals' module works (and for all packages). So this is probably our best current workaround answer. However it may defeat the user's use case for webpack, perhaps not.
If we switch to the global var, this might just work. We should probably do that anyway, to handle the "weird, hard" case.
Perhaps, however, it would be better for log correlation here to be from the APM side. It shouldn't just be Elastic APM here. The circular dep issue might be different here then.
The text was updated successfully, but these errors were encountered: