如何从Rail初始化程序在运行时调用代码?

时间:2017-09-19 13:34:22

标签: ruby-on-rails raygun

我在使用分片数据库的应用中使用Raygun进行错误跟踪。单独的客户端将其数据存储在自己的数据库服务器分片上。

rails c
1> MultiSite.get_shard
#=> master
2> Post.count
#=> 0
3> MultiSite.set_shard :client1_prod
#=> nil
4> MultiSite.get_shard
#=> client1_prod
5> Post.count
#=> 123

使用Raygun时,我可以使用Raygun config/initializers/raygun.rb设置错误标记:

Raygun.setup do |config|
  config.api_key = LOCAL_SETTINGS["raygun_token"]
  config.filter_parameters = Rails.application.config.filter_parameters
  config.version = EnvironmentInformation.get_version
  config.tags = [
                  EnvironmentInformation.get_server_name,
                  EnvironmentInformation.get_version,
                  EnvironmentInformation.get_commit_hash,
                  EnvironmentInformation.shard_name
                ]
  config.enable_reporting = true
end

所以在这里我尝试使用EnvironmentInformation.shard_name告诉我哪个客户端(哪个分片)遇到错误,以便我可以在Raygun应用上过滤该标记。

不幸的是,在应用启动时(运行此初始化程序中的代码时),我们仍然在master分片上。这意味着Raygun会将每个错误标记为master分片。

有什么方法可以修改我的初始化程序,以便在发生错误时可以调用EnvironmentInformation.shard_name

谷歌搜索还没有想出任何东西。

1 个答案:

答案 0 :(得分:0)

通过功能请求,Raygun的人员实现了一个proc,可以在运行时动态设置标签。

虽然仍然普遍感兴趣,但我的具体问题现在已经解决了。

https://raygun.com/thinktank/suggestion/94060

相关问题