UNPKG

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