@sentry/shim
TypeScript icon, indicating that this package has built-in type declarations

0.5.4 • Public • Published


Sentry JavaScript SDK Shim

npm version npm dm npm dt

A lightweight Sentry SDK shim 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 shim, you do not have to initialize an SDK. This should be handled by the user of your library. Instead, direcly use the exported functions of @sentry/shim to add breadcrumbs or capture events:

import * as Sentry from '@sentry/shim';

// Add a breadcrumb for future events
Sentry.addBreadcrumb({
  message: 'My Breadcrumb',
  // ...
});

// Capture exceptions, messages or manual events
Sentry.captureMessage('Hello, world!');
Sentry.captureException(new Error('Good bye'));
Sentry.captureEvent({
  message: 'Manual',
  stacktrace: [
    // ...
  ],
});

Note that while strictly possible, it is discouraged to interfer 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:

// Set user information, as well as tags and further extras
Sentry.setExtraContext({ battery: 0.7 });
Sentry.setTagsContext({ user_mode: 'admin' });
Sentry.setUserContext({ id: '4711' });

/@sentry/shim/

    Package Sidebar

    Install

    npm i @sentry/shim

    Weekly Downloads

    22

    Version

    0.5.4

    License

    BSD-3-Clause

    Unpacked Size

    72.2 kB

    Total Files

    44

    Last publish

    Collaborators

    • benvinegar
    • billyvg
    • mitsuhiko
    • haza
    • jauer
    • sentry-bot
    • evanpurkhiser
    • lynnagara
    • leedongwei
    • markstory
    • zeeg