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

Log uncaughtExceptions in our logging system #183530

Merged
merged 2 commits into from
May 16, 2024

Conversation

afharo
Copy link
Member

@afharo afharo commented May 15, 2024

Summary

Resolves #183182

Checklist

Risk Matrix

Risk Probability Severity Mitigation/Notes
According to the docs, the event might be called for unhandledRejections (refer to the origin parameter). High Low I didn't want to remove the previous logging to avoid introducing breaking changes. Also, IMO, additional logging in this case is not that big of a deal.

For maintainers

@afharo afharo added Team:Core Core services & architecture: plugins, logging, config, saved objects, http, ES client, i18n, etc technical debt Improvement of the software architecture and operational architecture release_note:skip Skip the PR/issue when compiling release notes backport:skip This commit does not require backporting labels May 15, 2024
@afharo afharo self-assigned this May 15, 2024

expect(logger.get('process').warn).toHaveBeenCalledTimes(1);
expect(logger.get('environment').warn).toHaveBeenCalledTimes(1);
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Weird that the test works with both words 🤷

await service.preboot({ analytics });

const err = new Error('something went wrong');
process.emit('unhandledRejection', err, new Promise((res, rej) => rej(err)));
process.emit('unhandledRejection', err, new Promise((res, rej) => {}));
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The problem was not the process.emit, was the actual Promise rejecting 😅

@@ -68,6 +68,14 @@ export class EnvironmentService {
const message = (reason as Error)?.stack ?? JSON.stringify(reason);
this.log.warn(`Detected an unhandled Promise rejection: ${message}`);
});
// Log uncaughtExceptions in our logger before crashing the process: https://github.com/elastic/kibana/issues/183182
process.on('uncaughtExceptionMonitor', (error, origin) => {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using uncaughtExceptionMonitor instead of uncaughtException because, according to the docs, the only difference is that the latter intercepts the exit call.

@afharo
Copy link
Member Author

afharo commented May 15, 2024

/ci

@afharo afharo marked this pull request as ready for review May 15, 2024 17:46
@afharo afharo requested a review from a team as a code owner May 15, 2024 17:46
@elasticmachine
Copy link
Contributor

Pinging @elastic/kibana-core (Team:Core)

@kibana-ci
Copy link
Collaborator

💚 Build Succeeded

Metrics [docs]

✅ unchanged

History

To update your PR or re-run it, just comment with:
@elasticmachine merge upstream

cc @afharo

@afharo afharo merged commit 8ec0c68 into elastic:main May 16, 2024
18 checks passed
@afharo afharo deleted the add-logs-for-uncaughtException branch May 16, 2024 10:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport:skip This commit does not require backporting release_note:skip Skip the PR/issue when compiling release notes Team:Core Core services & architecture: plugins, logging, config, saved objects, http, ES client, i18n, etc technical debt Improvement of the software architecture and operational architecture v8.15.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Should we handle uncaughtExceptions?
5 participants