|
3 | 3 | Source Maps
|
4 | 4 | ===========
|
5 | 5 |
|
6 |
| -In various browsers Sentry supports deminifying JavaScript via source |
7 |
| -maps. A source map is a file generated by your minifier which compresses a |
8 |
| -mapping of the minified file to the original uncompressed version(s). |
| 6 | +In various browsers Sentry supports deminifying JavaScript via source maps. A source map is a file generated |
| 7 | +by your minifier which compresses a mapping of the minified file to the original uncompressed version(s). |
9 | 8 |
|
10 |
| -One important thing to note is that even though we support mapping files, |
11 |
| -a users browser may not actually be able to collect the required |
12 |
| -information for the server to generate a sourcemap. |
| 9 | +One important thing to note is that even though we support mapping files, a users browser may not actually be able |
| 10 | +to collect the required information for the server to generate a sourcemap. |
13 | 11 |
|
14 |
| -Sentry requires the following to be able to map tracebacks to their |
15 |
| -source: |
| 12 | +Sentry requires the following to be able to map tracebacks to their source: |
16 | 13 |
|
17 |
| -* A source map header or footer |
18 |
| -* A publicly accessible uncompressed version of the source |
19 |
| -* A line of context that includes a line number, column number, and filename |
| 14 | +* A source map header or footer |
| 15 | +* A publicly accessible uncompressed version of the source |
| 16 | +* A line of context that includes a line number, column number, and filename |
20 | 17 |
|
21 |
| -The first two items are the responsibility of you, the end-user, and you |
22 |
| -can take care of publishing them as part of your build process. The latter |
23 |
| -however, with an individual line of context, is severely crippled in many |
24 |
| -browsers. |
| 18 | +The first two items are the responsibility of you, the end-user, and you can take care of publishing them as part |
| 19 | +of your build process. The latter however, with an individual line of context, is severely crippled in many browsers. |
25 | 20 |
|
26 |
| -One thing to note is that Sentry will attempt to process the source map |
27 |
| -before storing (or grouping) an event. This ensures that if we are able to |
28 |
| -deminify the source, we'll be able to more effectively group similar |
29 |
| -events over time. |
| 21 | +One thing to note is that Sentry will attempt to process the source map before storing (or grouping) an event. This ensures that if we are |
| 22 | +able to deminify the source, we'll be able to more effectively group similar events over time.</p> |
30 | 23 |
|
31 | 24 | Browser Support
|
32 | 25 | ---------------
|
33 | 26 |
|
34 |
| -In our experiences, the only browser that routinely delivers usable error |
35 |
| -reports is Google Chrome. |
| 27 | +In our experiences, the only browser that routinely delivers usable error reports is **Google Chrome**. |
36 | 28 |
|
37 |
| -For additional information, see this more up-to-date wiki page. |
| 29 | +For additional information, see this more up-to-date `wiki page <https://github.com/ryanseddon/source-map/wiki/Source-maps:-languages,-tools-and-other-inf>`_. |
38 | 30 |
|
39 | 31 | Generating a Source Map
|
40 | 32 | -----------------------
|
41 | 33 |
|
42 |
| -While there are several compression libraries which support source maps, |
43 |
| -as of writing our recommendation is to use UglifyJS. |
| 34 | +While there are several compression libraries which support source maps, as of writing our recommendation is to use |
| 35 | +`UglifyJS <https://github.com/mishoo/UglifyJS2>`_. That said, many tools such as `webpack <http://webpack.github.io/>`_ and `browserify <http://browserify.org/>`_. |
44 | 36 |
|
45 |
| -As an example, we can look at the Sentry source code to see how we |
46 |
| -generate internal source maps:: |
| 37 | +As an example, we can look at how we used to do things with Sentry (pre-webpack): |
47 | 38 |
|
48 |
| - node_modules/uglify-js/bin/uglifyjs {input} |
49 |
| - --source-map-root={relroot}/ |
50 |
| - --source-map-url={name}.map.js |
51 |
| - --source-map={relpath}/{name}.map.js -o {output} |
| 39 | +:: |
52 | 40 |
|
53 |
| -We won't attempt to go into the complexities of source maps, so we |
54 |
| -recommend taking a stab at compiling them, and running them against a |
55 |
| -validator. |
| 41 | + node_modules/uglify-js/bin/uglifyjs {input} \ |
| 42 | + --source-map-root={relroot}/ \ |
| 43 | + --source-map-url={name}.map.js \ |
| 44 | + --source-map={relpath}/{name}.map.js -o {output} |
| 45 | + |
| 46 | +We won't attempt to go into the complexities of source maps, so we recommend taking a stab at compiling them, and running them against a validator. |
56 | 47 |
|
57 | 48 | Validating a Source Map
|
58 | 49 | -----------------------
|
59 | 50 |
|
60 |
| -A third party tool is available to validate your source map: |
61 |
| -http://sourcemap-validator.herokuapp.com/ |
| 51 | +We maintain an online validation tool that can be used to test your source (and sourcemaps) against: `sourcemaps.io <http://sourcemaps.io>`_. |
| 52 | + |
| 53 | +Uploading SourceMaps to Sentry |
| 54 | +------------------------------ |
| 55 | + |
| 56 | +In many cases your application may sit behind firewalls or you simply can't expose source code to the public. Sentry provides an abstraction called |
| 57 | +**Releases** which you can attach source artifacts to. |
| 58 | + |
| 59 | +The release API is intended to allow you to store source files (and sourcemaps) within Sentry. This removes the requirement for them to be |
| 60 | +web-accessible, and also removes any inconsistency that could come from network flakiness (on either your end, or Sentry's end). |
| 61 | + |
| 62 | +* Start by creating a new API key under your organization's API Keys nav (on the home). |
| 63 | + |
| 64 | +* Ensure you you have ``project:write`` selected under scopes. |
| 65 | + |
| 66 | +* You'll use HTTP basic auth with the api key being your username, and an empty value for the password. |
| 67 | + |
| 68 | +Now you need to setup your build system to create a release, and attach the various source files. You will want to upload all dist |
| 69 | +files (i.e. the minified/shipped JS), the referenced sourcemaps, and the files that those sourcemaps point to. |
| 70 | + |
| 71 | +.. code-block:: bash |
| 72 | +
|
| 73 | + # Create a new release |
| 74 | + $ curl https://app.getsentry.com/api/0/projects/:organization_slug/:project_slug/releases/ \ |
| 75 | + -u [api_key]: \ |
| 76 | + -X POST \ |
| 77 | + -d '{"version": "abcdef"}' \ |
| 78 | + -H 'Content-Type: application/json' |
| 79 | +
|
| 80 | + { |
| 81 | + "dateCreated": "2015-03-06T04:51:32.723Z", |
| 82 | + "version": "2da95dfb052f477380608d59d32b4ab9" |
| 83 | + } |
| 84 | +
|
| 85 | +.. code-block:: bash |
| 86 | +
|
| 87 | + # Upload a file for the given release |
| 88 | + # Note: The filename should be the *full* url that this |
| 89 | + # would be referenced as in production. |
| 90 | + $ curl https://app.getsentry.com/api/0/projects/:organization_slug/:project_slug/releases/2da95dfb052f477380608d59d32b4ab9/files/ \ |
| 91 | + -u [api_key]: \ |
| 92 | + -X POST \ |
| 93 | + |
| 94 | + -F name="http://example.com/readme.rst" |
| 95 | +
|
| 96 | + { |
| 97 | + "dateCreated": "2015-03-06T04:53:00.308Z", |
| 98 | + "headers": { |
| 99 | + "Content-Type": "application/octet-stream" |
| 100 | + }, |
| 101 | + "id": "1", |
| 102 | + "name": "README.rst", |
| 103 | + "sha1": "22591348ed129fe016c535654f6493737f0f9df6", |
| 104 | + "size": 452 |
| 105 | + } |
| 106 | +
|
| 107 | +.. code-block:: bash |
| 108 | +
|
| 109 | + # If you make a mistake, you can also simply clear out the release |
| 110 | + $ curl https://app.getsentry.com/api/0/projects/:organization_slug/:project_slug/releases/2da95dfb052f477380608d59d32b4ab9/ \ |
| 111 | + -u [api_key]: \ |
| 112 | + -X DELETE |
| 113 | +
|
| 114 | +Additionally, you'll need to configure [raven-js](https://github.com/getsentry/raven-js) to send the ``release``: |
| 115 | + |
| 116 | +.. code-block:: javascript |
| 117 | +
|
| 118 | + Raven.config({ |
| 119 | + release: '2da95dfb052f477380608d59d32b4ab9' |
| 120 | + }); |
| 121 | +
|
| 122 | +Note: You dont *have* to upload the source files (ref'd by sourcemaps), but without them the grouping algorithm will not be as strong, and the UI will not show any contextual source. |
| 123 | + |
| 124 | +Additional information can be found in the `Releases API documentation <https://app.getsentry.com/docs/api/releases/>`_. |
62 | 125 |
|
63 | 126 | .. sentry:edition:: hosted
|
64 | 127 |
|
65 |
| - Source Map Fetching |
66 |
| - ------------------- |
| 128 | + Working Behind a Firewall |
| 129 | + ------------------------- |
67 | 130 |
|
68 |
| - Source maps are dynamically fetched "in reverse". If you are using |
69 |
| - Sentry Cloud then you might want to restrict the access to those |
70 |
| - sourcemaps by IP address. For the IP ranges used by Sentry Cloud and |
71 |
| - how to whitelist access please refer to :doc:`../../ip-ranges`. |
| 131 | + While the recommended solution is to upload your source artifacts to Sentry, sometimes its nescessary to allow communication from Sentry's internal IPs. To |
| 132 | + work around this you can whitelist our `:doc:`IP Ranges <../../ip-ranges>`. |
0 commit comments