Skip to content

Commit 3f5c202

Browse files
committed
Merge pull request #564 from getsentry/new-bc-api
Change breadcrumb data to match updated api
2 parents f3a70ee + e80d346 commit 3f5c202

File tree

3 files changed

+69
-69
lines changed

3 files changed

+69
-69
lines changed

src/raven.js

Lines changed: 23 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -357,12 +357,10 @@ Raven.prototype = {
357357
return this;
358358
},
359359

360-
captureBreadcrumb: function (type, data) {
361-
var crumb = {
362-
type: type,
363-
timestamp: now() / 1000,
364-
data: data
365-
};
360+
captureBreadcrumb: function (obj) {
361+
var crumb = objectMerge({
362+
timestamp: now() / 1000
363+
}, obj);
366364

367365
this._breadcrumbs.push(crumb);
368366
if (this._breadcrumbs.length > this._breadcrumbLimit) {
@@ -652,9 +650,9 @@ Raven.prototype = {
652650
target = '<unknown>';
653651
}
654652

655-
self.captureBreadcrumb('ui_event', {
656-
type: evtName,
657-
target: target
653+
self.captureBreadcrumb({
654+
category: 'ui.' + evtName, // e.g. ui.click, ui.input
655+
message: target
658656
});
659657
};
660658
},
@@ -718,9 +716,12 @@ Raven.prototype = {
718716
if (parsedLoc.protocol === parsedFrom.protocol && parsedLoc.host === parsedFrom.host)
719717
from = parsedFrom.path;
720718

721-
this.captureBreadcrumb('navigation', {
722-
to: to,
723-
from: from
719+
this.captureBreadcrumb({
720+
category: 'navigation',
721+
data: {
722+
to: to,
723+
from: from
724+
}
724725
});
725726
},
726727

@@ -858,7 +859,11 @@ Raven.prototype = {
858859
// an exception
859860
xhr.__raven_xhr.status_code = xhr.status;
860861
} catch (e) { /* do nothing */ }
861-
self.captureBreadcrumb('http_request', xhr.__raven_xhr);
862+
self.captureBreadcrumb({
863+
type: 'http',
864+
category: 'xhr',
865+
data: xhr.__raven_xhr
866+
});
862867
}
863868
}
864869

@@ -916,9 +921,10 @@ Raven.prototype = {
916921
consolePlugin(self, console, {
917922
levels: ['debug', 'info', 'warn', 'error', 'log'],
918923
callback: function (msg, data) {
919-
self.captureBreadcrumb('message', {
924+
self.captureBreadcrumb({
925+
message: msg,
920926
level: data.level,
921-
message: msg
927+
category: 'console'
922928
});
923929
}
924930
});
@@ -1253,8 +1259,8 @@ Raven.prototype = {
12531259
auth.sentry_secret = this._globalSecret;
12541260
}
12551261

1256-
// TODO: is captureMessage considered an 'error' breadcrumb? or 'message'?
1257-
this.captureBreadcrumb('error', {
1262+
this.captureBreadcrumb({
1263+
category: 'sentry',
12581264
message: data.message,
12591265
event_id: data.event_id
12601266
});

test/integration/test.js

Lines changed: 21 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -328,7 +328,7 @@ describe('integration', function () {
328328

329329
assert.equal(breadcrumbs.length, 1);
330330

331-
assert.equal(breadcrumbs[0].type, 'http_request');
331+
assert.equal(breadcrumbs[0].type, 'http');
332332
assert.equal(breadcrumbs[0].data.method, 'GET');
333333
// NOTE: not checking status code because we seem to get
334334
// statusCode 0/undefined from Phantom when fetching
@@ -362,7 +362,7 @@ describe('integration', function () {
362362

363363
assert.equal(breadcrumbs.length, 1);
364364

365-
assert.equal(breadcrumbs[0].type, 'http_request');
365+
assert.equal(breadcrumbs[0].type, 'http');
366366
assert.equal(breadcrumbs[0].data.method, 'GET');
367367
// NOTE: not checking status code because we seem to get
368368
// statusCode 0/undefined from Phantom when fetching
@@ -439,9 +439,8 @@ describe('integration', function () {
439439

440440
assert.equal(breadcrumbs.length, 1);
441441

442-
assert.equal(breadcrumbs[0].type, 'ui_event');
443-
assert.equal(breadcrumbs[0].data.target, 'body > form#foo-form > input[name="foo"][placeholder="lol"]');
444-
assert.equal(breadcrumbs[0].data.type, 'click');
442+
assert.equal(breadcrumbs[0].category, 'ui.click');
443+
assert.equal(breadcrumbs[0].message, 'body > form#foo-form > input[name="foo"][placeholder="lol"]');
445444
}
446445
);
447446
});
@@ -479,9 +478,8 @@ describe('integration', function () {
479478

480479
assert.equal(breadcrumbs.length, 1);
481480

482-
assert.equal(breadcrumbs[0].type, 'ui_event');
483-
assert.equal(breadcrumbs[0].data.target, 'body > form#foo-form > input[name="foo"][placeholder="lol"]');
484-
assert.equal(breadcrumbs[0].data.type, 'click');
481+
assert.equal(breadcrumbs[0].category, 'ui.click');
482+
assert.equal(breadcrumbs[0].message, 'body > form#foo-form > input[name="foo"][placeholder="lol"]');
485483
}
486484
);
487485
});
@@ -526,9 +524,8 @@ describe('integration', function () {
526524

527525
assert.equal(breadcrumbs.length, 1);
528526

529-
assert.equal(breadcrumbs[0].type, 'ui_event');
530-
assert.equal(breadcrumbs[0].data.target, 'body > div.c > div.b > div.a');
531-
assert.equal(breadcrumbs[0].data.type, 'click');
527+
assert.equal(breadcrumbs[0].category, 'ui.click');
528+
assert.equal(breadcrumbs[0].message, 'body > div.c > div.b > div.a');
532529
}
533530
);
534531
});
@@ -560,9 +557,8 @@ describe('integration', function () {
560557

561558
assert.equal(breadcrumbs.length, 1);
562559

563-
assert.equal(breadcrumbs[0].type, 'ui_event');
564-
assert.equal(breadcrumbs[0].data.target, 'body > form#foo-form > input[name="foo"][placeholder="lol"]');
565-
assert.equal(breadcrumbs[0].data.type, 'input');
560+
assert.equal(breadcrumbs[0].category, 'ui.input');
561+
assert.equal(breadcrumbs[0].message, 'body > form#foo-form > input[name="foo"][placeholder="lol"]');
566562
}
567563
);
568564
});
@@ -593,9 +589,8 @@ describe('integration', function () {
593589
// 2 breadcrumbs: `ui_event`, then `error`
594590
assert.equal(breadcrumbs.length, 2);
595591

596-
assert.equal(breadcrumbs[0].type, 'ui_event');
597-
assert.equal(breadcrumbs[0].data.target, 'body > form#foo-form > input[name="foo"][placeholder="lol"]');
598-
assert.equal(breadcrumbs[0].data.type, 'input');
592+
assert.equal(breadcrumbs[0].category, 'ui.input');
593+
assert.equal(breadcrumbs[0].message, 'body > form#foo-form > input[name="foo"][placeholder="lol"]');
599594
}
600595
);
601596
});
@@ -644,17 +639,14 @@ describe('integration', function () {
644639
// 2x `ui_event`
645640
assert.equal(breadcrumbs.length, 3);
646641

647-
assert.equal(breadcrumbs[0].type, 'ui_event');
648-
assert.equal(breadcrumbs[0].data.target, 'body > form#foo-form > input[name="foo"][placeholder="lol"]');
649-
assert.equal(breadcrumbs[0].data.type, 'input');
642+
assert.equal(breadcrumbs[0].category, 'ui.input');
643+
assert.equal(breadcrumbs[0].message, 'body > form#foo-form > input[name="foo"][placeholder="lol"]');
650644

651-
assert.equal(breadcrumbs[1].type, 'ui_event');
652-
assert.equal(breadcrumbs[1].data.target, 'body > form#foo-form > input[name="foo"][placeholder="lol"]');
653-
assert.equal(breadcrumbs[1].data.type, 'click');
645+
assert.equal(breadcrumbs[1].category, 'ui.click');
646+
assert.equal(breadcrumbs[1].message, 'body > form#foo-form > input[name="foo"][placeholder="lol"]');
654647

655-
assert.equal(breadcrumbs[2].type, 'ui_event');
656-
assert.equal(breadcrumbs[2].data.target, 'body > form#foo-form > input[name="foo"][placeholder="lol"]');
657-
assert.equal(breadcrumbs[2].data.type, 'input');
648+
assert.equal(breadcrumbs[2].category, 'ui.input');
649+
assert.equal(breadcrumbs[2].message, 'body > form#foo-form > input[name="foo"][placeholder="lol"]');
658650

659651
}
660652
);
@@ -684,9 +676,9 @@ describe('integration', function () {
684676
to;
685677

686678
assert.equal(breadcrumbs.length, 3);
687-
assert.equal(breadcrumbs[0].type, 'navigation'); // (start) => foo
688-
assert.equal(breadcrumbs[1].type, 'navigation'); // foo => bar
689-
assert.equal(breadcrumbs[2].type, 'navigation'); // bar => foo (back button)
679+
assert.equal(breadcrumbs[0].category, 'navigation'); // (start) => foo
680+
assert.equal(breadcrumbs[1].category, 'navigation'); // foo => bar
681+
assert.equal(breadcrumbs[2].category, 'navigation'); // bar => foo (back button)
690682

691683
// assert end of string because PhantomJS uses full system path
692684
assert.ok(/\/test\/integration\/frame\.html$/.test(Raven._breadcrumbs[0].data.from), '\'from\' url is incorrect');

test/raven.test.js

Lines changed: 25 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -740,7 +740,6 @@ describe('globals', function() {
740740
]
741741
}
742742
});
743-
744743
});
745744

