我正在Sidekiq中实现statsd发布,并且能够成功完成,但是似乎仅将标签添加到“全局” statsd消息中。正如您在下面看到的,app:
并未附加到实际的sidekiq.job
消息中,其他所有消息都包含该消息。为什么是这样?我希望app
标签始终存在。
sidekiq.processed:16|g|#app:test-app
sidekiq.enqueued:0|g|#app:test-app
sidekiq.retries:2|g|#app:test-app
sidekiq.dead:0|g|#app:test-app
sidekiq.scheduled:0|g|#app:test-app
sidekiq.busy:0|g|#app:test-app
sidekiq.enqueued.low:0|g|#app:test-app
sidekiq.enqueued.default:0|g|#app:test-app
sidekiq.job:1|c|#host:MacBook-Pro.local,env:development,name:test_cache_job,queue:default,status:ok
sidekiq.job.time:16034|ms|#host:MacBook-Pro.local,env:development,name:test_cache_job,queue:default,status:ok
这是我在sidekiq.rb
初始化程序中实现它的方式。
Sidekiq::Pro.dogstatsd = ->{ Datadog::Statsd.new(ENV['DD_HOST'], ENV['DD_PORT'], tags: ["app:#{ENV['APP_NAME']}"]) }
Sidekiq.configure_server do |config|
# Middleware for StatsD
config.server_middleware do |chain|
require 'sidekiq/middleware/server/datadog'
chain.add Sidekiq::Middleware::Server::Datadog
end
config.save_history(Sidekiq::Pro.metrics, 30)
...
答案 0 :(得分:0)
我的同事刚刚向我指出了这一点:https://github.com/mperham/sidekiq/wiki/Middleware#client-middleware-registered-in-both-places
我猜这可行:
config.server_middleware do |chain|
require 'sidekiq/middleware/server/datadog'
chain.add Sidekiq::Middleware::Server::Datadog, tags: ["test:app"]
end