Skip to content

Commit

Permalink
fix(errorTracking): add user configuration to sentry
Browse files Browse the repository at this point in the history
  • Loading branch information
marstamm committed Oct 25, 2024
1 parent 8cfa5f5 commit ea837b2
Show file tree
Hide file tree
Showing 4 changed files with 77 additions and 31 deletions.
40 changes: 32 additions & 8 deletions app/lib/util/__tests__/error-tracking-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,29 @@ describe('error-tracking', function() {
});


it('should configure user', function() {

// given
const setUserSpy = sinon.spy();

const config = mockConfig({
'editor.id': 'TEST_EDITOR_ID',
'editor.privacyPreferences': { 'ENABLE_CRASH_REPORTS': true }
});
const flags = mockFlags();
const renderer = mockRenderer();
const Sentry = mockSentry({ setUserSpy });

// when
errorTracking.start(Sentry, 'v2', config, flags, renderer);

// then
expect(setUserSpy).to.have.been.calledWith({
id: 'TEST_EDITOR_ID'
});
});


it('should listen to frontend', function() {

// given
Expand Down Expand Up @@ -300,14 +323,15 @@ function mockSentry(props = {}) {
props.sentryInitSpy(initParam);
}
},
configureScope: (fn) => {
fn({
setTag: (key, value) => {
if (props.setTagSpy) {
props.setTagSpy({ key, value });
}
}
});
setTag: (key, value) => {
if (props.setTagSpy) {
props.setTagSpy({ key, value });
}
},
setUser: (user) => {
if (props.setUserSpy) {
props.setUserSpy(user);
}
},
close: () => {
if (props.sentryCloseSpy) {
Expand Down
20 changes: 9 additions & 11 deletions app/lib/util/error-tracking.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,7 @@ module.exports.setTag = function(Sentry, key, value) {
additionalTags.push({ key, value });

if (isActive) {
Sentry.configureScope(scope => {
scope.setTag(key, value);
});
Sentry.setTag(key, value);
}
};

Expand Down Expand Up @@ -132,17 +130,17 @@ function initializeSentry(Sentry, editorID, release, dsn) {
]
});

Sentry.configureScope(scope => {
scope.setTag('editor-id', editorID);
scope.setTag('is-backend-error', true);
scope.setTag('platform', os.platform());
scope.setTag('os-version', os.release());
Sentry.setTag('editor-id', editorID);
Sentry.setTag('is-backend-error', true);
Sentry.setTag('platform', os.platform());
Sentry.setTag('os-version', os.release());

additionalTags.forEach(({ key, value }) => {
scope.setTag(key, value);
});
additionalTags.forEach(({ key, value }) => {
Sentry.setTag(key, value);
});

Sentry.setUser({ id: editorID });

log.info('Sentry initialized.');
isActive = true;
} catch (err) {
Expand Down
7 changes: 3 additions & 4 deletions client/src/plugins/error-tracking/ErrorTracking.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,13 +100,12 @@ export default class ErrorTracking extends PureComponent {

// OS information already exists by default in Sentry.
// We'll set editor ID and Camunda Modeler version.
this._sentry.configureScope(scope => { scope.setTag('editor-id', editorID); });
this._sentry.setTag('editor-id', editorID);
this._sentry.setUser({ id: editorID });

// add plugins information
const plugins = _getGlobal('plugins').getAppPlugins();
this._sentry.configureScope(scope => {
scope.setTag('plugins', generatePluginsTag(plugins));
});
this._sentry.setTag('plugins', generatePluginsTag(plugins));

const { subscribe } = this.props;

Expand Down
41 changes: 33 additions & 8 deletions client/src/plugins/error-tracking/__tests__/ErrorTrackingSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,30 @@ describe('<ErrorTracking>', function() {
});


it('should configure Sentry user', async function() {

// given
const setUserSpy = sinon.spy();

const instance = createErrorTracking({
setUserSpy,
dsn: 'TEST_DSN',
configValues: {
'editor.privacyPreferences': { ENABLE_CRASH_REPORTS: true },
'editor.id': 'TEST_EDITOR_ID'
}
});

// when
await instance.componentDidMount();

// then
expect(setUserSpy).to.have.been.calledWith({
id: 'TEST_EDITOR_ID'
});
});


it('should subscribe to app.error-handled event on initialization', async function() {

// given
Expand Down Expand Up @@ -498,14 +522,15 @@ function createErrorTracking(props = {}) {
props.sentryInitSpy(initParam);
}
},
configureScope: (fn) => {
fn({
setTag: (key, value) => {
if (props.setTagSpy) {
props.setTagSpy({ key, value });
}
}
});
setTag: (key, value) => {
if (props.setTagSpy) {
props.setTagSpy({ key, value });
}
},
setUser: (user) => {
if (props.setUserSpy) {
props.setUserSpy(user);
}
},
captureException: (err) => {
if (props.sentryCaptureExceptionSpy) {
Expand Down

0 comments on commit ea837b2

Please sign in to comment.