746745
it('should create and append \'error\' breadcrumb', function () {
@@ -756,14 +755,14 @@ describe('globals', function() {
756755
logger: 'javascript',
757756
maxMessageLength: 100
758757
};
759-
Raven._breadcrumbs = [{type: 'request', timestamp: 0.1, data: {method: 'POST', url: 'http://example.org/api/0/auth/'}}];
758+
Raven._breadcrumbs = [{type: 'http', timestamp: 0.1, data: {method: 'POST', url: 'http://example.org/api/0/auth/'}}];
760759

761760
Raven._send({message: 'bar'});
762761

763762
assert.deepEqual(Raven._breadcrumbs, [
764-
{ type: 'request', timestamp: 0.1, data: { method: 'POST', url: 'http://example.org/api/0/auth/' }},
765-
{ type: 'error', timestamp: 0.1, /* 100ms */ data: { message: 'bar', event_id: 'abc123' }}
766-
])
763+
{ type: 'http', timestamp: 0.1, data: { method: 'POST', url: 'http://example.org/api/0/auth/' }},
764+
{ category: 'sentry', message: 'bar', timestamp: 0.1, /* 100ms */ event_id: 'abc123' }
765+
]);
767766
});
768767

769768
it('should build a good data payload with a User', function() {
@@ -2052,38 +2051,41 @@ describe('Raven (public API)', function() {
20522051

20532052
describe('.captureBreadcrumb', function () {
20542053
it('should store the passed object in _breadcrumbs', function() {
2055-
Raven.captureBreadcrumb('http_request', {
2056-
url: 'http://example.org/api/0/auth/',
2057-
statusCode: 200
2054+
Raven.captureBreadcrumb({
2055+
type: 'http',
2056+
data: {
2057+
url: 'http://example.org/api/0/auth/',
2058+
status_code: 200
2059+
}
20582060
});
20592061

20602062
assert.deepEqual(Raven._breadcrumbs[0], {
2061-
type: 'http_request',
2063+
type: 'http',
20622064
timestamp: 0.1,
20632065
data: {
20642066
url: 'http://example.org/api/0/auth/',
2065-
statusCode: 200
2067+
status_code: 200
20662068
}
20672069
});
20682070
});
20692071

20702072
it('should dequeue the oldest breadcrumb when over limit', function() {
20712073
Raven._breadcrumbLimit = 5;
20722074
Raven._breadcrumbs = [
2073-
{ type: 'message', timestamp: 0.1, data: { message: '1' }},
2074-
{ type: 'message', timestamp: 0.1, data: { message: '2' }},
2075-
{ type: 'message', timestamp: 0.1, data: { message: '3' }},
2076-
{ type: 'message', timestamp: 0.1, data: { message: '4' }},
2077-
{ type: 'message', timestamp: 0.1, data: { message: '5' }}
2075+
{ message: '1', timestamp: 0.1 },
2076+
{ message: '2', timestamp: 0.1 },
2077+
{ message: '3', timestamp: 0.1 },
2078+
{ message: '4', timestamp: 0.1 },
2079+
{ message: '5', timestamp: 0.1 }
20782080
];
20792081

2080-
Raven.captureBreadcrumb('message', { message: 'lol' });
2082+
Raven.captureBreadcrumb({ message: 'lol' });
20812083
assert.deepEqual(Raven._breadcrumbs, [
2082-
{ type: 'message', timestamp: 0.1, data: { message: '2' }},
2083-
{ type: 'message', timestamp: 0.1, data: { message: '3' }},
2084-
{ type: 'message', timestamp: 0.1, data: { message: '4' }},
2085-
{ type: 'message', timestamp: 0.1, data: { message: '5' }},
2086-
{ type: 'message', timestamp: 0.1, data: { message: 'lol' }}
2084+
{ message: '2', timestamp: 0.1 },
2085+
{ message: '3', timestamp: 0.1 },
2086+
{ message: '4', timestamp: 0.1 },
2087+
{ message: '5', timestamp: 0.1 },
2088+
{ message: 'lol', timestamp: 0.1 }
20872089
]);
20882090
});
20892091
});
@@ -2093,7 +2095,7 @@ describe('Raven (public API)', function() {
20932095
Raven._breadcrumbs = [];
20942096
Raven._captureUrlChange('/foo', '/bar');
20952097
assert.deepEqual(Raven._breadcrumbs, [
2096-
{ type: 'navigation', timestamp: 0.1, data: { from: '/foo', to: '/bar' }}
2098+
{ category: 'navigation', timestamp: 0.1, data: { from: '/foo', to: '/bar' }}
20972099
]);
20982100
});
20992101

@@ -2103,7 +2105,7 @@ describe('Raven (public API)', function() {
21032105

21042106
Raven._captureUrlChange('http://example.com/foo', 'http://example.com/bar');
21052107
assert.deepEqual(Raven._breadcrumbs, [
2106-
{ type: 'navigation', timestamp: 0.1, data: { from: '/foo', to: '/bar' }}
2108+
{ category: 'navigation', timestamp: 0.1, data: { from: '/foo', to: '/bar' }}
21072109
]);
21082110
});
21092111
});

0 commit comments

Comments
 (0)