Class: FastlyNsq::NewRelic

Inherits:
Object
  • Object
show all
Includes:
NewRelic::Agent::Instrumentation::ControllerInstrumentation
Defined in:
lib/fastly_nsq/new_relic.rb

Overview

FastlyNsq::NewRelic supports tracing methods with NewRelic if the newrelic_rpm is enabled

Constant Summary collapse

CATEGORY =
"OtherTransaction/FastlyNsqProcessor"

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(agent = nil) ⇒ NewRelic

Create a FastlyNsq::NewRelic instance

Examples:

tracer = FastlyNsq::NewRelic.new
tracer.notice_error(exception)

Parameters:

  • agent (#notice_error) (defaults to: nil)

    optional and should only be used if you need to override the default NewRelic::Agent



24
25
26
# File 'lib/fastly_nsq/new_relic.rb', line 24

def initialize(agent = nil)
  @agent = agent || (Object.const_defined?(:NewRelic) ? NewRelic::Agent : nil)
end

Instance Attribute Details

#agentObject (readonly)

Returns the value of attribute agent.



16
17
18
# File 'lib/fastly_nsq/new_relic.rb', line 16

def agent
  @agent
end

Instance Method Details

#enabled?Boolean

Returns true if NewRelic is loaded and available.

Returns:

  • (Boolean)


31
32
33
# File 'lib/fastly_nsq/new_relic.rb', line 31

def enabled?
  @enabled ||= Object.const_defined?(:NewRelic)
end

#notice_error(exception) ⇒ Object

Notify NewRelic of an exception only if ‘enabled? == true` and an agent is defined

Parameters:

  • exception (Exception)


39
40
41
42
43
# File 'lib/fastly_nsq/new_relic.rb', line 39

def notice_error(exception)
  return unless enabled? && agent

  agent.notice_error(exception)
end

#trace_with_newrelic(**args) ⇒ Object

Trace passed block with new relic if ‘enabled? == true`



50
51
52
53
54
55
56
57
58
# File 'lib/fastly_nsq/new_relic.rb', line 50

def trace_with_newrelic(**args)
  if enabled?
    perform_action_with_newrelic_trace(trace_args(**args)) do
      yield
    end
  else
    yield
  end
end