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')
and Promise.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
{
"type": "module",
"name": "experiment",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC",
"dependencies": {
"elastic-apm-node": "^4.5.0",
"express": "^4.19.2"
}
}
index.js
import './apm.js'; // Must go first
import express from 'express';
const port = 3000;
const app = express();
app.get('/', (_req, res) => {
//Promise.reject(new Error('Kaboom')); // Uncomment either of these
res.send('Hello World!');
});
app.listen(port, () => {
console.log(`Example app listening on port ${port}`);
});
//throw new Error('Boom'); // Uncomment either of these
apm.js
import apm from 'elastic-apm-node';
apm.start({
environment: 'local',
serverUrl: 'https://example.com:12345/',
});
Also tried with CommonJS modules, as in, with require()
.
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)
- OS: Linux and MacOS
- Node.js version: 16.16.0
- APM Server version: 7.17.8
- Agent version: 3.42.0 and 4.3.0
How are you starting the agent? (please tick one of the boxes)
- Calling
agent.start()
directly (e.g.require('elastic-apm-node').start(...)
)
In particular, I have ainit-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'
. - Requiring
elastic-apm-node/start
from within the source code - Starting node with
-r elastic-apm-node/start
Additional context
Agent config options:
Click to expand
import { hostname } from 'node:os';
import pkg from '../../package.json' assert { type: 'json' };
{
serviceName: pkg.name.split('/')[1],
serviceVersion: pkg.version,
serviceNodeName: hostname(),
environment: process.env['APP_ENV'],
serverUrl: process.env['ELK_KIBANA_URL'],
captureBody: 'all',
captureExceptions: true, // <-- I've tried with default and explicit `captureExceptions`
}
package.json
dependencies:
Click to expand
"@aws-sdk/client-s3": "3.245.0",
"@aws-sdk/client-timestream-write": "3.245.0",
"@bluesialia/express-graphql": "0.15.0",
"@elastic/ecs-pino-format": "1.5.0",
"@sentry/node": "7.103.0",
"bcryptjs": "2.4.3",
"body-parser": "1.20.1",
"compression": "1.7.4",
"cors": "2.8.5",
"dotenv": "16.3.1",
"elastic-apm-node": "3.42.0",
"express": "4.18.2",
"express-async-errors": "3.1.1",
"extract-files": "13.0.0",
"firebase-admin": "11.10.1",
"google-auth-library": "8.7.0",
"graphql": "16.6.0",
"graphql-scalars": "1.20.1",
"graphql-upload": "13.0.0",
"graphql-ws": "5.11.2",
"http-status": "1.6.1",
"jszip": "3.10.1",
"knex": "2.4.0",
"modern-async": "1.1.3",
"node-fetch": "3.3.2",
"objection": "3.1.4",
"objection-paginator": "0.7.1",
"paddle-sdk": "3.2.0",
"pg": "8.8.0",
"pino": "8.17.1",
"stringify-object": "5.0.0",
"wasmagic": "0.0.32"