Created
July 20, 2021 12:15
-
-
Save danieldsf/8ac804f23ed898391432c12ca300b319 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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