|
| 1 | +Configuration |
| 2 | +============= |
| 3 | + |
| 4 | +We must first configure Sentry to allow certain hosts to report errors. |
| 5 | +This prevents abuse so somebody else couldn't start sending errors to your |
| 6 | +account from their site. |
| 7 | + |
| 8 | +**Note**: Without setting this, all messages will be rejected! |
| 9 | + |
| 10 | +This can be found under the *Project Details* page in Sentry. |
| 11 | + |
| 12 | +Now need to set up Raven.js to use your Sentry DSN. |
| 13 | + |
| 14 | +.. code-block:: javascript |
| 15 | +
|
| 16 | + Raven.config('___PUBLIC_DSN___').install() |
| 17 | +
|
| 18 | +At this point, Raven is ready to capture any uncaught exception. |
| 19 | + |
| 20 | +Although, this technically works, this is not going to yield the greatest |
| 21 | +results. It's highly recommended to next check out :doc:`usage`. |
| 22 | + |
| 23 | +Optional settings |
| 24 | +----------------- |
| 25 | + |
| 26 | +``Raven.config()`` can be passed an optional object for extra configuration. |
| 27 | + |
| 28 | +.. describe:: logger |
| 29 | + |
| 30 | + The name of the logger used by Sentry. Default: ``javascript`` |
| 31 | + |
| 32 | + .. code-block:: javascript |
| 33 | +
|
| 34 | + { |
| 35 | + logger: 'javascript' |
| 36 | + } |
| 37 | +
|
| 38 | +.. describe:: release |
| 39 | + |
| 40 | + Track the version of your application in Sentry. |
| 41 | + |
| 42 | + .. code-block:: javascript |
| 43 | +
|
| 44 | + { |
| 45 | + release: '721e41770371db95eee98ca2707686226b993eda' |
| 46 | + } |
| 47 | +
|
| 48 | + Can also be defined with ``Raven.setReleaseContext('721e41770371db95eee98ca2707686226b993eda')``. |
| 49 | + |
| 50 | +.. describe:: tags |
| 51 | + |
| 52 | + Additional `tags <https://www.getsentry.com/docs/tags/>`__ to assign to each event. |
| 53 | + |
| 54 | + .. code-block:: javascript |
| 55 | +
|
| 56 | + { |
| 57 | + tags: {git_commit: 'c0deb10c4'} |
| 58 | + } |
| 59 | +
|
| 60 | +.. _config-whitelist-urls: |
| 61 | + |
| 62 | +.. describe:: whitelistUrls |
| 63 | + |
| 64 | + The inverse of ``ignoreUrls``. Only report errors from whole urls |
| 65 | + matching a regex pattern or an exact string. ``whitelistUrls`` should |
| 66 | + match the url of your actual JavaScript files. It should match the url |
| 67 | + of your site if and only if you are inlining code inside ``<script>`` |
| 68 | + tags. |
| 69 | + |
| 70 | + Does not affect ``captureMessage`` or when non-error object is passed in |
| 71 | + as argument to captureException. |
| 72 | + |
| 73 | + .. code-block:: javascript |
| 74 | +
|
| 75 | + { |
| 76 | + whitelistUrls: [/getsentry\.com/, /cdn\.getsentry\.com/] |
| 77 | + } |
| 78 | +
|
| 79 | +.. describe:: ignoreErrors |
| 80 | + |
| 81 | + Very often, you will come across specific errors that are a result of |
| 82 | + something other than your application, or errors that you're |
| 83 | + completely not interested in. `ignoreErrors` is a list of these |
| 84 | + messages to be filtered out before being sent to Sentry as either |
| 85 | + regular expressions or strings. |
| 86 | + |
| 87 | + Does not affect captureMessage or when non-error object is passed in |
| 88 | + as argument to captureException. |
| 89 | + |
| 90 | + .. code-block:: javascript |
| 91 | +
|
| 92 | + { |
| 93 | + ignoreErrors: ['fb_xd_fragment'] |
| 94 | + } |
| 95 | +
|
| 96 | +.. describe:: ignoreUrls |
| 97 | + |
| 98 | + The inverse of ``whitelistUrls`` and similar to ``ignoreErrors``, but |
| 99 | + will ignore errors from whole urls matching a regex pattern or an |
| 100 | + exact string. |
| 101 | + |
| 102 | + .. code-block:: javascript |
| 103 | +
|
| 104 | + { |
| 105 | + ignoreUrls: [/graph\.facebook\.com/, 'http://example.com/script2.js'] |
| 106 | + } |
| 107 | +
|
| 108 | + Does not affect captureMessage or when non-error object is passed in |
| 109 | + as argument to ``captureException``. |
| 110 | + |
| 111 | +.. describe:: includePaths |
| 112 | + |
| 113 | + An array of regex patterns to indicate which urls are a part of your |
| 114 | + app in the stack trace. All other frames will appear collapsed inside |
| 115 | + Sentry to make it easier to discern between frames that happened in |
| 116 | + your code vs other code. It'd be suggested to add the current page |
| 117 | + url, and the host for your CDN. |
| 118 | + |
| 119 | + .. code-block:: javascript |
| 120 | +
|
| 121 | + { |
| 122 | + includePaths: [/https?:\/\/getsentry\.com/, /https?:\/\/cdn\.getsentry\.com/] |
| 123 | + } |
| 124 | +
|
| 125 | +.. describe:: dataCallback |
| 126 | + |
| 127 | + A function that allows mutation of the data payload right before being |
| 128 | + sent to Sentry. |
| 129 | + |
| 130 | + .. code-block:: javascript |
| 131 | +
|
| 132 | + { |
| 133 | + dataCallback: function(data) { |
| 134 | + // do something to data |
| 135 | + return data; |
| 136 | + } |
| 137 | + } |
| 138 | +
|
| 139 | +.. describe:: shouldSendCallback |
| 140 | + |
| 141 | + A callback function that allows you to apply your own filters to |
| 142 | + determine if the message should be sent to Sentry. |
| 143 | + |
| 144 | + .. code-block:: javascript |
| 145 | +
|
| 146 | + { |
| 147 | + shouldSendCallback: function(data) { |
| 148 | + return false; |
| 149 | + } |
| 150 | + } |
| 151 | +
|
| 152 | +.. describe:: maxMessageLength |
| 153 | + |
| 154 | + By default, raven truncates messages to a max length of 100 |
| 155 | + characters. You can customize the max length with this parameter. |
| 156 | + |
| 157 | +Putting it all together |
| 158 | +----------------------- |
| 159 | + |
| 160 | +.. code-block:: html |
| 161 | + |
| 162 | + <!doctype html> |
| 163 | + <html> |
| 164 | + <head> |
| 165 | + <title>Awesome stuff happening here</title> |
| 166 | + </head> |
| 167 | + <body> |
| 168 | + ... |
| 169 | + <script src="jquery.min.js"></script> |
| 170 | + <script src="//cdn.ravenjs.com/1.1.18/jquery,native/raven.min.js"></script> |
| 171 | + <script> |
| 172 | + Raven.config('___PUBLIC_DSN___', { |
| 173 | + logger: 'my-logger', |
| 174 | + whitelistUrls: [ |
| 175 | + /disqus\.com/, |
| 176 | + /getsentry\.com/ |
| 177 | + ], |
| 178 | + ignoreErrors: [ |
| 179 | + 'fb_xd_fragment', |
| 180 | + /ReferenceError:.*/ |
| 181 | + ], |
| 182 | + includePaths: [ |
| 183 | + /https?:\/\/(www\.)?getsentry\.com/ |
| 184 | + ] |
| 185 | + }).install(); |
| 186 | + </script> |
| 187 | + <script src="myapp.js"></script> |
| 188 | + </body> |
| 189 | + </html> |
| 190 | + |
| 191 | +TraceKit specific optional settings |
| 192 | +----------------------------------- |
| 193 | + |
| 194 | +Usually there is no need to touch these settings, but they exist in case |
| 195 | +you need to tweak something. |
| 196 | + |
| 197 | +.. describe:: fetchContext |
| 198 | + |
| 199 | + Enable TraceKit to attempt to fetch source files to look up anonymous |
| 200 | + function names, this can be useful to enable if you don't get the context |
| 201 | + for some entries in the stack trace. Default value is ``false``. |
| 202 | + |
| 203 | + .. code-block:: javascript |
| 204 | +
|
| 205 | + { |
| 206 | + fetchContext: true |
| 207 | + } |
| 208 | +
|
| 209 | +.. describe:: linesOfContext |
| 210 | + |
| 211 | + The count of lines surrounding the error line that should be used as |
| 212 | + context in the stack trace, default value is ``11``. Only applicable when |
| 213 | + ``fetchContext`` is enabled. |
| 214 | + |
| 215 | + .. code-block:: javascript |
| 216 | +
|
| 217 | + { |
| 218 | + linesOfContext: 11 |
| 219 | + } |
| 220 | +
|
| 221 | +.. describe:: collectWindowErrors |
| 222 | + |
| 223 | + Enable or disable the TraceKit ``window.onerror`` handler, default |
| 224 | + value is ``true``. |
| 225 | + |
| 226 | + .. code-block:: javascript |
| 227 | +
|
| 228 | + { |
| 229 | + collectWindowErrors: true |
| 230 | + } |
0 commit comments