Class: RSpecInstrumentation::NewRelic
- Inherits:
-
Object
- Object
- RSpecInstrumentation::NewRelic
- Defined in:
- lib/rspec_instrumentation/new_relic.rb
Constant Summary collapse
- RSPEC_EVENTS =
%i[example_finished example_started start stop].freeze
Class Method Summary collapse
Instance Method Summary collapse
- #example_finished(notification) ⇒ Object
- #example_started(notification) ⇒ Object
- #failed_example_details(example) ⇒ Object
-
#initialize(config) ⇒ NewRelic
constructor
A new instance of NewRelic.
- #start(_notification) ⇒ Object
- #stop(_notification) ⇒ Object
Constructor Details
#initialize(config) ⇒ NewRelic
Returns a new instance of NewRelic.
7 8 9 |
# File 'lib/rspec_instrumentation/new_relic.rb', line 7 def initialize(config) config.reporter.register_listener(self, *RSPEC_EVENTS) end |
Class Method Details
.setup ⇒ Object
41 42 43 44 45 46 |
# File 'lib/rspec_instrumentation/new_relic.rb', line 41 def setup require 'newrelic_rpm' require 'new_relic/agent/tracer' ::NewRelic::Agent.manual_start end |
Instance Method Details
#example_finished(notification) ⇒ Object
11 12 13 14 15 16 17 18 |
# File 'lib/rspec_instrumentation/new_relic.rb', line 11 def example_finished(notification) result = notification.example.execution_result if result.status == :failed details = failed_example_details(notification.example) ::NewRelic::Agent.notice_error(result.exception.to_s, custom_params: details) end @transaction.finish end |
#example_started(notification) ⇒ Object
20 21 22 23 |
# File 'lib/rspec_instrumentation/new_relic.rb', line 20 def example_started(notification) name = notification.example.id.delete_prefix('./') @transaction = ::NewRelic::Agent::Tracer.start_transaction_or_segment(partial_name: name, category: :task) end |
#failed_example_details(example) ⇒ Object
25 26 27 28 29 30 |
# File 'lib/rspec_instrumentation/new_relic.rb', line 25 def failed_example_details(example) { location: example.[:location], type: example.[:type] } end |
#start(_notification) ⇒ Object
32 33 34 |
# File 'lib/rspec_instrumentation/new_relic.rb', line 32 def start(_notification) # puts '> start' end |
#stop(_notification) ⇒ Object
36 37 38 |
# File 'lib/rspec_instrumentation/new_relic.rb', line 36 def stop(_notification) ::NewRelic::Agent.shutdown end |