Skip to content

Instantly share code, notes, and snippets.

@teebu
Created November 2, 2017 19:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save teebu/0a230908ae5ac0824e115ac8a6dae237 to your computer and use it in GitHub Desktop.
Save teebu/0a230908ae5ac0824e115ac8a6dae237 to your computer and use it in GitHub Desktop.
sample raven event logging
const async = require('async');
const download = require('download');
const fs = require('fs-extra');
const RavenLambdaWrapper = require('serverless-sentry-lib');
const Raven = require('raven')
// Wrap handler for automated error and exception logging
const ravenConfig = {
filterLocal: false,
captureErrors: true, // Don't log error responses from the Lambda ...
captureUnhandledRejections: true, // but keep unhandled exception logging, ...
captureMemoryWarnings: false, // memory warnings ...
captureTimeoutWarnings: false, // and timeout warnings enabled.
ravenClient: Raven
};
module.exports.handler = RavenLambdaWrapper.handler(ravenConfig, (event, context, callback) => {
// your Lambda Functions Handler code goes here...
console.log('event %j', event)
//somethingElse() // <= event in sentry
var option = event;
something(option, callback);
});
function something(options, callback){
async.series([
function (callback) { // download
console.log('downloading', options.file)
download(options.file).then(data => { // <= CULPRIT
fs.writeFileSync('/tmp/flip.jpg', data);
return callback()
}).catch(e => callback(e))
},
function (callback) { // throw an error
// throw an error
//somethingElse() // <= no event in sentry
return callback();
}], function (err, res) {
if (err) {
console.log('ERR:', err)
return callback(err)
}
return callback('error returned') // <= no event in sentry
//return callback(err, 'done')
});
}
function somethingElse(){
console.log(a)
}
{
"file" : "https://www.codeproject.com/KB/GDI-plus/ImageProcessing2/flip.jpg",
"nothing": "just text"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment