Socket
Socket
Sign inDemoInstall

@snapshot-labs/snapshot-sentry

Package Overview
Dependencies
9
Maintainers
2
Versions
11
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    @snapshot-labs/snapshot-sentry

`snapshot-sentry` is an npm package that contains the Sentry setup files and configurations for Snapshot backend projects. It simplifies the process of setting up Sentry for error tracking in any Snapshot service.


Version published
Weekly downloads
289
increased by7.43%
Maintainers
2
Install size
6.72 MB
Created
Weekly downloads
 

Readme

Source

Snapshot-sentry

snapshot-sentry is an npm package that contains the Sentry setup files and configurations for Snapshot backend projects. It simplifies the process of setting up Sentry for error tracking in any Snapshot service.

Install

yarn add @snapshot-labs/snapshot-sentry

Configure

Set the following env variables:

  • SENTRY_DSN (required)
  • SENTRY_TRACE_SAMPLE_RATE (Optional, default to 0.01)

Usage

Instantiate

For express

Import the library in your root file

import { initLogger, fallbackLogger } from '@snapshot-labs/snapshot-sentry'

Init sentry just after creating your express instance, before any middleware

const app = express();
initLogger(app);

Set the fallthrough error handler after all controllers, but before any other error middleware

fallbackLogger(app);

Note: If you have a catch-all route, set fallbackLogger() before it.

All uncaught errors, with code >= 500, will be handled automatically by Sentry. See Capture exception for how to handle caught exceptions.

For vanilla js

Import the library in your root file

import { initLogger } from '@snapshot-labs/snapshot-sentry'

Init sentry, as soon as possible to catch all errors.

initLogger()

See Capture exception for how to handle exceptions.

Capture exception

To capture an exception, use the capture function:

import { capture } from '@snapshot-labs/snapshot-sentry'

try { 
  throw new Error('Ooops, someting went wrong');
} catch (e: any) {
  // Send the error to sentry
  capture(e)
}

You can also pass additional context data to the capture function:

import { capture } from '@snapshot-labs/snapshot-sentry'

let url = '';
try { 
  url = getUrlFromSomewhere('argOne')
  throw new Error('Ooops, someting went wrong');
} catch (e: any) {
  // Send the error to sentry
  capture(e, { contexts: { input: { url: url } } })
}

When sentry is disabled, the capture function will fallback to a simple console.log, so no code change will be required when toggling this library on/off.

More info

License

Snapshot-sentry is open-sourced software licensed under the © MIT license.

FAQs

Last updated on 29 Jan 2024

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc