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 all commits
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
1 change: 1 addition & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,7 @@ services:
mysql:
image: mysql:5.6
environment:
- MYSQL_DATABASE=$TEST_MYSQL_DB
- MYSQL_ROOT_PASSWORD=$TEST_MYSQL_ROOT_PASSWORD
- MYSQL_PASSWORD=$TEST_MYSQL_PASSWORD
- MYSQL_USER=$TEST_MYSQL_USER
Expand Down
5 changes: 2 additions & 3 deletions docs/GettingStarted.md
Original file line number Diff line number Diff line change
Expand Up @@ -1163,13 +1163,12 @@ Where `options` is an optional `Hash` that accepts the following parameters:

The Sinatra integration traces requests and template rendering.

To start using the tracing client, make sure you import ``ddtrace`` and ``ddtrace/contrib/sinatra/tracer`` after
either ``sinatra`` or ``sinatra/base``:
To start using the tracing client, make sure you import ``ddtrace`` and ``use :sinatra`` after
either ``sinatra`` or ``sinatra/base``, and before you define your application/routes:

```ruby
require 'sinatra'
require 'ddtrace'
require 'ddtrace/contrib/sinatra/tracer'

Datadog.configure do |c|
c.use :sinatra, options
Expand Down
43 changes: 22 additions & 21 deletions lib/ddtrace.rb
Original file line number Diff line number Diff line change
Expand Up @@ -44,30 +44,31 @@ def configure(target = configuration, opts = {})
end

require 'ddtrace/contrib/base'
require 'ddtrace/contrib/active_model_serializers/patcher'
require 'ddtrace/contrib/active_model_serializers/integration'
require 'ddtrace/contrib/active_record/integration'
require 'ddtrace/contrib/aws/patcher'
require 'ddtrace/contrib/aws/integration'
require 'ddtrace/contrib/concurrent_ruby/integration'
require 'ddtrace/contrib/dalli/patcher'
require 'ddtrace/contrib/delayed_job/patcher'
require 'ddtrace/contrib/elasticsearch/patcher'
require 'ddtrace/contrib/excon/patcher'
require 'ddtrace/contrib/faraday/patcher'
require 'ddtrace/contrib/grape/patcher'
require 'ddtrace/contrib/graphql/patcher'
require 'ddtrace/contrib/grpc/patcher'
require 'ddtrace/contrib/http/patcher'
require 'ddtrace/contrib/dalli/integration'
require 'ddtrace/contrib/delayed_job/integration'
require 'ddtrace/contrib/elasticsearch/integration'
require 'ddtrace/contrib/excon/integration'
require 'ddtrace/contrib/faraday/integration'
require 'ddtrace/contrib/grape/integration'
require 'ddtrace/contrib/graphql/integration'
require 'ddtrace/contrib/grpc/integration'
require 'ddtrace/contrib/http/integration'
require 'ddtrace/contrib/integration'
require 'ddtrace/contrib/mongodb/patcher'
require 'ddtrace/contrib/mysql2/patcher'
require 'ddtrace/contrib/racecar/patcher'
require 'ddtrace/contrib/rack/patcher'
require 'ddtrace/contrib/rails/patcher'
require 'ddtrace/contrib/rake/patcher'
require 'ddtrace/contrib/redis/patcher'
require 'ddtrace/contrib/resque/patcher'
require 'ddtrace/contrib/mysql2/integration'
require 'ddtrace/contrib/mongodb/integration'
require 'ddtrace/contrib/racecar/integration'
require 'ddtrace/contrib/rack/integration'
require 'ddtrace/contrib/rails/integration'
require 'ddtrace/contrib/rake/integration'
require 'ddtrace/contrib/redis/integration'
require 'ddtrace/contrib/resque/integration'
require 'ddtrace/contrib/rest_client/integration'
require 'ddtrace/contrib/sequel/integration'
require 'ddtrace/contrib/sidekiq/patcher'
require 'ddtrace/contrib/sucker_punch/patcher'
require 'ddtrace/contrib/sidekiq/integration'
require 'ddtrace/contrib/sinatra/integration'
require 'ddtrace/contrib/sucker_punch/integration'
require 'ddtrace/monkey'
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
require 'ddtrace/contrib/configuration/settings'
require 'ddtrace/contrib/active_model_serializers/ext'

module Datadog
module Contrib
module ActiveModelSerializers
module Configuration
# Custom settings for the ActiveModelSerializers integration
class Settings < Contrib::Configuration::Settings
option :service_name, default: Ext::SERVICE_NAME
option :tracer, default: Datadog.tracer do |value|
(value || Datadog.tracer).tap do |v|
# Make sure to update tracers of all subscriptions
Events.subscriptions.each do |subscription|
subscription.tracer = v
end
end
end
end
end
end
end
end
6 changes: 4 additions & 2 deletions lib/ddtrace/contrib/active_model_serializers/event.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
require 'ddtrace/ext/http'
require 'ddtrace/contrib/active_support/notifications/event'
require 'ddtrace/contrib/active_model_serializers/ext'

module Datadog
module Contrib
Expand Down Expand Up @@ -31,12 +33,12 @@ def process(span, event, _id, payload)
# Set the resource name and serializer name
res = resource(payload[:serializer])
span.resource = res
span.set_tag('active_model_serializers.serializer', res)
span.set_tag(Ext::TAG_SERIALIZER, res)

span.span_type = Datadog::Ext::HTTP::TEMPLATE

# Will be nil in 0.9
span.set_tag('active_model_serializers.adapter', payload[:adapter].class) unless payload[:adapter].nil?
span.set_tag(Ext::TAG_ADAPTER, payload[:adapter].class) unless payload[:adapter].nil?
end

private
Expand Down
4 changes: 2 additions & 2 deletions lib/ddtrace/contrib/active_model_serializers/events/render.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
require 'ddtrace/contrib/active_model_serializers/ext'
require 'ddtrace/contrib/active_model_serializers/event'

module Datadog
Expand All @@ -9,7 +10,6 @@ module Render
include ActiveModelSerializers::Event

EVENT_NAME = 'render.active_model_serializers'.freeze
SPAN_NAME = 'active_model_serializers.render'.freeze

module_function

Expand All @@ -23,7 +23,7 @@ def event_name
end

def span_name
self::SPAN_NAME
Ext::SPAN_RENDER
end
end
end
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
require 'ddtrace/contrib/active_model_serializers/ext'
require 'ddtrace/contrib/active_model_serializers/event'

module Datadog
Expand All @@ -9,7 +10,6 @@ module Serialize
include ActiveModelSerializers::Event

EVENT_NAME = '!serialize.active_model_serializers'.freeze
SPAN_NAME = 'active_model_serializers.serialize'.freeze

module_function

Expand All @@ -26,7 +26,7 @@ def event_name
end

def span_name
self::SPAN_NAME
Ext::SPAN_SERIALIZE
end
end
end
Expand Down
17 changes: 17 additions & 0 deletions lib/ddtrace/contrib/active_model_serializers/ext.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
module Datadog
module Contrib
module ActiveModelSerializers
# ActiveModelSerializers integration constants
module Ext
APP = 'active_model_serializers'.freeze
SERVICE_NAME = 'active_model_serializers'.freeze

SPAN_RENDER = 'active_model_serializers.render'.freeze
SPAN_SERIALIZE = 'active_model_serializers.serialize'.freeze

TAG_ADAPTER = 'active_model_serializers.adapter'.freeze
TAG_SERIALIZER = 'active_model_serializers.serializer'.freeze
end
end
end
end
39 changes: 39 additions & 0 deletions lib/ddtrace/contrib/active_model_serializers/integration.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
require 'ddtrace/contrib/integration'
require 'ddtrace/contrib/active_model_serializers/configuration/settings'
require 'ddtrace/contrib/active_model_serializers/patcher'

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

register_as :active_model_serializers

def self.version
Gem.loaded_specs['active_model_serializers'] \
&& Gem.loaded_specs['active_model_serializers'].version
end

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

def self.compatible?
super \
&& defined?(::ActiveSupport::Notifications) \
&& version >= Gem::Version.new('0.9.0')
end

def default_configuration
Configuration::Settings.new
end

def patcher
Patcher
end
end
end
end
end
67 changes: 24 additions & 43 deletions lib/ddtrace/contrib/active_model_serializers/patcher.rb
Original file line number Diff line number Diff line change
@@ -1,60 +1,41 @@
require 'ddtrace/contrib/patcher'
require 'ddtrace/ext/app_types'
require 'ddtrace/ext/http'
require 'ddtrace/contrib/active_model_serializers/ext'
require 'ddtrace/contrib/active_model_serializers/events'

module Datadog
module Contrib
module ActiveModelSerializers
# Provides instrumentation for ActiveModelSerializers through ActiveSupport instrumentation signals
# Patcher enables patching of 'active_model_serializers' module.
module Patcher
include Base
include Contrib::Patcher

VERSION_REQUIRED = Gem::Version.new('0.9.0')
module_function

register_as :active_model_serializers
def patched?
done?(:active_model_serializers)
end

option :service_name, default: 'active_model_serializers'
option :tracer, default: Datadog.tracer do |value|
(value || Datadog.tracer).tap do |v|
# Make sure to update tracers of all subscriptions
Events.subscriptions.each do |subscription|
subscription.tracer = v
def patch
do_once(:active_model_serializers) do
begin
# Subscribe to ActiveModelSerializers events
Events.subscribe!

# Set service info
get_option(:tracer).set_service_info(
get_option(:service_name),
Ext::APP,
Datadog::Ext::AppTypes::WEB
)
rescue StandardError => e
Datadog::Tracer.log.error("Unable to apply ActiveModelSerializers integration: #{e}")
end
end
end

class << self
def patch
return patched? if patched? || !compatible?

# Subscribe to ActiveModelSerializers events
Events.subscribe!

# Set service info
configuration[:tracer].set_service_info(
configuration[:service_name],
'active_model_serializers',
Ext::AppTypes::WEB
)

@patched = true
end

def patched?
return @patched if defined?(@patched)
@patched = false
end

private

def configuration
Datadog.configuration[:active_model_serializers]
end

def compatible?
Gem.loaded_specs['active_model_serializers'] && Gem.loaded_specs['activesupport'] \
&& Gem.loaded_specs['active_model_serializers'].version >= VERSION_REQUIRED
end
def get_option(option)
Datadog.configuration[:active_model_serializers].get_option(option)
end
end
end
Expand Down
5 changes: 3 additions & 2 deletions lib/ddtrace/contrib/active_record/configuration/settings.rb
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
require 'ddtrace/contrib/configuration/settings'
require 'ddtrace/contrib/active_record/ext'
require 'ddtrace/contrib/active_record/utils'

module Datadog
module Contrib
module ActiveRecord
module Configuration
# Unique settings for ActiveRecord
# Custom settings for the ActiveRecord integration
class Settings < Contrib::Configuration::Settings
option :orm_service_name
option :service_name, depends_on: [:tracer] do |value|
(value || Utils.adapter_name).tap do |service_name|
tracer.set_service_info(service_name, 'active_record', Ext::AppTypes::DB)
tracer.set_service_info(service_name, Ext::APP, Datadog::Ext::AppTypes::DB)
end
end

Expand Down
13 changes: 6 additions & 7 deletions lib/ddtrace/contrib/active_record/events/instantiation.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
require 'ddtrace/contrib/active_record/ext'
require 'ddtrace/contrib/active_record/event'

module Datadog
Expand All @@ -9,8 +10,6 @@ module Instantiation
include ActiveRecord::Event

EVENT_NAME = 'instantiation.active_record'.freeze
SPAN_NAME = 'active_record.instantiation'.freeze
DEFAULT_SERVICE_NAME = 'active_record'.freeze

module_function

Expand All @@ -24,7 +23,7 @@ def event_name
end

def span_name
self::SPAN_NAME
Ext::SPAN_INSTANTIATION
end

def process(span, event, _id, payload)
Expand All @@ -34,13 +33,13 @@ def process(span, event, _id, payload)
elsif span.parent
span.parent.service
else
self::DEFAULT_SERVICE_NAME
Ext::SERVICE_NAME
end

span.resource = payload.fetch(:class_name)
span.span_type = 'custom'
span.set_tag('active_record.instantiation.class_name', payload.fetch(:class_name))
span.set_tag('active_record.instantiation.record_count', payload.fetch(:record_count))
span.span_type = Ext::SPAN_TYPE_INSTANTIATION
span.set_tag(Ext::TAG_INSTANTIATION_CLASS_NAME, payload.fetch(:class_name))
span.set_tag(Ext::TAG_INSTANTIATION_RECORD_COUNT, payload.fetch(:record_count))
rescue StandardError => e
Datadog::Tracer.log.debug(e.message)
end
Expand Down
Loading