UNPKG

2.29 kBMarkdownView Raw
1<p align="center">
2 <a href="https://sentry.io" target="_blank" align="center">
3 <img src="https://sentry-brand.storage.googleapis.com/sentry-logo-black.png" width="280">
4 </a>
5 <br />
6</p>
7
8# Sentry JavaScript SDK Minimal
9
10[![npm version](https://img.shields.io/npm/v/@sentry/minimal.svg)](https://www.npmjs.com/package/@sentry/minimal)
11[![npm dm](https://img.shields.io/npm/dm/@sentry/minimal.svg)](https://www.npmjs.com/package/@sentry/minimal)
12[![npm dt](https://img.shields.io/npm/dt/@sentry/minimal.svg)](https://www.npmjs.com/package/@sentry/minimal)
13[![typedoc](https://img.shields.io/badge/docs-typedoc-blue.svg)](http://getsentry.github.io/sentry-javascript/)
14
15## Links
16
17- [Official SDK Docs](https://docs.sentry.io/quickstart/)
18- [TypeDoc](http://getsentry.github.io/sentry-javascript/)
19
20## General
21
22A minimal Sentry SDK that uses a configured client when embedded into an application. It allows library authors add
23support for a Sentry SDK without having to bundle the entire SDK or being dependent on a specific platform. If the user
24is using Sentry in their application and your library uses `@sentry/minimal`, the user receives all
25breadcrumbs/messages/events you added to your libraries codebase.
26
27## Usage
28
29To use the minimal, you do not have to initialize an SDK. This should be handled by the user of your library. Instead,
30directly use the exported functions of `@sentry/minimal` to add breadcrumbs or capture events:
31
32```javascript
33import * as Sentry from '@sentry/minimal';
34
35// Add a breadcrumb for future events
36Sentry.addBreadcrumb({
37 message: 'My Breadcrumb',
38 // ...
39});
40
41// Capture exceptions, messages or manual events
42Sentry.captureMessage('Hello, world!');
43Sentry.captureException(new Error('Good bye'));
44Sentry.captureEvent({
45 message: 'Manual',
46 stacktrace: [
47 // ...
48 ],
49});
50```
51
52Note that while strictly possible, it is discouraged to interfere with the event context. If for some reason your
53library needs to inject context information, beware that this might override the user's context values:
54
55```javascript
56// Set user information, as well as tags and further extras
57Sentry.configureScope(scope => {
58 scope.setExtra('battery', 0.7);
59 scope.setTag('user_mode', 'admin');
60 scope.setUser({ id: '4711' });
61 // scope.clear();
62});
63```