Skip to content

Commit 2d220ee

Browse files
committed
Docs 1.x overhaul (#249)
* Integration example docs * working on context stuff * WIP * Added config stuff on breadcrumbs, cleaned up index overview * Update usage docs with all the things * Address Ben's feedback
1 parent 4fdced7 commit 2d220ee

File tree

6 files changed

+370
-126
lines changed

6 files changed

+370
-126
lines changed

docs/config.rst

Lines changed: 56 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,28 @@
11
Configuration
22
=============
33

4-
Configuration is passed as the second argument of the ``raven.Client`` constructor:
4+
To get started, you need to configure Raven to use your Sentry DSN:
55

6-
.. code-block:: javascript
6+
.. sourcecode:: javascript
77

8-
var raven = require("raven");
8+
var Raven = require('raven');
9+
Raven.config('___PUBLIC_DSN___').install()
910

10-
new raven.Client(String dsn[, Object options])
11+
At this point, Raven is ready to capture any uncaught exceptions.
1112

1213
Optional settings
1314
-----------------
1415

16+
``Raven.config()`` can optionally be passed an additional argument for extra configuration:
17+
18+
.. sourcecode:: javascript
19+
20+
Raven.config('___PUBLIC_DSN___', {
21+
release: '1.3.0'
22+
}).install()
23+
24+
Those configuration options are documented below:
25+
1526
.. describe:: logger
1627

1728
The name of the logger used by Sentry. Default: ``''``
@@ -81,6 +92,47 @@ Optional settings
8192
}
8293
}
8394
95+
.. describe:: shouldSendCallback
96+
97+
A callback function that allows you to apply your own filters to determine if the event should be sent to Sentry.
98+
99+
.. code-block:: javascript
100+
101+
{
102+
shouldSendCallback: function (data) {
103+
// randomly omit half of events
104+
return Math.random() > 0.5;
105+
}
106+
}
107+
108+
.. describe:: autoBreadcrumbs
109+
110+
Enables/disables automatic collection of breadcrumbs. Possible values are:
111+
112+
* `false` - all automatic breadcrumb collection disabled (default)
113+
* `true` - all automatic breadcrumb collection enabled
114+
* A dictionary of individual breadcrumb types that can be enabled/disabled:
115+
116+
.. code-block:: javascript
117+
118+
autoBreadcrumbs: {
119+
'console': false, // console logging
120+
'http': true, // http and https requests
121+
'postgres': true, // postgresql queries from pg module
122+
}
123+
124+
.. describe:: maxBreadcrumbs
125+
126+
Raven captures up to 30 breadcrumb entries by default. You can increase this to
127+
be as high as 100, or reduce it if you find 30 is too noisy, by setting `maxBreadcrumbs`.
128+
129+
Note that in very high-concurrency situations where you might have a large number of
130+
long-lived contexts each with a large number of associated breadcrumbs, there is potential
131+
for significant memory usage. 10,000 contexts with 10kB of breadcrumb data each will use
132+
around 120mB of memory. Most applications will be nowhere close to either of these numbers,
133+
but if yours might be, you can use the `maxBreadcrumbs` parameter to limit the amount of
134+
breadcrumb data each context will keep around.
135+
84136
.. describe:: transport
85137

86138
Override the default HTTP data transport handler.

docs/index.rst

Lines changed: 62 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
Node.js
1111
=======
1212

13-
raven-node is a Sentry's officially supported Node.js SDK.
13+
raven-node is the official Node.js client for Sentry.
1414

