Class: Sidekiq::Middleware::Datadog

Inherits:
Object
  • Object
show all
Defined in:
lib/sidekiq/middleware/datadog.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(opts) ⇒ Datadog

Configure and install datadog instrumentation. Example:

Sidekiq.configure_server do |config|
  config.server_middleware do |chain|
    chain.add Sidekiq::Middleware::Datadog
  end
end


18
19
20
21
22
23
24
25
26
27
28
# File 'lib/sidekiq/middleware/datadog.rb', line 18

def initialize(opts)
  statsd_host   = opts[:statsd_host] || "localhost"
  statsd_port   = (opts[:statsd_port] || 8125).to_i
  prefix        = opts[:prefix] || ""
  
  @metric_name  = opts[:metric_name] || "worker"
  @statsd       = opts[:statsd] || ::Datadog::Statsd.new(statsd_host, statsd_port, namespace: prefix)
  @tags         = opts[:tags] || []

  enrich_global_tags()
end

Instance Attribute Details

#hostnameObject

Returns the value of attribute hostname.



8
9
10
# File 'lib/sidekiq/middleware/datadog.rb', line 8

def hostname
  @hostname
end

#statsdObject

Returns the value of attribute statsd.



8
9
10
# File 'lib/sidekiq/middleware/datadog.rb', line 8

def statsd
  @statsd
end

#statsd_hostObject

Returns the value of attribute statsd_host.



8
9
10
# File 'lib/sidekiq/middleware/datadog.rb', line 8

def statsd_host
  @statsd_host
end

#statsd_portObject

Returns the value of attribute statsd_port.



8
9
10
# File 'lib/sidekiq/middleware/datadog.rb', line 8

def statsd_port
  @statsd_port
end

#xalalaObject

Returns the value of attribute xalala.



8
9
10
# File 'lib/sidekiq/middleware/datadog.rb', line 8

def xalala
  @xalala
end

Instance Method Details

#call(worker, job, queue) ⇒ Object



30
31
32
33
34
35
36
37
38
39
40
# File 'lib/sidekiq/middleware/datadog.rb', line 30

def call(worker, job, queue, *)
  start = Time.now
  
  begin
    yield
    record(worker, job, queue, start)
  rescue => e
    record(worker, job, queue, start, e)
    raise
  end
end