Skip to content

Commit 81ff5e7

Browse files
committed
Merge pull request #1 from duizendnegen/master
fill a meta tag with the current revision when uploading
2 parents bac4e5f + 5bde898 commit 81ff5e7

File tree

2 files changed

+53
-20
lines changed

2 files changed

+53
-20
lines changed

README.md

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -36,28 +36,33 @@ ENV.sentry {
3636
```
3737
- Integrate [raven-js][2] in your page
3838

39-
It's important to initialize the client with `release` as the `revisionKey`.
40-
You will probably need to either write the `revisionKey` into your `index.html` file at build time or when serving it.
41-
42-
For example add this to your `index.html` and dynamically replace the `$REVISION` string with `revisionKey`:
39+
By default a meta tag with the key name `sentry:revision` is inserted in your index.html, like so
4340
```html
44-
<meta name="revision" content="$REVISION">
41+
<meta name="sentry:revision" content="(revision)">
42+
```
43+
44+
Disabling this behavior is done by configuring in `deploy.js`:
45+
```javascript
46+
ENV.sentry {
47+
// ... other config options
48+
enableRevisionTagging: false
49+
}
4550
```
4651

47-
Then when you setup [raven-js][2] you can retrieve it like so:
52+
When you setup [raven-js][2] you can retrieve it like so:
4853

4954
```javascript
5055
Raven.config({
51-
release: $("meta[name='revision']").attr('content')
56+
release: $("meta[name='sentry:revision']").attr('content')
5257
});
5358
```
5459

5560
Last but not least make sure to setup proper exception catching like [this](https://github.com/getsentry/raven-js/blob/master/plugins/ember.js).
5661

5762

58-
We don't use it (yet), but [ember-cli-sentry](https://github.com/damiencaselli/ember-cli-sentry) is probably useful to get started quickly. (It also sets up the exception handlers for you)
59-
Apparently for it to work you will need to set `revisionKey` to your application's `config.APP.version` or set [raven-js][2]'s `release` option later via
60-
`Raven.setReleaseContext($("meta[name='revision']").attr('content'))`.
63+
Also, [ember-cli-sentry](https://github.com/damiencaselli/ember-cli-sentry) is useful to get started quickly. (It also sets up the exception handlers for you)
64+
For it to work you will need to set `revisionKey` to your application's `config.APP.version` or set [raven-js][2]'s `release` option later via
65+
`Raven.setReleaseContext($("meta[name='sentry:revision']").attr('content'))`. Doing this automatically
6166

6267
- Build sourcemaps in production environment
6368

index.js

Lines changed: 38 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,12 @@ var fs = require('fs');
1313
module.exports = {
1414
name: 'ember-cli-deploy-sentry',
1515

16+
contentFor: function(type, config) {
17+
if (type === 'head-footer') {
18+
return '<meta name="sentry:revision"></meta>';
19+
}
20+
},
21+
1622
createDeployPlugin: function(options) {
1723
var DeployPlugin = DeployPluginBase.extend({
1824
name: options.name,
@@ -24,6 +30,7 @@ module.exports = {
2430
revisionKey: function(context) {
2531
return context.revisionData && context.revisionData.revisionKey;
2632
},
33+
enableRevisionTagging: true,
2734

2835
didDeployMessage: function(context){
2936
return "Uploaded sourcemaps to sentry release: "
@@ -46,9 +53,30 @@ module.exports = {
4653
this.log('config ok');
4754
},
4855

56+
willUpload: function(context) {
57+
var isEnabled = this.readConfig('enableRevisionTagging');
58+
if(!isDisabled) {
59+
return;
60+
}
61+
62+
var revisionKey = this.readConfig('revisionKey');
63+
if(!revisionKey) {
64+
return new SilentError("Could not find revision key to fingerprint Sentry revision with.");
65+
}
66+
67+
// TODO instead of plainly reading index.html, minimatch
68+
// getConfig('revision patterns') on context.distFiles
69+
var indexPath = path.join(context.distDir, "index.html");
70+
var index = fs.readFileSync(indexPath, 'utf8');
71+
var index = index.replace('<meta name="sentry:revision">',
72+
'<meta name="sentry:revision" content="'+revisionKey+'">');
73+
74+
fs.writeFileSync(indexPath, index);
75+
},
76+
4977
_createRelease: function createRelease(sentrySettings) {
5078
var url = urljoin(sentrySettings.url, '/api/0/projects/', sentrySettings.organizationSlug, sentrySettings.projectSlug, '/releases/');
51-
79+
5280
return request({
5381
uri: url,
5482
method: 'POST',
@@ -64,7 +92,7 @@ module.exports = {
6492
},
6593
_deleteRelease: function createRelease(sentrySettings) {
6694
var url = urljoin(sentrySettings.url, '/api/0/projects/', sentrySettings.organizationSlug, sentrySettings.projectSlug, '/releases/', sentrySettings.release) + '/';
67-
95+
6896
return request({
6997
uri: url,
7098
method: 'DELETE',
@@ -78,7 +106,7 @@ module.exports = {
78106
resolveWithFullResponse: true
79107
});
80108
},
81-
109+
82110
_getUploadFiles: function getUploadFiles(dir, filePattern) {
83111
var pattern = path.join(dir, filePattern);
84112
return new Promise(function(resolve, reject) {
@@ -94,17 +122,17 @@ module.exports = {
94122
return files.map(function(file) {
95123
return path.relative(dir, file);
96124
});
97-
});
125+
});
98126
},
99-
127+
100128
_uploadFile: function uploadFile(sentrySettings, distDir, filePath) {
101129
var url = urljoin(sentrySettings.url, '/api/0/projects/', sentrySettings.organizationSlug, sentrySettings.projectSlug, '/releases/', sentrySettings.release, '/files/');
102-
130+
103131
var formData = {
104132
name: urljoin(sentrySettings.publicUrl, filePath),
105133
file: fs.createReadStream(path.join(distDir, filePath))
106134
};
107-
135+
108136
return request({
109137
method: 'POST',
110138
uri: url,
@@ -114,7 +142,7 @@ module.exports = {
114142
formData: formData
115143
});
116144
},
117-
145+
118146
_getReleaseFiles: function getReleaseFiles(sentrySettings) {
119147
var url = urljoin(sentrySettings.url, '/api/0/projects/', sentrySettings.organizationSlug, sentrySettings.projectSlug, '/releases/', sentrySettings.release, '/files') + '/';
120148
return request({
@@ -141,15 +169,15 @@ module.exports = {
141169
release: plugin.readConfig('revisionKey')
142170
};
143171
var filePattern = this.readConfig('filePattern');
144-
172+
145173
if(!sentrySettings.release) {
146174
throw new SilentError('revisionKey setting is not available, either provide it manually or make sure the ember-cli-deploy-revision-data plugin is loaded');
147175
}
148176
return this._deleteRelease(sentrySettings).then(function() {}, function() {}).then(function() {
149177
return plugin._createRelease(sentrySettings).then(function(response) {
150178
return plugin._getUploadFiles(distDir, filePattern).then(function(files) {
151179
var uploads = [];
152-
for(var i=0;i<files.length;i++) {
180+
for(var i=0;i<files.length;i++) {
153181
var file = files[i];
154182
uploads.push(plugin._uploadFile(sentrySettings, distDir, files[i]));
155183
}

0 commit comments

Comments
 (0)