Skip to content

feat(ember): Extract ember-specific logic into custom browserTracingIntegration#20702

Merged
mydea merged 6 commits into
developfrom
fn/ember-better-browserTracing
May 13, 2026
Merged

feat(ember): Extract ember-specific logic into custom browserTracingIntegration#20702
mydea merged 6 commits into
developfrom
fn/ember-better-browserTracing

Conversation

@mydea
Copy link
Copy Markdown
Member

@mydea mydea commented May 6, 2026

Kind of extracted/inspired by #19229, this refactors the ember logic for performance monitoring to use the more general pattern we already have in our code, delegating this fully into an ember-specific browserTracingIntegration.

For now, this should not be breaking, as the auto-wiring etc. remains the same - it just uses this integration under the hood instead of manually calling stuff etc.

In a follow up, this should make it much easier to use this in a more standalone fashion in the v2 addon.

I've split the logic into separate files as this was all a bit convoluted together, hopefully this makes it a bit easier to follow what belongs where etc.

This also generally aligns the ember package more with our own broader way of handling things, which is also nice IMHO. If you add the integration, you get everything set up, and if not, not - easy! :D

Status quo

This is still being added automatically - this is what instance-initializers/sentry-performance.ts does. that auto-runs and adds the browser tracing integration so it has access to the ember app instance, which we need to setup tracing stuff properly.

Future (v11)

We'll no longer have the auto instance-initializer, but instead users will have to manually add this. but this can be simplified then in their app code to:

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

export function initialize(appInstance) {
  Sentry.addIntegration(Sentry.browserTracingIntegration({ appInstance }));
}

@mydea mydea self-assigned this May 6, 2026
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 6, 2026

size-limit report 📦

⚠️ Warning: Base artifact is not the latest one, because the latest workflow run is not done yet. This may lead to incorrect results. Try to re-run all tests to get up to date results.

Path Size % Change Change
@sentry/browser 26.88 kB - -
@sentry/browser - with treeshaking flags 25.32 kB - -
@sentry/browser (incl. Tracing) 44.78 kB - -
@sentry/browser (incl. Tracing + Span Streaming) 46.75 kB - -
@sentry/browser (incl. Tracing, Profiling) 49.77 kB - -
@sentry/browser (incl. Tracing, Replay) 84.41 kB - -
@sentry/browser (incl. Tracing, Replay) - with treeshaking flags 73.84 kB - -
@sentry/browser (incl. Tracing, Replay with Canvas) 89.11 kB - -
@sentry/browser (incl. Tracing, Replay, Feedback) 101.75 kB - -
@sentry/browser (incl. Feedback) 44.06 kB - -
@sentry/browser (incl. sendFeedback) 31.69 kB - -
@sentry/browser (incl. FeedbackAsync) 36.8 kB - -
@sentry/browser (incl. Metrics) 27.97 kB - -
@sentry/browser (incl. Logs) 28.11 kB - -
@sentry/browser (incl. Metrics & Logs) 28.8 kB - -
@sentry/react 28.63 kB - -
@sentry/react (incl. Tracing) 47.05 kB - -
@sentry/vue 31.8 kB - -
@sentry/vue (incl. Tracing) 46.65 kB - -
@sentry/svelte 26.9 kB - -
CDN Bundle 29.26 kB - -
CDN Bundle (incl. Tracing) 47.17 kB - -
CDN Bundle (incl. Logs, Metrics) 30.64 kB - -
CDN Bundle (incl. Tracing, Logs, Metrics) 48.29 kB - -
CDN Bundle (incl. Replay, Logs, Metrics) 69.97 kB - -
CDN Bundle (incl. Tracing, Replay) 84.56 kB - -
CDN Bundle (incl. Tracing, Replay, Logs, Metrics) 85.63 kB - -
CDN Bundle (incl. Tracing, Replay, Feedback) 90.37 kB - -
CDN Bundle (incl. Tracing, Replay, Feedback, Logs, Metrics) 91.47 kB - -
CDN Bundle - uncompressed 86.08 kB - -
CDN Bundle (incl. Tracing) - uncompressed 141.53 kB - -
CDN Bundle (incl. Logs, Metrics) - uncompressed 90.28 kB - -
CDN Bundle (incl. Tracing, Logs, Metrics) - uncompressed 145 kB - -
CDN Bundle (incl. Replay, Logs, Metrics) - uncompressed 215.1 kB - -
CDN Bundle (incl. Tracing, Replay) - uncompressed 260.24 kB - -
CDN Bundle (incl. Tracing, Replay, Logs, Metrics) - uncompressed 263.69 kB - -
CDN Bundle (incl. Tracing, Replay, Feedback) - uncompressed 273.94 kB - -
CDN Bundle (incl. Tracing, Replay, Feedback, Logs, Metrics) - uncompressed 277.38 kB - -
@sentry/nextjs (client) 49.56 kB - -
@sentry/sveltekit (client) 45.27 kB - -
@sentry/node-core 60.84 kB +0.02% +11 B 🔺
@sentry/node 165.98 kB +0.01% +10 B 🔺
@sentry/node - without tracing 73.97 kB +0.01% +6 B 🔺
@sentry/aws-serverless 108.07 kB +0.01% +7 B 🔺
@sentry/cloudflare (withSentry) - minified 170.68 kB - -
@sentry/cloudflare (withSentry) 430.48 kB - -

View base workflow run

@mydea mydea force-pushed the fn/ember-better-browserTracing branch from 705bcf0 to bc9ce81 Compare May 6, 2026 14:05
Comment thread packages/ember/addon/instance-initializers/sentry-performance.ts
afterAllSetup(client: BrowserClient) {
integration.afterAllSetup(client);

// Run this in the next tick to ensure the ember router etc. is properly initialized
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

without this, the pageload instrumentation does not work. it seems that router.location is not properly resolved/available yet at this time. probably some timing issue. this was not a problem before because we had an await import before this which lead to no timing issues in that case.

@mydea mydea marked this pull request as ready for review May 6, 2026 14:23
@mydea mydea requested a review from a team as a code owner May 6, 2026 14:23
Comment thread packages/ember/addon/utils/performance.ts
Comment thread packages/ember/addon/utils/browserTracingIntegration.ts Outdated
Comment thread packages/ember/addon/instance-initializers/sentry-performance.ts
@mydea mydea force-pushed the fn/ember-better-browserTracing branch from 14cb4fa to 39a52a7 Compare May 6, 2026 14:55
@github-actions
Copy link
Copy Markdown
Contributor

👋 @getsentry/team-javascript-sdks-framework — Please review this PR when you get a chance!

Copy link
Copy Markdown
Member

@nicohrubec nicohrubec left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

Comment thread packages/ember/addon/instance-initializers/sentry-performance.ts Outdated
Comment thread packages/ember/addon/utils/performance.ts Outdated
Comment thread packages/ember/addon/utils/browserTracingIntegration.ts Outdated
mydea added 3 commits May 13, 2026 10:10
make it work with legacy stuff...

move stuff around and fix it

WIP move stuff around...

fix where stuff lives
@mydea mydea force-pushed the fn/ember-better-browserTracing branch from 39a52a7 to 9fc40f2 Compare May 13, 2026 08:16
Comment thread packages/ember/addon/utils/instrumentEmberGlobals.ts
Comment thread packages/ember/addon/index.ts
}
if (!disableInitialLoadInstrumentation) {
_instrumentInitialLoad();
}
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Performance marks not cleared when instrumentation disabled

Low Severity

When disableInitialLoadInstrumentation is true, _instrumentInitialLoad() is never called. The old code always called this function regardless, and it would explicitly clearMarks for @sentry/ember:initial-load-start and @sentry/ember:initial-load-end before returning early. The new code skips the function entirely, so those performance marks persist in the browser's performance timeline instead of being cleaned up.

Additional Locations (1)
Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit 9fc40f2. Configure here.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is fine, this is not added in the first place here.

disableInitialLoadInstrumentation?: boolean;
};

let _initialized = false;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bug: The module-level _initialized flag in browserTracingIntegration.ts is not reset between tests, causing instrumentGlobalsForPerformance to be skipped in subsequent test runs, leading to inconsistent behavior.
Severity: LOW

Suggested Fix

The _initialized flag should be reset between test runs. This can be achieved by exporting a reset function from the browserTracingIntegration.ts module and calling it in a beforeEach or afterEach hook within the test setup helpers, such as setupSentryTest.

Prompt for AI Agent
Review the code at the location below. A potential bug has been identified by an AI
agent. Verify if this is a real issue. If it is, propose a fix; if not, explain why it's
not valid.

Location: packages/ember/addon/utils/browserTracingIntegration.ts#L23

Potential issue: In a test environment, the `_initialized` flag in
`browserTracingIntegration.ts` is a module-level variable that is set to `true` on its
first execution and is never reset. If an Ember application instance is recreated
between tests, the `browserTracingIntegration` function will be called again. However,
because `_initialized` remains `true`, the call to `instrumentGlobalsForPerformance` is
skipped on subsequent runs. This can lead to inconsistent global instrumentation across
tests, potentially causing flaky or incorrect test outcomes for performance monitoring
features.

Comment on lines +75 to +84
// We only want to run this once in tests!
if (macroCondition(isTesting())) {
if (_initialized) {
return;
}
}

instrumentGlobalsForPerformance(globalsPerformanceConfig);
_initialized = true;
});
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bug: Using setTimeout() for deferred instrumentation creates a race condition in Ember tests, as it's not tracked by Ember's settled() state, causing assertions to run prematurely.
Severity: MEDIUM

Suggested Fix

Replace setTimeout() with an Ember-aware scheduling function like Ember.run.later(). This ensures the deferred work is tracked by Ember's test infrastructure, preventing the race condition and allowing tests to wait for instrumentation to complete before running assertions. Alternatively, re-expose a promise that resolves after instrumentation is complete, which tests can explicitly await.

Prompt for AI Agent
Review the code at the location below. A potential bug has been identified by an AI
agent. Verify if this is a real issue. If it is, propose a fix; if not, explain why it's
not valid.

Location: packages/ember/addon/utils/browserTracingIntegration.ts#L75-L84

Potential issue: The use of `setTimeout()` in `browserTracingIntegration.ts` to defer
performance instrumentation creates a race condition in Ember acceptance tests. Ember's
test helpers, such as `await visit()`, rely on a `settled()` state which waits for the
run loop and tracked timers to complete. However, `setTimeout()` schedules work outside
of the Ember run loop, so it is not tracked. Consequently, test assertions can execute
before the deferred instrumentation code runs. This can cause tests that check for
transaction spans created by this instrumentation to fail because the spans have not yet
been created when the assertions are made.

Also affects:

  • packages/ember/addon/instance-initializers/sentry-performance.ts:15~21

Copy link
Copy Markdown

@cursor cursor Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes and found 1 potential issue.

There are 2 total unresolved issues (including 1 from previous review).

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit 2ab8cf4. Configure here.

});
},
};
}
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing integration or E2E tests for new feature

Low Severity

This is a feat PR that introduces a new ember-specific browserTracingIntegration with significant refactored logic (new integration wrapper, setTimeout deferral, module-level _initialized guard, split config handling). However, the PR does not include any new integration or E2E tests for this new functionality. Existing tests were only updated for import path changes. Adding at least one integration test verifying the new integration's behavior would help catch regressions.

Fix in Cursor Fix in Web

Triggered by project rule: PR Review Guidelines for Cursor Bot

Reviewed by Cursor Bugbot for commit 2ab8cf4. Configure here.

@mydea mydea merged commit b4983b0 into develop May 13, 2026
267 checks passed
@mydea mydea deleted the fn/ember-better-browserTracing branch May 13, 2026 14:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants