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

Good job Integration #506

Merged
merged 1 commit into from
Sep 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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