Class: NexusSemanticLogger::DatadogSingleton

Inherits:
Object
  • Object
show all
Includes:
Singleton
Defined in:
lib/nexus_semantic_logger/datadog_singleton.rb

Overview

Application wide location to get datadog objects. dogstatsd-ruby maintains its own queue and thread for flushing, so the client code should never create its own statsd instance.

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#statsdObject

Returns the value of attribute statsd.



10
11
12
# File 'lib/nexus_semantic_logger/datadog_singleton.rb', line 10

def statsd
  @statsd
end

Instance Method Details

#count(metric, value, tags: []) ⇒ Object

Delegate to statsd (if available).

Parameters:

  • metric (String)

    Metric name.

  • value (Numeric)

    Count value.

  • tags (Array<String>) (defaults to: [])

    Additional tags.



63
64
65
66
# File 'lib/nexus_semantic_logger/datadog_singleton.rb', line 63

def count(metric, value, tags: [])
  statsd&.count(metric, value, tags: combine_tags(tags))
  flush
end

#decrement(metric, tags: []) ⇒ Object

Delegate to statsd (if available).

Parameters:

  • metric (String)

    Metric name.

  • tags (Array<String>) (defaults to: [])

    Additional tags.



27
28
29
30
# File 'lib/nexus_semantic_logger/datadog_singleton.rb', line 27

def decrement(metric, tags: [])
  statsd&.decrement(metric, tags: combine_tags(tags))
  flush
end

#distribution(metric, value, tags: []) ⇒ Object

Delegate to statsd (if available).

Parameters:

  • metric (String)

    Metric name.

  • value (Numeric)

    Distribution value.

  • tags (Array<String>) (defaults to: [])

    Additional tags.



45
46
47
48
# File 'lib/nexus_semantic_logger/datadog_singleton.rb', line 45

def distribution(metric, value, tags: [])
  statsd&.distribution(metric, value, tags: combine_tags(tags))
  flush
end

#flushObject



12
13
14
# File 'lib/nexus_semantic_logger/datadog_singleton.rb', line 12

def flush
  statsd&.flush(sync: Rails.env.development?) # Force flush sync in development, speed up checks.
end

#gauge(metric, value, tags: []) ⇒ Object

Delegate to statsd (if available).

Parameters:

  • metric (String)

    Metric name.

  • value (Numeric)

    Gauge value.

  • tags (Array<String>) (defaults to: [])

    Additional tags.



54
55
56
57
# File 'lib/nexus_semantic_logger/datadog_singleton.rb', line 54

def gauge(metric, value, tags: [])
  statsd&.gauge(metric, value, tags: combine_tags(tags))
  flush
end

#increment(metric, tags: []) ⇒ Object

Delegate to statsd (if available).

Parameters:

  • metric (String)

    Metric name.

  • tags (Array<String>) (defaults to: [])

    Additional tags.



19
20
21
22
# File 'lib/nexus_semantic_logger/datadog_singleton.rb', line 19

def increment(metric, tags: [])
  statsd&.increment(metric, tags: combine_tags(tags))
  flush
end

#timing(metric, ms, tags: []) ⇒ Object

Delegate to statsd (if available).

Parameters:

  • metric (String)

    Metric name.

  • ms (Integer)

    Timing in milliseconds.

  • tags (Array<String>) (defaults to: [])

    Additional tags.



36
37
38
39
# File 'lib/nexus_semantic_logger/datadog_singleton.rb', line 36

def timing(metric, ms, tags: [])
  statsd&.timing(metric, ms, tags: combine_tags(tags))
  flush
end