Skip to content

Commit

Permalink
Good job Integration (#506)
Browse files Browse the repository at this point in the history
  • Loading branch information
benngarcia authored Sep 6, 2024
1 parent ff64d3e commit efc5cbc
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 0 deletions.
1 change: 1 addition & 0 deletions lib/scout_apm.rb
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ module ScoutApm
require 'scout_apm/background_job_integrations/sneakers'
require 'scout_apm/background_job_integrations/que'
require 'scout_apm/background_job_integrations/legacy_sneakers'
require 'scout_apm/background_job_integrations/good_job'

require 'scout_apm/framework_integrations/rails_2'
require 'scout_apm/framework_integrations/rails_3_or_4'
Expand Down
49 changes: 49 additions & 0 deletions lib/scout_apm/background_job_integrations/good_job.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
module ScoutApm
module BackgroundJobIntegrations
class GoodJob
UNKNOWN_QUEUE_PLACEHOLDER = 'default'.freeze
attr_reader :logger

def name
:good_job
end

def present?
defined?(::GoodJob::VERSION)
end

def forking?
false
end

def install
ActiveSupport.on_load(:active_job) do
include ScoutApm::Tracer

around_perform do |job, block|
# I have a sneaking suspicion there is a better way to handle Agent starting
# Maybe hook into GoodJob lifecycle events?
req = ScoutApm::RequestManager.lookup
latency = Time.now - (job.scheduled_at || job.enqueued_at) rescue 0
req.annotate_request(queue_latency: latency)

begin
req.start_layer ScoutApm::Layer.new("Queue", job.queue_name.presence || UNKNOWN_QUEUE_PLACEHOLDER)
started_queue = true # Following Convention
req.start_layer ScoutApm::Layer.new("Job", job.class.name)
started_job = true # Following Convention

block.call
rescue
req.error!
raise
ensure
req.stop_layer if started_job
req.stop_layer if started_queue
end
end
end
end
end
end
end
1 change: 1 addition & 0 deletions lib/scout_apm/environment.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ class Environment
ScoutApm::BackgroundJobIntegrations::DelayedJob.new,
ScoutApm::BackgroundJobIntegrations::Que.new,
ScoutApm::BackgroundJobIntegrations::Faktory.new,
ScoutApm::BackgroundJobIntegrations::GoodJob.new,
]

FRAMEWORK_INTEGRATIONS = [
Expand Down

0 comments on commit efc5cbc

Please sign in to comment.