Skip to content

fix(ember): Fix Ember to work with Embroider and Fastboot #3181

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 6 commits into from
Jan 25, 2021
Merged
Show file tree
Hide file tree
Changes from 4 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
20 changes: 0 additions & 20 deletions packages/ember/addon/config.d.ts

This file was deleted.

11 changes: 6 additions & 5 deletions packages/ember/addon/index.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,21 @@
import * as Sentry from '@sentry/browser';
import { SDK_VERSION, BrowserOptions } from '@sentry/browser';
import environmentConfig from 'ember-get-config';
import { macroCondition, isDevelopingApp } from '@embroider/macros';
import { macroCondition, isDevelopingApp, getOwnConfig } from '@embroider/macros';
import { next } from '@ember/runloop';
import { assert, warn } from '@ember/debug';
import Ember from 'ember';
import { timestampWithMs } from '@sentry/utils';
import { OwnConfig } from './types';

declare module '@ember/debug' {
export function assert(desc: string, test: unknown): void;
}

export function InitSentryForEmber(_runtimeConfig: BrowserOptions | undefined) {
const config = environmentConfig['@sentry/ember'];
assert('Missing configuration', config);
assert('Missing configuration for Sentry.', config.sentry);
const config = getOwnConfig<OwnConfig>().sentryConfig;

assert('Missing configuration.', config);
assert('Missing configuration for Sentry.', config.sentry || _runtimeConfig);

const initConfig = Object.assign({}, config.sentry, _runtimeConfig || {});

Expand Down
20 changes: 12 additions & 8 deletions packages/ember/addon/instance-initializers/sentry-performance.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,20 @@
import ApplicationInstance from '@ember/application/instance';
import Ember from 'ember';
import { run } from '@ember/runloop';
import environmentConfig from 'ember-get-config';
import * as Sentry from '@sentry/browser';
import { Span, Transaction, Integration } from '@sentry/types';
import { EmberRunQueues } from '@ember/runloop/-private/types';
import { getActiveTransaction } from '..';
import { timestampWithMs } from '@sentry/utils';
import { macroCondition, isTesting } from '@embroider/macros';
import { macroCondition, isTesting, getOwnConfig } from '@embroider/macros';
import { EmberSentryConfig, OwnConfig } from '../types';

function getSentryConfig() {
return getOwnConfig<OwnConfig>().sentryConfig;
}

export function initialize(appInstance: ApplicationInstance): void {
const config = environmentConfig['@sentry/ember'];
const config = getSentryConfig();
if (config['disablePerformance']) {
return;
}
Expand All @@ -32,7 +36,7 @@ function getTransitionInformation(transition: any, router: any) {
export function _instrumentEmberRouter(
routerService: any,
routerMain: any,
config: typeof environmentConfig['@sentry/ember'],
config: EmberSentryConfig,
startTransaction: Function,
startTransactionOnPageLoad?: boolean,
) {
Expand Down Expand Up @@ -106,7 +110,7 @@ export function _instrumentEmberRouter(
};
}

function _instrumentEmberRunloop(config: typeof environmentConfig['@sentry/ember']) {
function _instrumentEmberRunloop(config: EmberSentryConfig) {
const { disableRunloopPerformance, minimumRunloopQueueDuration } = config;
if (disableRunloopPerformance) {
return;
Expand Down Expand Up @@ -227,7 +231,7 @@ function processComponentRenderAfter(
}
}

function _instrumentComponents(config: typeof environmentConfig['@sentry/ember']) {
function _instrumentComponents(config: EmberSentryConfig) {
const { disableInstrumentComponents, minimumComponentRenderDuration, enableComponentDefinitions } = config;
if (disableInstrumentComponents) {
return;
Expand Down Expand Up @@ -264,7 +268,7 @@ function _instrumentComponents(config: typeof environmentConfig['@sentry/ember']
_subscribeToRenderEvents();
}

function _instrumentInitialLoad(config: typeof environmentConfig['@sentry/ember']) {
function _instrumentInitialLoad(config: EmberSentryConfig) {
const startName = '@sentry/ember:initial-load-start';
const endName = '@sentry/ember:initial-load-end';

Expand Down Expand Up @@ -309,7 +313,7 @@ function _instrumentInitialLoad(config: typeof environmentConfig['@sentry/ember'
}

export async function instrumentForPerformance(appInstance: ApplicationInstance) {
const config = environmentConfig['@sentry/ember'];
const config = getSentryConfig();
const sentryConfig = config.sentry;

const tracing = await import('@sentry/tracing');
Expand Down
19 changes: 19 additions & 0 deletions packages/ember/addon/types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { BrowserOptions } from '@sentry/browser';

export type EmberSentryConfig = {
sentry: BrowserOptions;
transitionTimeout: number;
ignoreEmberOnErrorWarning: boolean;
disableInstrumentComponents: boolean;
disablePerformance: boolean;
disablePostTransitionRender: boolean;
disableRunloopPerformance: boolean;
disableInitialLoadInstrumentation: boolean;
enableComponentDefinitions: boolean;
minimumRunloopQueueDuration: number;
minimumComponentRenderDuration: number;
};

export type OwnConfig = {
sentryConfig: EmberSentryConfig;
};
2 changes: 2 additions & 0 deletions packages/ember/config/ember-try.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
'use strict';

const getChannelURL = require('ember-source-channel-url');
const { embroiderSafe } = require('@embroider/test-setup');

module.exports = async function() {
return {
Expand Down Expand Up @@ -47,6 +48,7 @@ module.exports = async function() {
},
},
},
embroiderSafe(),
// The default `.travis.yml` runs this scenario via `npm test`,
// not via `ember try`. It's still included here so that running
// `ember try:each` manually or from a customized CI config will run it
Expand Down
4 changes: 2 additions & 2 deletions packages/ember/ember-cli-build.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,6 @@ module.exports = function(defaults) {
This build file does *not* influence how the addon or the app using it
behave. You most likely want to be modifying `./index.js` or app's build file
*/

return app.toTree();
const { maybeEmbroider } = require('@embroider/test-setup');
return maybeEmbroider(app);
};
8 changes: 8 additions & 0 deletions packages/ember/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,18 @@ module.exports = {
babel: {
plugins: [require.resolve('ember-auto-import/babel-plugin')],
},
'@embroider/macros': {
setOwnConfig: {},
},
},

contentFor(type, config) {
const addonConfig = config['@sentry/ember'] || {};
const app = this._findHost(this);
this.app = app;
const options = Object.assign({}, addonConfig);
this.options['@embroider/macros'].setOwnConfig.sentryConfig = options;

const { disablePerformance, disableInitialLoadInstrumentation } = addonConfig;
if (disablePerformance || disableInitialLoadInstrumentation) {
return;
Expand Down
15 changes: 9 additions & 6 deletions packages/ember/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,29 +32,32 @@
},
"dependencies": {
"@embroider/macros": ">=0.25.0",
"@embroider/test-setup": "^0.35.1",
"@sentry/browser": "6.0.0",
"@sentry/tracing": "6.0.0",
"@sentry/types": "6.0.0",
"@sentry/utils": "6.0.0",
"ember-auto-import": "^1.6.0",
"ember-cli-babel": "^7.20.5",
"ember-cli-htmlbars": "^5.1.2",
"ember-cli-typescript": "^3.1.4",
"ember-get-config": "^0.2.4"
"ember-cli-typescript": "^3.1.4"
},
"devDependencies": {
"@ember/optional-features": "^1.3.0",
"@embroider/compat": "^0.35.1",
"@embroider/core": "^0.35.1",
"@embroider/webpack": "^0.35.1",
"@glimmer/component": "^1.0.0",
"@glimmer/tracking": "^1.0.0",
"@sentry-internal/eslint-config-sdk": "6.0.0",
"@types/ember": "^3.16.0",
"@types/ember": "^3.16.3",
"@types/ember-qunit": "^3.4.9",
"@types/ember__test-helpers": "^1.7.0",
"@types/qunit": "^2.9.1",
"@types/rsvp": "^4.0.3",
"babel-eslint": "^10.1.0",
"broccoli-asset-rev": "^3.0.0",
"ember-cli": "^3.21.2",
"ember-cli": "^3.24.0",
"ember-cli-dependency-checker": "^3.2.0",
"ember-cli-inject-live-reload": "^2.0.2",
"ember-cli-sri": "^2.1.1",
Expand All @@ -67,7 +70,7 @@
"ember-qunit": "^4.6.0",
"ember-resolver": "^8.0.0",
"ember-sinon-qunit": "^5.0.0",
"ember-source": "^3.21.1",
"ember-source": "^3.24.0",
"ember-source-channel-url": "^2.0.1",
"ember-template-lint": "^2.9.1",
"ember-test-selectors": "^4.1.0",
Expand All @@ -91,7 +94,7 @@
"configPath": "tests/dummy/config"
},
"volta": {
"node": "12.18.3",
"node": "14.15.4",
"yarn": "1.22.5"
}
}
3 changes: 2 additions & 1 deletion packages/ember/tests/dummy/config/targets.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,6 @@ if (isCI || isProduction) {
}

module.exports = {
browsers
browsers,
node: 'current'
};
10 changes: 8 additions & 2 deletions packages/ember/tests/test-helper.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import sinon from 'sinon';
import * as Sentry from '@sentry/browser';
import environmentConfig from 'ember-get-config';

/**
* Stub Sentry init function before application is imported to avoid actually setting up Sentry and needing a DSN
Expand All @@ -14,6 +13,12 @@ import { start } from 'ember-qunit';
import { Transports } from '@sentry/browser';
import Ember from 'ember';

import { getConfig } from '@embroider/macros';

function getSentryConfig() {
return getConfig('@sentry/ember').sentryConfig;
}

export class TestFetchTransport extends Transports.FetchTransport {
sendEvent(event) {
if (Ember.testing) {
Expand All @@ -27,7 +32,8 @@ export class TestFetchTransport extends Transports.FetchTransport {
}
}

environmentConfig['@sentry/ember'].sentry['transport'] = TestFetchTransport;
const sentryConfig = getSentryConfig();
sentryConfig.sentry['transport'] = TestFetchTransport;

setApplication(Application.create(config.APP));

Expand Down
Loading