ember-rollbar-client icon indicating copy to clipboard operation
ember-rollbar-client copied to clipboard

checkIgnore config function doesn't work

Open sdhull opened this issue 7 years ago • 4 comments

Ember config is compiled into index.html and stored as [content] on <meta name="appname/config/environment"> element after being jsonified & uri encoded (eg encodeURIComponent(JSON.stringify(configHash)) or similar).

Because JSON doesn't have a representation for function type, the checkIgnore function is lost.

See here for history / more discussion, but discussion should be continued here.

sdhull avatar Dec 18 '17 21:12 sdhull

I'm facing the same issue but when I set the transform function. It's the recommend approach to use source maps on many domains.

https://rollbar.com/docs/source-maps/#using-source-maps-on-many-domains

@Exelord Should I open a new issue or could you change the title of this issue?

viniciussbs avatar Mar 29 '18 17:03 viniciussbs

So currently we are unable to set functions in ember config :/ however it's very easy to override it in rollbar service.... Well it should be. I don't have too much time right now but what we should have is to allow override tge options property in the service and set it up correctly with our needs

Exelord avatar Mar 29 '18 21:03 Exelord

According to source maps. This should be sth that users should define by themselves. As many domains is not so common case.

Exelord avatar Mar 29 '18 21:03 Exelord

Yes, overriding the service works. But, since transform and checkIgnore are valid Rollbar configuration, why don't we simplify the process?

This is how I'm solving the problem right now:

import RollbarService from 'ember-rollbar-client/services/rollbar';
import config from 'v2v-web/config/environment';
import { get, computed } from '@ember/object';
import { assign } from '@ember/polyfills';
import { isPresent } from '@ember/utils';

export default RollbarService.extend({
  config: computed(function () {
    let transform = this.transform.bind(this);
    let { emberRollbarClient } = config;

    return assign({ transform }, emberRollbarClient);
  }).readOnly(),

  transform(payload) {
    let filenameRegex = /^(https?):\/\/[a-zA-Z0-9._-]+\.mycompanydomain\.net(.*)/;
    let { trace } = payload.body;

    if (isPresent(trace.frames)) {
      trace.frames.forEach((frame) => {
        let { filename } = frame;

        if (filename) {
          let [, protocol, path] = filename.match(filenameRegex);
          frame.filename = `${protocol}://dynamichost${path}`;
        }
      });
    }
  }
});

This is how I would like to solve it:

import RollbarService from 'ember-rollbar-client/services/rollbar';
import { isPresent } from '@ember/utils';

export default RollbarService.extend({
  transform(payload) {
    let filenameRegex = /^(https?):\/\/[a-zA-Z0-9._-]+\.mycompanydomain\.net(.*)/;
    let { trace } = payload.body;

    if (isPresent(trace.frames)) {
      trace.frames.forEach((frame) => {
        let { filename } = frame;

        if (filename) {
          let [, protocol, path] = filename.match(filenameRegex);
          frame.filename = `${protocol}://dynamichost${path}`;
        }
      });
    }
  }
});

The default implementation of Rollbar service could include transform and checkIgnore when they are provided. This is how we used to config middlewares with ember-apollo-client: providing the middleware definition and letting the addon to get them when provided.

viniciussbs avatar Apr 02 '18 21:04 viniciussbs