Skip to content

Commit 2be35b4

Browse files
committed
Change captureBreadcrumb api to accept crumb name, crumb data
1 parent 99cf147 commit 2be35b4

File tree

3 files changed

+52
-58
lines changed

3 files changed

+52
-58
lines changed

src/raven.js

Lines changed: 24 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -354,10 +354,14 @@ Raven.prototype = {
354354
return this;
355355
},
356356

357-
captureBreadcrumb: function (obj) {
358-
obj.timestamp = (obj.timestamp || now()) / 1000;
357+
captureBreadcrumb: function (type, data) {
358+
var crumb = {
359+
type: type,
360+
timestamp: now() / 1000,
361+
data: data
362+
};
359363

360-
this._breadcrumbs.push(obj);
364+
this._breadcrumbs.push(crumb);
361365
if (this._breadcrumbs.length > this._breadcrumbLimit) {
362366
this._breadcrumbs.shift();
363367
}
@@ -631,12 +635,9 @@ Raven.prototype = {
631635

632636
self._lastCapturedEvent = evt;
633637
var elem = evt.target;
634-
self.captureBreadcrumb({
635-
type: 'ui_event',
636-
data: {
637-
type: evtName,
638-
target: htmlElementAsString(elem)
639-
}
638+
self.captureBreadcrumb('ui_event', {
639+
type: evtName,
640+
target: htmlElementAsString(elem)
640641
});
641642
};
642643
},
@@ -750,10 +751,7 @@ Raven.prototype = {
750751
// an exception
751752
xhr.__raven_xhr.statusCode = xhr.status;
752753
} catch (e) { /* do nothing */ }
753-
self.captureBreadcrumb({
754-
type: 'http_request',
755-
data: xhr.__raven_xhr
756-
});
754+
self.captureBreadcrumb('http_request', xhr.__raven_xhr);
757755
}
758756
return self.wrap(orig);
759757
}, true /* noUndo */); // don't track filled methods on XHR instances
@@ -769,12 +767,9 @@ Raven.prototype = {
769767
// TODO: remove onpopstate handler on uninstall()
770768
var oldOnPopState = window.onpopstate;
771769
window.onpopstate = function () {
772-
self.captureBreadcrumb({
773-
type: 'navigation',
774-
data: {
775-
from: self._lastHref,
776-
to: location.href
777-
}
770+
self.captureBreadcrumb('navigation', {
771+
from: self._lastHref,
772+
to: location.href
778773
});
779774

780775
// because onpopstate only tells you the "new" (to) value of location.href, and
@@ -791,12 +786,9 @@ Raven.prototype = {
791786
// params to preserve 0 arity
792787
return function(/* state, title, url */) {
793788
var url = arguments.length > 2 ? arguments[2] : undefined;
794-
self.captureBreadcrumb({
795-
type: 'navigation',
796-
data: {
797-
to: url,
798-
from: location.href
799-
}
789+
self.captureBreadcrumb('navigation', {
790+
to: url,
791+
from: location.href
800792
});
801793
if (url) self._lastHref = url;
802794
return origPushState.apply(this, arguments);
@@ -809,13 +801,10 @@ Raven.prototype = {
809801
consolePlugin(self, console, {
810802
levels: ['debug', 'info', 'warn', 'error', 'log'],
811803
callback: function (msg, data) {
812-
self.captureBreadcrumb({
813-
type: 'message',
814-
data: {
815-
level: data.level,
816-
message: msg
817-
}
818-
})
804+
self.captureBreadcrumb('message', {
805+
level: data.level,
806+
message: msg
807+
});
819808
}
820809
});
821810
}
@@ -1147,12 +1136,9 @@ Raven.prototype = {
11471136
auth.sentry_secret = this._globalSecret;
11481137
}
11491138

1150-
this.captureBreadcrumb({
1151-
type: 'sentry',
1152-
data: {
1153-
message: data.message,
1154-
eventId: data.event_id
1155-
}
1139+
this.captureBreadcrumb('sentry', {
1140+
message: data.message,
1141+
eventId: data.event_id
11561142
});
11571143

11581144
var url = this._globalEndpoint;

test/integration/test.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,6 @@ describe('integration', function () {
173173
iframeExecute(iframe, done,
174174
function () {
175175
setTimeout(done);
176-
debugger;
177176

178177
var div = document.createElement('div');
179178
document.body.appendChild(div);

test/raven.test.js

Lines changed: 28 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1537,7 +1537,15 @@ describe('globals', function() {
15371537
describe('Raven (public API)', function() {
15381538

15391539
beforeEach(function () {
1540+
this.clock = sinon.useFakeTimers();
1541+
this.clock.tick(0); // Raven initialized at time "0"
15401542
Raven = new _Raven();
1543+
1544+
this.clock.tick(100); // tick 100 ms
1545+
});
1546+
1547+
afterEach(function () {
1548+
this.clock.restore();
15411549
});
15421550

15431551
describe('.VERSION', function() {
@@ -2153,37 +2161,38 @@ describe('Raven (public API)', function() {
21532161

21542162
describe('.captureBreadcrumb', function () {
21552163
it('should store the passed object in _breadcrumbs', function() {
2156-
var breadcrumb = {
2157-
type: 'request',
2158-
timestamp: 100,
2164+
Raven.captureBreadcrumb('http_request', {
2165+
url: 'http://example.org/api/0/auth/',
2166+
statusCode: 200
2167+
});
2168+
2169+
assert.deepEqual(Raven._breadcrumbs[0], {
2170+
type: 'http_request',
2171+
timestamp: 0.1,
21592172
data: {
21602173
url: 'http://example.org/api/0/auth/',
21612174
statusCode: 200
21622175
}
2163-
};
2164-
2165-
Raven.captureBreadcrumb(breadcrumb);
2166-
2167-
assert.equal(Raven._breadcrumbs[0], breadcrumb);
2176+
});
21682177
});
21692178

21702179
it('should dequeue the oldest breadcrumb when over limit', function() {
21712180
Raven._breadcrumbLimit = 5;
21722181
Raven._breadcrumbs = [
2173-
{ id: 1 },
2174-
{ id: 2 },
2175-
{ id: 3 },
2176-
{ id: 4 },
2177-
{ id: 5 }
2182+
{ type: 'message', timestamp: 0.1, data: { message: '1' }},
2183+
{ type: 'message', timestamp: 0.1, data: { message: '2' }},
2184+
{ type: 'message', timestamp: 0.1, data: { message: '3' }},
2185+
{ type: 'message', timestamp: 0.1, data: { message: '4' }},
2186+
{ type: 'message', timestamp: 0.1, data: { message: '5' }}
21782187
];
21792188

2180-
Raven.captureBreadcrumb({ id: 6, timestamp: 100 });
2189+
Raven.captureBreadcrumb('message', { message: 'lol' });
21812190
assert.deepEqual(Raven._breadcrumbs, [
2182-
{ id: 2 },
2183-
{ id: 3 },
2184-
{ id: 4 },
2185-
{ id: 5 },
2186-
{ id: 6, timestamp: 0.1 }
2191+
{ type: 'message', timestamp: 0.1, data: { message: '2' }},
2192+
{ type: 'message', timestamp: 0.1, data: { message: '3' }},
2193+
{ type: 'message', timestamp: 0.1, data: { message: '4' }},
2194+
{ type: 'message', timestamp: 0.1, data: { message: '5' }},
2195+
{ type: 'message', timestamp: 0.1, data: { message: 'lol' }}
21872196
]);
21882197
});
21892198
});

0 commit comments

Comments
 (0)