league-sentry-error-logger
v1.0.0
Published
Setup a project to initialize and use Sentry to send error events within a cloud node function
Downloads
2
Readme
Node package to initialize Sentry and send an error event to Sentry that contains all the expected user and environment breadcrumbs
- This package is designed to Initialize Sentry and send an error event to Sentry that contains all the expected user and environment breadcrumbs
- To Send an error event to Sentry the caller has two options:
- logExceptionWithConfig - takes a configuration object and uses it to build Sentry attributes for the event.
- logExceptionWithSentryData - takes custom prebuilt Sentry attributes { sentryDsn, sentryEnv, fingerPrint, tags } and uses for the event. See the definition of logExceptionWithConfig and logExceptionWithSentryData for more details.
/**
- logExceptionWithConfig captures an error/exception and forwards it to Sentry as an event.
- This function takes a configuration object and uses it to build Sentry attributes
- See the implementation of buildLogData for more context.
- Note: if you need the flexibility of using custom tags and fingerprint generated based your own custom rules, use logExceptionWithSentryData
- @param exception - The error object to be logged.
- @param severity - log level or severity level of the failure e.g "fatal", "error"
- @param userId - A unique user Id, identifying the user who made the failed request.
- @param configuration - The configuration object required to build customs Sentry tags and fingerprint.
- @returns {Promise}
*/
async function logExceptionWithConfig(
exception,
severity,
userId,
configuration
)
*
Example:
const sentry = require("@everlong/sentry-error-logging"); const configuration = { tenantId:"tenant", env: "dev", sentryDsn:"https://dsn.string" }; try{ // doSomething(); }catch(err){ await sentry.logExceptionWithConfig(err, "fatal", userId, configuration); }