question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Airbrake Not Reporting On Serverless Beta Environment Errors

See original GitHub issue

I 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:closed
  • Created 4 years ago
  • Comments:10 (5 by maintainers)

github_iconTop GitHub Comments

2reactions
vmihailencocommented, Oct 7, 2019

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:

await airbrake.notify("hello world")

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

0reactions
zefercommented, Sep 25, 2019

Are you saying that I should look into option 2 I outlined above?

@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!

Read more comments on GitHub >

github_iconTop Results From Across the Web

2022 Airbrake Error Data Report
The 2022 Airbrake Error Data Report​​ That's a lot of code. And with this amount of code, there will be countless errors, no...
Read more >
Airbrake-js NPM
This is the JavaScript notifier for capturing errors in web browsers and reporting them to Airbrake. For Node.js there is a separate package....
Read more >
11 Best Tools to Monitor and Debug JavaScript in 2023 - Atatus
Error detection and correction are made simple by the tools. ... Airbrake notifiers are agentless and serverless, support more than 50 ...
Read more >
Top 10 Serverless Deployment Errors (and How to Fix Them)
Referencing a layer that is in a different region than the deployed stack/environment · Referencing a layer that hasn't granted layer-permissions ...
Read more >
Add-ons - Heroku Elements
Errors and Exceptions · Bugsnag · Raygun Crash Reporting · Sentry · Honeybadger · AppSignal APM · Airbrake Error Monitoring · Rollbar.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found