|
| 1 | +Electron |
| 2 | +======== |
| 3 | + |
| 4 | +To use Sentry with your Electron application, you will need to use both Raven.js SDKs, one for Browser and one for Node.js. |
| 5 | +Browser SDK is used to report all errors from Electron's ``renderer process``, while Node.js is used to report ``main process`` errors. |
| 6 | + |
| 7 | +On its own, Raven.js will report any uncaught exceptions triggered from your application. For advanced usage examples of Raven.js, please read :doc:`Raven.js usage <../usage>`. |
| 8 | + |
| 9 | +Installation |
| 10 | +------------ |
| 11 | + |
| 12 | +Both packages are available via npm. |
| 13 | + |
| 14 | +.. code-block:: sh |
| 15 | +
|
| 16 | + $ npm install raven raven-js --save |
| 17 | +
|
| 18 | +First, let's configure ``main process``, which uses the Node.js SDK: |
| 19 | + |
| 20 | +.. code-block:: javascript |
| 21 | +
|
| 22 | + var Raven = require('raven'); |
| 23 | +
|
| 24 | + Raven.config('___PUBLIC_DSN___', { |
| 25 | + captureUnhandledRejections: true |
| 26 | + }).install(); |
| 27 | +
|
| 28 | +And now ``renderer process``, which uses the Browser SDK: |
| 29 | + |
| 30 | +.. code-block:: javascript |
| 31 | +
|
| 32 | + var Raven = require('raven-js'); |
| 33 | + Raven.config('___PUBLIC_DSN___').install(); |
| 34 | +
|
| 35 | + window.addEventListener('unhandledrejection', function (event) { |
| 36 | + Raven.captureException(event.reason); |
| 37 | + }); |
| 38 | +
|
| 39 | +This configuration will also take care of unhandled Promise rejections, which can be handled in various ways. By default, Electron uses standard JS API. |
| 40 | +To learn more about handling promises, refer to :doc:`Promises <../usage#promises>` documentation. |
| 41 | + |
| 42 | +Sending environment information |
| 43 | +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 44 | + |
| 45 | +It's often a good idea to send platform information along with a caught error. |
| 46 | +Some things that we can easily add, but are not limited to, are: |
| 47 | + |
| 48 | +- Environment type (browser/renderer) |
| 49 | +- Electron version |
| 50 | +- Chrome version |
| 51 | +- Operation System type |
| 52 | +- Operation System release |
| 53 | + |
| 54 | +You can configure both processes in the same way. To do this, require the standard Node.js module `os` and add a `tags` attribute to your `config` call: |
| 55 | + |
| 56 | +.. code-block:: javascript |
| 57 | +
|
| 58 | + var os = require('os'); |
| 59 | + var Raven = require('raven'); |
| 60 | +
|
| 61 | + Raven.config('___PUBLIC_DSN___', { |
| 62 | + captureUnhandledRejections: true, |
| 63 | + tags: { |
| 64 | + process: process.type, |
| 65 | + electron: process.versions.electron, |
| 66 | + chrome: process.versions.chrome, |
| 67 | + platform: os.platform(), |
| 68 | + platform_release: os.release() |
| 69 | + } |
| 70 | + }).install(); |
0 commit comments