Security News
Fluent Assertions Faces Backlash After Abandoning Open Source Licensing
Fluent Assertions is facing backlash after dropping the Apache license for a commercial model, leaving users blindsided and questioning contributor rights.
@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.
The @sentry/serverless
package was discontinued in version 8.0.0 of the Sentry JavaScript SDKs in favour of dedicated
SDK packages for AWS Lambda and Google Cloud. For more information, head over to the respective v8 migration guides for
Google Cloud and
AWS Lambda.
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:
To use this SDK, call Sentry.AWSLambda.init(options)
at the very beginning of your JavaScript file.
import * as Sentry from '@sentry/serverless';
Sentry.AWSLambda.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!');
});
If you also want to trace performance of all the incoming requests and also outgoing AWS service requests, just set the
tracesSampleRate
option.
import * as Sentry from '@sentry/serverless';
Sentry.AWSLambda.init({
dsn: '__DSN__',
tracesSampleRate: 1.0,
});
Another and much simpler way to integrate Sentry to your AWS Lambda function is to add an official layer.
arn:aws:lambda:us-west-1:TODO:layer:TODO:VERSION
.NODE_OPTIONS
: -r @sentry/serverless/build/npm/cjs/awslambda-auto
.SENTRY_DSN
: your dsn
.SENTRY_TRACES_SAMPLE_RATE
: a number between 0 and 1 representing the chance a transaction is sent to Sentry. For
more information, see
docs.To use this SDK, call Sentry.GCPFunction.init(options)
at the very beginning of your JavaScript file.
import * as Sentry from '@sentry/serverless';
Sentry.GCPFunction.init({
dsn: '__DSN__',
tracesSampleRate: 1.0,
// ...
});
// For HTTP Functions:
exports.helloHttp = Sentry.GCPFunction.wrapHttpFunction((req, res) => {
throw new Error('oh, hello there!');
});
// For Background Functions:
exports.helloEvents = Sentry.GCPFunction.wrapEventFunction((data, context, callback) => {
throw new Error('oh, hello there!');
});
// For CloudEvents:
exports.helloEvents = Sentry.GCPFunction.wrapCloudEventFunction((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 10 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
Fluent Assertions is facing backlash after dropping the Apache license for a commercial model, leaving users blindsided and questioning contributor rights.
Research
Security News
Socket researchers uncover the risks of a malicious Python package targeting Discord developers.
Security News
The UK is proposing a bold ban on ransomware payments by public entities to disrupt cybercrime, protect critical services, and lead global cybersecurity efforts.