Commit 5617a222 authored by Robert Knight's avatar Robert Knight

Add app configuration metadata to Sentry reports

Add the parsed app configuration from the `#config=<JSON blob>` URL fragment
to Sentry reports. This makes it easier to read that the URL-encoded,
JSON-stringified form in which it currently appears.
parent f3c3d0d3
import * as Sentry from '@sentry/browser';
import { parseConfigFragment } from '../../shared/config-fragment';
import warnOnce from '../../shared/warn-once';
/**
......@@ -102,6 +103,12 @@ export function init(config) {
},
});
try {
Sentry.setExtra('host_config', parseConfigFragment(window.location.href));
} catch (e) {
// Ignore errors parsing configuration.
}
// In the sidebar application, it is often useful to know the URL which the
// client was loaded into. This information is usually available in an iframe
// via `document.referrer`. More information about the document is available
......
......@@ -3,10 +3,13 @@ import * as sentry from '../sentry';
describe('sidebar/util/sentry', () => {
let fakeDocumentReferrer;
let fakeDocumentCurrentScript;
let fakeParseConfigFragment;
let fakeSentry;
let fakeWarnOnce;
beforeEach(() => {
fakeParseConfigFragment = sinon.stub().returns({});
fakeSentry = {
init: sinon.stub(),
setExtra: sinon.stub(),
......@@ -17,6 +20,9 @@ describe('sidebar/util/sentry', () => {
sentry.$imports.$mock({
'@sentry/browser': fakeSentry,
'../../shared/config-fragment': {
parseConfigFragment: fakeParseConfigFragment,
},
'../../shared/warn-once': fakeWarnOnce,
});
});
......@@ -104,6 +110,21 @@ describe('sidebar/util/sentry', () => {
);
});
it('adds "host_config" context to reports', () => {
fakeParseConfigFragment.returns({ appType: 'via' });
sentry.init({ dsn: 'test-dsn', environment: 'dev' });
assert.calledWith(fakeParseConfigFragment, window.location.href);
assert.calledWith(fakeSentry.setExtra, 'host_config', { appType: 'via' });
});
it('does not add "host_config" context if `parseConfigFragment` throws', () => {
fakeParseConfigFragment.throws(new Error('Parse error'));
sentry.init({ dsn: 'test-dsn', environment: 'dev' });
assert.neverCalledWith(fakeSentry.setExtra, 'host_config');
});
it('adds "document_url" context to reports', () => {
sentry.init({ dsn: 'test-dsn', environment: 'dev' });
assert.calledWith(
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment