Module: ElasticAPM::Spies::RakeSpy::Ext Private

Defined in:
lib/elastic_apm/spies/rake.rb

This module is part of a private API. You should avoid using this module if possible, as it may be removed or be changed in the future.

Instance Method Summary collapse

Instance Method Details

#execute(*args) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/elastic_apm/spies/rake.rb', line 27

def execute(*args)
  agent = ElasticAPM.start

  unless agent && agent.config.instrumented_rake_tasks.include?(name)
    return super(*args)
  end

  transaction =
    ElasticAPM.start_transaction("Rake::Task[#{name}]", 'Rake')

  begin
    result = super(*args)

    transaction&.result = 'success'
    transaction&.outcome = Transaction::Outcome::SUCCESS
  rescue StandardError => e
    transaction&.result = 'error'
    transaction&.outcome = Transaction::Outcome::FAILURE
    ElasticAPM.report(e)

    raise
  ensure
    ElasticAPM.end_transaction
    ElasticAPM.stop
  end

  result
end