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

Upgrade to integrations to new configuration API #544

Merged
merged 23 commits into from
Oct 2, 2018
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
e0dfbe5
Refactored: Rack to use Datadog::Contrib::Integration. (#541)
delner Sep 17, 2018
3df964b
Refactored: Rails to use Datadog::Contrib::Integration. (#540)
delner Sep 17, 2018
8074a42
Refactored: Sidekiq to use Datadog::Contrib::Integration. (#545)
delner Sep 20, 2018
982b739
Implement Resque integration configuration (#546)
delner Sep 20, 2018
9089bb1
Refactored: DelayedJob to use Datadog::Contrib::Integration. (#547)
delner Sep 20, 2018
41f1621
Refactored: Racecar to use Datadog::Contrib::Integration. (#548)
delner Sep 20, 2018
16d9782
Refactored: SuckerPunch to use Datadog::Contrib::Integration. (#549)
delner Sep 20, 2018
611bcdd
Refactored: Rake to use Datadog::Contrib::Integration. (#554)
delner Sep 26, 2018
d96e660
Refactored: HTTP to use Datadog::Contrib::Integration. (#556)
delner Sep 26, 2018
57c29ff
Refactored: AWS to use Datadog::Contrib::Integration. (#562)
delner Sep 26, 2018
4a5e313
Implement Mysql2 integration configuration (#559)
delner Sep 26, 2018
c754c2c
Refactored: Elasticsearch to use Datadog::Contrib::Integration. (#561)
delner Sep 26, 2018
9e68bab
Refactored: Dalli to use Datadog::Contrib::Integration. (#560)
delner Sep 26, 2018
65c91f2
Refactored: Redis to use Datadog::Contrib::Integration. (#555)
delner Sep 26, 2018
cc9d368
Refactored: MongoDB to use Datadog::Contrib::Integration. (#558)
delner Sep 26, 2018
d386618
Refactored: Integration configurations to be more consistent. (#576)
delner Oct 1, 2018
09988b3
Refactored: ActiveModelSerializers to use Datadog::Contrib::Integrati…
delner Oct 1, 2018
8e27d4b
Refactored: Sinatra to use Datadog::Contrib::Integration. (#575)
delner Oct 1, 2018
a5ea7a1
Refactored: Excon to use Datadog::Contrib::Integration. (#569)
delner Oct 1, 2018
c3f31ed
Refactored: Grape to use Datadog::Contrib::Integration. (#571)
delner Oct 1, 2018
ffb31fc
Refactored: gRPC to use Datadog::Contrib::Integration. (#563)
delner Oct 1, 2018
f9fed67
Refactored: Faraday to use Datadog::Contrib::Integration. (#570)
delner Oct 1, 2018
fa7327b
Refactored: GraphQL to use Datadog::Contrib::Integration. (#572)
delner Oct 1, 2018
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
Prev Previous commit
Next Next commit
Implement Resque integration configuration (#546)
* Changed: ConfigurationHelpers#remove_patch! to work with Integration patchers.

* Refactored: Resque to use Datadog::Contrib::Integration.
  • Loading branch information
delner committed Sep 24, 2018
commit 982b739fb0d5efd62b36ba682529b83e37f1f87b
2 changes: 1 addition & 1 deletion lib/ddtrace.rb
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ def configure(target = configuration, opts = {})
require 'ddtrace/contrib/rails/integration'
require 'ddtrace/contrib/rake/patcher'
require 'ddtrace/contrib/redis/patcher'
require 'ddtrace/contrib/resque/patcher'
require 'ddtrace/contrib/resque/integration'
require 'ddtrace/contrib/rest_client/integration'
require 'ddtrace/contrib/sequel/integration'
require 'ddtrace/contrib/sidekiq/integration'
Expand Down
16 changes: 16 additions & 0 deletions lib/ddtrace/contrib/resque/configuration/settings.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
require 'ddtrace/contrib/configuration/settings'
require 'ddtrace/contrib/resque/ext'

module Datadog
module Contrib
module Resque
module Configuration
# Custom settings for the Resque integration
class Settings < Contrib::Configuration::Settings
option :service_name, default: Ext::SERVICE_NAME
option :workers, default: []
end
end
end
end
end
13 changes: 13 additions & 0 deletions lib/ddtrace/contrib/resque/ext.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
module Datadog
module Contrib
module Resque
# Resque integration constants
module Ext
APP = 'resque'.freeze
SERVICE_NAME = 'resque'.freeze

SPAN_JOB = 'resque.job'.freeze
end
end
end
end
37 changes: 37 additions & 0 deletions lib/ddtrace/contrib/resque/integration.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
require 'ddtrace/contrib/integration'
require 'ddtrace/contrib/resque/configuration/settings'
require 'ddtrace/contrib/resque/patcher'

module Datadog
module Contrib
module Resque
# Description of Resque integration
class Integration
include Contrib::Integration

register_as :resque, auto_patch: true

def self.version
Gem.loaded_specs['resque'] && Gem.loaded_specs['resque'].version
end

def self.present?
super && defined?(::Resque)
end

def default_configuration
Configuration::Settings.new
end

def patcher
Patcher
end

class << self
# Globally-acccesible reference for pre-forking optimization
attr_accessor :sync_writer
end
end
end
end
end
63 changes: 27 additions & 36 deletions lib/ddtrace/contrib/resque/patcher.rb
Original file line number Diff line number Diff line change
@@ -1,49 +1,40 @@
require 'ddtrace/contrib/patcher'
require 'ddtrace/ext/app_types'
require 'ddtrace/contrib/sidekiq/ext'

module Datadog
module Contrib
# Namespace for `resque` integration
module Resque
SERVICE = 'resque'.freeze

class << self
# Globally-acccesible reference for pre-forking optimization
attr_accessor :sync_writer
end

# Patcher for Resque integration - sets up the pin for the integration
# Patcher enables patching of 'resque' module.
module Patcher
include Base
register_as :resque, auto_patch: true
option :service_name, default: SERVICE

@patched = false
option :workers, default: []

class << self
def patch
return @patched if patched? || !defined?(::Resque)
include Contrib::Patcher

require 'ddtrace/ext/app_types'
require_relative 'resque_job'
module_function

add_pin
get_option(:workers).each { |worker| worker.extend(ResqueJob) }
@patched = true
rescue => e
Tracer.log.error("Unable to apply Resque integration: #{e}")
@patched
end
def patched?
done?(:resque)
end

def patched?
@patched
def patch
do_once(:resque) do
begin
require_relative 'resque_job'
add_pin
get_option(:workers).each { |worker| worker.extend(ResqueJob) }
rescue StandardError => e
Datadog::Tracer.log.error("Unable to apply Resque integration: #{e}")
end
end
end

private
def add_pin
Pin
.new(get_option(:service_name), app: Ext::APP, app_type: Datadog::Ext::AppTypes::WORKER)
.onto(::Resque)
end

def add_pin
Pin
.new(get_option(:service_name), app: 'resque', app_type: Ext::AppTypes::WORKER)
.onto(::Resque)
end
def get_option(option)
Datadog.configuration[:resque].get_option(option)
end
end
end
Expand Down
3 changes: 2 additions & 1 deletion lib/ddtrace/contrib/resque/resque_job.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
require 'ddtrace/ext/app_types'
require 'ddtrace/sync_writer'
require 'ddtrace/contrib/sidekiq/ext'
require 'resque'

module Datadog
Expand All @@ -10,7 +11,7 @@ module ResqueJob
def around_perform(*args)
pin = Pin.get_from(::Resque)
return yield unless pin && pin.tracer
pin.tracer.trace('resque.job', service: pin.service) do |span|
pin.tracer.trace(Ext::SPAN_JOB, service: pin.service) do |span|
span.resource = name
span.span_type = pin.app_type
yield
Expand Down
14 changes: 11 additions & 3 deletions spec/support/configuration_helpers.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,15 @@
module ConfigurationHelpers
def remove_patch!(integration)
Datadog
.registry[integration]
.instance_variable_set('@patched', false)
if Datadog.registry[integration].respond_to?(:patcher)
Datadog.registry[integration].patcher.tap do |patcher|
if patcher.instance_variable_defined?(:@done_once)
patcher.instance_variable_get(:@done_once).delete(integration)
end
end
else
Datadog
.registry[integration]
.instance_variable_set('@patched', false)
end
end
end