Skip to content

@sentry/ember: Can't disable Sentry in specific environments with Sentry configuration options. "Failed to execute 'measure' on 'Performance': The mark '@sentry/ember:initial-load-start' does not exist." #3391

@jayjayjpg

Description

@jayjayjpg

Package + Version

  • @sentry/browser: 6.2.5,
  • @sentry/node: 6.2.5
  • raven-js: 3.27.2
  • raven-node (raven for node)
  • @sentry/ember: "^6.2.5",
  • ember-source: 3.26.2

Version:

6.2.5

Description

Current behaviour

After reviewing the documentation on how to initialise Sentry in Ember apps and looking into the configuration options I haven't found a solution to enable / disable Sentry in specific environments in an Ember app yet.

When I try to run my tests via ember test --server, I see the following error showing up repeatedly any time my app throws an error:

Source: | Error: Failed to execute 'measure' on 'Performance': 
The mark '@sentry/ember:initial-load-start' does not exist.     at _instrumentInitialLoad (http://localhost:7357/assets/vendor.js:95882:17)     at instrumentForPerformance (http://localhost:7357/assets/vendor.js:95927:5)

Expected behaviour

I would expect Sentry to be entirely disabled for the testing environment with my current setup and therefore I would not expect to see any Sentry-related errors in my testing output.

Current Setup

My setup looks as follows in my Ember app my-app:

// my-app/app/app.js
// ...
import config from 'my-app/config/environment';
import { InitSentryForEmber } from '@sentry/ember';

InitSentryForEmber();

export default class App extends Application {
  modulePrefix = config.modulePrefix;
  podModulePrefix = config.podModulePrefix;
  Resolver = Resolver;
}

loadInitializers(App, config.modulePrefix);

I setup the @sentry/ember configuration as follows with the goal to disable Sentry in dev and testing environments and enable Sentry for production only:

// my-app/config/environment.js
'use strict';

module.exports = function (environment) {
  let ENV = {
     // ...
   };
   
  ENV['@sentry/ember'] = {
    sentry: {
      environment,
    },
  };

  if (environment === 'development') {
   // ...
  }

  if (environment === 'test') {
    // ...
  }

  if (environment === 'production') {
    // ...
    ENV['@sentry/ember'].sentry.dsn = process.env.MY_DSN;
    ENV['@sentry/ember'].sentry.tracesSampleRate = 1.0;
  }

  return ENV;
};

Current Workaround

When I debugged the error, I noticed that there's a disableInitialLoadInstrumentation configuration flag that will allow an early exit from the initialising function that is throwing the error in my-app's tests:

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

function _instrumentInitialLoad(config: EmberSentryConfig) {
   // ...

  if (config.disableInitialLoadInstrumentation) {
      performance.clearMarks(startName);
      performance.clearMarks(endName);
      return;
  }

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

If I update my app's configuration file as follows to set this flag to true, in the testing environment, my test suite passes again:

// my-app/config/environment.js
'use strict';

module.exports = function (environment) {
  let ENV = {
     // ...
   };
   
  ENV['@sentry/ember'] = {
    sentry: {
      environment,
    },
    disableInitialLoadInstrumentation: true,
  };

  if (environment === 'development') {
   // ...
  }

  if (environment === 'test') {
    // ...
  }

  if (environment === 'production') {
    // ...
    ENV['@sentry/ember'].sentry.dsn = process.env.MY_DSN;
    ENV['@sentry/ember'].sentry.tracesSampleRate = 1.0;
    ENV['@sentry/ember'].disableInitialLoadInstrumentation = false;
  }

  return ENV;
};

How to fix?

Since I couldn't find any documentation on the disableInitialLoadInstrumentation flag, I assume this is not public API and this behaviour is a bug? If this was the case, how can this be fixed? Happy to send a PR if anyone has ideas on how this could be resolved.

Metadata

Metadata

Assignees

Labels

Package: emberIssues related to the Sentry Ember SDK

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions