1.1.0 • Published 3 months ago

sentry-vir v1.1.0

Weekly downloads
-
License
(MIT or CC0 1.0)
Repository
github
Last release
3 months ago

sentry-vir

Heroic and opinionated Sentry wrapper.

Installation

npm i sentry-vir

Usage

Full api reference: https://electrovir.github.io/sentry-vir

  • Use initSentry to initialize Sentry.
  • Use sendLog and handleError to send events to Sentry.
  • Use throwWithExtraContext to throw an error while attaching extra event context for Sentry to pick up.

Basic setup example

/**
 * If initializing sentry for node, instead import from 'sentry-vir/dist/esm/node' (for ESM) or
 * 'sentry-vir/dist/cjs/node' (for CommonJS).
 */
import {SentryReleaseEnvEnum} from 'sentry-vir';
import {initSentry} from 'sentry-vir/dist/esm/browser';

initSentry({
    dsn: 'Sentry project id provided by Sentry',
    releaseEnv: SentryReleaseEnvEnum.Dev,
    releaseName: 'my release',
    /** Optional. */
    createUniversalContext() {
        return {
            /** Or any other desired extra context. */
            userTimezone: Intl.DateTimeFormat().resolvedOptions().timeZone,
        };
    },
});

Logging example

import {SentryReleaseEnvEnum, handleError, sendLog, throwWithExtraContext} from 'sentry-vir';
import {initSentry} from 'sentry-vir/dist/esm/browser';

sendLog.info('starting file');
/** Extra log context can be added as the second argument to a sendLog method. */
sendLog.info('starting file 2', {addExtraContext: 'here'});
/** Other severities are covered. */
sendLog.debug('debug log');
/** Logs and errors will be buffered so it's safe to call this before initSentry has been called. */
sendLog.warning('warning log');

/** Standard init. Note that this returns a promise. */
initSentry({
    dsn: 'Sentry project id provided by Sentry',
    releaseEnv: SentryReleaseEnvEnum.Dev,
    releaseName: 'my release',
    createUniversalContext() {
        return {
            /** Or any other desired extra context. */
            userTimezone: Intl.DateTimeFormat().resolvedOptions().timeZone,
        };
    },
});

handleError(new Error('test error'));
/** Extra error context can be added as the second argument to handleError. */
handleError(new Error('test error 2'), {addExtraContext: 'here'});
/** These will be included in the Sentry buffer even if initSentry has not been awaited yet. */
handleError(new Error('test error 2'), {addExtraContext: 'here'});

/** Throw an error with extra context attached for Sentry to pick up. */
throwWithExtraContext(new Error('final error'), {addExtraContext: 'here'});
1.1.0

3 months ago

1.0.1

3 months ago

1.0.0

5 months ago

0.2.3

7 months ago

0.2.5

6 months ago

0.2.4

6 months ago

0.2.2

7 months ago

0.2.1

7 months ago

0.2.0

7 months ago

0.1.2

7 months ago

0.1.1

7 months ago

0.1.0

7 months ago

0.0.4

7 months ago

0.0.3

7 months ago

0.0.2

7 months ago

0.0.1

7 months ago

0.0.0

7 months ago