Skip to content

Commit

Permalink
feat: Integrate sentry JS and remove raven (#4091)
Browse files Browse the repository at this point in the history
  • Loading branch information
iamareebjamal authored Feb 15, 2020
1 parent 0456445 commit d26672c
Show file tree
Hide file tree
Showing 12 changed files with 199 additions and 63 deletions.
1 change: 1 addition & 0 deletions app/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import Application from '@ember/application';
import Resolver from './resolver';
import loadInitializers from 'ember-load-initializers';
import config from 'open-event-frontend/config/environment';
import './sentry';

const App = Application.extend({
modulePrefix : config.modulePrefix,
Expand Down
5 changes: 5 additions & 0 deletions app/config/environment.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,9 @@ declare const config: {
podModulePrefix: string;
locationType: string;
rootURL: string;
sentry: {
dsn: string;
debug: boolean;
development: boolean;
}
};
3 changes: 2 additions & 1 deletion app/helpers/currency-symbol.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ import { find } from 'lodash-es';
import { paymentCurrencies } from 'open-event-frontend/utils/dictionary/payment';

export function currencySymbol(params) {
return find(paymentCurrencies, ['code', params[0]]).symbol;
const currency = find(paymentCurrencies, ['code', params[0]]);
return currency ? currency.symbol : 'UNKNOWN';
}

export default Helper.helper(currencySymbol);
26 changes: 26 additions & 0 deletions app/sentry.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import * as Sentry from '@sentry/browser';
import { Ember } from '@sentry/integrations';
import config from 'open-event-frontend/config/environment';

Sentry.init({
integrations: [new Ember()],
beforeSend(event: Sentry.Event) {
const exception = event.exception?.values?.[0];
const errorValue = exception?.value;
if (errorValue?.includes("Ember Data Request") &&
errorValue?.includes("404")) {
// Ignore 404 errors from Ember Data because
// I don't know how to turn them off
return null;
}

if (errorValue?.includes("TransitionAborted") &&
exception?.mechanism?.handled) {
// Every page load has a handled TransitionAborted for some reason
return null;
}

return event;
},
...config.sentry
});
13 changes: 10 additions & 3 deletions app/services/auth-manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@ import { mapKeys } from 'lodash-es';

export default Service.extend({

session : service(),
metrics : service(),
store : service(),
session : service(),
metrics : service(),
store : service(),
bugTracker : service(),

currentUser: computed('session.data.currentUserFallback.id', 'currentUserModel', function() {
if (this.currentUserModel) {
Expand Down Expand Up @@ -59,12 +60,18 @@ export default Service.extend({
distinctId : this.currentUser.id,
email : this.currentUser.email
});
this.bugTracker.setUser({
id : this.currentUser.id,
email : this.currentUser.email
});
}
},

identifyStranger() {
this.metrics.identify(null);
this.bugTracker.clearUser();
},

async loadUser() {
if (this.currentUserModel) {
return this.currentUserModel;
Expand Down
21 changes: 21 additions & 0 deletions app/services/bug-tracker.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import Service from '@ember/service';
import * as Sentry from '@sentry/browser';

export default class BugTracker extends Service {

setUser(user: Sentry.User | null) {
Sentry.setUser(user)
}

clearUser() {
Sentry.setUser(null);
}

}

// DO NOT DELETE: this is how TypeScript knows how to look up your services.
declare module '@ember/service' {
interface Registry {
'bug-tracker': BugTracker;
}
}
26 changes: 0 additions & 26 deletions app/services/raven.js

This file was deleted.

3 changes: 1 addition & 2 deletions config/environment.js
Original file line number Diff line number Diff line change
Expand Up @@ -150,8 +150,7 @@ module.exports = function(environment) {
'https://platform.twitter.com',
'https://cdn.syndication.twimg.com',
'http://127.0.0.1:5000',
'cdn.omise.co/omise.js',
'cdn.ravenjs.com'
'cdn.omise.co/omise.js'
],
'font-src': [
'\'self\'',
Expand Down
3 changes: 3 additions & 0 deletions ember-cli-build.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ module.exports = function(defaults) {
exclude : ['package.json'],
extensions : ['js', 'css', 'png', 'jpg', 'gif', 'map', 'svg', 'json']
},
sourcemaps: {
enabled: true
},
autoImport: {
webpack: {
node: {
Expand Down
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@
"@ember/optional-features": "^1.3.0",
"@glimmer/component": "^1.0.0",
"@glimmer/tracking": "^1.0.0",
"@sentry/browser": "^5.12.1",
"@sentry/integrations": "^5.12.0",
"@sentry/node": "^5.12.3",
"@types/ember": "^3.1.1",
"@types/ember-data": "^3.1.9",
"@types/ember-qunit": "^3.4.7",
Expand Down Expand Up @@ -70,7 +73,6 @@
"ember-cli-qunit": "^4.4.0",
"ember-cli-sass": "^10.0.0",
"ember-cli-scss-lint": "^2.4.1",
"ember-cli-sentry": "^4.1.0",
"ember-cli-shims": "^1.2.0",
"ember-cli-string-helpers": "^4.0.6",
"ember-cli-stripe": "^3.0.0",
Expand Down Expand Up @@ -146,7 +148,6 @@
"@bower_components/js-polyfills": "inexorabletash/polyfill#^0.1.34",
"@bower_components/open-event-theme": "fossasia/open-event-theme#^0.0.6",
"@bower_components/pace": "HubSpot/pace#^1.0.2",
"@bower_components/raven-js": "getsentry/raven-js#~3.3",
"@bower_components/semantic-ui-calendar": "mdehoog/semantic-ui-calendar#^0.0.8",
"@bower_components/tinyColorPicker": "PitPik/tinyColorPicker#^1.1.1",
"@bower_components/wysihtml": "Voog/wysihtml#^0.5.5",
Expand Down
12 changes: 12 additions & 0 deletions tests/unit/services/bug-tracker-test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { module, test } from 'qunit';
import { setupTest } from 'ember-qunit';

module('Unit | Service | bug-tracker', function(hooks) {
setupTest(hooks);

// Replace this with your real tests.
test('it exists', function(assert) {
let service = this.owner.lookup('service:bug-tracker');
assert.ok(service);
});
});
Loading

0 comments on commit d26672c

Please sign in to comment.