Skip to content

Commit

Permalink
feat(error-tracking): normalize event URL before sending to Sentry
Browse files Browse the repository at this point in the history
Closes #1831
  • Loading branch information
oguzeroglu committed Jun 24, 2020
1 parent 9d0c501 commit cabb4d9
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 5 deletions.
43 changes: 42 additions & 1 deletion client/src/plugins/error-tracking/ErrorTracking.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,16 @@ export default class ErrorTracking extends PureComponent {
// - we don't initialize dev in Sentry.)
this._sentry.init({
dsn: this.SENTRY_DSN,
release: releaseTag
release: releaseTag,
beforeSend: (event) => {

// We need to normalize the event path to match with uploaded sourcemaps.
// Since we're distributing the app to the clients, every exception
// has a different path. That's why if we skip this step, we'd have
// unmeaningful exceptions in Sentry.
// See this: https://github.com/camunda/camunda-modeler/issues/1831
return this.normalizeEventPath(event);
}
});

// OS information already exists by default in Sentry.
Expand Down Expand Up @@ -180,7 +189,39 @@ export default class ErrorTracking extends PureComponent {
return this.recheckSentry();
}

normalizeEventPath = (event) => {
try {

const { exception, request } = event;
const { values } = exception;

request.url = normalizeUrl(request.url);

values.forEach((exceptionVal) => {
const { stacktrace } = exceptionVal;
const { frames } = stacktrace;

frames.forEach((frame) => {
frame.filename = normalizeUrl(frame.filename);
});
});

return event;
} catch (err) {

// Don't loose the actual event in case things go wrong
return event;
}
}

render() {
return null;
}
}

const normalizeUrl = (path) => {

// eslint-disable-next-line
const filename = path.replace(/^.*[\\\/]/, '');
return '~/build/' + filename;
};
10 changes: 6 additions & 4 deletions client/src/plugins/error-tracking/__tests__/ErrorTrackingSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -174,11 +174,13 @@ describe('<ErrorTracking>', () => {
// when
await instance.componentDidMount();

const args = sentryInitSpy.getCall(0).args;

// then
expect(sentryInitSpy).to.have.been.calledWith({
dsn: 'TEST_DSN',
release: '3.5.0'
});
expect(args).to.have.length(1);

expect(args[0].dsn).to.eql('TEST_DSN');
expect(args[0].release).to.eql('3.5.0');
});


Expand Down

0 comments on commit cabb4d9

Please sign in to comment.