ddtrace 0.11.0.beta2 → 0.11.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rspec +1 -0
- data/Appraisals +11 -11
- data/Gemfile +3 -0
- data/README.md +1 -1
- data/Rakefile +67 -5
- data/ddtrace.gemspec +6 -4
- data/docs/GettingStarted.md +239 -432
- data/gemfiles/contrib.gemfile +2 -1
- data/gemfiles/contrib_old.gemfile +5 -3
- data/gemfiles/rails30_postgres.gemfile +1 -0
- data/gemfiles/rails30_postgres_sidekiq.gemfile +1 -0
- data/gemfiles/rails32_mysql2.gemfile +1 -0
- data/gemfiles/rails32_postgres.gemfile +1 -0
- data/gemfiles/rails32_postgres_redis.gemfile +1 -0
- data/gemfiles/rails32_postgres_sidekiq.gemfile +1 -0
- data/gemfiles/rails4_mysql2.gemfile +1 -0
- data/gemfiles/rails4_postgres.gemfile +2 -1
- data/gemfiles/rails4_postgres_redis.gemfile +2 -1
- data/gemfiles/rails4_postgres_sidekiq.gemfile +2 -1
- data/gemfiles/rails5_mysql2.gemfile +1 -0
- data/gemfiles/rails5_postgres.gemfile +2 -1
- data/gemfiles/rails5_postgres_redis.gemfile +3 -2
- data/gemfiles/rails5_postgres_sidekiq.gemfile +2 -1
- data/lib/ddtrace.rb +6 -2
- data/lib/ddtrace/configuration.rb +2 -0
- data/lib/ddtrace/configuration/pin_setup.rb +30 -0
- data/lib/ddtrace/contrib/active_record/patcher.rb +6 -0
- data/lib/ddtrace/contrib/aws/patcher.rb +3 -4
- data/lib/ddtrace/contrib/dalli/patcher.rb +3 -4
- data/lib/ddtrace/contrib/dalli/quantize.rb +5 -2
- data/lib/ddtrace/contrib/elasticsearch/patcher.rb +0 -1
- data/lib/ddtrace/contrib/faraday/patcher.rb +6 -5
- data/lib/ddtrace/contrib/grape/patcher.rb +0 -3
- data/lib/ddtrace/contrib/mongodb/patcher.rb +0 -3
- data/lib/ddtrace/contrib/rack/patcher.rb +12 -4
- data/lib/ddtrace/contrib/rails/active_record.rb +2 -5
- data/lib/ddtrace/contrib/rails/active_support.rb +2 -1
- data/lib/ddtrace/contrib/rails/core_extensions.rb +24 -7
- data/lib/ddtrace/contrib/rails/utils.rb +6 -4
- data/lib/ddtrace/contrib/redis/patcher.rb +7 -20
- data/lib/ddtrace/contrib/redis/quantize.rb +4 -4
- data/lib/ddtrace/contrib/resque/patcher.rb +3 -3
- data/lib/ddtrace/contrib/resque/resque_job.rb +0 -1
- data/lib/ddtrace/contrib/sidekiq/patcher.rb +33 -0
- data/lib/ddtrace/contrib/sidekiq/tracer.rb +1 -15
- data/lib/ddtrace/contrib/sucker_punch/patcher.rb +1 -2
- data/lib/ddtrace/error.rb +3 -13
- data/lib/ddtrace/ext/cache.rb +1 -0
- data/lib/ddtrace/ext/priority.rb +16 -0
- data/lib/ddtrace/monkey.rb +1 -0
- data/lib/ddtrace/pin.rb +17 -9
- data/lib/ddtrace/sampler.rb +4 -2
- data/lib/ddtrace/utils.rb +22 -3
- metadata +41 -9
data/gemfiles/contrib.gemfile
CHANGED
@@ -2,6 +2,7 @@
|
|
2
2
|
|
3
3
|
source "https://rubygems.org"
|
4
4
|
|
5
|
+
gem "pry-nav", git: "https://github.com/nixme/pry-nav.git", branch: "master"
|
5
6
|
gem "elasticsearch-transport"
|
6
7
|
gem "mongo"
|
7
8
|
gem "grape"
|
@@ -16,7 +17,7 @@ gem "sidekiq"
|
|
16
17
|
gem "aws-sdk"
|
17
18
|
gem "sucker_punch"
|
18
19
|
gem "dalli"
|
19
|
-
gem "resque"
|
20
|
+
gem "resque", "< 2.0"
|
20
21
|
gem "racecar", ">= 0.3.5"
|
21
22
|
|
22
23
|
gemspec path: "../"
|
@@ -2,18 +2,20 @@
|
|
2
2
|
|
3
3
|
source "https://rubygems.org"
|
4
4
|
|
5
|
+
gem "pry-nav", git: "https://github.com/nixme/pry-nav.git", branch: "master"
|
5
6
|
gem "elasticsearch-transport"
|
6
7
|
gem "mongo"
|
7
|
-
gem "redis", "< 4.0
|
8
|
+
gem "redis", "< 4.0"
|
8
9
|
gem "hiredis"
|
9
10
|
gem "rack", "1.4.7"
|
10
|
-
gem "rack-test"
|
11
|
+
gem "rack-test", "0.7.0"
|
11
12
|
gem "sinatra", "1.4.5"
|
12
13
|
gem "sqlite3"
|
13
14
|
gem "activerecord", "3.2.22.5"
|
14
15
|
gem "sidekiq", "4.0.0"
|
15
16
|
gem "aws-sdk", "~> 2.0"
|
16
17
|
gem "sucker_punch"
|
17
|
-
gem "
|
18
|
+
gem "dalli"
|
19
|
+
gem "resque", "< 2.0"
|
18
20
|
|
19
21
|
gemspec path: "../"
|
@@ -2,8 +2,9 @@
|
|
2
2
|
|
3
3
|
source "https://rubygems.org"
|
4
4
|
|
5
|
+
gem "pry-nav", git: "https://github.com/nixme/pry-nav.git", branch: "master"
|
5
6
|
gem "rails", "4.2.7.1"
|
6
|
-
gem "pg", platform: :ruby
|
7
|
+
gem "pg", "< 1.0", platform: :ruby
|
7
8
|
gem "activerecord-jdbcpostgresql-adapter", platform: :jruby
|
8
9
|
|
9
10
|
gemspec path: "../"
|
@@ -2,8 +2,9 @@
|
|
2
2
|
|
3
3
|
source "https://rubygems.org"
|
4
4
|
|
5
|
+
gem "pry-nav", git: "https://github.com/nixme/pry-nav.git", branch: "master"
|
5
6
|
gem "rails", "4.2.7.1"
|
6
|
-
gem "pg", platform: :ruby
|
7
|
+
gem "pg", "< 1.0", platform: :ruby
|
7
8
|
gem "activerecord-jdbcpostgresql-adapter", platform: :jruby
|
8
9
|
gem "redis-rails"
|
9
10
|
gem "redis", "< 4.0"
|
@@ -2,8 +2,9 @@
|
|
2
2
|
|
3
3
|
source "https://rubygems.org"
|
4
4
|
|
5
|
+
gem "pry-nav", git: "https://github.com/nixme/pry-nav.git", branch: "master"
|
5
6
|
gem "rails", "4.2.7.1"
|
6
|
-
gem "pg", platform: :ruby
|
7
|
+
gem "pg", "< 1.0", platform: :ruby
|
7
8
|
gem "activerecord-jdbcpostgresql-adapter", platform: :jruby
|
8
9
|
gem "sidekiq"
|
9
10
|
gem "activejob"
|
@@ -2,9 +2,10 @@
|
|
2
2
|
|
3
3
|
source "https://rubygems.org"
|
4
4
|
|
5
|
+
gem "pry-nav", git: "https://github.com/nixme/pry-nav.git", branch: "master"
|
5
6
|
gem "rails", "5.0.1"
|
6
|
-
gem "pg", platform: :ruby
|
7
|
+
gem "pg", "< 1.0", platform: :ruby
|
7
8
|
gem "redis-rails"
|
8
|
-
gem "redis"
|
9
|
+
gem "redis"
|
9
10
|
|
10
11
|
gemspec path: "../"
|
data/lib/ddtrace.rb
CHANGED
@@ -39,8 +39,12 @@ module Datadog
|
|
39
39
|
@configuration ||= Configuration.new
|
40
40
|
end
|
41
41
|
|
42
|
-
def configure
|
43
|
-
|
42
|
+
def configure(target = configuration, opts = {})
|
43
|
+
if target.is_a?(Configuration)
|
44
|
+
yield(target)
|
45
|
+
else
|
46
|
+
Configuration::PinSetup.new(target, opts).call
|
47
|
+
end
|
44
48
|
end
|
45
49
|
end
|
46
50
|
end
|
@@ -1,5 +1,6 @@
|
|
1
1
|
require_relative 'configuration/proxy'
|
2
2
|
require_relative 'configuration/resolver'
|
3
|
+
require_relative 'configuration/pin_setup'
|
3
4
|
|
4
5
|
module Datadog
|
5
6
|
# Configuration provides a unique access point for configurations
|
@@ -30,6 +31,7 @@ module Datadog
|
|
30
31
|
instance = options.fetch(:instance, Datadog.tracer)
|
31
32
|
|
32
33
|
instance.configure(options)
|
34
|
+
instance.class.log = options[:log] if options[:log]
|
33
35
|
instance.set_tags(options[:tags]) if options[:tags]
|
34
36
|
instance.set_tags(env: options[:env]) if options[:env]
|
35
37
|
instance.class.debug_logging = options.fetch(:debug, false)
|
@@ -0,0 +1,30 @@
|
|
1
|
+
module Datadog
|
2
|
+
class Configuration
|
3
|
+
# PinSetup translates a flat hash into a Pin configuration
|
4
|
+
# This class should be removed if we ever remove/refactor the Pin class
|
5
|
+
class PinSetup
|
6
|
+
def initialize(target, opts = {})
|
7
|
+
@pin = Pin.get_from(target)
|
8
|
+
@opts = opts
|
9
|
+
end
|
10
|
+
|
11
|
+
def call
|
12
|
+
return unless pin
|
13
|
+
|
14
|
+
ATTRS.each { |key| pin.public_send("#{key}=", opts[key]) if opts[key] }
|
15
|
+
|
16
|
+
pin.config = opts.reject { |key, _| ATTRS.include?(key) }
|
17
|
+
|
18
|
+
true
|
19
|
+
end
|
20
|
+
|
21
|
+
private
|
22
|
+
|
23
|
+
attr_reader :pin, :opts
|
24
|
+
|
25
|
+
ATTRS = [:app, :tags, :app_type, :name, :tracer, :service_name].freeze
|
26
|
+
|
27
|
+
private_constant :ATTRS
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
@@ -80,12 +80,18 @@ module Datadog
|
|
80
80
|
span_type: span_type
|
81
81
|
)
|
82
82
|
|
83
|
+
# Find out if the SQL query has been cached in this request. This meta is really
|
84
|
+
# helpful to users because some spans may have 0ns of duration because the query
|
85
|
+
# is simply cached from memory, so the notification is fired with start == finish.
|
86
|
+
cached = payload[:cached] || (payload[:name] == 'CACHE')
|
87
|
+
|
83
88
|
# the span should have the query ONLY in the Resource attribute,
|
84
89
|
# so that the ``sql.query`` tag will be set in the agent with an
|
85
90
|
# obfuscated version
|
86
91
|
span.span_type = Datadog::Ext::SQL::TYPE
|
87
92
|
span.set_tag('active_record.db.vendor', adapter_name)
|
88
93
|
span.set_tag('active_record.db.name', database_name)
|
94
|
+
span.set_tag('active_record.db.cached', cached) if cached
|
89
95
|
span.set_tag('out.host', adapter_host)
|
90
96
|
span.set_tag('out.port', adapter_port)
|
91
97
|
span.start_time = start
|
@@ -23,7 +23,6 @@ module Datadog
|
|
23
23
|
|
24
24
|
add_pin
|
25
25
|
add_plugin(Seahorse::Client::Base, *loaded_constants)
|
26
|
-
Datadog.tracer.set_service_info(get_option(:service_name), 'aws', Ext::AppTypes::WEB)
|
27
26
|
|
28
27
|
@patched = true
|
29
28
|
rescue => e
|
@@ -38,9 +37,9 @@ module Datadog
|
|
38
37
|
private
|
39
38
|
|
40
39
|
def add_pin
|
41
|
-
Pin
|
42
|
-
|
43
|
-
|
40
|
+
Pin
|
41
|
+
.new(get_option(:service_name), app: 'aws', app_type: Ext::AppTypes::WEB)
|
42
|
+
.onto(::Aws)
|
44
43
|
end
|
45
44
|
|
46
45
|
def add_plugin(*targets)
|
@@ -22,7 +22,6 @@ module Datadog
|
|
22
22
|
|
23
23
|
add_pin!
|
24
24
|
Instrumentation.patch!
|
25
|
-
Datadog.tracer.set_service_info(get_option(:service_name), 'dalli', Ext::AppTypes::CACHE)
|
26
25
|
|
27
26
|
@patched = true
|
28
27
|
rescue => e
|
@@ -43,9 +42,9 @@ module Datadog
|
|
43
42
|
end
|
44
43
|
|
45
44
|
def add_pin!
|
46
|
-
Pin
|
47
|
-
|
48
|
-
|
45
|
+
Pin
|
46
|
+
.new(get_option(:service_name), app: 'dalli', app_type: Ext::AppTypes::CACHE)
|
47
|
+
.onto(::Dalli)
|
49
48
|
end
|
50
49
|
end
|
51
50
|
end
|
@@ -8,10 +8,13 @@ module Datadog
|
|
8
8
|
module_function
|
9
9
|
|
10
10
|
def format_command(operation, args)
|
11
|
+
placeholder = "#{operation} BLOB (OMITTED)"
|
11
12
|
command = [operation, *args].join(' ').strip
|
13
|
+
command = Utils.utf8_encode(command, binary: true, placeholder: placeholder)
|
12
14
|
Utils.truncate(command, MAX_CMD_LENGTH)
|
13
|
-
rescue
|
14
|
-
"#{
|
15
|
+
rescue => e
|
16
|
+
Tracer.log.debug("Error sanitizing Dalli operation: #{e}")
|
17
|
+
placeholder
|
15
18
|
end
|
16
19
|
end
|
17
20
|
end
|
@@ -31,7 +31,6 @@ module Datadog
|
|
31
31
|
|
32
32
|
add_pin
|
33
33
|
add_middleware
|
34
|
-
register_service(get_option(:service_name))
|
35
34
|
|
36
35
|
@patched = true
|
37
36
|
rescue => e
|
@@ -56,10 +55,12 @@ module Datadog
|
|
56
55
|
end
|
57
56
|
|
58
57
|
def add_pin
|
59
|
-
Pin.new(
|
60
|
-
|
61
|
-
|
62
|
-
|
58
|
+
Pin.new(
|
59
|
+
get_option(:service_name),
|
60
|
+
app: 'faraday',
|
61
|
+
app_type: Ext::AppTypes::WEB,
|
62
|
+
tracer: get_option(:tracer)
|
63
|
+
).onto(::Faraday)
|
63
64
|
end
|
64
65
|
|
65
66
|
def add_middleware
|
@@ -35,9 +35,6 @@ module Datadog
|
|
35
35
|
service = get_option(:service_name)
|
36
36
|
pin = Datadog::Pin.new(service, app: 'grape', app_type: Datadog::Ext::AppTypes::WEB)
|
37
37
|
pin.onto(::Grape)
|
38
|
-
if pin.tracer && pin.service
|
39
|
-
pin.tracer.set_service_info(pin.service, 'grape', pin.app_type)
|
40
|
-
end
|
41
38
|
|
42
39
|
# subscribe to ActiveSupport events
|
43
40
|
Datadog::Contrib::Grape::Endpoint.subscribe()
|
@@ -67,9 +67,6 @@ module Datadog
|
|
67
67
|
service = Datadog.configuration[:mongo][:service_name]
|
68
68
|
pin = Datadog::Pin.new(service, app: APP, app_type: Datadog::Ext::AppTypes::DB)
|
69
69
|
pin.onto(self)
|
70
|
-
if pin.tracer && pin.service
|
71
|
-
pin.tracer.set_service_info(pin.service, 'mongodb', pin.app_type)
|
72
|
-
end
|
73
70
|
end
|
74
71
|
|
75
72
|
def datadog_pin
|
@@ -22,16 +22,24 @@ module Datadog
|
|
22
22
|
require_relative 'middlewares'
|
23
23
|
@patched = true
|
24
24
|
|
25
|
-
|
26
|
-
|
27
|
-
top = get_option(:application) || rails_app
|
28
|
-
retain_middleware_name(top)
|
25
|
+
enable_middleware_names if get_option(:middleware_names)
|
29
26
|
end
|
30
27
|
|
31
28
|
def patched?
|
32
29
|
@patched ||= false
|
33
30
|
end
|
34
31
|
|
32
|
+
def enable_middleware_names
|
33
|
+
root = get_option(:application) || rails_app
|
34
|
+
retain_middleware_name(root)
|
35
|
+
rescue => e
|
36
|
+
# We can safely ignore these exceptions since they happen only in the
|
37
|
+
# context of middleware patching outside a Rails server process (eg. a
|
38
|
+
# process that doesn't serve HTTP requests but has Rails environment
|
39
|
+
# loaded such as a Resque master process)
|
40
|
+
Tracer.log.debug("Error patching middleware stack: #{e}")
|
41
|
+
end
|
42
|
+
|
35
43
|
def rails_app
|
36
44
|
return unless Datadog.registry[:rails].compatible?
|
37
45
|
::Rails.application.app
|
@@ -33,13 +33,10 @@ module Datadog
|
|
33
33
|
span_type: span_type
|
34
34
|
)
|
35
35
|
|
36
|
-
#
|
36
|
+
# Find out if the SQL query has been cached in this request. This meta is really
|
37
37
|
# helpful to users because some spans may have 0ns of duration because the query
|
38
38
|
# is simply cached from memory, so the notification is fired with start == finish.
|
39
|
-
|
40
|
-
# We're supporting this action as a best effort, but we should add a test after
|
41
|
-
# a new version of Rails is out.
|
42
|
-
cached = payload[:cached]
|
39
|
+
cached = payload[:cached] || (payload[:name] == 'CACHE')
|
43
40
|
|
44
41
|
# the span should have the query ONLY in the Resource attribute,
|
45
42
|
# so that the ``sql.query`` tag will be set in the agent with an
|
@@ -45,7 +45,8 @@ module Datadog
|
|
45
45
|
# discard parameters from the cache_store configuration
|
46
46
|
store, = *Array.wrap(::Rails.configuration.cache_store).flatten
|
47
47
|
span.set_tag('rails.cache.backend', store)
|
48
|
-
|
48
|
+
cache_key = Datadog::Utils.truncate(payload.fetch(:key), Ext::CACHE::MAX_KEY_SIZE)
|
49
|
+
span.set_tag('rails.cache.key', cache_key)
|
49
50
|
span.set_error(payload[:exception]) if payload[:exception]
|
50
51
|
ensure
|
51
52
|
span.finish()
|