Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Instrumentation hooks for block execution #17

Open
corytheboyd opened this issue Jul 18, 2017 · 0 comments
Open

Instrumentation hooks for block execution #17

corytheboyd opened this issue Jul 18, 2017 · 0 comments

Comments

@corytheboyd
Copy link

There is a nice hook for handling exceptions raised by blocks registered with every, but no such hook for instrumenting the execution of those blocks.

What happened for us was that a block was failing to execute and we were not aware since we did not register an error_handler. This worked for reporting errors, but did not include enough context to tell us that the error came from clockwork, which is required to implement a different alert policy on failure (create an incident after a very small number of failures, as opposed to relying on the error rate of our already high-throughput web application to create an incident).

What we ended up doing was patching the every method to instrument execution of the registered block with the New Relic Ruby gem, as such:

module Clockwork
  extend ::NewRelic::Agent::MethodTracer
  class << self
    include ::NewRelic::Agent::Instrumentation::ControllerInstrumentation

    alias every_original every
    def every(period, job, options = {}, &_block)
      if block_given?
        every_original(period, job, options) do |*arguments|
          perform_action_with_newrelic_trace(class_name: 'Clockwork', category: :task, name: 'every', params: { 'Clockwork.job': job }) do
            yield(*arguments)
          end
        end
      else
        every_original(period, job, options)
      end
    end
  end
end

This seems like behavior that could be added to the Manager in a clean way. Thoughts?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant