-
Notifications
You must be signed in to change notification settings - Fork 227
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
Express with Webpack not sending Transactions #1962
Comments
Maybe to workaround, I can use the "Starting node with I don't know this option. |
Nice to meet you @baruchiro, and thank you for the detailed bug report. Here's the usual problem we see with webpack (or other compiler/transpiler/bundlers). Although you've add Using the So
Yes, step one will be giving that a try :) Change how you're invoking node in your production environment to include the |
Hi, nice to meet you too! I will try it, although it is the opposite way from webpack. Think about that, to use But I will try and update you, than we will think on another solution. |
Let know how it goes @baruchiro! Also, if you have a moment: What benefit does your team get from bundling a Node.js server side application? Is there something specific you get from doing this, or are you just applying a best practice from your front end development workflows to the back end? |
Off-topic- why do we use Webpack for the backend? I thought to write an article about that. Anyway, we have two use-cases. For our discussion, we are talking about a backend service with Express. We are running that service in a Docker, and we have a lot of services (micro-services). To reduce the Docker Image size, we are using Webpack to tree-shaking the dependencies and so on, so that we getting a minimal Docker Image:
|
@baruchiro Interesting. Thanks for telling your use case. Only if you know off hand, I'm curious how big of a difference that can make in the Docker size. (I'm guessing you would not know off hand, however, if you've been using webpack for a while.) |
@trentm Mmmm you're right, I can't give you off-hand (I can checkout an old version, you know, just ask me). Anyway, I added the package to the docker:
And it is working! Now I have some points:
|
Sounds like the equivalent potential issue as #608 (where TypeScript fully removes the import of "elastic-apm-node" if the retval isn't actually used directly). I'm not sure, it might also be an ordering of imports thing. Back then a note about using
You should be able to also re-import the module in JS code to get a handle on the agent:
the return value from that |
I've opened #1967 to add better docs for this. |
Mmmm... Sounds logical, but I think it didn't work. Because remember, we are talking about running a bundle, so I'm not sure it still a singleton. I mean, when you require a module multiple times, it actually requiring it once, right? But here I'm requiring it outside the bundle, but in the bundle, I'm not requiring it at all, because of the tree-shaking, it runs the code itself, duplicated. When I'm trying to require it by
(It seems like someone requesting the service. Or maybe it a health check from one of the connections inside the service) After sending request which should use the spanned code, I can't see the span in Kibana. I added this code: const span = apm.startSpan('validating log')
console.log('start span', span)
try {
// ... Original Code
} finally {
console.log('finally span', span)
span?.end()
} and this is the log:
Note to the |
Same problem for us, we use angular universal (babel, typescript included). |
I think you are right. Sorry, I know this issue has languished. I have some more notes here in case it helps for now: #2318 (comment) |
@trentm huge thank you for your help on this. We had a similar issue to @baruchiro. Loading the agent first in the Dockerfile did the trick! I'm hopeful #1967 is merged soon 🤞 |
#1967 is in now, which will hopefully help more. PR: #2837 https://www.elastic.co/guide/en/apm/agent/nodejs/master/starting-the-agent.html#start-bundlers tries to cover issues with bundlers, such as Webpack. Basically to use the agent requires that it be excluded from the bundle. The docs cover options for doing that for Webpack and esbuild. (Instructions for other bundlers, if you have experience using it and the APM agent, would be welcome.) I realize this is just a workaround. I think future work that would be good would be to see if the APM agent can tell if it has been bundled, and then complain with a warning and then deactivate. I haven't looked to far into if that is feasible. We might in the future look into if it would be possible to improve on the story with bundlers, possibly including:
I'm closing this issue. Please re-open and let me know if, in my haste, I missed points that should still be answered here. Thanks very much for the bug reports. |
Describe the bug
I have an express service that bundled with Webpack and runs on Docker (it's mean that in the Dockerfile you just need
CMD ["node", "--enable-source-maps", "main.js"]
To Reproduce
Steps to reproduce the behavior:
import apm from 'elastic-apm-node/start'
at the top on the file.webpack.config.js
file:Expected behavior
When I'm running in debug mode, without webpack, by
babel-node --inspect=33180 src/index.js
, I'm getting the transactions as expected.Here is the configuration output from Debug mode:
Actual behavior
But in production, I can see the service, I even capturing errors manually, but I can't see the transactions.
Here is the config output from the production (webpack) run:
Please note there are no
ancestors
, and there are fewershimming
. Also, note I named the "production" (webpack) service with a different name ('service-name-dev-env
) to identify it.Environment (please complete the following information)
You can see the config output. It is better.
APM Server version:
How are you starting the agent? (please tick one of the boxes)
agent.start()
directly (e.g.require('elastic-apm-node').start(...)
)elastic-apm-node/start
from within the source code-r elastic-apm-node/start
Additional context
package.json
dependencies:Click to expand
The text was updated successfully, but these errors were encountered: