ddtrace 0.11.0.beta1 → 0.11.0.beta2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/Appraisals +4 -1
- data/Rakefile +4 -3
- data/circle.yml +22 -14
- data/ddtrace.gemspec +5 -2
- data/docs/GettingStarted.md +7 -5
- data/gemfiles/contrib.gemfile +2 -1
- data/gemfiles/rails4_postgres_redis.gemfile +1 -0
- data/gemfiles/rails5_postgres_redis.gemfile +1 -0
- data/lib/ddtrace/configurable.rb +7 -1
- data/lib/ddtrace/configuration/proxy.rb +1 -5
- data/lib/ddtrace/contrib/active_record/patcher.rb +16 -10
- data/lib/ddtrace/contrib/aws/patcher.rb +1 -0
- data/lib/ddtrace/contrib/dalli/patcher.rb +2 -1
- data/lib/ddtrace/contrib/dalli/quantize.rb +2 -0
- data/lib/ddtrace/contrib/elasticsearch/patcher.rb +9 -2
- data/lib/ddtrace/contrib/faraday/middleware.rb +13 -19
- data/lib/ddtrace/contrib/faraday/patcher.rb +18 -3
- data/lib/ddtrace/contrib/http/patcher.rb +5 -15
- data/lib/ddtrace/contrib/racecar/patcher.rb +81 -0
- data/lib/ddtrace/contrib/rack/middlewares.rb +28 -53
- data/lib/ddtrace/contrib/rack/patcher.rb +58 -0
- data/lib/ddtrace/contrib/rails/active_record.rb +7 -2
- data/lib/ddtrace/contrib/rails/framework.rb +13 -29
- data/lib/ddtrace/contrib/rails/patcher.rb +1 -1
- data/lib/ddtrace/contrib/rails/railtie.rb +2 -2
- data/lib/ddtrace/contrib/rails/utils.rb +26 -0
- data/lib/ddtrace/contrib/redis/quantize.rb +1 -0
- data/lib/ddtrace/contrib/resque/patcher.rb +3 -0
- data/lib/ddtrace/contrib/sidekiq/tracer.rb +1 -1
- data/lib/ddtrace/contrib/sinatra/tracer.rb +10 -2
- data/lib/ddtrace/contrib/sucker_punch/patcher.rb +1 -0
- data/lib/ddtrace/ext/app_types.rb +1 -0
- data/lib/ddtrace/monkey.rb +2 -0
- metadata +47 -3
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA1:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 6258854e3f07ec379803b25748a5ca5b2d816bc0
|
|
4
|
+
data.tar.gz: 7ab966119e1ee29ce4039b55cb1e264d99116143
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: c5e5b3c715534df2cd421239d7040ffd819a4bc0dcd5b141fba1ab5dba7f63fe2150610a432ad9028c149901cd82201899e527ba5a5d86679e89789d710d4805
|
|
7
|
+
data.tar.gz: 0cbba845ea24b2dff595843e147171b14e5ac162173c606ba3302c3e04c1056fe98f302a97f18f11b934b4b1e3872330f43be2a481e8c56dabca65ca34725104
|
data/Appraisals
CHANGED
|
@@ -72,6 +72,7 @@ if RUBY_VERSION < '2.4.0' && RUBY_PLATFORM != 'java'
|
|
|
72
72
|
gem 'pg', platform: :ruby
|
|
73
73
|
gem 'activerecord-jdbcpostgresql-adapter', platform: :jruby
|
|
74
74
|
gem 'redis-rails'
|
|
75
|
+
gem 'redis', '< 4.0'
|
|
75
76
|
end
|
|
76
77
|
end
|
|
77
78
|
|
|
@@ -90,6 +91,7 @@ if RUBY_VERSION < '2.4.0' && RUBY_PLATFORM != 'java'
|
|
|
90
91
|
gem 'rails', '5.0.1'
|
|
91
92
|
gem 'pg', platform: :ruby
|
|
92
93
|
gem 'redis-rails'
|
|
94
|
+
gem 'redis', '< 4.0'
|
|
93
95
|
end
|
|
94
96
|
|
|
95
97
|
appraise 'rails5-postgres-sidekiq' do
|
|
@@ -116,7 +118,7 @@ if RUBY_VERSION >= '2.2.2' && RUBY_PLATFORM != 'java'
|
|
|
116
118
|
gem 'grape'
|
|
117
119
|
gem 'rack'
|
|
118
120
|
gem 'rack-test'
|
|
119
|
-
gem 'redis'
|
|
121
|
+
gem 'redis', '< 4.0'
|
|
120
122
|
gem 'hiredis'
|
|
121
123
|
gem 'sinatra'
|
|
122
124
|
gem 'sqlite3'
|
|
@@ -126,6 +128,7 @@ if RUBY_VERSION >= '2.2.2' && RUBY_PLATFORM != 'java'
|
|
|
126
128
|
gem 'sucker_punch'
|
|
127
129
|
gem 'dalli'
|
|
128
130
|
gem 'resque'
|
|
131
|
+
gem 'racecar', '>= 0.3.5'
|
|
129
132
|
end
|
|
130
133
|
else
|
|
131
134
|
appraise 'contrib-old' do
|
data/Rakefile
CHANGED
|
@@ -63,6 +63,7 @@ namespace :test do
|
|
|
63
63
|
:aws,
|
|
64
64
|
:sucker_punch,
|
|
65
65
|
:mongodb,
|
|
66
|
+
:racecar,
|
|
66
67
|
:resque,
|
|
67
68
|
:dalli
|
|
68
69
|
].each do |contrib|
|
|
@@ -147,13 +148,11 @@ task :ci do
|
|
|
147
148
|
case ENV['CIRCLE_NODE_INDEX'].to_i
|
|
148
149
|
when 0
|
|
149
150
|
sh 'rvm $MRI_VERSIONS,$MRI_OLD_VERSIONS,$JRUBY_VERSIONS --verbose do rake test:main'
|
|
150
|
-
sh 'rvm $LAST_STABLE --verbose do rake benchmark'
|
|
151
151
|
when 1
|
|
152
152
|
sh 'rvm $MRI_VERSIONS --verbose do appraisal contrib rake test:elasticsearch'
|
|
153
153
|
sh 'rvm $MRI_VERSIONS --verbose do appraisal contrib rake test:http'
|
|
154
154
|
sh 'rvm $MRI_VERSIONS --verbose do appraisal contrib rake test:redis'
|
|
155
155
|
sh 'rvm $MRI_VERSIONS --verbose do appraisal contrib rake test:sinatra'
|
|
156
|
-
sh 'rvm $MRI_VERSIONS --verbose do appraisal contrib rake test:sidekiq'
|
|
157
156
|
sh 'rvm $MRI_VERSIONS --verbose do appraisal contrib rake test:rack'
|
|
158
157
|
sh 'rvm $MRI_VERSIONS --verbose do appraisal contrib rake test:grape'
|
|
159
158
|
sh 'rvm $MRI_VERSIONS --verbose do appraisal contrib rake test:faraday'
|
|
@@ -174,8 +173,9 @@ task :ci do
|
|
|
174
173
|
sh 'rvm $MRI_OLD_VERSIONS --verbose do appraisal contrib-old rake test:sucker_punch'
|
|
175
174
|
sh 'rvm $MRI_OLD_VERSIONS --verbose do appraisal contrib-old rake test:dalli'
|
|
176
175
|
sh 'rvm $MRI_OLD_VERSIONS --verbose do appraisal contrib-old rake test:resque'
|
|
177
|
-
sh 'rvm $SIDEKIQ_OLD_VERSIONS --verbose do appraisal contrib-old rake test:sidekiq'
|
|
178
176
|
when 2
|
|
177
|
+
sh 'rvm $MRI_VERSIONS --verbose do appraisal contrib rake test:sidekiq'
|
|
178
|
+
sh 'rvm $SIDEKIQ_OLD_VERSIONS --verbose do appraisal contrib-old rake test:sidekiq'
|
|
179
179
|
sh 'rvm $RAILS3_VERSIONS --verbose do appraisal rails30-postgres rake test:rails'
|
|
180
180
|
sh 'rvm $RAILS3_VERSIONS --verbose do appraisal rails30-postgres rake test:railsdisableenv'
|
|
181
181
|
sh 'rvm $RAILS3_VERSIONS --verbose do appraisal rails32-mysql2 rake test:rails'
|
|
@@ -196,6 +196,7 @@ task :ci do
|
|
|
196
196
|
sh 'rvm $RAILS5_VERSIONS --verbose do appraisal rails5-postgres-sidekiq rake test:railssidekiq'
|
|
197
197
|
sh 'rvm $RAILS5_VERSIONS --verbose do appraisal rails5-postgres-sidekiq rake test:railsactivejob'
|
|
198
198
|
sh 'rvm $RAILS5_VERSIONS --verbose do appraisal rails5-postgres rake test:railsdisableenv'
|
|
199
|
+
sh 'rvm $LAST_STABLE --verbose do rake benchmark'
|
|
199
200
|
else
|
|
200
201
|
puts 'Too many workers than parallel tasks'
|
|
201
202
|
end
|
data/circle.yml
CHANGED
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
machine:
|
|
2
2
|
services:
|
|
3
3
|
- docker
|
|
4
|
+
ruby:
|
|
5
|
+
version:
|
|
6
|
+
2.2.7
|
|
4
7
|
environment:
|
|
5
8
|
LAST_STABLE: 2.4.1
|
|
6
9
|
EARLY_STABLE: 2.2.7
|
|
@@ -12,7 +15,7 @@ machine:
|
|
|
12
15
|
RAILS5_VERSIONS: 2.3.4,2.2.7
|
|
13
16
|
RAILS3_SIDEKIQ_VERSIONS: 2.1.10,2.0.0
|
|
14
17
|
RAILS4_SIDEKIQ_VERSIONS: 2.3.4,2.2.7
|
|
15
|
-
JRUBY_VERSIONS: jruby-9.1.
|
|
18
|
+
JRUBY_VERSIONS: jruby-9.1.13.0
|
|
16
19
|
AGENT_BUILD_PATH: "/home/ubuntu/agent"
|
|
17
20
|
TEST_DATADOG_INTEGRATION: 1
|
|
18
21
|
|
|
@@ -20,31 +23,36 @@ dependencies:
|
|
|
20
23
|
cache_directories:
|
|
21
24
|
# Cache Ruby binaries and gems
|
|
22
25
|
- "/opt/circleci/.rvm/"
|
|
26
|
+
- ~/rubies_cache
|
|
23
27
|
pre:
|
|
28
|
+
- mkdir -p ~/rubies_cache
|
|
29
|
+
- rsync -a -v --ignore-existing ~/rubies_cache/ /opt/circleci/.rvm/rubies
|
|
24
30
|
# we should use an old docker-compose because CircleCI supports
|
|
25
31
|
# only docker-engine==1.9
|
|
26
32
|
- pip install docker-compose==1.7.1
|
|
27
33
|
- docker-compose up -d | cat
|
|
28
34
|
# installing dev dependencies
|
|
29
|
-
-
|
|
30
|
-
|
|
31
|
-
|
|
35
|
+
- |
|
|
36
|
+
for version in $(echo "$MRI_VERSIONS,$MRI_OLD_VERSIONS,$JRUBY_VERSIONS" | tr "," "\n"); do
|
|
37
|
+
$(rvm list | grep -q $version) || rvm install $version --rubygems 2.6.11
|
|
38
|
+
done
|
|
39
|
+
- gem install bundler
|
|
40
|
+
# remove line below once `msgpack` have a consistent version for jruby
|
|
41
|
+
- bundle inject msgpack 1.1.0 && sed -i "y/\"/'/" Gemfile
|
|
32
42
|
- bundle install
|
|
33
|
-
# configure Ruby interpreters
|
|
34
|
-
- rvm get head
|
|
35
|
-
- rvm install $MRI_VERSIONS,$MRI_OLD_VERSIONS,$JRUBY_VERSIONS
|
|
36
43
|
override:
|
|
37
|
-
- rvm $MRI_VERSIONS,$MRI_OLD_VERSIONS,$JRUBY_VERSIONS --verbose do gem update --system=2.6.11
|
|
38
44
|
- rvm $MRI_VERSIONS,$MRI_OLD_VERSIONS,$JRUBY_VERSIONS --verbose do gem install bundler
|
|
39
45
|
- rvm $MRI_VERSIONS,$MRI_OLD_VERSIONS,$JRUBY_VERSIONS --verbose do bundle install
|
|
40
46
|
# [FIXME] appraisal does not work with jruby (problem with native ext, eg sqlite3)
|
|
41
|
-
- rvm $MRI_VERSIONS,$MRI_OLD_VERSIONS --verbose do appraisal install
|
|
47
|
+
- rvm $MRI_VERSIONS,$MRI_OLD_VERSIONS --verbose do bundle exec appraisal install || echo FIX-ME: Ignoring non-zero exit status
|
|
48
|
+
post:
|
|
49
|
+
- rsync -a -v --ignore-existing /opt/circleci/.rvm/rubies/ ~/rubies_cache
|
|
42
50
|
|
|
43
51
|
test:
|
|
44
52
|
override:
|
|
45
|
-
- rvm $EARLY_STABLE --verbose do rake rubocop
|
|
53
|
+
- rvm $EARLY_STABLE --verbose do bundle exec rake rubocop
|
|
46
54
|
# TODO: integration tests should run with the master branch of the agent
|
|
47
|
-
- rake ci:
|
|
55
|
+
- bundle exec rake ci:
|
|
48
56
|
parallel: true
|
|
49
57
|
|
|
50
58
|
deployment:
|
|
@@ -52,10 +60,10 @@ deployment:
|
|
|
52
60
|
branch: /(master)|(develop)/
|
|
53
61
|
# CircleCI is configured to provide VERSION_SUFFIX=$CIRCLE_BUILD_NUM
|
|
54
62
|
commands:
|
|
55
|
-
- S3_DIR=trace-dev rake release:docs
|
|
56
|
-
- S3_DIR=trace-dev rake release:gem
|
|
63
|
+
- S3_DIR=trace-dev bundle exec rake release:docs
|
|
64
|
+
- S3_DIR=trace-dev bundle exec rake release:gem
|
|
57
65
|
- cp -r ./rubygems/* $CIRCLE_ARTIFACTS
|
|
58
66
|
public:
|
|
59
67
|
tag: /v[0-9]+(\.[0-9]+)*/
|
|
60
68
|
commands:
|
|
61
|
-
- S3_DIR=trace rake release:docs
|
|
69
|
+
- S3_DIR=trace bundle exec rake release:docs
|
data/ddtrace.gemspec
CHANGED
|
@@ -6,7 +6,7 @@ require 'ddtrace/version'
|
|
|
6
6
|
|
|
7
7
|
Gem::Specification.new do |spec|
|
|
8
8
|
spec.name = 'ddtrace'
|
|
9
|
-
spec.version = "#{Datadog::VERSION::STRING}.
|
|
9
|
+
spec.version = "#{Datadog::VERSION::STRING}.beta2#{ENV['VERSION_SUFFIX']}"
|
|
10
10
|
spec.required_ruby_version = '>= 1.9.1'
|
|
11
11
|
spec.authors = ['Datadog, Inc.']
|
|
12
12
|
spec.email = ['dev@datadoghq.com']
|
|
@@ -40,7 +40,10 @@ EOS
|
|
|
40
40
|
spec.add_development_dependency 'appraisal', '~> 2.2'
|
|
41
41
|
spec.add_development_dependency 'yard', '~> 0.9'
|
|
42
42
|
spec.add_development_dependency 'webmock', '~> 2.0'
|
|
43
|
+
spec.add_development_dependency 'builder'
|
|
43
44
|
# locking transitive dependency of webmock
|
|
44
|
-
spec.add_development_dependency 'addressable',
|
|
45
|
+
spec.add_development_dependency 'addressable', '~> 2.4.0'
|
|
45
46
|
spec.add_development_dependency 'redcarpet', '~> 3.4' if RUBY_PLATFORM != 'java'
|
|
47
|
+
spec.add_development_dependency 'pry', '>= 0.10.4'
|
|
48
|
+
spec.add_development_dependency 'pry-stack_explorer', '>= 0.4.9.2'
|
|
46
49
|
end
|
data/docs/GettingStarted.md
CHANGED
|
@@ -182,20 +182,22 @@ To start using the middleware in your generic Rack application, add it to your `
|
|
|
182
182
|
|
|
183
183
|
run app
|
|
184
184
|
|
|
185
|
-
|
|
186
|
-
You need to set the ``:distributed_tracing_enabled`` option to true, for example:
|
|
185
|
+
The Rack middleware can be configured using the global configuration object:
|
|
187
186
|
|
|
188
187
|
# config.ru example
|
|
188
|
+
require 'ddtrace'
|
|
189
189
|
require 'ddtrace/contrib/rack/middlewares'
|
|
190
190
|
|
|
191
|
-
|
|
191
|
+
Datadog.configure do |c|
|
|
192
|
+
c.use :rack, service_name: 'api-intake', distributed_tracing: true
|
|
193
|
+
end
|
|
192
194
|
|
|
193
195
|
app = proc do |env|
|
|
194
|
-
# trace and read 'x-datadog-trace-id' and 'x-datadog-parent-id'
|
|
195
196
|
[ 200, {'Content-Type' => 'text/plain'}, "OK" ]
|
|
196
197
|
end
|
|
197
198
|
|
|
198
|
-
|
|
199
|
+
In the example above, we've activated the Distributed Tracing flag, please
|
|
200
|
+
see [distributed tracing](#Distributed_Tracing) for more details.
|
|
199
201
|
|
|
200
202
|
#### Configure the tracer
|
|
201
203
|
|
data/gemfiles/contrib.gemfile
CHANGED
|
@@ -7,7 +7,7 @@ gem "mongo"
|
|
|
7
7
|
gem "grape"
|
|
8
8
|
gem "rack"
|
|
9
9
|
gem "rack-test"
|
|
10
|
-
gem "redis"
|
|
10
|
+
gem "redis", "< 4.0"
|
|
11
11
|
gem "hiredis"
|
|
12
12
|
gem "sinatra"
|
|
13
13
|
gem "sqlite3"
|
|
@@ -17,5 +17,6 @@ gem "aws-sdk"
|
|
|
17
17
|
gem "sucker_punch"
|
|
18
18
|
gem "dalli"
|
|
19
19
|
gem "resque"
|
|
20
|
+
gem "racecar", ">= 0.3.5"
|
|
20
21
|
|
|
21
22
|
gemspec path: "../"
|
data/lib/ddtrace/configurable.rb
CHANGED
|
@@ -20,7 +20,7 @@ module Datadog
|
|
|
20
20
|
def get_option(name)
|
|
21
21
|
__assert_valid!(name)
|
|
22
22
|
|
|
23
|
-
return
|
|
23
|
+
return __default_value(name) unless __options[name][:set_flag]
|
|
24
24
|
|
|
25
25
|
__options[name][:value]
|
|
26
26
|
end
|
|
@@ -47,6 +47,7 @@ module Datadog
|
|
|
47
47
|
name = name.to_sym
|
|
48
48
|
meta[:setter] ||= (block || IDENTITY)
|
|
49
49
|
meta[:depends_on] ||= []
|
|
50
|
+
meta[:lazy] ||= false
|
|
50
51
|
__options[name] = meta
|
|
51
52
|
end
|
|
52
53
|
|
|
@@ -72,6 +73,11 @@ module Datadog
|
|
|
72
73
|
graph[name] = meta[:depends_on]
|
|
73
74
|
end
|
|
74
75
|
end
|
|
76
|
+
|
|
77
|
+
def __default_value(name)
|
|
78
|
+
return __options[name][:default].call if __options[name][:lazy]
|
|
79
|
+
__options[name][:default]
|
|
80
|
+
end
|
|
75
81
|
end
|
|
76
82
|
end
|
|
77
83
|
end
|
|
@@ -42,21 +42,24 @@ module Datadog
|
|
|
42
42
|
end
|
|
43
43
|
end
|
|
44
44
|
|
|
45
|
-
def self.
|
|
46
|
-
|
|
47
|
-
# @tracer ||= defined?(::Rails) && ::Rails.configuration.datadog_trace
|
|
48
|
-
@datadog_trace ||= defined?(::Sinatra) && Datadog.configuration[:sinatra].to_h
|
|
45
|
+
def self.adapter_name
|
|
46
|
+
@adapter_name ||= Datadog::Contrib::Rails::Utils.adapter_name
|
|
49
47
|
end
|
|
50
48
|
|
|
51
|
-
def self.
|
|
52
|
-
@
|
|
53
|
-
|
|
54
|
-
|
|
49
|
+
def self.database_name
|
|
50
|
+
@database_name ||= Datadog::Contrib::Rails::Utils.database_name
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
def self.adapter_host
|
|
54
|
+
@adapter_host ||= Datadog::Contrib::Rails::Utils.adapter_host
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
def self.adapter_port
|
|
58
|
+
@adapter_port ||= Datadog::Contrib::Rails::Utils.adapter_port
|
|
55
59
|
end
|
|
56
60
|
|
|
57
61
|
def self.tracer
|
|
58
|
-
|
|
59
|
-
@tracer ||= datadog_trace.fetch(:tracer)
|
|
62
|
+
@tracer ||= Datadog.configuration[:sinatra][:tracer]
|
|
60
63
|
end
|
|
61
64
|
|
|
62
65
|
def self.database_service
|
|
@@ -82,6 +85,9 @@ module Datadog
|
|
|
82
85
|
# obfuscated version
|
|
83
86
|
span.span_type = Datadog::Ext::SQL::TYPE
|
|
84
87
|
span.set_tag('active_record.db.vendor', adapter_name)
|
|
88
|
+
span.set_tag('active_record.db.name', database_name)
|
|
89
|
+
span.set_tag('out.host', adapter_host)
|
|
90
|
+
span.set_tag('out.port', adapter_port)
|
|
85
91
|
span.start_time = start
|
|
86
92
|
span.finish(finish)
|
|
87
93
|
rescue StandardError => e
|
|
@@ -22,6 +22,7 @@ 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)
|
|
25
26
|
|
|
26
27
|
@patched = true
|
|
27
28
|
rescue => e
|
|
@@ -42,7 +43,7 @@ module Datadog
|
|
|
42
43
|
end
|
|
43
44
|
|
|
44
45
|
def add_pin!
|
|
45
|
-
Pin.new(get_option(:service_name), app_type: Ext::AppTypes::
|
|
46
|
+
Pin.new(get_option(:service_name), app_type: Ext::AppTypes::CACHE).tap do |pin|
|
|
46
47
|
pin.onto(::Dalli)
|
|
47
48
|
end
|
|
48
49
|
end
|
|
@@ -9,7 +9,6 @@ module Datadog
|
|
|
9
9
|
BODY = 'elasticsearch.body'.freeze
|
|
10
10
|
|
|
11
11
|
SERVICE = 'elasticsearch'.freeze
|
|
12
|
-
SPAN_TYPE = 'elasticsearch'.freeze
|
|
13
12
|
|
|
14
13
|
# Patcher enables patching of 'elasticsearch/transport' module.
|
|
15
14
|
# This is used in monkey.rb to automatically apply patches
|
|
@@ -35,6 +34,7 @@ module Datadog
|
|
|
35
34
|
require 'ddtrace/contrib/elasticsearch/quantize'
|
|
36
35
|
|
|
37
36
|
patch_elasticsearch_transport_client()
|
|
37
|
+
Datadog.tracer.set_service_info(get_option(:service_name), 'elasticsearch', Ext::AppTypes::DB)
|
|
38
38
|
|
|
39
39
|
@patched = true
|
|
40
40
|
rescue StandardError => e
|
|
@@ -45,6 +45,7 @@ module Datadog
|
|
|
45
45
|
end
|
|
46
46
|
|
|
47
47
|
# rubocop:disable Metrics/MethodLength
|
|
48
|
+
# rubocop:disable Metrics/AbcSize
|
|
48
49
|
def patch_elasticsearch_transport_client
|
|
49
50
|
# rubocop:disable Metrics/BlockLength
|
|
50
51
|
::Elasticsearch::Transport::Client.class_eval do
|
|
@@ -77,8 +78,12 @@ module Datadog
|
|
|
77
78
|
response = nil
|
|
78
79
|
pin.tracer.trace('elasticsearch.query') do |span|
|
|
79
80
|
begin
|
|
81
|
+
connection = transport.connections.first
|
|
82
|
+
host = connection.host[:host] if connection
|
|
83
|
+
port = connection.host[:port] if connection
|
|
84
|
+
|
|
80
85
|
span.service = pin.service
|
|
81
|
-
span.span_type =
|
|
86
|
+
span.span_type = Ext::AppTypes::DB
|
|
82
87
|
|
|
83
88
|
# load JSON for the following fields unless they're already strings
|
|
84
89
|
params = JSON.generate(params) if params && !params.is_a?(String)
|
|
@@ -88,6 +93,8 @@ module Datadog
|
|
|
88
93
|
span.set_tag(URL, url)
|
|
89
94
|
span.set_tag(PARAMS, params) if params
|
|
90
95
|
span.set_tag(BODY, body) if body
|
|
96
|
+
span.set_tag('out.host', host) if host
|
|
97
|
+
span.set_tag('out.port', port) if port
|
|
91
98
|
|
|
92
99
|
quantized_url = Datadog::Contrib::Elasticsearch::Quantize.format_url(url)
|
|
93
100
|
span.resource = "#{method} #{quantized_url}"
|
|
@@ -10,32 +10,24 @@ module Datadog
|
|
|
10
10
|
class Middleware < ::Faraday::Middleware
|
|
11
11
|
include Ext::DistributedTracing
|
|
12
12
|
|
|
13
|
-
DEFAULT_ERROR_HANDLER = lambda do |env|
|
|
14
|
-
Ext::HTTP::ERROR_RANGE.cover?(env[:status])
|
|
15
|
-
end
|
|
16
|
-
|
|
17
|
-
DEFAULT_OPTIONS = {
|
|
18
|
-
distributed_tracing: false,
|
|
19
|
-
split_by_domain: false,
|
|
20
|
-
error_handler: DEFAULT_ERROR_HANDLER
|
|
21
|
-
}.freeze
|
|
22
|
-
|
|
23
13
|
def initialize(app, options = {})
|
|
24
14
|
super(app)
|
|
25
|
-
@options =
|
|
15
|
+
@options = Datadog.configuration[:faraday].merge(options)
|
|
16
|
+
@tracer = Pin.get_from(::Faraday).tracer
|
|
17
|
+
setup_service!
|
|
26
18
|
end
|
|
27
19
|
|
|
28
20
|
def call(env)
|
|
29
|
-
|
|
21
|
+
tracer.trace(NAME) do |span|
|
|
30
22
|
annotate!(span, env)
|
|
31
|
-
propagate!(span, env) if options[:distributed_tracing] &&
|
|
23
|
+
propagate!(span, env) if options[:distributed_tracing] && tracer.enabled
|
|
32
24
|
app.call(env).on_complete { |resp| handle_response(span, resp) }
|
|
33
25
|
end
|
|
34
26
|
end
|
|
35
27
|
|
|
36
28
|
private
|
|
37
29
|
|
|
38
|
-
attr_reader :app, :options
|
|
30
|
+
attr_reader :app, :options, :tracer
|
|
39
31
|
|
|
40
32
|
def annotate!(span, env)
|
|
41
33
|
span.resource = env[:method].to_s.upcase
|
|
@@ -59,14 +51,16 @@ module Datadog
|
|
|
59
51
|
Datadog::HTTPPropagator.inject!(span.context, env[:request_headers])
|
|
60
52
|
end
|
|
61
53
|
|
|
62
|
-
def dd_pin
|
|
63
|
-
Pin.get_from(::Faraday)
|
|
64
|
-
end
|
|
65
|
-
|
|
66
54
|
def service_name(env)
|
|
67
55
|
return env[:url].host if options[:split_by_domain]
|
|
68
56
|
|
|
69
|
-
|
|
57
|
+
options[:service_name]
|
|
58
|
+
end
|
|
59
|
+
|
|
60
|
+
def setup_service!
|
|
61
|
+
return if options[:service_name] == Datadog.configuration[:faraday][:service_name]
|
|
62
|
+
|
|
63
|
+
Patcher.register_service(options[:service_name])
|
|
70
64
|
end
|
|
71
65
|
end
|
|
72
66
|
end
|
|
@@ -2,13 +2,23 @@ module Datadog
|
|
|
2
2
|
module Contrib
|
|
3
3
|
module Faraday
|
|
4
4
|
COMPATIBLE_UNTIL = Gem::Version.new('1.0.0')
|
|
5
|
-
SERVICE = 'faraday
|
|
5
|
+
SERVICE = 'faraday'.freeze
|
|
6
|
+
NAME = 'faraday.request'.freeze
|
|
6
7
|
|
|
7
8
|
# Responsible for hooking the instrumentation into faraday
|
|
8
9
|
module Patcher
|
|
9
10
|
include Base
|
|
11
|
+
|
|
10
12
|
register_as :faraday, auto_patch: true
|
|
13
|
+
|
|
14
|
+
DEFAULT_ERROR_HANDLER = lambda do |env|
|
|
15
|
+
Ext::HTTP::ERROR_RANGE.cover?(env[:status])
|
|
16
|
+
end
|
|
17
|
+
|
|
11
18
|
option :service_name, default: SERVICE
|
|
19
|
+
option :distributed_tracing, default: false
|
|
20
|
+
option :error_handler, default: DEFAULT_ERROR_HANDLER
|
|
21
|
+
option :tracer, default: Datadog.tracer
|
|
12
22
|
|
|
13
23
|
@patched = false
|
|
14
24
|
|
|
@@ -21,6 +31,7 @@ module Datadog
|
|
|
21
31
|
|
|
22
32
|
add_pin
|
|
23
33
|
add_middleware
|
|
34
|
+
register_service(get_option(:service_name))
|
|
24
35
|
|
|
25
36
|
@patched = true
|
|
26
37
|
rescue => e
|
|
@@ -32,6 +43,10 @@ module Datadog
|
|
|
32
43
|
@patched
|
|
33
44
|
end
|
|
34
45
|
|
|
46
|
+
def register_service(name)
|
|
47
|
+
get_option(:tracer).set_service_info(name, 'faraday', Ext::AppTypes::WEB)
|
|
48
|
+
end
|
|
49
|
+
|
|
35
50
|
private
|
|
36
51
|
|
|
37
52
|
def compatible?
|
|
@@ -41,9 +56,9 @@ module Datadog
|
|
|
41
56
|
end
|
|
42
57
|
|
|
43
58
|
def add_pin
|
|
44
|
-
Pin.new(
|
|
59
|
+
Pin.new(get_option(:service_name), app_type: Ext::AppTypes::WEB).tap do |pin|
|
|
45
60
|
pin.onto(::Faraday)
|
|
46
|
-
pin.
|
|
61
|
+
pin.tracer = get_option(:tracer)
|
|
47
62
|
end
|
|
48
63
|
end
|
|
49
64
|
|
|
@@ -14,16 +14,6 @@ module Datadog
|
|
|
14
14
|
|
|
15
15
|
module_function
|
|
16
16
|
|
|
17
|
-
# TODO: Remove this once we drop support for legacy configuration
|
|
18
|
-
def distributed_tracing_enabled
|
|
19
|
-
Datadog.configuration[:http][:distributed_tracing_enabled]
|
|
20
|
-
end
|
|
21
|
-
|
|
22
|
-
# TODO: Remove this once we drop support for legacy configuration
|
|
23
|
-
def distributed_tracing_enabled=(value)
|
|
24
|
-
Datadog.configuration[:http][:distributed_tracing_enabled] = value
|
|
25
|
-
end
|
|
26
|
-
|
|
27
17
|
def should_skip_tracing?(req, address, port, transport, pin)
|
|
28
18
|
# we don't want to trace our own call to the API (they use net/http)
|
|
29
19
|
# when we know the host & port (from the URI) we use it, else (most-likely
|
|
@@ -46,11 +36,11 @@ module Datadog
|
|
|
46
36
|
end
|
|
47
37
|
|
|
48
38
|
def should_skip_distributed_tracing?(pin)
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
return !pin.config.fetch(:distributed_tracing_enabled, global_value)
|
|
39
|
+
if pin.config && pin.config.key?(:distributed_tracing)
|
|
40
|
+
return !pin.config[:distributed_tracing]
|
|
52
41
|
end
|
|
53
|
-
|
|
42
|
+
|
|
43
|
+
!Datadog.configuration[:http][:distributed_tracing]
|
|
54
44
|
end
|
|
55
45
|
|
|
56
46
|
# Patcher enables patching of 'net/http' module.
|
|
@@ -58,7 +48,7 @@ module Datadog
|
|
|
58
48
|
module Patcher
|
|
59
49
|
include Base
|
|
60
50
|
register_as :http, auto_patch: true
|
|
61
|
-
option :
|
|
51
|
+
option :distributed_tracing, default: false
|
|
62
52
|
|
|
63
53
|
@patched = false
|
|
64
54
|
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
require 'ddtrace/ext/app_types'
|
|
2
|
+
|
|
3
|
+
module Datadog
|
|
4
|
+
module Contrib
|
|
5
|
+
module Racecar
|
|
6
|
+
# Provides instrumentation for `racecar` through ActiveSupport instrumentation signals
|
|
7
|
+
module Patcher
|
|
8
|
+
include Base
|
|
9
|
+
NAME_MESSAGE = 'racecar.message'.freeze
|
|
10
|
+
NAME_BATCH = 'racecar.batch'.freeze
|
|
11
|
+
register_as :racecar
|
|
12
|
+
option :tracer, default: Datadog.tracer
|
|
13
|
+
option :service_name, default: 'racecar'
|
|
14
|
+
|
|
15
|
+
class << self
|
|
16
|
+
def patch
|
|
17
|
+
return patched? if patched? || !compatible?
|
|
18
|
+
|
|
19
|
+
::ActiveSupport::Notifications.subscribe('start_process_batch.racecar', &method(:start))
|
|
20
|
+
::ActiveSupport::Notifications.subscribe('start_process_message.racecar', &method(:start))
|
|
21
|
+
::ActiveSupport::Notifications.subscribe('process_batch.racecar', &method(:finish))
|
|
22
|
+
::ActiveSupport::Notifications.subscribe('process_message.racecar', &method(:finish))
|
|
23
|
+
|
|
24
|
+
configuration[:tracer].set_service_info(
|
|
25
|
+
configuration[:service_name],
|
|
26
|
+
'racecar',
|
|
27
|
+
Ext::AppTypes::WORKER
|
|
28
|
+
)
|
|
29
|
+
|
|
30
|
+
@patched = true
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
def patched?
|
|
34
|
+
return @patched if defined?(@patched)
|
|
35
|
+
@patched = false
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
private
|
|
39
|
+
|
|
40
|
+
def configuration
|
|
41
|
+
Datadog.configuration[:racecar]
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
def compatible?
|
|
45
|
+
defined?(::Racecar) && defined?(::ActiveSupport::Notifications)
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
def start(event, *_, payload)
|
|
49
|
+
ensure_clean_context!
|
|
50
|
+
|
|
51
|
+
name = event[/message/] ? NAME_MESSAGE : NAME_BATCH
|
|
52
|
+
span = configuration[:tracer].trace(name)
|
|
53
|
+
span.service = configuration[:service_name]
|
|
54
|
+
span.resource = payload[:consumer_class]
|
|
55
|
+
span.set_tag('kafka.topic', payload[:topic])
|
|
56
|
+
span.set_tag('kafka.consumer', payload[:consumer_class])
|
|
57
|
+
span.set_tag('kafka.partition', payload[:partition])
|
|
58
|
+
span.set_tag('kafka.offset', payload[:offset]) if payload.key?(:offset)
|
|
59
|
+
span.set_tag('kafka.first_offset', payload[:first_offset]) if payload.key?(:first_offset)
|
|
60
|
+
span.set_tag('kafka.message_count', payload[:message_count]) if payload.key?(:message_count)
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
def finish(*_, payload)
|
|
64
|
+
current_span = configuration[:tracer].call_context.current_span
|
|
65
|
+
|
|
66
|
+
return unless current_span
|
|
67
|
+
|
|
68
|
+
current_span.set_error(payload[:exception_object]) if payload[:exception_object]
|
|
69
|
+
current_span.finish
|
|
70
|
+
end
|
|
71
|
+
|
|
72
|
+
def ensure_clean_context!
|
|
73
|
+
return unless configuration[:tracer].call_context.current_span
|
|
74
|
+
|
|
75
|
+
configuration[:tracer].provider.context = Context.new
|
|
76
|
+
end
|
|
77
|
+
end
|
|
78
|
+
end
|
|
79
|
+
end
|
|
80
|
+
end
|
|
81
|
+
end
|
|
@@ -13,64 +13,35 @@ module Datadog
|
|
|
13
13
|
# application. If request tags are not set by the app, they will be set using
|
|
14
14
|
# information available at the Rack level.
|
|
15
15
|
class TraceMiddleware
|
|
16
|
-
|
|
17
|
-
register_as :rack
|
|
18
|
-
|
|
19
|
-
option :tracer, default: Datadog.tracer
|
|
20
|
-
option :service_name, default: 'rack', depends_on: [:tracer] do |value|
|
|
21
|
-
get_option(:tracer).set_service_info(value, 'rack', Ext::AppTypes::WEB)
|
|
22
|
-
value
|
|
23
|
-
end
|
|
24
|
-
option :distributed_tracing_enabled, default: false
|
|
25
|
-
|
|
26
|
-
def initialize(app, options = {})
|
|
27
|
-
# update options with our configuration, unless it's already available
|
|
28
|
-
[:tracer, :service_name, :distributed_tracing_enabled].each do |k|
|
|
29
|
-
Datadog.configuration[:rack][k] = options[k] unless options[k].nil?
|
|
30
|
-
end
|
|
31
|
-
|
|
16
|
+
def initialize(app)
|
|
32
17
|
@app = app
|
|
33
18
|
end
|
|
34
19
|
|
|
35
|
-
def configure
|
|
36
|
-
# ensure that the configuration is executed only once
|
|
37
|
-
return clean_context if @tracer && @service
|
|
38
|
-
|
|
39
|
-
# retrieve the current tracer and service
|
|
40
|
-
@tracer = Datadog.configuration[:rack][:tracer]
|
|
41
|
-
@service = Datadog.configuration[:rack][:service_name]
|
|
42
|
-
@distributed_tracing_enabled = Datadog.configuration[:rack][:distributed_tracing_enabled]
|
|
43
|
-
|
|
44
|
-
# configure the Rack service
|
|
45
|
-
end
|
|
46
|
-
|
|
47
|
-
# rubocop:disable Metrics/MethodLength
|
|
48
20
|
def call(env)
|
|
49
|
-
#
|
|
50
|
-
|
|
21
|
+
# retrieve integration settings
|
|
22
|
+
tracer = Datadog.configuration[:rack][:tracer]
|
|
23
|
+
service = Datadog.configuration[:rack][:service_name]
|
|
24
|
+
distributed_tracing = Datadog.configuration[:rack][:distributed_tracing]
|
|
51
25
|
|
|
52
26
|
trace_options = {
|
|
53
|
-
service:
|
|
27
|
+
service: service,
|
|
54
28
|
resource: nil,
|
|
55
29
|
span_type: Datadog::Ext::HTTP::TYPE
|
|
56
30
|
}
|
|
57
31
|
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
if
|
|
61
|
-
context = HTTPPropagator.extract(env)
|
|
62
|
-
@tracer.provider.context = context if context.trace_id
|
|
63
|
-
end
|
|
64
|
-
ensure
|
|
65
|
-
# start a new request span and attach it to the current Rack environment;
|
|
66
|
-
# we must ensure that the span `resource` is set later
|
|
67
|
-
request_span = @tracer.trace('rack.request', trace_options)
|
|
32
|
+
if distributed_tracing
|
|
33
|
+
context = HTTPPropagator.extract(env)
|
|
34
|
+
tracer.provider.context = context if context.trace_id
|
|
68
35
|
end
|
|
69
36
|
|
|
37
|
+
# start a new request span and attach it to the current Rack environment;
|
|
38
|
+
# we must ensure that the span `resource` is set later
|
|
39
|
+
request_span = tracer.trace('rack.request', trace_options)
|
|
70
40
|
env[:datadog_rack_request_span] = request_span
|
|
71
41
|
|
|
72
42
|
# call the rest of the stack
|
|
73
43
|
status, headers, response = @app.call(env)
|
|
44
|
+
[status, headers, response]
|
|
74
45
|
|
|
75
46
|
# rubocop:disable Lint/RescueException
|
|
76
47
|
# Here we really want to catch *any* exception, not only StandardError,
|
|
@@ -82,7 +53,7 @@ module Datadog
|
|
|
82
53
|
# catch exceptions that may be raised in the middleware chain
|
|
83
54
|
# Note: if a middleware catches an Exception without re raising,
|
|
84
55
|
# the Exception cannot be recorded here.
|
|
85
|
-
request_span.set_error(e)
|
|
56
|
+
request_span.set_error(e) unless request_span.nil?
|
|
86
57
|
raise e
|
|
87
58
|
ensure
|
|
88
59
|
# the source of truth in Rack is the PATH_INFO key that holds the
|
|
@@ -98,7 +69,7 @@ module Datadog
|
|
|
98
69
|
# the result for this request; `resource` and `tags` are expected to
|
|
99
70
|
# be set in another level but if they're missing, reasonable defaults
|
|
100
71
|
# are used.
|
|
101
|
-
request_span.resource
|
|
72
|
+
request_span.resource ||= resource_name_for(env, status)
|
|
102
73
|
if request_span.get_tag(Datadog::Ext::HTTP::METHOD).nil?
|
|
103
74
|
request_span.set_tag(Datadog::Ext::HTTP::METHOD, env['REQUEST_METHOD'])
|
|
104
75
|
end
|
|
@@ -115,18 +86,22 @@ module Datadog
|
|
|
115
86
|
request_span.status = 1
|
|
116
87
|
end
|
|
117
88
|
|
|
118
|
-
request_span
|
|
89
|
+
# ensure the request_span is finished and the context reset;
|
|
90
|
+
# this assumes that the Rack middleware creates a root span
|
|
91
|
+
request_span.finish
|
|
119
92
|
|
|
120
|
-
|
|
93
|
+
# TODO: Remove this once we change how context propagation works. This
|
|
94
|
+
# ensures we clean thread-local variables on each HTTP request avoiding
|
|
95
|
+
# memory leaks.
|
|
96
|
+
tracer.provider.context = Datadog::Context.new
|
|
121
97
|
end
|
|
122
98
|
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
@tracer.provider.context = Datadog::Context.new
|
|
99
|
+
def resource_name_for(env, status)
|
|
100
|
+
if Datadog.configuration[:rack][:middleware_names]
|
|
101
|
+
"#{env['RESPONSE_MIDDLEWARE']}##{env['REQUEST_METHOD']}"
|
|
102
|
+
else
|
|
103
|
+
"#{env['REQUEST_METHOD']} #{status}".strip
|
|
104
|
+
end
|
|
130
105
|
end
|
|
131
106
|
end
|
|
132
107
|
end
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
module Datadog
|
|
2
|
+
module Contrib
|
|
3
|
+
module Rack
|
|
4
|
+
# Provides instrumentation for `rack`
|
|
5
|
+
module Patcher
|
|
6
|
+
include Base
|
|
7
|
+
register_as :rack
|
|
8
|
+
option :tracer, default: Datadog.tracer
|
|
9
|
+
option :distributed_tracing, default: false
|
|
10
|
+
option :middleware_names, default: false
|
|
11
|
+
option :application
|
|
12
|
+
option :service_name, default: 'rack', depends_on: [:tracer] do |value|
|
|
13
|
+
get_option(:tracer).set_service_info(value, 'rack', Ext::AppTypes::WEB)
|
|
14
|
+
value
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
module_function
|
|
18
|
+
|
|
19
|
+
def patch
|
|
20
|
+
return true if patched?
|
|
21
|
+
|
|
22
|
+
require_relative 'middlewares'
|
|
23
|
+
@patched = true
|
|
24
|
+
|
|
25
|
+
return unless get_option(:middleware_names)
|
|
26
|
+
|
|
27
|
+
top = get_option(:application) || rails_app
|
|
28
|
+
retain_middleware_name(top)
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
def patched?
|
|
32
|
+
@patched ||= false
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
def rails_app
|
|
36
|
+
return unless Datadog.registry[:rails].compatible?
|
|
37
|
+
::Rails.application.app
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
def retain_middleware_name(middleware)
|
|
41
|
+
return unless middleware && middleware.respond_to?(:call)
|
|
42
|
+
|
|
43
|
+
middleware.singleton_class.class_eval do
|
|
44
|
+
alias_method :__call, :call
|
|
45
|
+
|
|
46
|
+
def call(env)
|
|
47
|
+
env['RESPONSE_MIDDLEWARE'] = self.class.to_s
|
|
48
|
+
__call(env)
|
|
49
|
+
end
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
following = middleware.instance_variable_get('@app')
|
|
53
|
+
retain_middleware_name(following)
|
|
54
|
+
end
|
|
55
|
+
end
|
|
56
|
+
end
|
|
57
|
+
end
|
|
58
|
+
end
|
|
@@ -20,8 +20,10 @@ module Datadog
|
|
|
20
20
|
def self.sql(_name, start, finish, _id, payload)
|
|
21
21
|
tracer = Datadog.configuration[:rails][:tracer]
|
|
22
22
|
database_service = Datadog.configuration[:rails][:database_service]
|
|
23
|
-
adapter_name = ::
|
|
24
|
-
|
|
23
|
+
adapter_name = Datadog::Contrib::Rails::Utils.adapter_name
|
|
24
|
+
database_name = Datadog::Contrib::Rails::Utils.database_name
|
|
25
|
+
adapter_host = Datadog::Contrib::Rails::Utils.adapter_host
|
|
26
|
+
adapter_port = Datadog::Contrib::Rails::Utils.adapter_port
|
|
25
27
|
span_type = Datadog::Ext::SQL::TYPE
|
|
26
28
|
|
|
27
29
|
span = tracer.trace(
|
|
@@ -44,7 +46,10 @@ module Datadog
|
|
|
44
46
|
# obfuscated version
|
|
45
47
|
span.span_type = Datadog::Ext::SQL::TYPE
|
|
46
48
|
span.set_tag('rails.db.vendor', adapter_name)
|
|
49
|
+
span.set_tag('rails.db.name', database_name)
|
|
47
50
|
span.set_tag('rails.db.cached', cached) if cached
|
|
51
|
+
span.set_tag('out.host', adapter_host)
|
|
52
|
+
span.set_tag('out.port', adapter_port)
|
|
48
53
|
span.start_time = start
|
|
49
54
|
span.finish(finish)
|
|
50
55
|
rescue StandardError => e
|
|
@@ -11,17 +11,6 @@ require 'ddtrace/contrib/rails/active_record'
|
|
|
11
11
|
require 'ddtrace/contrib/rails/active_support'
|
|
12
12
|
require 'ddtrace/contrib/rails/utils'
|
|
13
13
|
|
|
14
|
-
# Rails < 3.1
|
|
15
|
-
if defined?(::ActiveRecord) && !defined?(::ActiveRecord::Base.connection_config)
|
|
16
|
-
ActiveRecord::Base.class_eval do
|
|
17
|
-
class << self
|
|
18
|
-
def connection_config
|
|
19
|
-
connection_pool.spec.config
|
|
20
|
-
end
|
|
21
|
-
end
|
|
22
|
-
end
|
|
23
|
-
end
|
|
24
|
-
|
|
25
14
|
module Datadog
|
|
26
15
|
module Contrib
|
|
27
16
|
# Instrument Rails.
|
|
@@ -31,18 +20,16 @@ module Datadog
|
|
|
31
20
|
# - instrument parts of the framework when needed
|
|
32
21
|
module Framework
|
|
33
22
|
# configure Datadog settings
|
|
34
|
-
def self.
|
|
35
|
-
user_config = rails_config[:config].datadog_trace rescue {}
|
|
36
|
-
Datadog.configuration.use(:rails, user_config)
|
|
23
|
+
def self.setup
|
|
37
24
|
config = Datadog.configuration[:rails]
|
|
38
|
-
tracer = config[:tracer]
|
|
39
25
|
config[:service_name] ||= Utils.app_name
|
|
26
|
+
tracer = config[:tracer]
|
|
40
27
|
|
|
41
28
|
Datadog.configuration.use(
|
|
42
29
|
:rack,
|
|
43
30
|
tracer: tracer,
|
|
44
31
|
service_name: config[:service_name],
|
|
45
|
-
|
|
32
|
+
distributed_tracing: config[:distributed_tracing]
|
|
46
33
|
)
|
|
47
34
|
|
|
48
35
|
config[:controller_service] ||= config[:service_name]
|
|
@@ -50,25 +37,22 @@ module Datadog
|
|
|
50
37
|
|
|
51
38
|
tracer.set_service_info(config[:controller_service], 'rails', Ext::AppTypes::WEB)
|
|
52
39
|
tracer.set_service_info(config[:cache_service], 'rails', Ext::AppTypes::CACHE)
|
|
40
|
+
set_database_service
|
|
53
41
|
|
|
54
42
|
# By default, default service would be guessed from the script
|
|
55
43
|
# being executed, but here we know better, get it from Rails config.
|
|
56
44
|
tracer.default_service = config[:service_name]
|
|
45
|
+
end
|
|
57
46
|
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
# set default database service details and store it in the configuration
|
|
61
|
-
conn_cfg = ::ActiveRecord::Base.connection_config()
|
|
62
|
-
adapter_name = Datadog::Contrib::Rails::Utils.normalize_vendor(conn_cfg[:adapter])
|
|
63
|
-
config[:database_service] ||= "#{config[:service_name]}-#{adapter_name}"
|
|
64
|
-
tracer.set_service_info(config[:database_service], adapter_name, Ext::AppTypes::DB)
|
|
65
|
-
rescue StandardError => e
|
|
66
|
-
Datadog::Tracer.log.warn("Unable to get database config (#{e}), skipping ActiveRecord instrumentation")
|
|
67
|
-
end
|
|
68
|
-
end
|
|
47
|
+
def self.set_database_service
|
|
48
|
+
return unless defined?(::ActiveRecord)
|
|
69
49
|
|
|
70
|
-
|
|
71
|
-
|
|
50
|
+
config = Datadog.configuration[:rails]
|
|
51
|
+
adapter_name = Utils.adapter_name
|
|
52
|
+
config[:database_service] ||= "#{config[:service_name]}-#{adapter_name}"
|
|
53
|
+
config[:tracer].set_service_info(config[:database_service], adapter_name, Ext::AppTypes::DB)
|
|
54
|
+
rescue => e
|
|
55
|
+
Tracer.log.warn("Unable to get database config (#{e}), skipping ActiveRecord instrumentation")
|
|
72
56
|
end
|
|
73
57
|
end
|
|
74
58
|
end
|
|
@@ -10,7 +10,7 @@ module Datadog
|
|
|
10
10
|
option :controller_service
|
|
11
11
|
option :cache_service
|
|
12
12
|
option :database_service
|
|
13
|
-
option :
|
|
13
|
+
option :distributed_tracing, default: false
|
|
14
14
|
option :template_base_path, default: 'views/'
|
|
15
15
|
option :tracer, default: Datadog.tracer
|
|
16
16
|
|
|
@@ -8,8 +8,8 @@ module Datadog
|
|
|
8
8
|
config.app_middleware.insert_before(0, Datadog::Contrib::Rack::TraceMiddleware)
|
|
9
9
|
config.app_middleware.use(Datadog::Contrib::Rails::ExceptionMiddleware)
|
|
10
10
|
|
|
11
|
-
config.after_initialize do
|
|
12
|
-
Datadog::Contrib::Rails::Framework.
|
|
11
|
+
config.after_initialize do
|
|
12
|
+
Datadog::Contrib::Rails::Framework.setup
|
|
13
13
|
Datadog::Contrib::Rails::ActionController.instrument
|
|
14
14
|
Datadog::Contrib::Rails::ActionView.instrument
|
|
15
15
|
Datadog::Contrib::Rails::ActiveRecord.instrument
|
|
@@ -45,6 +45,32 @@ module Datadog
|
|
|
45
45
|
::Rails.application.class.to_s.underscore
|
|
46
46
|
end
|
|
47
47
|
end
|
|
48
|
+
|
|
49
|
+
def self.adapter_name
|
|
50
|
+
normalize_vendor(connection_config[:adapter])
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
def self.database_name
|
|
54
|
+
connection_config[:database]
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
def self.adapter_host
|
|
58
|
+
connection_config[:host]
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
def self.adapter_port
|
|
62
|
+
connection_config[:port]
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
def self.connection_config
|
|
66
|
+
if defined?(::ActiveRecord::Base.connection_config)
|
|
67
|
+
::ActiveRecord::Base.connection_config
|
|
68
|
+
else
|
|
69
|
+
::ActiveRecord::Base.connection_pool.spec.config
|
|
70
|
+
end
|
|
71
|
+
end
|
|
72
|
+
|
|
73
|
+
private_class_method :connection_config
|
|
48
74
|
end
|
|
49
75
|
end
|
|
50
76
|
end
|
|
@@ -12,6 +12,7 @@ module Datadog
|
|
|
12
12
|
|
|
13
13
|
def format_arg(arg)
|
|
14
14
|
str = arg.is_a?(Symbol) ? arg.to_s.upcase : arg.to_s
|
|
15
|
+
str = str.encode('UTF-8', 'binary', invalid: :replace, undef: :replace, replace: '')
|
|
15
16
|
Utils.truncate(str, VALUE_MAX_LEN, TOO_LONG_MARK)
|
|
16
17
|
rescue StandardError => e
|
|
17
18
|
Datadog::Tracer.log.debug("non formattable Redis arg #{str}: #{e}")
|
|
@@ -16,14 +16,17 @@ module Datadog
|
|
|
16
16
|
option :service_name, default: SERVICE
|
|
17
17
|
|
|
18
18
|
@patched = false
|
|
19
|
+
option :workers, default: []
|
|
19
20
|
|
|
20
21
|
class << self
|
|
21
22
|
def patch
|
|
22
23
|
return @patched if patched? || !defined?(::Resque)
|
|
23
24
|
|
|
24
25
|
require 'ddtrace/ext/app_types'
|
|
26
|
+
require_relative 'resque_job'
|
|
25
27
|
|
|
26
28
|
add_pin
|
|
29
|
+
get_option(:workers).each { |worker| worker.extend(ResqueJob) }
|
|
27
30
|
@patched = true
|
|
28
31
|
rescue => e
|
|
29
32
|
Tracer.log.error("Unable to apply Resque integration: #{e}")
|
|
@@ -40,7 +40,7 @@ module Datadog
|
|
|
40
40
|
service = sidekiq_service(resource_worker(resource))
|
|
41
41
|
set_service_info(service)
|
|
42
42
|
|
|
43
|
-
@tracer.trace('sidekiq.job', service: service, span_type:
|
|
43
|
+
@tracer.trace('sidekiq.job', service: service, span_type: Datadog::Ext::AppTypes::WORKER) do |span|
|
|
44
44
|
span.resource = resource
|
|
45
45
|
span.set_tag('sidekiq.job.id', job['jid'])
|
|
46
46
|
span.set_tag('sidekiq.job.retry', job['retry'])
|
|
@@ -30,11 +30,19 @@ module Datadog
|
|
|
30
30
|
|
|
31
31
|
option :tracer, default: Datadog.tracer
|
|
32
32
|
|
|
33
|
+
option :resource_script_names, default: false
|
|
34
|
+
|
|
33
35
|
def route(verb, action, *)
|
|
34
36
|
# Keep track of the route name when the app is instantiated for an
|
|
35
37
|
# incoming request.
|
|
36
38
|
condition do
|
|
37
|
-
|
|
39
|
+
# If the option to prepend script names is enabled, then
|
|
40
|
+
# prepend the script name from the request onto the action.
|
|
41
|
+
@datadog_route = if Datadog.configuration[:sinatra][:resource_script_names]
|
|
42
|
+
"#{request.script_name}#{action}"
|
|
43
|
+
else
|
|
44
|
+
action
|
|
45
|
+
end
|
|
38
46
|
end
|
|
39
47
|
|
|
40
48
|
super
|
|
@@ -48,7 +56,7 @@ module Datadog
|
|
|
48
56
|
output = ''
|
|
49
57
|
tracer = Datadog.configuration[:sinatra][:tracer]
|
|
50
58
|
if tracer.enabled
|
|
51
|
-
tracer.trace('sinatra.render_template') do |span|
|
|
59
|
+
tracer.trace('sinatra.render_template', span_type: Datadog::Ext::HTTP::TEMPLATE) do |span|
|
|
52
60
|
# If data is a string, it is a literal template and we don't
|
|
53
61
|
# want to record it.
|
|
54
62
|
span.set_tag('sinatra.template_name', data) if data.is_a? Symbol
|
data/lib/ddtrace/monkey.rb
CHANGED
|
@@ -4,6 +4,7 @@ require 'thread'
|
|
|
4
4
|
# because patchers do not include any 3rd party module nor even our
|
|
5
5
|
# patching code, which is required on demand, when patching.
|
|
6
6
|
require 'ddtrace/contrib/base'
|
|
7
|
+
require 'ddtrace/contrib/rack/patcher'
|
|
7
8
|
require 'ddtrace/contrib/rails/patcher'
|
|
8
9
|
require 'ddtrace/contrib/active_record/patcher'
|
|
9
10
|
require 'ddtrace/contrib/elasticsearch/patcher'
|
|
@@ -16,6 +17,7 @@ require 'ddtrace/contrib/sucker_punch/patcher'
|
|
|
16
17
|
require 'ddtrace/contrib/mongodb/patcher'
|
|
17
18
|
require 'ddtrace/contrib/dalli/patcher'
|
|
18
19
|
require 'ddtrace/contrib/resque/patcher'
|
|
20
|
+
require 'ddtrace/contrib/racecar/patcher'
|
|
19
21
|
|
|
20
22
|
module Datadog
|
|
21
23
|
# Monkey is used for monkey-patching 3rd party libs.
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: ddtrace
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.11.0.
|
|
4
|
+
version: 0.11.0.beta2
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Datadog, Inc.
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: exe
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2017-12-
|
|
11
|
+
date: 2017-12-27 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: msgpack
|
|
@@ -108,6 +108,20 @@ dependencies:
|
|
|
108
108
|
- - "~>"
|
|
109
109
|
- !ruby/object:Gem::Version
|
|
110
110
|
version: '2.0'
|
|
111
|
+
- !ruby/object:Gem::Dependency
|
|
112
|
+
name: builder
|
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
|
114
|
+
requirements:
|
|
115
|
+
- - ">="
|
|
116
|
+
- !ruby/object:Gem::Version
|
|
117
|
+
version: '0'
|
|
118
|
+
type: :development
|
|
119
|
+
prerelease: false
|
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
121
|
+
requirements:
|
|
122
|
+
- - ">="
|
|
123
|
+
- !ruby/object:Gem::Version
|
|
124
|
+
version: '0'
|
|
111
125
|
- !ruby/object:Gem::Dependency
|
|
112
126
|
name: addressable
|
|
113
127
|
requirement: !ruby/object:Gem::Requirement
|
|
@@ -136,6 +150,34 @@ dependencies:
|
|
|
136
150
|
- - "~>"
|
|
137
151
|
- !ruby/object:Gem::Version
|
|
138
152
|
version: '3.4'
|
|
153
|
+
- !ruby/object:Gem::Dependency
|
|
154
|
+
name: pry
|
|
155
|
+
requirement: !ruby/object:Gem::Requirement
|
|
156
|
+
requirements:
|
|
157
|
+
- - ">="
|
|
158
|
+
- !ruby/object:Gem::Version
|
|
159
|
+
version: 0.10.4
|
|
160
|
+
type: :development
|
|
161
|
+
prerelease: false
|
|
162
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
163
|
+
requirements:
|
|
164
|
+
- - ">="
|
|
165
|
+
- !ruby/object:Gem::Version
|
|
166
|
+
version: 0.10.4
|
|
167
|
+
- !ruby/object:Gem::Dependency
|
|
168
|
+
name: pry-stack_explorer
|
|
169
|
+
requirement: !ruby/object:Gem::Requirement
|
|
170
|
+
requirements:
|
|
171
|
+
- - ">="
|
|
172
|
+
- !ruby/object:Gem::Version
|
|
173
|
+
version: 0.4.9.2
|
|
174
|
+
type: :development
|
|
175
|
+
prerelease: false
|
|
176
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
177
|
+
requirements:
|
|
178
|
+
- - ">="
|
|
179
|
+
- !ruby/object:Gem::Version
|
|
180
|
+
version: 0.4.9.2
|
|
139
181
|
description: |
|
|
140
182
|
ddtrace is Datadog’s tracing client for Ruby. It is used to trace requests
|
|
141
183
|
as they flow across web servers, databases and microservices so that developers
|
|
@@ -201,7 +243,9 @@ files:
|
|
|
201
243
|
- lib/ddtrace/contrib/mongodb/parsers.rb
|
|
202
244
|
- lib/ddtrace/contrib/mongodb/patcher.rb
|
|
203
245
|
- lib/ddtrace/contrib/mongodb/subscribers.rb
|
|
246
|
+
- lib/ddtrace/contrib/racecar/patcher.rb
|
|
204
247
|
- lib/ddtrace/contrib/rack/middlewares.rb
|
|
248
|
+
- lib/ddtrace/contrib/rack/patcher.rb
|
|
205
249
|
- lib/ddtrace/contrib/rails/action_controller.rb
|
|
206
250
|
- lib/ddtrace/contrib/rails/action_view.rb
|
|
207
251
|
- lib/ddtrace/contrib/rails/active_record.rb
|
|
@@ -274,7 +318,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
274
318
|
version: 1.3.1
|
|
275
319
|
requirements: []
|
|
276
320
|
rubyforge_project:
|
|
277
|
-
rubygems_version: 2.
|
|
321
|
+
rubygems_version: 2.4.5.2
|
|
278
322
|
signing_key:
|
|
279
323
|
specification_version: 4
|
|
280
324
|
summary: Datadog tracing code for your Ruby applications
|