Module: TingYun::Agent::Instrumentation::RakeInstrumentation

Defined in:
lib/ting_yun/instrumentation/rake.rb

Class Method Summary collapse

Class Method Details

.before_invoke_transaction(task) ⇒ Object



49
50
51
52
53
54
55
56
57
58
59
# File 'lib/ting_yun/instrumentation/rake.rb', line 49

def self.before_invoke_transaction(task)
  ensure_at_exit

  if task.application.options.always_multitask
    instrument_invoke_prerequisites_concurrently(task)
  else
    instrument_execute_on_prereqs(task)
  end
rescue => e
  TingYun::Agent.logger.error("Error during Rake task invoke", e)
end

.ensure_at_exitObject



68
69
70
71
72
73
74
75
76
77
78
# File 'lib/ting_yun/instrumentation/rake.rb', line 68

def self.ensure_at_exit
  return if @installed_at_exit

  at_exit do
    # The agent's default at_exit might not default to installing, but
    # if we are running an instrumented rake task, we always want it.
    TingYun::Agent.shutdown
  end

  @installed_at_exit = true
end

.instrument_execute(task) ⇒ Object



86
87
88
89
90
91
92
93
94
95
96
97
98
99
# File 'lib/ting_yun/instrumentation/rake.rb', line 86

def self.instrument_execute(task)
  return if task.instance_variable_get(:@__tingyun_instrumented_execute)

  task.instance_variable_set(:@__tingyun_instrumented_execute, true)
  task.instance_eval do
    def execute(*args, &block)
      TingYun::Agent::MethodTracerHelpers.trace_execution_scoped("Rake/execute/#{self.name}") do
        super
      end
    end
  end

  instrument_execute_on_prereqs(task)
end

.instrument_execute_on_prereqs(task) ⇒ Object



80
81
82
83
84
# File 'lib/ting_yun/instrumentation/rake.rb', line 80

def self.instrument_execute_on_prereqs(task)
  task.prerequisite_tasks.each do |child_task|
    instrument_execute(child_task)
  end
end

.instrument_invoke_prerequisites_concurrently(task) ⇒ Object



101
102
103
104
105
106
107
108
109
# File 'lib/ting_yun/instrumentation/rake.rb', line 101

def self.instrument_invoke_prerequisites_concurrently(task)
  task.instance_eval do
    def invoke_prerequisites_concurrently(*_)
      TingYun::Agent::MethodTracerHelpers.trace_execution_scoped("Rake/execute/multitask") do
        super
      end
    end
  end
end

.should_trace?(name) ⇒ Boolean

Returns:

  • (Boolean)


61
62
63
64
65
66
# File 'lib/ting_yun/instrumentation/rake.rb', line 61

def self.should_trace? name

  return ::TingYun::Agent.config[:'rake.tasks'].include?(name) if ::TingYun::Agent.config[:'rake.tasks'].any?
  return !TingYun::Agent.config[:'rake.black.tasks'].include?(name) if ::TingYun::Agent.config[:'rake.black.tasks'].any?
  return false
end

.supported_instrument?Boolean

Returns:

  • (Boolean)


111
112
113
# File 'lib/ting_yun/instrumentation/rake.rb', line 111

def self.supported_instrument?
  ::TingYun::Agent.config[:'rake.tasks'].any? or ::TingYun::Agent.config[:'rake.black.tasks'].any?
end

.supported_version?Boolean

Returns:

  • (Boolean)


45
46
47
# File 'lib/ting_yun/instrumentation/rake.rb', line 45

def self.supported_version?
  ::TingYun::Support::VersionNumber.new(::Rake::VERSION) >= ::TingYun::Support::VersionNumber.new("10.0.0")
end