忽略使用Airbrake JS的环境。

huangapple go评论107阅读模式
英文:

Ignore environments with Airbrake JS

问题

我们使用Airbrake来跟踪我们的Rails应用程序中的错误,使用他们的SDK的Ruby和JS版本...但注意到我们无法在JS代码中忽略某些环境,如开发和测试环境。

在我们的配置中,我们有:

var airbrake = new Airbrake.Notifier({
  host: '<%= Settings.airbrake_host %>',
  projectId: 1,
  projectKey: '<%= Settings.airbrake_key %>',
  environment: '<%= Rails.env %>',
  ignoreEnvironments: ['development', 'test'] // Not working???
});

我们基于Ruby端的配置进行了这个设置:

Airbrake.configure do |config|
  config.host = Settings.airbrake_host
  config.project_id = 1
  config.project_key = Settings.airbrake_key
  config.environment = Rails.env
  config.ignore_environments = %w[development test]
end

查看代码中的可用选项:https://github.com/airbrake/airbrake-js/blob/master/packages/browser/src/options.ts 看起来没有ignoreEnvironments,这就是为什么它不起作用的原因...是否有一种方式可以忽略环境?我们不想在调用Airbrake的任何地方都包装条件以检查环境。

英文:

We use Airbrake to track errors in our Rails application using the Ruby and JS versions of their SDK... but noticed that we're unable to ignore certain environments such as development and test in our JS code.

In our configuration we have:

var airbrake = new Airbrake.Notifier({
  host: &#39;&lt;%= Settings.airbrake_host %&gt;&#39;,
  projectId: 1,
  projectKey: &#39;&lt;%= Settings.airbrake_key %&gt;&#39;,
  environment: &#39;&lt;%= Rails.env %&gt;&#39;,
  ignoreEnvironments: [&#39;development&#39;, &#39;test&#39;] // Not working???
});

We've based this on what we have for the Ruby-side:

Airbrake.configure do |config|
  config.host = Settings.airbrake_host
  config.project_id = 1
  config.project_key = Settings.airbrake_key
  config.environment = Rails.env
  config.ignore_environments = %w[development test]
end

Looking at the available options in the code: https://github.com/airbrake/airbrake-js/blob/master/packages/browser/src/options.ts it seems there's no ignoreEnvironments so that's why it's not working... is there a way to ignore environments? We don't want to have to wrap any calls to Airbrake with a conditional to check the environment.

答案1

得分: 0

One way I've found to handle this is to add a filter after the configuration that checks if the environment matches one of our ignored ones:

airbrake.addFilter((notice) => {
  if (['development', 'test'].includes(notice.context.environment)) return null;
  return notice;
});
英文:

One way I've found to handle this is to add a filter after the configuration that checks if the environment matches one of our ignored ones:

airbrake.addFilter((notice) =&gt; {
  if ([&#39;development&#39;, &#39;test&#39;].includes(notice.context.environment)) return null;
  return notice;
});

huangapple
  • 本文由 发表于 2023年5月17日 17:30:13
  • 转载请务必保留本文链接:https://go.coder-hub.com/76270576.html
  • airbrake
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定