Skip to content

Commit 8f66ed8

Browse files
authored
refactor(ember): Use @embroider/macros instead of runInDebug for @sentry/ember (#2873)
* Use @embroider/macros instead of runInDebug for @sentry/ember This ensures that the debug code is actually stripped from production builds.
1 parent 57af9b1 commit 8f66ed8

File tree

4 files changed

+223
-12
lines changed

4 files changed

+223
-12
lines changed

packages/ember/addon/index.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import * as Sentry from '@sentry/browser';
22
import { addGlobalEventProcessor, SDK_VERSION, BrowserOptions } from '@sentry/browser';
33
import environmentConfig from 'ember-get-config';
4-
4+
import { macroCondition, isDevelopingApp } from '@embroider/macros';
55
import { next } from '@ember/runloop';
6-
import { assert, warn, runInDebug } from '@ember/debug';
6+
import { assert, warn } from '@ember/debug';
77
import Ember from 'ember';
88
import { timestampWithMs } from '@sentry/utils';
99

@@ -22,7 +22,7 @@ export function InitSentryForEmber(_runtimeConfig: BrowserOptions | undefined) {
2222

2323
Sentry.init(initConfig);
2424

25-
runInDebug(() => {
25+
if (macroCondition(isDevelopingApp())) {
2626
if (config.ignoreEmberOnErrorWarning) {
2727
return;
2828
}
@@ -35,7 +35,7 @@ export function InitSentryForEmber(_runtimeConfig: BrowserOptions | undefined) {
3535
},
3636
);
3737
});
38-
});
38+
}
3939
}
4040

4141
export const getActiveTransaction = () => {

packages/ember/addon/instance-initializers/sentry-performance.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,15 @@ import { Span, Transaction, Integration } from '@sentry/types';
77
import { EmberRunQueues } from '@ember/runloop/-private/types';
88
import { getActiveTransaction } from '..';
99
import { timestampWithMs } from '@sentry/utils';
10+
import { macroCondition, isTesting } from '@embroider/macros';
1011

1112
export function initialize(appInstance: ApplicationInstance): void {
1213
const config = environmentConfig['@sentry/ember'];
1314
if (config['disablePerformance']) {
1415
return;
1516
}
1617
const performancePromise = instrumentForPerformance(appInstance);
17-
if (Ember.testing) {
18+
if (macroCondition(isTesting())) {
1819
(<any>window)._sentryPerformanceLoad = performancePromise;
1920
}
2021
}
@@ -42,7 +43,7 @@ export function _instrumentEmberRouter(
4243

4344
const url = location && location.getURL && location.getURL();
4445

45-
if (Ember.testing) {
46+
if (macroCondition(isTesting())) {
4647
routerService._sentryInstrumented = true;
4748
routerService._startTransaction = startTransaction;
4849
}
@@ -329,7 +330,7 @@ export async function instrumentForPerformance(appInstance: ApplicationInstance)
329330
}),
330331
];
331332

332-
if (Ember.testing && Sentry.getCurrentHub()?.getIntegration(tracing.Integrations.BrowserTracing)) {
333+
if (isTesting() && Sentry.getCurrentHub()?.getIntegration(tracing.Integrations.BrowserTracing)) {
333334
// Initializers are called more than once in tests, causing the integrations to not be setup correctly.
334335
return;
335336
}

packages/ember/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
"pack": "npm pack"
3232
},
3333
"dependencies": {
34+
"@embroider/macros": ">=0.25.0",
3435
"@sentry/browser": "5.25.0",
3536
"@sentry/tracing": "5.25.0",
3637
"@sentry/types": "5.25.0",

0 commit comments

Comments
 (0)