1515
**Note**: If you're using JavaScript in the browser, you'll need
1616
`raven-js <https://github.com/getsentry/raven-js>`_.
@@ -32,55 +32,91 @@ Next you need to initialize the Raven client and configure it to use your `Sentr
3232

3333
.. code-block:: javascript
3434
35-
var raven = require('raven');
36-
var client = new raven.Client('___DSN___');
35+
var Raven = require('raven');
36+
Raven.config('___DSN___').install();
3737
38-
You can optionally pass an object of configuration options as the 2nd argument to `Client`. For
38+
At this point, Raven is set up to capture and report any uncaught exceptions.
39+
40+
You can optionally pass an object of configuration options as the 2nd argument to `Raven.config`. For
3941
more information, see :doc:`config`.
4042

4143
Reporting Errors
4244
----------------
4345

44-
To get started passing errors to Raven, it is recommended to initialize Raven's global error handler using
45-
``patchGlobal``. This will cause any uncaught exception which would bubble up to the Node runtime to be
46-
captured and processed by Raven.
46+
Raven's ``install`` method sets up a global handler to automatically capture any uncaught exceptions. You can also report errors manually with ``try...catch`` and
47+
a call to ``captureException``:
4748

4849
.. code-block:: javascript
4950
50-
client.patchGlobal();
51+
try {
52+
doSomething(a[0]);
53+
} catch (e) {
54+
Raven.captureException(e);
55+
}
5156
52-
Additionally, you can manually capture and report potentially problematic code with ``try...catch`` and
53-
``captureException``:
57+
You can also use ``wrap`` and ``context`` to have Raven wrap a function and automatically capture any exceptions it throws:
5458

5559
.. code-block:: javascript
5660
57-
try {
58-
doSomething(a[0])
59-
} catch(e) {
60-
client.captureException(e)
61-
}
61+
Raven.context(function () {
62+
doSomething(a[0]);
63+
});
6264
63-
The ``captureException`` method optionally takes an object of configuration options as the 2nd argument. For more information, and to learn about other methods provided by the Raven API, see :doc:`usage`.
65+
For more information on reporting errors, see :doc:`usage`.
6466

6567
Adding Context
6668
--------------
6769

68-
While a user is logged in, you can tell Sentry to associate errors with
69-
user data. This data is then submitted with each error which allows you
70-
to figure out which users are affected.
70+
Code run via ``wrap`` or ``context`` has an associated set of context data, and Raven provides methods for managing that data.
71+
72+
You'll most commonly use this to associate the current user with an exception:
7173

7274
.. code-block:: javascript
7375
74-
client.setUserContext({
76+
Raven.context(function () {
77+
Raven.setContext({
78+
user: {
7579
7680
id: '123'
77-
})
81+
}
82+
});
83+
// errors thrown here will be associated with matt
84+
});
85+
// errors thrown here will not be associated with matt
86+
87+
This can also be used to set ``tags`` and ``extra`` keys for associated tags and extra data.
88+
89+
You can update the context data with ``mergeContext`` or retrieve it with ``getContext``. When an exception is captured by a wrapper, the current context state will be passed as options to ``captureException``.
90+
91+
See :ref:`raven-node-additional-context` for more.
92+
93+
Breadcrumbs
94+
-----------
95+
96+
Breadcrumbs are records of server and application lifecycle events that can be helpful in understanding the state of the application leading up to a crash.
97+
98+
We can capture breadcrumbs and associate them with a context, and then send them along with any errors captured from that context:
99+
100+
.. code-block:: javascript
101+
102+
Raven.context(function () {
103+
Raven.captureBreadcrumb({
104+
message: 'Received payment confirmation',
105+
category: 'payment',
106+
data: {
107+
amount: 312,
108+
}
109+
});
110+
// errors thrown here will have breadcrumb attached
111+
});
112+
113+
Raven can be configured to automatically capture breadcrubs for certain events including:
78114

79-
If at any point, the user becomes unauthenticated, you can call
80-
``client.setUserContext()`` with no arguments to remove their data.
115+
* http/https requests
116+
* console log statements
117+
* postgres queries
81118

82-
Other similar methods are ``client.setExtraContext`` and
83-
``client.setTagsContext``. See :ref:`raven-node-additional-context` for more info.
119+
For more information, see :ref:`raven-recording-breadcrumbs`.
84120

85121
Middleware and Integrations
86122
---------------------------
@@ -91,7 +127,7 @@ to configure one of Raven's server middleware integrations. See doc:`integration
91127
Deep Dive
92128
---------
93129

94-
For more detailed information about how to get most out of Raven.js there
130+
For more detailed information about how to get most out of Raven there
95131
is additional documentation available that covers all the rest:
96132

97133
.. toctree::

docs/integrations/connect.rst

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,10 @@ Connect
44
.. code-block:: javascript
55
66
var connect = require('connect');
7-
var raven = require('raven');
7+
var Raven = require('raven');
8+
9+
// Must configure Raven before doing anything else with it
10+
Raven.config('___DSN___').install();
811
912
function mainHandler(req, res) {
1013
throw new Error('Broke!');
@@ -14,19 +17,19 @@ Connect
1417
// The error id is attached to `res.sentry` to be returned
1518
// and optionally displayed to the user for support.
1619
res.statusCode = 500;
17-
res.end(res.sentry+'\n');
20+
res.end(res.sentry + '\n');
1821
}
1922
2023
connect(
2124
// The request handler be the first item
22-
raven.middleware.connect.requestHandler('___DSN___'),
25+
Raven.requestHandler(),
2326
2427
connect.bodyParser(),
2528
connect.cookieParser(),
2629
mainHandler,
2730
2831
// The error handler must be before any other error middleware
29-
raven.middleware.connect.errorHandler('___DSN___'),
32+
Raven.errorHandler(),
3033
3134
// Optional fallthrough error handler
3235
onError,

docs/integrations/express.rst

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,26 +4,27 @@ Express
44
.. code-block:: javascript
55
66
var app = require('express')();
7-
var raven = require('raven');
7+
var Raven = require('raven');
88
9-
function onError(err, req, res, next) {
10-
// The error id is attached to `res.sentry` to be returned
11-
// and optionally displayed to the user for support.
12-
res.statusCode = 500;
13-
res.end(res.sentry+'\n');
14-
}
9+
// Must configure Raven before doing anything else with it
10+
Raven.config('__DSN__').install();
1511
16-
// The request handler must be the first item
17-
app.use(raven.middleware.express.requestHandler('___DSN___'));
12+
// The request handler must be the first middleware on the app
13+
app.use(Raven.requestHandler());
1814
1915
app.get('/', function mainHandler(req, res) {
2016
throw new Error('Broke!');
2117
});
2218
2319
// The error handler must be before any other error middleware
24-
app.use(raven.middleware.express.errorHandler('___DSN___'));
20+
app.use(Raven.errorHandler());
2521
2622
// Optional fallthrough error handler
27-
app.use(onError);
23+
app.use(function onError(err, req, res, next) {
24+
// The error id is attached to `res.sentry` to be returned
25+
// and optionally displayed to the user for support.
26+
res.statusCode = 500;
27+
res.end(res.sentry + '\n');
28+
});
2829
2930
app.listen(3000);

docs/integrations/koa.rst

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,15 @@ Koa
44
.. code-block:: javascript
55
66
var koa = require('koa');
7-
var raven = require('raven');
7+
var Raven = require('raven');
88
99
var app = koa();
10-
var sentry = new raven.Client('___DSN___');
10+
Raven.config('___DSN___').install();
1111
12-
app.on('error', function(err) {
13-
sentry.captureException(err);
12+
app.on('error', function (err) {
13+
sentry.captureException(err, function (err, eventId) {
14+
console.log('Reported error ' + eventId);
15+
});
1416
});
1517
1618
app.listen(3000);

0 commit comments

Comments
 (0)