New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More

@sentry/serverless

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@sentry/serverless

Offical Sentry SDK for various serverless solutions

6.3.0-beta.6
Version published
Weekly downloads
237K
1.02%
Maintainers
12
Weekly downloads
 
Created

What is @sentry/serverless?

@sentry/serverless is an npm package that provides error tracking and performance monitoring for serverless applications. It helps developers capture and report errors, exceptions, and performance issues in serverless environments such as AWS Lambda, Google Cloud Functions, and Azure Functions.

What are @sentry/serverless's main functionalities?

Error Tracking

This feature allows you to capture and report errors in your serverless functions. The code sample demonstrates how to initialize Sentry for AWS Lambda and wrap a handler to automatically capture any errors that occur.

const Sentry = require('@sentry/serverless');

Sentry.AWSLambda.init({
  dsn: 'your-dsn-url',
});

exports.handler = Sentry.AWSLambda.wrapHandler(async (event, context) => {
  // Your handler code
  throw new Error('Something went wrong!');
});

Performance Monitoring

This feature allows you to monitor the performance of your serverless functions. The code sample demonstrates how to initialize Sentry with performance monitoring enabled and how to create and finish a transaction to measure the duration of a task.

const Sentry = require('@sentry/serverless');

Sentry.AWSLambda.init({
  dsn: 'your-dsn-url',
  tracesSampleRate: 1.0,
});

exports.handler = Sentry.AWSLambda.wrapHandler(async (event, context) => {
  // Your handler code
  const transaction = Sentry.startTransaction({
    op: 'task',
    name: 'My Task',
  });

  // Simulate some work
  await new Promise(resolve => setTimeout(resolve, 1000));

  transaction.finish();
});

Custom Context

This feature allows you to add custom context to your error reports. The code sample demonstrates how to set tags, user information, and extra data in the Sentry scope before throwing an error.

const Sentry = require('@sentry/serverless');

Sentry.AWSLambda.init({
  dsn: 'your-dsn-url',
});

exports.handler = Sentry.AWSLambda.wrapHandler(async (event, context) => {
  Sentry.configureScope(scope => {
    scope.setTag('my-tag', 'my-value');
    scope.setUser({ id: 'user-id' });
    scope.setExtra('extra-info', 'some extra information');
  });

  // Your handler code
  throw new Error('Something went wrong!');
});

Other packages similar to @sentry/serverless

FAQs

Package last updated on 13 Apr 2021

Did you know?

Socket

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