Class: SemanticLogger::Metrics::NewRelic
- Inherits:
-
Subscriber
- Object
- Base
- Subscriber
- SemanticLogger::Metrics::NewRelic
- Defined in:
- lib/semantic_logger/metrics/new_relic.rb
Instance Attribute Summary collapse
-
#prefix ⇒ Object
Returns the value of attribute prefix.
Attributes inherited from Subscriber
#application, #formatter, #host
Attributes inherited from Base
Instance Method Summary collapse
- #call(log) ⇒ Object
-
#initialize(options = {}) ⇒ NewRelic
constructor
Parameters: :prefix [String] Prefix to add to every metric before forwarding to NewRelic Default: ‘Custom’.
Methods inherited from Subscriber
#close, #default_formatter, #flush, #level
Methods inherited from Base
#fast_tag, #level, #level=, #measure, #payload, #pop_tags, #push_tags, #silence, #tagged, #tags, #with_payload
Constructor Details
#initialize(options = {}) ⇒ NewRelic
Parameters:
:prefix [String]
Prefix to add to every metric before forwarding to NewRelic
Default: 'Custom'
10 11 12 13 14 |
# File 'lib/semantic_logger/metrics/new_relic.rb', line 10 def initialize( = {}) = .dup @prefix = .delete(:prefix) || 'Custom' raise(ArgumentError, "Unknown options: #{.inspect}") if .size > 0 end |
Instance Attribute Details
#prefix ⇒ Object
Returns the value of attribute prefix.
4 5 6 |
# File 'lib/semantic_logger/metrics/new_relic.rb', line 4 def prefix @prefix end |
Instance Method Details
#call(log) ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/semantic_logger/metrics/new_relic.rb', line 16 def call(log) metric = log.metric # Add prefix for NewRelic metric = "#{prefix}/#{metric}" unless metric.start_with?(prefix) if duration = log.duration # Convert duration to seconds ::NewRelic::Agent.record_metric(metric, duration / 1000.0) else ::NewRelic::Agent.increment_metric(metric, log.metric_amount || 1) end end |