Airbrake Not Reporting On Serverless Beta Environment Errors
See original GitHub issueI was able to test airbrake locally. Airbrake caught an uncaught exception and reported it – tagging the environment in which the error occurred as development
. This is great.
However, when I deploy the same code to a now lambda written in node
, and I use a different environment variable – beta
as the value – airbrake will not catch this exception and report on it. Has anyone had issues with airbrake reporting on uncaught exceptions locally but not remotely in a deployed environment?
This is my logged out airbrake client in beta if knowing it helps:
2019-07-18T15:27:31.668Z f2d56d40-71fa-4ef3-97b0-120cf367eda6 airbrake object Client {
filters:
[ [Function: filter],
[Function],
[Function: filter],
[Function: filter],
[Function],
[Function: filter] ],
offline: false,
todo: [],
onClose: [],
opts:
{ projectId: #{projectId},
projectKey: #{projectKey},
environment: 'beta',
host: 'https://api.airbrake.io',
timeout: 10000,
keysBlacklist: [ /password/, /secret/ ] },
url: 'https://api.airbrake.io/api/v3/projects/#{projectId}/notices?key=#{someKey}',
processor: [Function: processor],
requester: [Function: request],
historian:
Historian {
historyMaxLen: 20,
notifiers: [ [Circular] ],
errors: [],
ignoreWindowError: 0,
history: [ [Object] ],
ignoreNextXHR: 0,
consoleError: [Function: prettyConsoleLog],
lastState:
{ type: 'log',
severity: 'log',
arguments: [Array],
date: 2019-07-18T15:26:36.013Z } } }
This is the code I have:
var AirbrakeClient = require('airbrake-js');
var airbrakeExpress = require('airbrake-js/dist/instrumentation/express');
var airbrake = new AirbrakeClient({
projectId: process.env.AIRBRAKE_PROJECT_ID,
projectKey: process.env.AIRBRAKE_PROJECT_KEY,
environment: process.env.ENVIRONMENT
})
const app = express();
app.use(airbrakeExpress.makeMiddleware(airbrake));
//Routes
app.get('/some-error', (req, res) => {
throw("some errorr!!!!!!!!!!")
})
app.use(airbrakeExpress.makeErrorHandler(airbrake));
Whenever I hit the /some-error
endpoint an exception is thrown but airbrake never catches and reports on the exception in my beta environment as it does locally for me.
Here’s my package.json:
{
"name": "nodejs-express",
"version": "1.0.0",
"main": "index.js",
"license": "MIT",
"dependencies": {
"airbrake-js": "^1.6.8",
"axios": "^0.18.0",
"body-parser": "^1.19.0",
"cors": "^2.8.5",
"cross-fetch": "^3.0.4",
"date-fns": "^1.30.1",
"dotenv": "^8.0.0",
"express": "^4.16.4",
"helmet": "^3.16.0"
},
"devDependencies": {
"chai": "^4.2.0",
"mocha": "^6.1.4",
"nock": "^10.0.6",
"nodemon": "^1.19.0",
"sanitize-filename": "^1.6.1",
"sinon": "^7.3.2",
"testdouble": "^3.11.0"
},
"scripts": {
"start": "node ./index.js",
"dev": "nodemon index.js",
"test": "./node_modules/mocha/bin/mocha test/**/*.js"
}
}
Issue Analytics
- State:
- Created 4 years ago
- Comments:10 (5 by maintainers)
Top GitHub Comments
The problem here is that airbrake-js (and JS generally) sends data via HTTP asynchronously but in serverless environment app exits (paused?) immediately after request is served and airbrake-js does not have any chance to finish sending the error. So the fix is to either send errors synchronously or flush pending errors just before the app exits. To send errors synchronously you can use
await
:To flush pending errors you can use
airbrake.flush
which is available in @airbrake/node since v1.0.0-beta.5. The only problem is that it is not clear when and where to call it - it looks like https://zeit.co/ does not provide any suitable hook…Related PR that tries to solve similar problem is https://github.com/zeit/next.js/issues/8685
@robskrob Yes, that’s where I would start, because it’s possible there is an error for a failing HTTP request which would explain what’s happening. Possibly not, depending on what the problem is, but it should be relatively quick and easy to try!