What is @sentry/minimal?
The @sentry/minimal package is a core part of the Sentry SDK for JavaScript, which is designed for error tracking and monitoring in applications. It provides a minimalistic interface to capture exceptions and messages, allowing developers to report errors to Sentry without needing the full Sentry SDK. This can be particularly useful for lightweight applications or specific use cases where the full functionality of Sentry is not required.
What are @sentry/minimal's main functionalities?
Capture exceptions
This feature allows developers to manually capture exceptions and send them to Sentry for monitoring and analysis. It's useful for catching and reporting errors that occur in try-catch blocks or in parts of the application where automatic error capturing isn't feasible.
Sentry.captureException(new Error('Something went wrong'));
Capture messages
This functionality enables the sending of custom messages to Sentry. It's useful for tracking events or states in the application that aren't necessarily errors but are significant enough to be monitored.
Sentry.captureMessage('Something important happened');
Other packages similar to @sentry/minimal
raven-js
Raven-js is the legacy JavaScript client for Sentry. It offers similar functionalities to @sentry/minimal, such as capturing exceptions and messages. However, it's no longer actively maintained, and users are encouraged to migrate to the newer Sentry SDK (@sentry/browser) for improved features and support.
bugsnag-js
Bugsnag-js is an error monitoring and reporting tool for JavaScript applications. Like @sentry/minimal, it provides features for capturing exceptions and custom events. Bugsnag offers a different interface and additional features such as release tracking and user sessions, making it a more comprehensive solution compared to the minimalistic approach of @sentry/minimal.
logrocket
LogRocket is a logging and session replay platform for JavaScript applications. While it focuses more on recording and replaying user sessions to identify UI issues, it also offers error tracking capabilities. Compared to @sentry/minimal, LogRocket provides a broader set of features aimed at understanding user interactions and experiences in addition to error monitoring.
Sentry JavaScript SDK Minimal
A lightweight Sentry SDK minimal that uses a configured client when embedded
into an application. It allows library authors add support for a Sentry SDK
without having to bundle the entire SDK or being dependent on a specific
platform.
Usage
To use the minimal, you do not have to initialize an SDK. This should be handled
by the user of your library. Instead, directly use the exported functions of
@sentry/minimal
to add breadcrumbs or capture events:
import * as Sentry from '@sentry/minimal';
Sentry.addBreadcrumb({
message: 'My Breadcrumb',
});
Sentry.captureMessage('Hello, world!');
Sentry.captureException(new Error('Good bye'));
Sentry.captureEvent({
message: 'Manual',
stacktrace: [
],
});
Note that while strictly possible, it is discouraged to interfere with the event
context. If for some reason your library needs to inject context information,
beware that this might override the user's context values:
Sentry.configureScope(scope => {
scope.setExtra('battery', 0.7);
scope.setTag('user_mode', 'admin');
scope.setUser({ id: '4711' });
});