Skip to content

Sentry: Replace @sentry/browser with @sentry/ember #8778

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

Merged
merged 1 commit into from
Jun 3, 2024
Merged
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
58 changes: 1 addition & 57 deletions app/sentry.js
Original file line number Diff line number Diff line change
@@ -1,24 +1,15 @@
import { runInDebug } from '@ember/debug';

import * as Sentry from '@sentry/browser';
import { getGlobalObject, isInstanceOf, logger } from '@sentry/utils';
import * as Sentry from '@sentry/ember';

import config from './config/environment';

export function init() {
let integrations = [];
if (config.environment === 'production') {
integrations.push(new Ember());
}

let isProd = location.hostname === 'crates.io';
let isStaging = location.hostname === 'staging.crates.io';
let environment = isProd ? 'production' : isStaging ? 'staging' : 'unknown';

Sentry.init({
environment,
...config.sentry,
integrations,

allowUrls: ['crates.io', 'crates-io.herokuapp.com', 'staging.crates-io', 'staging-crates-io.herokuapp.com'],

Expand All @@ -35,50 +26,3 @@ export function init() {
},
});
}

export class Ember {
static id = 'Ember';

name = Ember.id;
_Ember;

constructor(options = {}) {
this._Ember = options.Ember || getGlobalObject().Ember;
}

setupOnce(_, getCurrentHub) {
if (!this._Ember) {
runInDebug(() => logger.error('EmberIntegration is missing an Ember instance'));
return;
}

const oldOnError = this._Ember.onerror;

// eslint-disable-next-line unicorn/prefer-add-event-listener
this._Ember.onerror = error => {
if (getCurrentHub().getIntegration(Ember)) {
getCurrentHub().captureException(error, { originalException: error });
}

if (typeof oldOnError === 'function') {
oldOnError.call(this._Ember, error);
} else if (this._Ember.testing) {
throw error;
}
};

this._Ember.RSVP.on('error', reason => {
if (getCurrentHub().getIntegration(Ember)) {
getCurrentHub().withScope(scope => {
if (isInstanceOf(reason, Error)) {
scope.setExtra('context', 'Unhandled Promise error detected');
getCurrentHub().captureException(reason, { originalException: reason });
} else {
scope.setExtra('reason', reason);
getCurrentHub().captureMessage('Unhandled Promise error detected');
}
});
}
});
}
}
2 changes: 1 addition & 1 deletion app/services/sentry.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import Service from '@ember/service';

import * as Sentry from '@sentry/browser';
import * as Sentry from '@sentry/ember';

export default class SentryService extends Service {
captureException(error, captureContext) {
Expand Down
4 changes: 4 additions & 0 deletions config/environment.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@ module.exports = function (environment) {
// We don't want to use Mirage if a proxy backend has been provided.
enabled: !process.env.PROXY_BACKEND,
},

'@sentry/ember': {
disablePerformance: true,
},
};

if (environment === 'development') {
Expand Down
3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,7 @@
},
"dependencies": {
"@juggle/resize-observer": "3.4.0",
"@sentry/browser": "7.116.0",
"@sentry/utils": "7.116.0",
"@sentry/ember": "7.116.0",
"chart.js": "4.4.3",
"date-fns": "3.6.0",
"highlight.js": "11.9.0",
Expand Down
27 changes: 22 additions & 5 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading