Skip to content

test(breadcrumb): Add test case for creating breadcrumbs for requests to the envelope endpoint #2603

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 30 additions & 2 deletions packages/browser/src/integrations/breadcrumbs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -325,7 +325,35 @@ function addSentryBreadcrumb(serializedData: string): void {
event,
},
);
} catch (_oO) {
logger.error('Error while adding sentry type breadcrumb');
} catch (error) {
logger.error('Error while adding sentry type breadcrumb will try envelope', error);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will add a lot of noise when we know envelopes are not "exceptional behavior".

What if we explicitly selected whether to try to decode application/x-sentry-envelope vs application/json, and then log a potential error as before?

There must be a way to distinguish the two without parsing all input. Or maybe a way for addSentryBreadcrumb to get the event object directly instead of a serialized version of it.

As it is implemented now, this error path requires deserializing the event and maybe that's not necessary?

addSentryBreadcrumbWithEnvelope(serializedData);
}
}

/**
* Does the same as {@link addSentryBreadcrumb} but works with envelope
*/
function addSentryBreadcrumbWithEnvelope(envelope: string): void {
try {
// We are dealing with an envelope here
// For simplicity we only deal with transactions
const envelopeLines = envelope.split('\n');
const envelopeHeader = JSON.parse(envelopeLines[0]);
const itemHeader = JSON.parse(envelopeLines[1]);
const item = JSON.parse(envelopeLines[2]);
getCurrentHub().addBreadcrumb(
{
category: `sentry.${itemHeader.type}`,
event_id: envelopeHeader.event_id,
level: item.level,
message: getEventDescription(item),
},
{
item,
},
);
} catch (error) {
logger.error('Error while adding sentry type breadcrumb', error);
}
}
1 change: 1 addition & 0 deletions packages/browser/test/integration/karma.conf.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ module.exports = config => {
"/base/variants/123": "/base/subjects/123",
// Supresses warnings
"/api/1/store/": "/",
"/api/1/envelope/": "/",
},
frameworks: ["mocha", "chai", "sinon"],
files,
Expand Down
37 changes: 37 additions & 0 deletions packages/browser/test/integration/suites/breadcrumbs.js
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,43 @@ describe("breadcrumbs", function() {
}
);

it(
optional(
"should transform XMLHttpRequests with transactions type to the Sentry envelope endpoint as sentry.transaction type breadcrumb",
IS_LOADER
),
function() {
return runInSandbox(sandbox, { manual: true }, function() {
var envelope =
document.location.protocol +
"//" +
document.location.hostname +
(document.location.port ? ":" + document.location.port : "") +
"/api/1/envelope/" +
"?sentry_key=1337";

var xhr = new XMLHttpRequest();
xhr.open("POST", envelope);
xhr.send(
'{"event_id": "aa3ff046696b4bc6b609ce6d28fde9e2","sent_at": "2020-05-19T15:44:49.028Z"}\n{"type": "transaction"}\n{"message":"someMessage","transaction":"wat","level":"warning"}'
);
waitForXHR(xhr, function() {
Sentry.captureMessage("test");
window.finalizeManualTest();
});
}).then(function(summary) {
// The async loader doesn't wrap XHR
if (IS_LOADER) {
return;
}
assert.equal(summary.breadcrumbs.length, 1);
assert.equal(summary.breadcrumbs[0].category, "sentry.transaction");
assert.equal(summary.breadcrumbs[0].level, "warning");
assert.equal(summary.breadcrumbs[0].message, "someMessage");
});
}
);

it(
optional(
"should not transform XMLHttpRequests with transactions attribute to the Sentry store endpoint as sentry.transaction type breadcrumb",
Expand Down