英文:
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: '<%= Settings.airbrake_host %>',
projectId: 1,
projectKey: '<%= Settings.airbrake_key %>',
environment: '<%= Rails.env %>',
ignoreEnvironments: ['development', 'test'] // 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) => {
if (['development', 'test'].includes(notice.context.environment)) return null;
return notice;
});
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。


评论