Skip to content
This repository was archived by the owner on Apr 3, 2019. It is now read-only.

Commit 18ddbf6

Browse files
authored
feat(sentry): move sentry release version to front-end (#4220) r=vbudhram
Fixes #3474
1 parent 9af4895 commit 18ddbf6

File tree

5 files changed

+38
-8
lines changed

5 files changed

+38
-8
lines changed

app/scripts/lib/app-start.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,11 @@ define(function (require, exports, module) {
172172
},
173173

174174
enableSentryMetrics () {
175-
this._sentryMetrics = new SentryMetrics(this._window.location.host);
175+
let release;
176+
if (this._config && this._config.release) {
177+
release = this._config.release;
178+
}
179+
this._sentryMetrics = new SentryMetrics(this._window.location.host, release);
176180
},
177181

178182
initializeL10n () {

app/scripts/lib/sentry.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,10 +130,12 @@ define(function (require, exports, module) {
130130
* Read more at https://github.com/getsentry/raven-js
131131
*
132132
* @param {String} host
133+
* @param {String} [release] - content server release version
133134
* @constructor
134135
*/
135-
function SentryMetrics (host) {
136+
function SentryMetrics (host, release) {
136137
this._logger = new Logger();
138+
this._release = release;
137139

138140
if (host) {
139141
// use __API_KEY__ instead of the real API key because raven.js requires it
@@ -202,6 +204,11 @@ define(function (require, exports, module) {
202204
tags: tags
203205
};
204206

207+
if (this._release) {
208+
// add release version if available
209+
extraContext.release = this._release;
210+
}
211+
205212
Raven.captureException(err, extraContext);
206213
},
207214

app/tests/spec/lib/sentry.js

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -208,8 +208,8 @@ define(function (require, exports, module) {
208208
// do not call the real captureException,
209209
// no need to make network requests.
210210
sandbox.stub(Raven, 'captureException', function () {});
211-
212-
var sentry = new SentryMetrics(host);
211+
var release = '0.1.0';
212+
var sentry = new SentryMetrics(host, release);
213213

214214
var err = new Error('uh oh');
215215
err.code = 400;
@@ -222,6 +222,7 @@ define(function (require, exports, module) {
222222
sentry.captureException(err);
223223

224224
assert.isTrue(Raven.captureException.calledWith(err, {
225+
release: release,
225226
tags: {
226227
code: 400,
227228
context: '/signup',
@@ -233,6 +234,24 @@ define(function (require, exports, module) {
233234

234235
sandbox.restore();
235236
});
237+
238+
it('reports the error even if release version is not set', function () {
239+
var sandbox = sinon.sandbox.create();
240+
sandbox.stub(Raven, 'captureException', function () {});
241+
var sentry = new SentryMetrics(host);
242+
243+
var err = new Error('uh oh');
244+
err.code = 400;
245+
246+
sentry.captureException(err);
247+
assert.isTrue(Raven.captureException.calledWith(err, {
248+
tags: {
249+
code: 400
250+
}
251+
}));
252+
253+
sandbox.restore();
254+
});
236255
});
237256

238257
describe('shouldSendCallback', function () {

server/lib/routes/get-index.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ module.exports = function (config) {
1515
var OAUTH_SERVER_URL = config.get('oauth_url');
1616
var PROFILE_SERVER_URL = config.get('profile_url');
1717
var STATIC_RESOURCE_URL = config.get('static_resource_url');
18+
// add version from package.json to config
19+
var RELEASE = require('../../../package.json').version;
1820

1921
var serializedConfig = encodeURIComponent(JSON.stringify({
2022
allowedParentOrigins: ALLOWED_PARENT_ORIGINS,
@@ -24,7 +26,8 @@ module.exports = function (config) {
2426
marketingEmailServerUrl: MARKETING_EMAIL_API_URL,
2527
oAuthClientId: CLIENT_ID,
2628
oAuthUrl: OAUTH_SERVER_URL,
27-
profileUrl: PROFILE_SERVER_URL
29+
profileUrl: PROFILE_SERVER_URL,
30+
release: RELEASE
2831
}));
2932

3033
var route = {};

server/lib/routes/post-metrics-errors.js

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ var sentryConfig = config.get('sentry');
1313
var API_KEY = sentryConfig.api_key;
1414
var API_SECRET = sentryConfig.api_secret;
1515
var STACK_TRACE_LENGTH = 20;
16-
var CONTENT_SERVER_VERSION = require('../../../package.json').version;
1716

1817
/**
1918
* Attaches extra tags to sentry data
@@ -30,8 +29,6 @@ function setExtraSentryData(data) {
3029
}
3130

3231
if (sentryData) {
33-
sentryData.release = CONTENT_SERVER_VERSION;
34-
3532
if (sentryData.stacktrace && sentryData.stacktrace.frames) {
3633
// the limit for the sentryRequest is controlled by nginx,
3734
// by default the request url should not be greater than ~8000 characters.

0 commit comments

Comments
 (0)