Class: SemanticLogger::Metric::NewRelic
- Inherits:
-
Subscriber
- Object
- Base
- Subscriber
- SemanticLogger::Metric::NewRelic
- Defined in:
- lib/semantic_logger/metric/new_relic.rb
Instance Attribute Summary collapse
-
#prefix ⇒ Object
Returns the value of attribute prefix.
Attributes inherited from Subscriber
#application, #environment, #formatter, #host, #logger, #metrics
Attributes inherited from Base
Instance Method Summary collapse
-
#call(log, _logger) ⇒ Object
Returns metric name to use.
-
#initialize(prefix: "Custom", **args, &block) ⇒ NewRelic
constructor
Create Appender.
- #log(log) ⇒ Object
-
#should_log?(log) ⇒ Boolean
Only forward log entries that contain metrics.
Methods inherited from Subscriber
#close, #console_output?, #default_formatter, #flush, #level
Methods inherited from Base
#backtrace, #fast_tag, #level, #level=, #measure, #named_tags, #pop_tags, #push_tags, #silence, #tagged, #tags
Constructor Details
#initialize(prefix: "Custom", **args, &block) ⇒ NewRelic
Create Appender
Parameters
:prefix [String]
Prefix to add to every metric before forwarding to NewRelic.
Default: 'Custom'
level: [:trace | :debug | :info | :warn | :error | :fatal]
Override the log level for this appender.
Default: :error
formatter: [Object|Proc]
An instance of a class that implements #call, or a Proc to be used to format
the output from this appender
Default: Use the built-in formatter (See: #call)
filter: [Regexp|Proc]
RegExp: Only include log where the class name matches the supplied.
regular expression. All other will be ignored.
Proc: Only include log where the supplied Proc returns true
The Proc must return true or false.
40 41 42 43 |
# File 'lib/semantic_logger/metric/new_relic.rb', line 40 def initialize(prefix: "Custom", **args, &block) @prefix = prefix super(**args, &block) end |
Instance Attribute Details
#prefix ⇒ Object
Returns the value of attribute prefix.
17 18 19 |
# File 'lib/semantic_logger/metric/new_relic.rb', line 17 def prefix @prefix end |
Instance Method Details
#call(log, _logger) ⇒ Object
Returns metric name to use.
46 47 48 49 50 51 |
# File 'lib/semantic_logger/metric/new_relic.rb', line 46 def call(log, _logger) metric = log.metric # Add prefix for NewRelic metric = "#{prefix}/#{metric}" unless metric.start_with?(prefix) metric end |
#log(log) ⇒ Object
53 54 55 56 57 58 59 60 61 62 |
# File 'lib/semantic_logger/metric/new_relic.rb', line 53 def log(log) name = formatter.call(log, self) if (duration = log.duration) # Convert duration to seconds ::NewRelic::Agent.record_metric(name, duration / 1000.0) else ::NewRelic::Agent.increment_metric(name, log.metric_amount || 1) end true end |
#should_log?(log) ⇒ Boolean
Only forward log entries that contain metrics.
65 66 67 68 |
# File 'lib/semantic_logger/metric/new_relic.rb', line 65 def should_log?(log) # Does not support metrics with dimensions. log.metric && !log.dimensions && meets_log_level?(log) && !filtered?(log) end |