Class: Sidekiq::Datadog::TagBuilder
- Inherits:
-
Object
- Object
- Sidekiq::Datadog::TagBuilder
- Defined in:
- lib/sidekiq/datadog/tag_builder.rb
Instance Method Summary collapse
- #build_tags(worker_or_worker_class, job, queue = nil, error = nil) ⇒ Object
-
#initialize(custom_tags = [], skip_tags = [], custom_hostname = nil) ⇒ TagBuilder
constructor
A new instance of TagBuilder.
Constructor Details
#initialize(custom_tags = [], skip_tags = [], custom_hostname = nil) ⇒ TagBuilder
Returns a new instance of TagBuilder.
4 5 6 7 8 9 10 11 |
# File 'lib/sidekiq/datadog/tag_builder.rb', line 4 def initialize( = [], = [], custom_hostname = nil) @tags = Array() @skip_tags = Array().map(&:to_s) env = Sidekiq.[:environment] || ENV['RACK_ENV'] host = custom_hostname || ENV['INSTRUMENTATION_HOSTNAME'] || Socket.gethostname setup_defaults(host: host, env: env) end |
Instance Method Details
#build_tags(worker_or_worker_class, job, queue = nil, error = nil) ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/sidekiq/datadog/tag_builder.rb', line 13 def (worker_or_worker_class, job, queue = nil, error = nil) = @tags.flat_map do |tag| case tag when String then tag when Proc then tag.call(worker_or_worker_class, job, queue, error) end end .compact! .push "name:#{job_name(worker_or_worker_class, job)}" if include_tag?('name') .push "queue:#{queue}" if queue && include_tag?('queue') if error.nil? .push 'status:ok' if include_tag?('status') else kind = underscore(error.class.name.sub(/Error$/, '')) .push 'status:error' if include_tag?('status') .push "error:#{kind}" if include_tag?('error') end end |