UNPKG

1.93 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# Official Sentry SDK for Browsers
9
10[![npm version](https://img.shields.io/npm/v/@sentry/browser.svg)](https://www.npmjs.com/package/@sentry/browser)
11[![npm dm](https://img.shields.io/npm/dm/@sentry/browser.svg)](https://www.npmjs.com/package/@sentry/browser)
12[![npm dt](https://img.shields.io/npm/dt/@sentry/browser.svg)](https://www.npmjs.com/package/@sentry/browser)
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## Usage
21
22To use this SDK, call `init(options)` as early as possible after loading the page. This will initialize the SDK and hook
23into the environment. Note that you can turn off almost all side effects using the respective options.
24
25```javascript
26import { init } from '@sentry/browser';
27
28init({
29 dsn: '__DSN__',
30 // ...
31});
32```
33
34To set context information or send manual events, use the exported functions of `@sentry/browser`. Note that these
35functions will not perform any action before you have called `init()`:
36
37```javascript
38import * as Sentry from '@sentry/browser';
39
40// Set user information, as well as tags and further extras
41Sentry.configureScope(scope => {
42 scope.setExtra('battery', 0.7);
43 scope.setTag('user_mode', 'admin');
44 scope.setUser({ id: '4711' });
45 // scope.clear();
46});
47
48// Add a breadcrumb for future events
49Sentry.addBreadcrumb({
50 message: 'My Breadcrumb',
51 // ...
52});
53
54// Capture exceptions, messages or manual events
55Sentry.captureMessage('Hello, world!');
56Sentry.captureException(new Error('Good bye'));
57Sentry.captureEvent({
58 message: 'Manual',
59 stacktrace: [
60 // ...
61 ],
62});
63```