-
Notifications
You must be signed in to change notification settings - Fork 225
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
Agent doesn't capture uncaught exceptions or unhandled rejections #3960
Comments
Added a minimal example. Those 3 files. Just run |
I've run you example uncommenting the li within the request handler but haven't been able to reproduce. I can see the error in Kibana. Are you able to get the initial line of log output from the APM agent? It looks something like this:
If so, check if the line contains something like
This is to check there is no other source setting the configuration option. |
Also if you can make local edits, you can apply this change to log if the agent's exception handler is properly attached to the process. diff --git a/lib/agent.js b/lib/agent.js
index 2a1e26df..64fe1c59 100644
--- a/lib/agent.js
+++ b/lib/agent.js
@@ -776,6 +776,8 @@ Agent.prototype.handleUncaughtExceptions = function (cb) {
});
};
+ console.log('XXX attaching uncaughtException handler to process')
+
process.on('uncaughtException', this._uncaughtExceptionListener);
}; to "node_modules/elastic-apm-node/lib/agent.js", restart, and reproduce. Then post here full log to check if this new line appears |
This is the initial log line:
This is with With the file
The following line would be the error If I'm not mistaken. These outputs are what they should be, yet still no errors show on the APM panel. I think I read somewhere that the agent prints something to console whenever it captures a fatal error and sends it to ELK. Is that correct? If that's the case I don't see that log either. |
as your logs show the exception handler is set when the agent starts so we can assume the agent starts correctly. Next thing to try is to set the log level to You can start you example with the defined log level like this ELASTIC_APM_LOG_LEVEL=trace node index.js Ref: https://www.elastic.co/guide/en/apm/agent/nodejs/current/configuration.html#log-level once you got the logs please paste them here :) |
Sorry for the delay. These are the logs:
|
I see the line that says |
I do not see anything wrong in this log this line
reveals that the http client received a successful response from the endpoint. To discard any other communication issue we should check if the URL configured in the agent is pointing to the APM server or any other component like a proxy. @Vectarian-Jorge could you please check it? I ran my tests with the same node and agent version specified in the issue but a different APM server version (8.12.1). I'll try to run the tests with same APM server 7.17.8 to discard any version incompatibility |
Ran the test with
slight modification of the server script to test more cases import './apm.js'; // Must go first
import express from 'express';
const port = 3000;
const app = express();
app.get('/reject', (_req, res) => {
Promise.reject(new Error('Rejection')); // 1. This is unhandled so ti should be reported
res.send('Hello World!');
});
app.get('/error', (_req, res) => {
throw new Error('Exception'); // 2. This is handled by express, no error
});
app.listen(port, () => {
console.log(`Example app listening on port ${port}`);
});
throw new Error('Boom'); // 3. This should also be reported, comment to test rejection (1) The service errors appear in Kibana @Vectarian-Jorge I'm inclined to check the transit from the agent to the APM server. Have you checked for any proxy/nodes in between the app and the APM server? |
Thanks for checking all this @david-luna. @PeterBero, you may need to check with Tomas about any possible proxy. |
Describe the bug
Suddenly my Express applications do not capture errors or exceptions that cause the application to crash. Up until the 21st of February I can see both in the Error tab of the APM and in the Discover tool of ELK that there were crashes reported due to silly mistakes, like a missing environment variable. But nothing since then. And I've tried to crash the application deliberately adding
throw new Error('Boom')
andPromise.reject(new Error('Kaboom'))
and neither is reported by the APM.Investigating any possible changes I've made I can only think of upgrading the agent's version from 3.42.0 to 4.3.0. But I've tried with the old version and it behaves the same way.
To Reproduce
package.json
index.js
apm.js
Expected behavior
Uncaught exceptions and unhandled rejections being reported by the agent so that they can be monitored in the APM tool of ELK.
Environment (please complete the following information)
How are you starting the agent? (please tick one of the boxes)
agent.start()
directly (e.g.require('elastic-apm-node').start(...)
)In particular, I have a
init-elastic-apm.ts
file where I start the agent with a config dependent on some environment variables. Then the first line of myindex.ts
file isimport apm from 'elastic-apm-node'
.elastic-apm-node/start
from within the source code-r elastic-apm-node/start
Additional context
Agent config options:
Click to expand
package.json
dependencies:Click to expand
The text was updated successfully, but these errors were encountered: