Skip to content

Commit 8363af8

Browse files
committed
Add support for tracking releases
Fixes #325
1 parent 15bccd1 commit 8363af8

File tree

3 files changed

+74
-0
lines changed

3 files changed

+74
-0
lines changed

docs/config/index.rst

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,19 @@ The name of the logger used by Sentry. Default: ``javascript``
3535
logger: 'javascript'
3636
}
3737
38+
release
39+
-------
40+
41+
Track the version of your application in Sentry.
42+
43+
.. code-block:: javascript
44+
45+
{
46+
release: '721e41770371db95eee98ca2707686226b993eda'
47+
}
48+
49+
Can also be defined with ``Raven.setReleaseContext('721e41770371db95eee98ca2707686226b993eda')``.
50+
3851
.. _config-whitelist-urls:
3952

4053
tags

src/raven.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -314,6 +314,18 @@ var Raven = {
314314
return Raven;
315315
},
316316

317+
/*
318+
* Set release version of application
319+
*
320+
* @param {string} release Typically something like a git SHA to identify version
321+
* @return {Raven}
322+
*/
323+
setReleaseContext: function(release) {
324+
globalOptions.release = release;
325+
326+
return Raven;
327+
},
328+
317329
/*
318330
* Get the latest raw exception that was captured by Raven.
319331
*
@@ -683,6 +695,9 @@ function send(data) {
683695
data.user = globalUser;
684696
}
685697

698+
// Include the release iff it's defined in globalOptions
699+
if (globalOptions.release) data.release = globalOptions.release;
700+
686701
if (isFunction(globalOptions.dataCallback)) {
687702
data = globalOptions.dataCallback(data);
688703
}

test/raven.test.js

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ function flushRavenState() {
88
globalProject = undefined;
99
globalOptions = {
1010
logger: 'javascript',
11+
release: undefined,
1112
ignoreErrors: [],
1213
ignoreUrls: [],
1314
whitelistUrls: [],
@@ -1008,6 +1009,38 @@ describe('globals', function() {
10081009
extra: {'session:duration': 100}
10091010
});
10101011
});
1012+
1013+
it('should attach release if available', function() {
1014+
this.sinon.stub(window, 'isSetup').returns(true);
1015+
this.sinon.stub(window, 'makeRequest');
1016+
this.sinon.stub(window, 'getHttpData').returns({
1017+
url: 'http://localhost/?a=b',
1018+
headers: {'User-Agent': 'lolbrowser'}
1019+
});
1020+
1021+
globalOptions = {
1022+
projectId: 2,
1023+
logger: 'javascript',
1024+
release: 'abc123',
1025+
};
1026+
1027+
send({foo: 'bar'});
1028+
assert.deepEqual(window.makeRequest.lastCall.args[0], {
1029+
project: '2',
1030+
release: 'abc123',
1031+
logger: 'javascript',
1032+
platform: 'javascript',
1033+
request: {
1034+
url: 'http://localhost/?a=b',
1035+
headers: {
1036+
'User-Agent': 'lolbrowser'
1037+
}
1038+
},
1039+
event_id: 'abc123',
1040+
foo: 'bar',
1041+
extra: {'session:duration': 100}
1042+
});
1043+
});
10111044
});
10121045

10131046
describe('makeRequest', function() {
@@ -1560,6 +1593,19 @@ describe('Raven (public API)', function() {
15601593
});
15611594
});
15621595

1596+
describe('.setReleaseContext', function() {
1597+
it('should set the globalOptions.release attribute', function() {
1598+
Raven.setReleaseContext('abc123');
1599+
assert.equal(globalOptions.release, 'abc123');
1600+
});
1601+
1602+
it('should clear globalOptions.release with no arguments', function() {
1603+
globalOptions.release = 'abc123';
1604+
Raven.setReleaseContext();
1605+
assert.isUndefined(globalOptions.release);
1606+
});
1607+
});
1608+
15631609
describe('.captureMessage', function() {
15641610
it('should work as advertised', function() {
15651611
this.sinon.stub(window, 'send');

0 commit comments

Comments
 (0)