Skip to content

Instantly share code, notes, and snippets.

@danieldsf
Created July 20, 2021 12:15
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 danieldsf/8ac804f23ed898391432c12ca300b319 to your computer and use it in GitHub Desktop.
Save danieldsf/8ac804f23ed898391432c12ca300b319 to your computer and use it in GitHub Desktop.
const Sentry = require("@sentry/node");
const SentryLambda = require("@sentry/serverless");
var sentryDns = null;
var sentryHandler = null;
function captureError(error){
console.log(error);
if(sentryHandler){
sentryHandler.captureException(error);
}
};
// Override the original implementation.
function initSentry(dsn) {
if(!sentryDns){
Sentry.init({
dsn: dsn,
tracesSampleRate: 1.0,
});
sentryDns = dsn;
sentryHandler = Sentry;
}
return sentryDns;
};
function initSentryLambda(dsn){
if(!sentryDns){
SentryLambda.AWSLambda.init({
dsn: dns,
// We recommend adjusting this value in production, or using tracesSampler
// for finer control
tracesSampleRate: 1.0,
});
sentryDns = dsn;
sentryHandler = SentryLambda;
}
return sentryDns;
}
function sentryLambdaHandler(callBack){
SentryLambda.AWSLambda.wrapHandler(callBack, {
captureTimeoutWarning: false,
});
}
module.exports = {
captureError,
initSentry,
initSentryLambda,
sentryLambdaHandler
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment