-
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
capture an error for unhandledRejection
#2366
Comments
This came from discussion from a user that was confused that "errors are not being reported to APM." The issue was that their app output showed |
Look like i am hitting the same issue. due to ELK APM server network problem, agent is timing out. Due to STRICT configuration at node level, this result into application call itself failing, Though we don't want application call to fail just because APM server is not reachable/timing out. |
@sardanam I think this might be something different. It is definitely a bug in the APM agent if it is crashing the application when it is unable to talk to APM server. Would you be willing to open a separate issue (to not get mixed up with this one) and provide some more details?
|
Hi @trentm Two questions regarding this issue:
|
I mean that the APM agent should report an "error" event to the APM server so it can be reported in the Kibana APM app.
The
While looking at this, I notice the (new to me) This makes me wonder if just handling If I re-run the original
and the error reported to APM server is: {
"error": {
"id": "51170e84eb39acdf94f87d3bb5020173",
"timestamp": 1675881611904000,
"context": {
"user": {},
"tags": {},
"custom": {}
},
"exception": {
"message": "This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). The promise rejected with the reason \"boom\".",
"type": "UnhandledPromiseRejection",
"handled": false,
"code": "ERR_UNHANDLED_REJECTION",
"stacktrace": [
{
"filename": "UnhandledPromiseRejection: This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch. The promise rejected with the reason \"boom\".",
"library_frame": true,
"abs_path": "UnhandledPromiseRejection: This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch. The promise rejected with the reason \"boom\"."
}
]
},
"culprit": "undefined (UnhandledPromiseRejection: This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch. The promise rejected with the reason \"boom\".)"
}
} I think this issue can be closed as not necessary. Side note: Note the separate issue for perhaps switching to |
Hi @trentm
This makes me thing some customers either were not aware of this option or development team did not have control on how the node process is started in the host machine. Implementing a handler for rejections may come handy in the second case but that implementation has already an expiration date. I guess a paragraph in captureExceptions config option could be enough. The note should explain that APM is capable of reporting unhandled rejections with the proper value in But also I think it might be a good idea to inform in the console messages that the
This way we notice:
So to summarize we can do 2 things:
|
Or perhaps explicitly using Most likely "some customers either were not aware of this option", as you suggest.
Yes, and perhaps also in the shared section of "docs/shared-set-up.asciidoc":
that is used in a number of the "Get started ..." doc pages, e.g. https://www.elastic.co/guide/en/apm/agent/nodejs/current/express.html#express-error-logging
Did you mean If we consider only more recent versions of node, for a moment -- those versions where I haven't played with code for this, but my suspicion and worry is that if the APM agent added a Aside: if you want to read a LONG passionate discussion on how |
Hi @trentm I'll run some test but I'd say that adding a listener to the The goal of my proposal is:
On these two options I'd like the one which logs anyway. I like the tools I?m using to give me hints on how to use them but probably is best to not log since probably |
So I did some tests with different node versions to see how it behaves when adding the handlers and doing some variations on the The script used to perform tests is quite straightforward. We inspect process object to resolve which is the mode and if it's overwritten by the CLI option when the process starts. then we add a couple of handlers for rejections and an exception handler. // Check the version
const [major, minor, patch] = process.versions.node.split('.').map(n => parseInt(n, 10))
console.log('Node major version: ' + major)
// Check if --unhandled-rejections override is present and resolve the mode
const defaultMode = major >= 15 ? 'throw' : 'warn';
const overrideMode = process.execArgv.find(arg => arg.indexOf('--unhandled-rejections') !== -1)
const currentMode = overrideMode ? overrideMode.split('=')[1] : defaultMode
console.log('--unhandled-rejections mode is ' + currentMode, overrideMode ? '(override)' : '(default)')
// This could be APM handler
process.on('unhandledRejection', function (rej) {
console.log('APM agent detected unhandledRejection', rej);
})
// And this the monitored APP handler
process.on('unhandledRejection', function (rej) {
console.log('Application detected unhandledRejection', rej);
})
// APM or Application handler for exceptions
process.on('uncaughtException', function (err) {
console.log('uncaughtException => ', err);
})
Promise.reject('boom') I can summarize the mode is consistent across versions and that indeed adding a handler changes the behavior of the App when the mode is the default About the other modes:
This validates your thought about changing the behavior of the App because of the handlers. IMHO the most we can do is to detect the mode & version at startup and provide a suggestion if applies.
So for sure the documentation update is a must and this suggestion message at startup is a nice to have that could avoid some questions from customers in the future. |
@david-luna Thanks for verifying that it would cause app behaviour changes.
I think some doc updates could be helpful to users, yes.
I'm still unsure about this. For one, I don't recall any user questions about this in the past two years. As well:
In this case, the default is
The
This suggests that the APM agent knows better than the user, which isn't always the case. Granted, I don't know of a valid reason for using 'none'. |
Hi @trentm I'll proceed to update the docs and do not implement the suggestion message in the node process. As you said this implies APM agent knowing better than the user and it is not true always. Let me know if you have any suggestion for the copy. You can write on the PR (which I'm going to create) directly. |
Currently the agent will capture an APM error for an
uncaughtException
(process event) -- depending on thecaptureExceptions
config option (default true). We should do the same forunhandledRejection
. I'm not sure if we'd want that to be a separate config option or piggy-back oncaptureExceptions
.Using node v12, without the APM agent:
and with the APM agent:
No "error" event is reported to APM server in the second case. It should be, without changing the behaviour of the node app (which I hope is possible).
Node has the following option:
and the default value for that has changed over the major node.js versions. I think this probably means we should make this separately configurable. The default should be to capture an exception.
The text was updated successfully, but these errors were encountered: