Class: Datadog::Metrics::Logging::Adapter
- Inherits:
-
Object
- Object
- Datadog::Metrics::Logging::Adapter
- Defined in:
- lib/ddtrace/metrics.rb
Overview
Surrogate for Datadog::Statsd to log elsewhere
Instance Attribute Summary collapse
-
#logger ⇒ Object
Returns the value of attribute logger.
Instance Method Summary collapse
- #count(stat, value, options = nil) ⇒ Object
- #distribution(stat, value, options = nil) ⇒ Object
- #gauge(stat, value, options = nil) ⇒ Object
- #increment(stat, options = nil) ⇒ Object
-
#initialize(logger = nil) ⇒ Adapter
constructor
A new instance of Adapter.
Constructor Details
#initialize(logger = nil) ⇒ Adapter
Returns a new instance of Adapter.
188 189 190 191 192 193 194 195 196 197 |
# File 'lib/ddtrace/metrics.rb', line 188 def initialize(logger = nil) @logger = logger || Logger.new(STDOUT).tap do |l| l.level = Logger::INFO l.progname = nil l.formatter = proc do |_severity, datetime, _progname, msg| stat = JSON.parse(msg[3..-1]) # Trim off leading progname... "#{JSON.dump(timestamp: datetime.to_i, message: 'Metric sent.', metric: stat)}\n" end end end |
Instance Attribute Details
#logger ⇒ Object
Returns the value of attribute logger.
186 187 188 |
# File 'lib/ddtrace/metrics.rb', line 186 def logger @logger end |
Instance Method Details
#count(stat, value, options = nil) ⇒ Object
199 200 201 |
# File 'lib/ddtrace/metrics.rb', line 199 def count(stat, value, = nil) logger.info({ stat: stat, type: :count, value: value, options: }.to_json) end |
#distribution(stat, value, options = nil) ⇒ Object
203 204 205 |
# File 'lib/ddtrace/metrics.rb', line 203 def distribution(stat, value, = nil) logger.info({ stat: stat, type: :distribution, value: value, options: }.to_json) end |
#gauge(stat, value, options = nil) ⇒ Object
211 212 213 |
# File 'lib/ddtrace/metrics.rb', line 211 def gauge(stat, value, = nil) logger.info({ stat: stat, type: :gauge, value: value, options: }.to_json) end |
#increment(stat, options = nil) ⇒ Object
207 208 209 |
# File 'lib/ddtrace/metrics.rb', line 207 def increment(stat, = nil) logger.info({ stat: stat, type: :increment, options: }.to_json) end |