Security News
New Python Packaging Proposal Aims to Solve Phantom Dependency Problem with SBOMs
PEP 770 proposes adding SBOM support to Python packages to improve transparency and catch hidden non-Python dependencies that security tools often miss.
@sentry/serverless
Advanced tools
@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.
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!');
});
New Relic is a comprehensive monitoring and observability platform that provides error tracking, performance monitoring, and more for various environments, including serverless applications. Compared to @sentry/serverless, New Relic offers a broader range of monitoring capabilities but may be more complex to set up and use.
Datadog Lambda is a monitoring and analytics platform specifically designed for serverless applications. It provides error tracking, performance monitoring, and custom metrics. Compared to @sentry/serverless, Datadog Lambda offers more specialized features for serverless environments but may require additional configuration and integration with the Datadog platform.
LogDNA is a log management and analysis platform that can be used to monitor serverless applications. It provides real-time log aggregation, error tracking, and alerting. Compared to @sentry/serverless, LogDNA focuses more on log management and may require additional setup to achieve the same level of error tracking and performance monitoring.
This package is a wrapper around @sentry/node
, with added functionality related to various Serverless solutions. All
methods available in @sentry/node
can be imported from @sentry/serverless
.
Currently supported environment:
AWS Lambda
To use this SDK, call Sentry.init(options)
at the very beginning of your JavaScript file.
import * as Sentry from '@sentry/serverless';
Sentry.init({
dsn: '__DSN__',
// ...
});
// async (recommended)
exports.handler = Sentry.AWSLambda.wrapHandler(async (event, context) => {
throw new Error('oh, hello there!');
});
// sync
exports.handler = Sentry.AWSLambda.wrapHandler((event, context, callback) => {
throw new Error('oh, hello there!');
});
FAQs
Official Sentry SDK for various serverless solutions
We found that @sentry/serverless demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 11 open source maintainers collaborating on the project.
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.
Security News
PEP 770 proposes adding SBOM support to Python packages to improve transparency and catch hidden non-Python dependencies that security tools often miss.
Security News
Socket CEO Feross Aboukhadijeh discusses open source security challenges, including zero-day attacks and supply chain risks, on the Cyber Security Council podcast.
Security News
Research
Socket researchers uncover how threat actors weaponize Out-of-Band Application Security Testing (OAST) techniques across the npm, PyPI, and RubyGems ecosystems to exfiltrate sensitive data.