Skip to content

Commit c94100a

Browse files
authored
ref(ember): Improve sdk consistency with other sdk usage (#3611)
Considering how being able to pass Sentry config into the init function at runtime is now supported, this cleans up the way the Ember sdk works to be more in-line with our other sdk's (like Vue). This should primarily make our general docs more correct for Ember usage as we can shift to always recommending passing config to init (instead of a lot of special cases) as well as keep maintenance of the sdk simple. - Switches to exporting an 'init' function (still exporting the old function for backwards compatibility) - Allows passing browserTracingOptions in the Sentry config at runtime as well, since it's not really an addon option and we might need to pass functions like 'beforeNavigate', which Ember config doesn't really support.
1 parent 301c7cd commit c94100a

File tree

5 files changed

+23
-9
lines changed

5 files changed

+23
-9
lines changed

packages/ember/addon/index.ts

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,15 +73,25 @@ export const instrumentRoutePerformance = (BaseRoute: any) => {
7373
return {
7474
[BaseRoute.name]: class extends BaseRoute {
7575
beforeModel(...args: any[]) {
76-
return instrumentFunction('ember.route.beforeModel', (<any>this).fullRouteName, super.beforeModel.bind(this), args);
76+
return instrumentFunction(
77+
'ember.route.beforeModel',
78+
(<any>this).fullRouteName,
79+
super.beforeModel.bind(this),
80+
args,
81+
);
7782
}
7883

7984
async model(...args: any[]) {
8085
return instrumentFunction('ember.route.model', (<any>this).fullRouteName, super.model.bind(this), args);
8186
}
8287

8388
async afterModel(...args: any[]) {
84-
return instrumentFunction('ember.route.afterModel', (<any>this).fullRouteName, super.afterModel.bind(this), args);
89+
return instrumentFunction(
90+
'ember.route.afterModel',
91+
(<any>this).fullRouteName,
92+
super.afterModel.bind(this),
93+
args,
94+
);
8595
}
8696

8797
async setupController(...args: any[]) {
@@ -97,3 +107,6 @@ export const instrumentRoutePerformance = (BaseRoute: any) => {
97107
};
98108

99109
export * from '@sentry/browser';
110+
111+
// init is now the preferred way to call initialization for this addon.
112+
export const init = InitSentryForEmber;

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -333,7 +333,8 @@ function _instrumentInitialLoad(config: EmberSentryConfig) {
333333
export async function instrumentForPerformance(appInstance: ApplicationInstance) {
334334
const config = getSentryConfig();
335335
const sentryConfig = config.sentry;
336-
const browserTracingOptions = config.browserTracingOptions || {};
336+
// Maintaining backwards compatibility with config.browserTracingOptions, but passing it with Sentry options is preferred.
337+
const browserTracingOptions = config.browserTracingOptions || config.sentry.browserTracingOptions || {};
337338

338339
const tracing = await import('@sentry/tracing');
339340

packages/ember/addon/types.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { BrowserOptions } from '@sentry/browser';
22

33
export type EmberSentryConfig = {
4-
sentry: BrowserOptions;
4+
sentry: BrowserOptions & { browserTracingOptions: Object };
55
transitionTimeout: number;
66
ignoreEmberOnErrorWarning: boolean;
77
disableInstrumentComponents: boolean;

packages/ember/tests/dummy/app/app.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import Application from '@ember/application';
22
import Resolver from 'ember-resolver';
33
import loadInitializers from 'ember-load-initializers';
44
import config from './config/environment';
5-
import { InitSentryForEmber } from '@sentry/ember';
5+
import * as Sentry from '@sentry/ember';
66

77
import { Transports } from '@sentry/browser';
88
import Ember from 'ember';
@@ -20,7 +20,7 @@ class TestFetchTransport extends Transports.FetchTransport {
2020
}
2121
}
2222

23-
InitSentryForEmber({
23+
Sentry.init({
2424
transport: TestFetchTransport,
2525
});
2626

packages/ember/tests/dummy/config/environment.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,9 @@ module.exports = function(environment) {
2727
sentry: {
2828
tracesSampleRate: 1,
2929
dsn: process.env.SENTRY_DSN,
30-
},
31-
browserTracingOptions: {
32-
tracingOrigins: ['localhost', 'doesntexist.example'],
30+
browserTracingOptions: {
31+
tracingOrigins: ['localhost', 'doesntexist.example'],
32+
},
3333
},
3434
ignoreEmberOnErrorWarning: true,
3535
minimumRunloopQueueDuration: 5,

0 commit comments

Comments
 (0)