ddtrace 0.11.0.beta2 → 0.11.0
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/.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
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA1:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: b3bb99f4104ccd84acde3279b412e90d531ecfea
|
|
4
|
+
data.tar.gz: 63d063737c4e830b84d24471fc1ff356ca703af6
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: b271d08b6eae8c40116c68b21ef46c4fb110fba35b331913b902e9fc0b7ce5fa4868e997c7984eff71d8f325f98f3276c6bc11b6da69bdf877903338fb599948
|
|
7
|
+
data.tar.gz: d86ca3ce85531ea82e437f2f9495deed831ab10a2e15d35a78a1095607f99c9ef901cb6cf800f084a4f4142f200f339997b60e30fa87b80d66de3c9706f23346
|
data/.rspec
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
--require spec_helper
|
data/Appraisals
CHANGED
|
@@ -63,13 +63,13 @@ if RUBY_VERSION < '2.4.0' && RUBY_PLATFORM != 'java'
|
|
|
63
63
|
|
|
64
64
|
appraise 'rails4-postgres' do
|
|
65
65
|
gem 'rails', '4.2.7.1'
|
|
66
|
-
gem 'pg', platform: :ruby
|
|
66
|
+
gem 'pg', '< 1.0', platform: :ruby
|
|
67
67
|
gem 'activerecord-jdbcpostgresql-adapter', platform: :jruby
|
|
68
68
|
end
|
|
69
69
|
|
|
70
70
|
appraise 'rails4-postgres-redis' do
|
|
71
71
|
gem 'rails', '4.2.7.1'
|
|
72
|
-
gem 'pg', platform: :ruby
|
|
72
|
+
gem 'pg', '< 1.0', platform: :ruby
|
|
73
73
|
gem 'activerecord-jdbcpostgresql-adapter', platform: :jruby
|
|
74
74
|
gem 'redis-rails'
|
|
75
75
|
gem 'redis', '< 4.0'
|
|
@@ -84,26 +84,26 @@ if RUBY_VERSION < '2.4.0' && RUBY_PLATFORM != 'java'
|
|
|
84
84
|
|
|
85
85
|
appraise 'rails5-postgres' do
|
|
86
86
|
gem 'rails', '5.0.1'
|
|
87
|
-
gem 'pg', platform: :ruby
|
|
87
|
+
gem 'pg', '< 1.0', platform: :ruby
|
|
88
88
|
end
|
|
89
89
|
|
|
90
90
|
appraise 'rails5-postgres-redis' do
|
|
91
91
|
gem 'rails', '5.0.1'
|
|
92
|
-
gem 'pg', platform: :ruby
|
|
92
|
+
gem 'pg', '< 1.0', platform: :ruby
|
|
93
93
|
gem 'redis-rails'
|
|
94
|
-
gem 'redis'
|
|
94
|
+
gem 'redis'
|
|
95
95
|
end
|
|
96
96
|
|
|
97
97
|
appraise 'rails5-postgres-sidekiq' do
|
|
98
98
|
gem 'rails', '5.0.1'
|
|
99
|
-
gem 'pg', platform: :ruby
|
|
99
|
+
gem 'pg', '< 1.0', platform: :ruby
|
|
100
100
|
gem 'sidekiq'
|
|
101
101
|
gem 'activejob'
|
|
102
102
|
end
|
|
103
103
|
|
|
104
104
|
appraise 'rails4-postgres-sidekiq' do
|
|
105
105
|
gem 'rails', '4.2.7.1'
|
|
106
|
-
gem 'pg', platform: :ruby
|
|
106
|
+
gem 'pg', '< 1.0', platform: :ruby
|
|
107
107
|
gem 'activerecord-jdbcpostgresql-adapter', platform: :jruby
|
|
108
108
|
gem 'sidekiq'
|
|
109
109
|
gem 'activejob'
|
|
@@ -127,17 +127,17 @@ if RUBY_VERSION >= '2.2.2' && RUBY_PLATFORM != 'java'
|
|
|
127
127
|
gem 'aws-sdk'
|
|
128
128
|
gem 'sucker_punch'
|
|
129
129
|
gem 'dalli'
|
|
130
|
-
gem 'resque'
|
|
130
|
+
gem 'resque', '< 2.0'
|
|
131
131
|
gem 'racecar', '>= 0.3.5'
|
|
132
132
|
end
|
|
133
133
|
else
|
|
134
134
|
appraise 'contrib-old' do
|
|
135
135
|
gem 'elasticsearch-transport'
|
|
136
136
|
gem 'mongo'
|
|
137
|
-
gem 'redis', '< 4.0
|
|
137
|
+
gem 'redis', '< 4.0'
|
|
138
138
|
gem 'hiredis'
|
|
139
139
|
gem 'rack', '1.4.7'
|
|
140
|
-
gem 'rack-test'
|
|
140
|
+
gem 'rack-test', '0.7.0'
|
|
141
141
|
gem 'sinatra', '1.4.5'
|
|
142
142
|
gem 'sqlite3'
|
|
143
143
|
gem 'activerecord', '3.2.22.5'
|
|
@@ -145,6 +145,6 @@ else
|
|
|
145
145
|
gem 'aws-sdk', '~> 2.0'
|
|
146
146
|
gem 'sucker_punch'
|
|
147
147
|
gem 'dalli'
|
|
148
|
-
gem 'resque'
|
|
148
|
+
gem 'resque', '< 2.0'
|
|
149
149
|
end
|
|
150
150
|
end
|
data/Gemfile
CHANGED
data/README.md
CHANGED
data/Rakefile
CHANGED
|
@@ -1,11 +1,70 @@
|
|
|
1
1
|
require 'bundler/gem_tasks'
|
|
2
2
|
require 'ddtrace/version'
|
|
3
3
|
require 'rubocop/rake_task' if RUBY_VERSION >= '2.1.0'
|
|
4
|
+
require 'rspec/core/rake_task'
|
|
4
5
|
require 'rake/testtask'
|
|
5
6
|
require 'appraisal'
|
|
6
7
|
require 'yard'
|
|
7
8
|
|
|
9
|
+
desc 'Run RSpec'
|
|
8
10
|
# rubocop:disable Metrics/BlockLength
|
|
11
|
+
namespace :spec do
|
|
12
|
+
task all: [:main,
|
|
13
|
+
:rails, :railsredis, :railssidekiq, :railsactivejob,
|
|
14
|
+
:elasticsearch, :http, :redis, :sidekiq, :sinatra, :monkey]
|
|
15
|
+
|
|
16
|
+
RSpec::Core::RakeTask.new(:main) do |t|
|
|
17
|
+
t.pattern = 'spec/**/*_spec.rb'
|
|
18
|
+
t.exclude_pattern = 'spec/**/{contrib,benchmark,redis}/**/*_spec.rb,spec/monkey_spec.rb'
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
RSpec::Core::RakeTask.new(:rails) do |t|
|
|
22
|
+
t.pattern = 'spec/ddtrace/contrib/rails/**/*_spec.rb'
|
|
23
|
+
t.exclude_pattern = 'spec/ddtrace/contrib/rails/**/*{sidekiq,active_job,disable_env}*_spec.rb'
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
RSpec::Core::RakeTask.new(:railsredis) do |t|
|
|
27
|
+
t.pattern = 'spec/ddtrace/contrib/rails/**/*redis*_spec.rb'
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
RSpec::Core::RakeTask.new(:railssidekiq) do |t|
|
|
31
|
+
t.pattern = 'spec/ddtrace/contrib/rails/**/*sidekiq*_spec.rb'
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
RSpec::Core::RakeTask.new(:railsactivejob) do |t|
|
|
35
|
+
t.pattern = 'spec/ddtrace/contrib/rails/**/*active_job*_spec.rb'
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
RSpec::Core::RakeTask.new(:railsdisableenv) do |t|
|
|
39
|
+
t.pattern = 'spec/ddtrace/contrib/rails/**/*disable_env*_spec.rb'
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
[
|
|
43
|
+
:elasticsearch,
|
|
44
|
+
:http,
|
|
45
|
+
:redis,
|
|
46
|
+
:sinatra,
|
|
47
|
+
:sidekiq,
|
|
48
|
+
:rack,
|
|
49
|
+
:faraday,
|
|
50
|
+
:grape,
|
|
51
|
+
:aws,
|
|
52
|
+
:sucker_punch,
|
|
53
|
+
:mongodb,
|
|
54
|
+
:racecar,
|
|
55
|
+
:resque,
|
|
56
|
+
:dalli
|
|
57
|
+
].each do |contrib|
|
|
58
|
+
RSpec::Core::RakeTask.new(contrib) do |t|
|
|
59
|
+
t.pattern = "spec/ddtrace/contrib/#{contrib}/*_spec.rb"
|
|
60
|
+
end
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
RSpec::Core::RakeTask.new(:monkey) do |t|
|
|
64
|
+
t.pattern = 'spec/ddtrace/monkey_spec.rb'
|
|
65
|
+
end
|
|
66
|
+
end
|
|
67
|
+
|
|
9
68
|
namespace :test do
|
|
10
69
|
task all: [:main,
|
|
11
70
|
:rails, :railsredis, :railssidekiq, :railsactivejob,
|
|
@@ -63,9 +122,7 @@ namespace :test do
|
|
|
63
122
|
:aws,
|
|
64
123
|
:sucker_punch,
|
|
65
124
|
:mongodb,
|
|
66
|
-
:
|
|
67
|
-
:resque,
|
|
68
|
-
:dalli
|
|
125
|
+
:resque
|
|
69
126
|
].each do |contrib|
|
|
70
127
|
Rake::TestTask.new(contrib) do |t|
|
|
71
128
|
t.libs << %w[test lib]
|
|
@@ -148,6 +205,8 @@ task :ci do
|
|
|
148
205
|
case ENV['CIRCLE_NODE_INDEX'].to_i
|
|
149
206
|
when 0
|
|
150
207
|
sh 'rvm $MRI_VERSIONS,$MRI_OLD_VERSIONS,$JRUBY_VERSIONS --verbose do rake test:main'
|
|
208
|
+
# RSpec
|
|
209
|
+
sh 'rvm $MRI_VERSIONS,$MRI_OLD_VERSIONS,$JRUBY_VERSIONS --verbose do rake spec:main'
|
|
151
210
|
when 1
|
|
152
211
|
sh 'rvm $MRI_VERSIONS --verbose do appraisal contrib rake test:elasticsearch'
|
|
153
212
|
sh 'rvm $MRI_VERSIONS --verbose do appraisal contrib rake test:http'
|
|
@@ -159,7 +218,6 @@ task :ci do
|
|
|
159
218
|
sh 'rvm $MRI_VERSIONS --verbose do appraisal contrib rake test:aws'
|
|
160
219
|
sh 'rvm $MRI_VERSIONS --verbose do appraisal contrib rake test:mongodb'
|
|
161
220
|
sh 'rvm $MRI_VERSIONS --verbose do appraisal contrib rake test:sucker_punch'
|
|
162
|
-
sh 'rvm $MRI_VERSIONS --verbose do appraisal contrib rake test:dalli'
|
|
163
221
|
sh 'rvm $MRI_VERSIONS --verbose do appraisal contrib rake test:resque'
|
|
164
222
|
sh 'rvm $MRI_OLD_VERSIONS --verbose do appraisal contrib-old rake test:monkey'
|
|
165
223
|
sh 'rvm $MRI_OLD_VERSIONS --verbose do appraisal contrib-old rake test:elasticsearch'
|
|
@@ -171,8 +229,11 @@ task :ci do
|
|
|
171
229
|
sh 'rvm $MRI_OLD_VERSIONS --verbose do appraisal contrib-old rake test:aws'
|
|
172
230
|
sh 'rvm $MRI_OLD_VERSIONS --verbose do appraisal contrib-old rake test:mongodb'
|
|
173
231
|
sh 'rvm $MRI_OLD_VERSIONS --verbose do appraisal contrib-old rake test:sucker_punch'
|
|
174
|
-
sh 'rvm $MRI_OLD_VERSIONS --verbose do appraisal contrib-old rake test:dalli'
|
|
175
232
|
sh 'rvm $MRI_OLD_VERSIONS --verbose do appraisal contrib-old rake test:resque'
|
|
233
|
+
# RSpec
|
|
234
|
+
sh 'rvm $MRI_VERSIONS --verbose do appraisal contrib rake spec:dalli'
|
|
235
|
+
sh 'rvm $MRI_VERSIONS --verbose do appraisal contrib rake spec:racecar'
|
|
236
|
+
sh 'rvm $MRI_OLD_VERSIONS --verbose do appraisal contrib-old rake spec:dalli'
|
|
176
237
|
when 2
|
|
177
238
|
sh 'rvm $MRI_VERSIONS --verbose do appraisal contrib rake test:sidekiq'
|
|
178
239
|
sh 'rvm $SIDEKIQ_OLD_VERSIONS --verbose do appraisal contrib-old rake test:sidekiq'
|
|
@@ -196,6 +257,7 @@ task :ci do
|
|
|
196
257
|
sh 'rvm $RAILS5_VERSIONS --verbose do appraisal rails5-postgres-sidekiq rake test:railssidekiq'
|
|
197
258
|
sh 'rvm $RAILS5_VERSIONS --verbose do appraisal rails5-postgres-sidekiq rake test:railsactivejob'
|
|
198
259
|
sh 'rvm $RAILS5_VERSIONS --verbose do appraisal rails5-postgres rake test:railsdisableenv'
|
|
260
|
+
# RSpec
|
|
199
261
|
sh 'rvm $LAST_STABLE --verbose do rake benchmark'
|
|
200
262
|
else
|
|
201
263
|
puts 'Too many workers than parallel tasks'
|
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}#{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']
|
|
@@ -35,7 +35,9 @@ EOS
|
|
|
35
35
|
spec.add_dependency 'msgpack'
|
|
36
36
|
|
|
37
37
|
spec.add_development_dependency 'rake', '~> 10.5'
|
|
38
|
-
spec.add_development_dependency
|
|
38
|
+
spec.add_development_dependency 'rubocop', '= 0.49.1' if RUBY_VERSION >= '2.1.0'
|
|
39
|
+
spec.add_development_dependency 'rspec', '~> 3.0'
|
|
40
|
+
spec.add_development_dependency 'rspec-collection_matchers', '~> 1.1'
|
|
39
41
|
spec.add_development_dependency 'minitest', '= 5.10.1'
|
|
40
42
|
spec.add_development_dependency 'appraisal', '~> 2.2'
|
|
41
43
|
spec.add_development_dependency 'yard', '~> 0.9'
|
|
@@ -44,6 +46,6 @@ EOS
|
|
|
44
46
|
# locking transitive dependency of webmock
|
|
45
47
|
spec.add_development_dependency 'addressable', '~> 2.4.0'
|
|
46
48
|
spec.add_development_dependency 'redcarpet', '~> 3.4' if RUBY_PLATFORM != 'java'
|
|
47
|
-
spec.add_development_dependency 'pry', '
|
|
48
|
-
spec.add_development_dependency 'pry-stack_explorer', '
|
|
49
|
+
spec.add_development_dependency 'pry', '~> 0.10.4'
|
|
50
|
+
spec.add_development_dependency 'pry-stack_explorer', '~> 0.4.9.2'
|
|
49
51
|
end
|
data/docs/GettingStarted.md
CHANGED
|
@@ -20,8 +20,23 @@ We strongly suggest pinning the version of the library you deploy.
|
|
|
20
20
|
|
|
21
21
|
## Quickstart
|
|
22
22
|
|
|
23
|
-
The easiest way to get started with the tracing client is to instrument your web application.
|
|
24
|
-
|
|
23
|
+
The easiest way to get started with the tracing client is to instrument your web application.
|
|
24
|
+
All configuration is done through ``Datadog.configure`` method. As an
|
|
25
|
+
example, below is a setup that enables auto instrumentation for Rails, Redis and
|
|
26
|
+
Grape, and sets a custom endpoint for the trace agent:
|
|
27
|
+
|
|
28
|
+
# config/initializers/datadog-tracer.rb
|
|
29
|
+
|
|
30
|
+
Datadog.configure do |c|
|
|
31
|
+
c.tracer hostname: 'trace-agent.local'
|
|
32
|
+
c.use :rails
|
|
33
|
+
c.use :grape
|
|
34
|
+
c.use :redis, service_name: 'cache'
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
For further details and options, check our integrations list.
|
|
38
|
+
|
|
39
|
+
## Available Integrations
|
|
25
40
|
|
|
26
41
|
* [Ruby on Rails](#Ruby_on_Rails)
|
|
27
42
|
* [Sinatra](#Sinatra)
|
|
@@ -50,89 +65,26 @@ To enable the Rails auto instrumentation, create an initializer file in your ``c
|
|
|
50
65
|
|
|
51
66
|
# config/initializers/datadog-tracer.rb
|
|
52
67
|
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
default_service: 'my-rails-app'
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
If you're using Rails 3 or higher, your application will be listed as ``my-rails-app`` in your service list.
|
|
60
|
-
To integrate Rails instrumentation with third-party libraries such as Grape, please check the available settings below.
|
|
61
|
-
|
|
62
|
-
#### Configure the tracer with initializers
|
|
63
|
-
|
|
64
|
-
All tracing settings are namespaced under the ``Rails.configuration.datadog_tracer`` hash. To change the default behavior
|
|
65
|
-
of the Datadog tracer, you can override the following defaults:
|
|
66
|
-
|
|
67
|
-
# config/initializers/datadog-tracer.rb
|
|
68
|
-
|
|
69
|
-
Rails.configuration.datadog_trace = {
|
|
70
|
-
enabled: true,
|
|
71
|
-
auto_instrument: false,
|
|
72
|
-
auto_instrument_redis: false,
|
|
73
|
-
auto_instrument_grape: false,
|
|
74
|
-
default_service: 'rails-app',
|
|
75
|
-
default_controller_service: 'rails-controller',
|
|
76
|
-
default_cache_service: 'rails-cache',
|
|
77
|
-
default_database_service: 'postgresql',
|
|
78
|
-
distributed_tracing_enabled: false,
|
|
79
|
-
template_base_path: 'views/',
|
|
80
|
-
tracer: Datadog.tracer,
|
|
81
|
-
debug: false,
|
|
82
|
-
trace_agent_hostname: 'localhost',
|
|
83
|
-
trace_agent_port: 8126,
|
|
84
|
-
env: nil,
|
|
85
|
-
tags: {}
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
Available settings are:
|
|
89
|
-
|
|
90
|
-
* ``enabled``: defines if the ``tracer`` is enabled or not. If set to ``false`` the code could be still instrumented
|
|
91
|
-
because of other settings, but no spans are sent to the local trace agent.
|
|
92
|
-
* ``auto_instrument``: if set to +true+ the code will be automatically instrumented. You may change this value
|
|
93
|
-
with a condition, to enable the auto-instrumentation only for particular environments (production, staging, etc...).
|
|
94
|
-
* ``auto_instrument_redis``: if set to ``true`` Redis calls will be traced as such. Calls to Redis cache may be
|
|
95
|
-
still instrumented but you will not have the detail of low-level Redis calls.
|
|
96
|
-
* ``auto_instrument_grape``: if set to ``true`` and you're using a Grape application, all calls to your endpoints are
|
|
97
|
-
traced, including filters execution.
|
|
98
|
-
* ``default_service``: set the service name used when tracing application requests. Defaults to ``rails-app``
|
|
99
|
-
* ``default_controller_service``: set the service name used when tracing a Rails action controller. Defaults to ``rails-controller``
|
|
100
|
-
* ``default_cache_service``: set the cache service name used when tracing cache activity. Defaults to ``rails-cache``
|
|
101
|
-
* ``default_database_service``: set the database service name used when tracing database activity. Defaults to the
|
|
102
|
-
current adapter name, so if you're using PostgreSQL it will be ``postgres``.
|
|
103
|
-
* ``distributed_tracing_enabled``: enable [distributed tracing](#Distributed_Tracing) so that this service trace is
|
|
104
|
-
connected with a trace of another service if tracing headers are sent
|
|
105
|
-
* ``default_grape_service``: set the service name used when tracing a Grape application mounted in your Rails router.
|
|
106
|
-
Defaults to ``grape``
|
|
107
|
-
* ``template_base_path``: used when the template name is parsed in the auto instrumented code. If you don't store
|
|
108
|
-
your templates in the ``views/`` folder, you may need to change this value
|
|
109
|
-
* ``tracer``: is the global tracer used by the tracing application. Usually you don't need to change that value
|
|
110
|
-
unless you're already using a different initialized ``tracer`` somewhere else
|
|
111
|
-
* ``debug``: set to true to enable debug logging.
|
|
112
|
-
* ``trace_agent_hostname``: set the hostname of the trace agent.
|
|
113
|
-
* ``trace_agent_port``: set the port the trace agent is listening on.
|
|
114
|
-
* ``env``: set the environment. Rails users may set it to ``Rails.env`` to use their application settings.
|
|
115
|
-
* ``tags``: set global tags that should be applied to all spans. Defaults to an empty hash
|
|
116
|
-
|
|
117
|
-
#### Disabling Rails auto-instrumentation
|
|
118
|
-
|
|
119
|
-
If you wish to disable all Rails auto-instrumentation, you need to set the env var ``DISABLE_DATADOG_RAILS``.
|
|
120
|
-
|
|
121
|
-
Eg, within Ruby:
|
|
68
|
+
Datadog.configure do |c|
|
|
69
|
+
c.use :rails, options
|
|
70
|
+
end
|
|
122
71
|
|
|
123
|
-
|
|
124
|
-
require 'ddtrace'
|
|
72
|
+
Where `options` is an optional `Hash` that accepts the following parameters:
|
|
125
73
|
|
|
126
|
-
Or, shell syntax, before launching Rails:
|
|
127
74
|
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
75
|
+
| Key | Description | Default |
|
|
76
|
+
| --- | --- | --- |
|
|
77
|
+
| ``service_name`` | Service name used when tracing application requests (on the `rack` level) | ``<app_name>`` (inferred from your Rails application namespace) |
|
|
78
|
+
| ``controller_service`` | Service name used when tracing a Rails action controller | ``<app_name>-controller`` |
|
|
79
|
+
| ``cache_service`` | Cache service name used when tracing cache activity | ``<app_name>-cache`` |
|
|
80
|
+
| ``database_service`` | Database service name used when tracing database activity | ``<app_name>-<adapter_name>``. |
|
|
81
|
+
| ``distributed_tracing`` | Enables [distributed tracing](#Distributed_Tracing) so that this service trace is connected with a trace of another service if tracing headers are received | `false` |
|
|
82
|
+
| ``template_base_path`` | Used when the template name is parsed. If you don't store your templates in the ``views/`` folder, you may need to change this value | ``views/`` |
|
|
83
|
+
| ``tracer`` | A ``Datadog::Tracer`` instance used to instrument the application. Usually you don't need to set that. | ``Datadog.tracer`` |
|
|
131
84
|
|
|
132
85
|
### Sinatra
|
|
133
86
|
|
|
134
|
-
The Sinatra integration traces requests and template rendering.
|
|
135
|
-
``Datadog::Contrib::Sinatra::Tracer`` extension.
|
|
87
|
+
The Sinatra integration traces requests and template rendering.
|
|
136
88
|
|
|
137
89
|
To start using the tracing client, make sure you import ``ddtrace`` and ``ddtrace/contrib/sinatra/tracer`` after
|
|
138
90
|
either ``sinatra`` or ``sinatra/base``:
|
|
@@ -142,105 +94,67 @@ either ``sinatra`` or ``sinatra/base``:
|
|
|
142
94
|
require 'ddtrace/contrib/sinatra/tracer'
|
|
143
95
|
|
|
144
96
|
Datadog.configure do |c|
|
|
145
|
-
c.use :sinatra,
|
|
97
|
+
c.use :sinatra, options
|
|
146
98
|
end
|
|
147
99
|
|
|
148
100
|
get '/' do
|
|
149
101
|
'Hello world!'
|
|
150
102
|
end
|
|
151
103
|
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
#### Configure the tracer
|
|
155
|
-
|
|
156
|
-
Available settings are:
|
|
104
|
+
Where `options` is an optional `Hash` that accepts the following parameters:
|
|
157
105
|
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
* ``debug``: set to ``true`` to enable debug logging.
|
|
164
|
-
* ``trace_agent_hostname``: set the hostname of the trace agent.
|
|
165
|
-
* ``trace_agent_port``: set the port the trace agent is listening on.
|
|
106
|
+
| Key | Description | Default |
|
|
107
|
+
| --- | --- | --- |
|
|
108
|
+
| ``service_name`` | Service name used for `sinatra` instrumentation | sinatra |
|
|
109
|
+
| ``resource_script_names`` | Prepend resource names with script name | ``false`` |
|
|
110
|
+
| ``tracer`` | A ``Datadog::Tracer`` instance used to instrument the application. Usually you don't need to set that. | ``Datadog.tracer`` |
|
|
166
111
|
|
|
167
112
|
### Rack
|
|
168
113
|
|
|
169
114
|
The Rack integration provides a middleware that traces all requests before they reach the underlying framework
|
|
170
115
|
or application. It responds to the Rack minimal interface, providing reasonable values that can be
|
|
171
|
-
retrieved at the Rack level.
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
# config.ru example
|
|
175
|
-
require 'ddtrace/contrib/rack/middlewares'
|
|
176
|
-
|
|
177
|
-
use Datadog::Contrib::Rack::TraceMiddleware
|
|
178
|
-
|
|
179
|
-
app = proc do |env|
|
|
180
|
-
[ 200, {'Content-Type' => 'text/plain'}, "OK" ]
|
|
181
|
-
end
|
|
182
|
-
|
|
183
|
-
run app
|
|
184
|
-
|
|
185
|
-
The Rack middleware can be configured using the global configuration object:
|
|
116
|
+
retrieved at the Rack level. This integration is automatically activated with web frameworks like Rails.
|
|
117
|
+
If you're using a plain Rack application, just enable the integration it to your ``config.ru``:
|
|
186
118
|
|
|
187
119
|
# config.ru example
|
|
188
120
|
require 'ddtrace'
|
|
189
|
-
require 'ddtrace/contrib/rack/middlewares'
|
|
190
121
|
|
|
191
122
|
Datadog.configure do |c|
|
|
192
|
-
c.use :rack,
|
|
123
|
+
c.use :rack, options
|
|
193
124
|
end
|
|
194
125
|
|
|
195
|
-
|
|
196
|
-
[ 200, {'Content-Type' => 'text/plain'}, "OK" ]
|
|
197
|
-
end
|
|
198
|
-
|
|
199
|
-
In the example above, we've activated the Distributed Tracing flag, please
|
|
200
|
-
see [distributed tracing](#Distributed_Tracing) for more details.
|
|
201
|
-
|
|
202
|
-
#### Configure the tracer
|
|
203
|
-
|
|
204
|
-
To modify the default middleware configuration, you can use middleware options as follows:
|
|
205
|
-
|
|
206
|
-
# config.ru example
|
|
207
|
-
require 'ddtrace/contrib/rack/middlewares'
|
|
208
|
-
|
|
209
|
-
Datadog.tracer.configure(
|
|
210
|
-
enabled: true,
|
|
211
|
-
hostname: localhost,
|
|
212
|
-
port: 8126
|
|
213
|
-
)
|
|
214
|
-
|
|
215
|
-
use Datadog::Contrib::Rack::TraceMiddleware, default_service: 'rack-stack'
|
|
126
|
+
use Datadog::Contrib::Rack::TraceMiddleware
|
|
216
127
|
|
|
217
128
|
app = proc do |env|
|
|
218
|
-
[ 200, {'Content-Type' => 'text/plain'},
|
|
129
|
+
[ 200, {'Content-Type' => 'text/plain'}, ['OK'] ]
|
|
219
130
|
end
|
|
220
131
|
|
|
221
132
|
run app
|
|
222
133
|
|
|
223
|
-
|
|
134
|
+
Where `options` is an optional `Hash` that accepts the following parameters:
|
|
224
135
|
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
136
|
+
| Key | Description | Default |
|
|
137
|
+
| --- | --- | --- |
|
|
138
|
+
| ``service_name`` | Service name used when tracing application requests | rack |
|
|
139
|
+
| ``distributed_tracing`` | Enables [distributed tracing](#Distributed_Tracing) so that this service trace is connected with a trace of another service if tracing headers are received | `false` |
|
|
140
|
+
| ``middleware_names`` | Enable this if you want to use the middleware classes as the resource names for `rack` spans | ``false`` |
|
|
141
|
+
| ``tracer`` | A ``Datadog::Tracer`` instance used to instrument the application. Usually you don't need to set that. | ``Datadog.tracer`` |
|
|
230
142
|
|
|
231
143
|
## Other libraries
|
|
232
144
|
|
|
233
145
|
### Grape
|
|
234
146
|
|
|
235
147
|
The Grape integration adds the instrumentation to Grape endpoints and filters. This integration can work side by side
|
|
236
|
-
with other integrations like Rack and Rails. To activate your integration, use the ``
|
|
148
|
+
with other integrations like Rack and Rails. To activate your integration, use the ``Datadog.configure`` method before
|
|
237
149
|
defining your Grape application:
|
|
238
150
|
|
|
239
151
|
# api.rb
|
|
240
152
|
require 'grape'
|
|
241
153
|
require 'ddtrace'
|
|
242
154
|
|
|
243
|
-
Datadog
|
|
155
|
+
Datadog.configure do |c|
|
|
156
|
+
c.use :grape, options
|
|
157
|
+
end
|
|
244
158
|
|
|
245
159
|
# then define your application
|
|
246
160
|
class RackTestingAPI < Grape::API
|
|
@@ -250,6 +164,12 @@ defining your Grape application:
|
|
|
250
164
|
end
|
|
251
165
|
end
|
|
252
166
|
|
|
167
|
+
Where `options` is an optional `Hash` that accepts the following parameters:
|
|
168
|
+
|
|
169
|
+
| Key | Description | Default |
|
|
170
|
+
| --- | --- | --- |
|
|
171
|
+
| ``service_name`` | Service name used for `grape` instrumentation | grape |
|
|
172
|
+
|
|
253
173
|
### Active Record
|
|
254
174
|
|
|
255
175
|
Most of the time, Active Record is set up as part of a web framework (Rails, Sinatra...)
|
|
@@ -260,7 +180,9 @@ however it can be set up alone:
|
|
|
260
180
|
require 'active_record'
|
|
261
181
|
require 'ddtrace'
|
|
262
182
|
|
|
263
|
-
Datadog
|
|
183
|
+
Datadog.configure do |c|
|
|
184
|
+
c.use :active_record, options
|
|
185
|
+
end
|
|
264
186
|
|
|
265
187
|
Dir::Tmpname.create(['test', '.sqlite']) do |db|
|
|
266
188
|
conn = ActiveRecord::Base.establish_connection(adapter: 'sqlite3',
|
|
@@ -268,6 +190,12 @@ however it can be set up alone:
|
|
|
268
190
|
conn.connection.execute('SELECT 42') # traced!
|
|
269
191
|
end
|
|
270
192
|
|
|
193
|
+
Where `options` is an optional `Hash` that accepts the following parameters:
|
|
194
|
+
|
|
195
|
+
| Key | Description | Default |
|
|
196
|
+
| --- | --- | --- |
|
|
197
|
+
| ``service_name`` | Service name used for `active_record` instrumentation | active_record |
|
|
198
|
+
|
|
271
199
|
### Elastic Search
|
|
272
200
|
|
|
273
201
|
The Elasticsearch integration will trace any call to ``perform_request``
|
|
@@ -276,15 +204,19 @@ in the ``Client`` object:
|
|
|
276
204
|
require 'elasticsearch/transport'
|
|
277
205
|
require 'ddtrace'
|
|
278
206
|
|
|
279
|
-
Datadog
|
|
207
|
+
Datadog.configure do |c|
|
|
208
|
+
c.use :elasticsearch, options
|
|
209
|
+
end
|
|
280
210
|
|
|
281
211
|
# now do your Elastic Search stuff, eg:
|
|
282
212
|
client = Elasticsearch::Client.new url: 'http://127.0.0.1:9200'
|
|
283
213
|
response = client.perform_request 'GET', '_cluster/health'
|
|
284
214
|
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
215
|
+
Where `options` is an optional `Hash` that accepts the following parameters:
|
|
216
|
+
|
|
217
|
+
| Key | Description | Default |
|
|
218
|
+
| --- | --- | --- |
|
|
219
|
+
| ``service_name`` | Service name used for `elasticsearch` instrumentation | elasticsearch |
|
|
288
220
|
|
|
289
221
|
### MongoDB
|
|
290
222
|
|
|
@@ -296,16 +228,23 @@ if they use the official Ruby driver. To activate the integration, simply:
|
|
|
296
228
|
require 'mongo'
|
|
297
229
|
require 'ddtrace'
|
|
298
230
|
|
|
299
|
-
Datadog
|
|
231
|
+
Datadog.configure do |c|
|
|
232
|
+
c.use :mongo, options
|
|
233
|
+
end
|
|
300
234
|
|
|
301
235
|
# now create a MongoDB client and use it as usual:
|
|
302
236
|
client = Mongo::Client.new([ '127.0.0.1:27017' ], :database => 'artists')
|
|
303
237
|
collection = client[:people]
|
|
304
238
|
collection.insert_one({ name: 'Steve' })
|
|
305
239
|
|
|
306
|
-
# to
|
|
307
|
-
|
|
308
|
-
|
|
240
|
+
# In case you want to override the global configuration for a certain client instance
|
|
241
|
+
Datadog.configure(client, service_name: 'mongodb-primary')
|
|
242
|
+
|
|
243
|
+
Where `options` is an optional `Hash` that accepts the following parameters:
|
|
244
|
+
|
|
245
|
+
| Key | Description | Default |
|
|
246
|
+
| --- | --- | --- |
|
|
247
|
+
| ``service_name`` | Service name used for `mongo` instrumentation | mongodb |
|
|
309
248
|
|
|
310
249
|
### Net/HTTP
|
|
311
250
|
|
|
@@ -315,7 +254,9 @@ Net::HTTP module.
|
|
|
315
254
|
require 'net/http'
|
|
316
255
|
require 'ddtrace'
|
|
317
256
|
|
|
318
|
-
Datadog
|
|
257
|
+
Datadog.configure do |c|
|
|
258
|
+
c.use :http, options
|
|
259
|
+
end
|
|
319
260
|
|
|
320
261
|
Net::HTTP.start('127.0.0.1', 8080) do |http|
|
|
321
262
|
request = Net::HTTP::Get.new '/index'
|
|
@@ -324,30 +265,17 @@ Net::HTTP module.
|
|
|
324
265
|
|
|
325
266
|
content = Net::HTTP.get(URI('http://127.0.0.1/index.html'))
|
|
326
267
|
|
|
327
|
-
|
|
328
|
-
By default, this is disabled. You need to enable it, either on a per-connection basis,
|
|
329
|
-
by setting the ``:distributed_tracing_enabled`` config entry to ``true`` using
|
|
330
|
-
the ``Pin`` object attached to the client. Example:
|
|
268
|
+
Where `options` is an optional `Hash` that accepts the following parameters:
|
|
331
269
|
|
|
332
|
-
|
|
333
|
-
|
|
270
|
+
| Key | Description | Default |
|
|
271
|
+
| --- | --- | --- |
|
|
272
|
+
| ``service_name`` | Service name used for `http` instrumentation | http |
|
|
273
|
+
| ``distributed_tracing`` | Enables distributed tracing | ``false`` |
|
|
334
274
|
|
|
335
|
-
|
|
275
|
+
If you wish to configure each connection object individually, you may use the ``Datadog.configure`` as it follows:
|
|
336
276
|
|
|
337
277
|
client = Net::HTTP.new(host, port)
|
|
338
|
-
Datadog
|
|
339
|
-
response = client.get('foo') # trace and send 'x-datadog-trace-id' and 'x-datadog-parent-id'
|
|
340
|
-
|
|
341
|
-
Or, by enabling distributed tracing for all HTTP calls:
|
|
342
|
-
|
|
343
|
-
require 'net/http'
|
|
344
|
-
require 'ddtrace'
|
|
345
|
-
|
|
346
|
-
Datadog::Monkey.patch_module(:http) # explicitly patch it
|
|
347
|
-
|
|
348
|
-
Datadog::Contrib::HTTP.distributed_tracing_enabled = true
|
|
349
|
-
|
|
350
|
-
See [distributed tracing](#Distributed_Tracing) for details.
|
|
278
|
+
Datadog.configure(client, options)
|
|
351
279
|
|
|
352
280
|
### Faraday
|
|
353
281
|
|
|
@@ -356,7 +284,9 @@ The `faraday` integration is available through the `ddtrace` middleware:
|
|
|
356
284
|
require 'faraday'
|
|
357
285
|
require 'ddtrace'
|
|
358
286
|
|
|
359
|
-
Datadog
|
|
287
|
+
Datadog.configure do |c|
|
|
288
|
+
c.use :faraday, service_name: 'faraday' # global service name
|
|
289
|
+
end
|
|
360
290
|
|
|
361
291
|
connection = Faraday.new('https://example.com') do |builder|
|
|
362
292
|
builder.use(:ddtrace, options)
|
|
@@ -367,20 +297,12 @@ The `faraday` integration is available through the `ddtrace` middleware:
|
|
|
367
297
|
|
|
368
298
|
Where `options` is an optional `Hash` that accepts the following parameters:
|
|
369
299
|
|
|
370
|
-
| Key |
|
|
371
|
-
| --- | --- | --- |
|
|
372
|
-
| `
|
|
373
|
-
| `
|
|
374
|
-
| `
|
|
375
|
-
|
|
376
|
-
It's worth mentioning that `ddtrace` also supports instrumentation for the
|
|
377
|
-
`net/http` library, so if you're using it as farady's backend you might see
|
|
378
|
-
instrumentation both on `faraday` and `net/http` levels. If you want to avoid
|
|
379
|
-
multiple levels of instrumentation for your HTTP requests, remember that you can
|
|
380
|
-
always fine tune which libraries are patched by calling:
|
|
381
|
-
|
|
382
|
-
Datadog::Monkey.patch([:faraday, :redis])
|
|
383
|
-
# instead of using Datadog::Monkey.patch_all
|
|
300
|
+
| Key | Default | Description |
|
|
301
|
+
| --- | --- | --- |
|
|
302
|
+
| `service_name` | Global service name (default: `faraday`) | Service name for this specific connection object. |
|
|
303
|
+
| `split_by_domain` | `false` | Uses the request domain as the service name when set to `true`. |
|
|
304
|
+
| `distributed_tracing` | `false` | Propagates tracing context along the HTTP request when set to `true`. |
|
|
305
|
+
| `error_handler` | ``5xx`` evaluated as errors | A callable object that receives a single argument – the request environment. If it evaluates to a *truthy* value, the trace span is marked as an error. |
|
|
384
306
|
|
|
385
307
|
### AWS
|
|
386
308
|
|
|
@@ -390,10 +312,18 @@ services (S3, ElastiCache etc.).
|
|
|
390
312
|
require 'aws-sdk'
|
|
391
313
|
require 'ddtrace'
|
|
392
314
|
|
|
393
|
-
Datadog
|
|
315
|
+
Datadog.configure do |c|
|
|
316
|
+
c.use :aws, options
|
|
317
|
+
end
|
|
394
318
|
|
|
395
319
|
Aws::S3::Client.new.list_buckets # traced call
|
|
396
320
|
|
|
321
|
+
Where `options` is an optional `Hash` that accepts the following parameters:
|
|
322
|
+
|
|
323
|
+
| Key | Description | Default |
|
|
324
|
+
| --- | --- | --- |
|
|
325
|
+
| ``service_name`` | Service name used for `aws` instrumentation | aws |
|
|
326
|
+
|
|
397
327
|
### Dalli
|
|
398
328
|
|
|
399
329
|
Dalli integration will trace all calls to your ``memcached`` server:
|
|
@@ -401,15 +331,18 @@ Dalli integration will trace all calls to your ``memcached`` server:
|
|
|
401
331
|
require 'dalli'
|
|
402
332
|
require 'ddtrace'
|
|
403
333
|
|
|
404
|
-
|
|
405
|
-
|
|
334
|
+
Datadog.configure do |c|
|
|
335
|
+
c.use :dalli, service_name: 'dalli'
|
|
336
|
+
end
|
|
406
337
|
|
|
407
338
|
client = Dalli::Client.new('localhost:11211', options)
|
|
408
339
|
client.set('abc', 123)
|
|
409
340
|
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
341
|
+
Where `options` is an optional `Hash` that accepts the following parameters:
|
|
342
|
+
|
|
343
|
+
| Key | Description | Default |
|
|
344
|
+
| --- | --- | --- |
|
|
345
|
+
| ``service_name`` | Service name used for `dalli` instrumentation | memcached |
|
|
413
346
|
|
|
414
347
|
### Redis
|
|
415
348
|
|
|
@@ -418,103 +351,131 @@ The Redis integration will trace simple calls as well as pipelines.
|
|
|
418
351
|
require 'redis'
|
|
419
352
|
require 'ddtrace'
|
|
420
353
|
|
|
421
|
-
Datadog
|
|
354
|
+
Datadog.configure do |c|
|
|
355
|
+
c.use :redis, service_name: 'redis'
|
|
356
|
+
end
|
|
422
357
|
|
|
423
358
|
# now do your Redis stuff, eg:
|
|
424
359
|
redis = Redis.new
|
|
425
360
|
redis.set 'foo', 'bar' # traced!
|
|
426
361
|
|
|
362
|
+
Where `options` is an optional `Hash` that accepts the following parameters:
|
|
363
|
+
|
|
364
|
+
| Key | Description | Default |
|
|
365
|
+
| --- | --- | --- |
|
|
366
|
+
| ``service_name`` | Service name used for `redis` instrumentation | redis |
|
|
367
|
+
|
|
368
|
+
You can also set *per-instance* configuration as it follows:
|
|
369
|
+
|
|
370
|
+
customer_cache = Redis.new
|
|
371
|
+
invoice_cache = Redis.new
|
|
372
|
+
|
|
373
|
+
Datadog.configure(customer_cache, service_name: 'customer-cache')
|
|
374
|
+
Datadog.configure(invoice_cache, service_name: invoice-cache')
|
|
375
|
+
|
|
376
|
+
customer_cache.get(...) # traced call will belong to `customer-cache` service
|
|
377
|
+
invoice_cache.get(...) # traced call will belong to `invoice-cache` service
|
|
378
|
+
|
|
427
379
|
### Sidekiq
|
|
428
380
|
|
|
429
381
|
The Sidekiq integration is a server-side middleware which will trace job
|
|
430
|
-
executions.
|
|
382
|
+
executions. You can enable it through `Datadog.configure`:
|
|
431
383
|
|
|
432
|
-
require 'sidekiq'
|
|
433
384
|
require 'ddtrace'
|
|
434
|
-
require 'ddtrace/contrib/sidekiq/tracer'
|
|
435
385
|
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
chain.add(Datadog::Contrib::Sidekiq::Tracer)
|
|
439
|
-
end
|
|
386
|
+
Datadog.configure do |c|
|
|
387
|
+
c.use :sidekiq, options
|
|
440
388
|
end
|
|
441
389
|
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
To modify the default configuration, simply pass arguments to the middleware.
|
|
445
|
-
For example, to change the default service name:
|
|
446
|
-
|
|
447
|
-
Sidekiq.configure_server do |config|
|
|
448
|
-
config.server_middleware do |chain|
|
|
449
|
-
chain.add(
|
|
450
|
-
Datadog::Contrib::Sidekiq::Tracer,
|
|
451
|
-
sidekiq_service: 'sidekiq-notifications'
|
|
452
|
-
)
|
|
453
|
-
end
|
|
454
|
-
end
|
|
390
|
+
Where `options` is an optional `Hash` that accepts the following parameters:
|
|
455
391
|
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
``false``, the code is still instrumented but no spans are sent to the local
|
|
460
|
-
trace agent.
|
|
461
|
-
* ``sidekiq_service``: set the service name used when tracing application
|
|
462
|
-
requests. Defaults to ``sidekiq``.
|
|
463
|
-
* ``tracer``: set the tracer to use. Usually you don't need to change that
|
|
464
|
-
value unless you're already using a different initialized tracer somewhere
|
|
465
|
-
else.
|
|
466
|
-
* ``debug``: set to ``true`` to enable debug logging.
|
|
467
|
-
* ``trace_agent_hostname``: set the hostname of the trace agent.
|
|
468
|
-
* ``trace_agent_port``: set the port the trace agent is listening on.
|
|
469
|
-
|
|
470
|
-
If you're using Sidekiq along with [Ruby on Rails](#label-Ruby+on+Rails) auto-instrumentation,
|
|
471
|
-
the Sidekiq middleware will re-use the Rails configuration defined in the initializer file before
|
|
472
|
-
giving precedence to the middleware settings. Inherited configurations are:
|
|
473
|
-
|
|
474
|
-
* ``enabled``
|
|
475
|
-
* ``tracer``
|
|
476
|
-
* ``debug``
|
|
477
|
-
* ``trace_agent_hostname``
|
|
478
|
-
* ``trace_agent_port``
|
|
392
|
+
| Key | Description | Default |
|
|
393
|
+
| --- | --- | --- |
|
|
394
|
+
| ``service_name`` | Service name used for `sidekiq` instrumentation | sidekiq |
|
|
479
395
|
|
|
480
396
|
### Resque
|
|
481
397
|
|
|
482
398
|
The Resque integration uses Resque hooks that wraps the ``perform`` method.
|
|
483
|
-
To add tracing to a Resque job,
|
|
484
|
-
one:
|
|
399
|
+
To add tracing to a Resque job, simply do as follows:
|
|
485
400
|
|
|
486
401
|
require 'ddtrace'
|
|
487
|
-
require 'ddtrace/contrib/resque/resque_job'
|
|
488
|
-
|
|
489
|
-
# patch Resque
|
|
490
|
-
Datadog::Monkey.patch_module(:resque)
|
|
491
402
|
|
|
492
403
|
class MyJob
|
|
493
|
-
# extend MyJob with integration hooks
|
|
494
|
-
extend Datadog::Contrib::Resque::ResqueJob
|
|
495
|
-
|
|
496
404
|
def self.perform(*args)
|
|
497
405
|
# do_something
|
|
498
406
|
end
|
|
499
407
|
end
|
|
500
408
|
|
|
409
|
+
Datadog.configure do |c|
|
|
410
|
+
c.use :resque, options
|
|
411
|
+
end
|
|
412
|
+
|
|
413
|
+
Where `options` is an optional `Hash` that accepts the following parameters:
|
|
414
|
+
|
|
415
|
+
| Key | Description | Default |
|
|
416
|
+
| --- | --- | --- |
|
|
417
|
+
| ``service_name`` | Service name used for `resque` instrumentation | resque |
|
|
418
|
+
| ``workers`` | An array including all worker classes you want to trace (eg ``[MyJob]``) | ``[]`` |
|
|
419
|
+
|
|
501
420
|
### SuckerPunch
|
|
502
421
|
|
|
503
422
|
The `sucker_punch` integration traces all scheduled jobs:
|
|
504
423
|
|
|
505
424
|
require 'ddtrace'
|
|
506
425
|
|
|
507
|
-
Datadog
|
|
426
|
+
Datadog.configure do |c|
|
|
427
|
+
c.use :sucker_punch, options
|
|
428
|
+
end
|
|
508
429
|
|
|
509
430
|
# the execution of this job is traced
|
|
510
431
|
LogJob.perform_async('login')
|
|
511
432
|
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
433
|
+
Where `options` is an optional `Hash` that accepts the following parameters:
|
|
434
|
+
|
|
435
|
+
| Key | Description | Default |
|
|
436
|
+
| --- | --- | --- |
|
|
437
|
+
| ``service_name`` | Service name used for `sucker_punch` instrumentation | sucker_punch |
|
|
515
438
|
|
|
516
439
|
## Advanced usage
|
|
517
440
|
|
|
441
|
+
### Configure the tracer
|
|
442
|
+
|
|
443
|
+
To change the default behavior of the Datadog tracer, you can provide custom options inside the `Datadog.configure` block as in:
|
|
444
|
+
|
|
445
|
+
# config/initializers/datadog-tracer.rb
|
|
446
|
+
|
|
447
|
+
Datadog.configure do |c|
|
|
448
|
+
c.tracer option_name: option_value, ...
|
|
449
|
+
end
|
|
450
|
+
|
|
451
|
+
Available options are:
|
|
452
|
+
|
|
453
|
+
* ``enabled``: defines if the ``tracer`` is enabled or not. If set to ``false`` the code could be still instrumented
|
|
454
|
+
because of other settings, but no spans are sent to the local trace agent.
|
|
455
|
+
* ``debug``: set to true to enable debug logging.
|
|
456
|
+
* ``hostname``: set the hostname of the trace agent.
|
|
457
|
+
* ``port``: set the port the trace agent is listening on.
|
|
458
|
+
* ``env``: set the environment. Rails users may set it to ``Rails.env`` to use their application settings.
|
|
459
|
+
* ``tags``: set global tags that should be applied to all spans. Defaults to an empty hash
|
|
460
|
+
* ``log``: defines a custom logger.
|
|
461
|
+
|
|
462
|
+
#### Using a custom logger
|
|
463
|
+
|
|
464
|
+
By default, all logs are processed by the default Ruby logger.
|
|
465
|
+
Typically, when using Rails, you should see the messages in your application log file.
|
|
466
|
+
Datadog client log messages are marked with ``[ddtrace]`` so you should be able
|
|
467
|
+
to isolate them from other messages.
|
|
468
|
+
|
|
469
|
+
Additionally, it is possible to override the default logger and replace it by a
|
|
470
|
+
custom one. This is done using the ``log`` attribute of the tracer.
|
|
471
|
+
|
|
472
|
+
f = File.new("my-custom.log", "w+") # Log messages should go there
|
|
473
|
+
Datadog.configure do |c|
|
|
474
|
+
c.tracer log: Logger.new(f) # Overriding the default tracer
|
|
475
|
+
end
|
|
476
|
+
|
|
477
|
+
Datadog::Tracer.log.info { "this is typically called by tracing code" }
|
|
478
|
+
|
|
518
479
|
### Manual Instrumentation
|
|
519
480
|
|
|
520
481
|
If you aren't using a supported framework instrumentation, you may want to to manually instrument your code.
|
|
@@ -547,148 +508,9 @@ to trace requests to the home page:
|
|
|
547
508
|
tracer.trace('template.render') do
|
|
548
509
|
erb :index
|
|
549
510
|
end
|
|
550
|
-
|
|
551
|
-
# trace using start_span (fine-grain control, requires explicit call to finish)
|
|
552
|
-
child = tracer.start_span('child', child_of: span)
|
|
553
|
-
# do something
|
|
554
|
-
child.finish
|
|
555
|
-
end
|
|
556
|
-
end
|
|
557
|
-
|
|
558
|
-
### Patching methods
|
|
559
|
-
|
|
560
|
-
Integrations such as Redis or Elasticsearch use monkey patching.
|
|
561
|
-
|
|
562
|
-
The available methods are:
|
|
563
|
-
|
|
564
|
-
* ``autopatch_modules``: returns a hash of all modules available for monkey patching,
|
|
565
|
-
the key is the name of the module and the value ``true`` or ``false``. If it is ``true``,
|
|
566
|
-
a call to ``patch_all`` will enable the module, if it is ``false``, it will do nothing.
|
|
567
|
-
* ``patch_all``: patches all modules which are supported. Make sure all the necessary
|
|
568
|
-
calls to ``require`` have been done before this is called, else monkey patching will
|
|
569
|
-
not work.
|
|
570
|
-
* ``patch_module``: patches a single module, regardless of its settings in the
|
|
571
|
-
``autopatch_modules`` list.
|
|
572
|
-
* ``patch``: patches some modules, you should pass a hash like the one returned
|
|
573
|
-
by ``autopatch_modules``
|
|
574
|
-
* ``get_patched_modules``: returns the list of patched modules, a module has been
|
|
575
|
-
correctly patched only if it is in this hash, with a value set to ``true``.
|
|
576
|
-
|
|
577
|
-
Example:
|
|
578
|
-
|
|
579
|
-
require 'ddtrace'
|
|
580
|
-
|
|
581
|
-
puts Datadog::Monkey.autopatch_modules # lists all modules available for monkey patching
|
|
582
|
-
Datadog::Monkey.patch_module(:redis) # patch only one module
|
|
583
|
-
Datadog::Monkey.patch(elasticsearch: false, redis: true) # patch redis, but not elasticsearch
|
|
584
|
-
Datadog::Monkey.patch_all # patch all the available modules
|
|
585
|
-
puts Datadog::Monkey.get_patched_modules # tells wether modules are patched or not
|
|
586
|
-
|
|
587
|
-
It is safe to call ``patch_all``, ``patch_module`` or ``patch`` several times.
|
|
588
|
-
Make sure the library you want to patch is imported before you call ``patch_module``.
|
|
589
|
-
In doubt, check with ``get_patched_modules``.
|
|
590
|
-
Once a module is patched, it is not possible to unpatch it.
|
|
591
|
-
|
|
592
|
-
### Patch Info (PIN)
|
|
593
|
-
|
|
594
|
-
The Patch Info, AKA ``Pin`` object, gives you control on the integration.
|
|
595
|
-
|
|
596
|
-
It has one class method:
|
|
597
|
-
|
|
598
|
-
* ``get_from``: returns the Pin object which has been pinned onto some random
|
|
599
|
-
object. It is safe to call ``get_from`` on any object, but it might return ``nil``.
|
|
600
|
-
|
|
601
|
-
Some instance methods:
|
|
602
|
-
|
|
603
|
-
* ``enabled?``: wether tracing is enabled for this object
|
|
604
|
-
* ``onto``: applies the patch information to some random object. It is the companion
|
|
605
|
-
function of ``get_from``.
|
|
606
|
-
|
|
607
|
-
Accessors:
|
|
608
|
-
|
|
609
|
-
* ``service``: service, you should typically set some meaningful value for this.
|
|
610
|
-
* ``app``: application name
|
|
611
|
-
* ``tags``: optional tags
|
|
612
|
-
* ``app_type``: application type
|
|
613
|
-
* ``name``: span name
|
|
614
|
-
* ``tracer``: the tracer object used for tracing
|
|
615
|
-
|
|
616
|
-
By default, a traced integration such as Redis or Elasticsearch carries a Pin object. Eg:
|
|
617
|
-
|
|
618
|
-
require 'redis'
|
|
619
|
-
require 'ddtrace'
|
|
620
|
-
|
|
621
|
-
Datadog::Monkey.patch_all
|
|
622
|
-
|
|
623
|
-
redis = Redis.new
|
|
624
|
-
pin = Datadog::Pin.get_from(redis)
|
|
625
|
-
pin.service = 'my-redis-cache'
|
|
626
|
-
puts redis.get 'my-key' # this will be traced as belonging to 'my-redis-cache' service
|
|
627
|
-
pin.tracer = nil
|
|
628
|
-
puts pin.enabled? # false
|
|
629
|
-
puts redis.get 'my-key' # this won't be traced, tracing has been disabled now
|
|
630
|
-
|
|
631
|
-
You can use this object to instrument your own code:
|
|
632
|
-
|
|
633
|
-
require 'ddtrace'
|
|
634
|
-
require 'ddtrace/ext/app_types'
|
|
635
|
-
|
|
636
|
-
class MyWebSite
|
|
637
|
-
def initialize
|
|
638
|
-
pin = Datadog::Pin.new('my-web-site', app_type: Datadog::Ext::AppTypes::WEB)
|
|
639
|
-
pin.onto(self)
|
|
640
|
-
end
|
|
641
|
-
|
|
642
|
-
def serve(something)
|
|
643
|
-
pin = Datadog::Pin.get_from(self)
|
|
644
|
-
pin.tracer.trace('serve') do |span|
|
|
645
|
-
span.resource = something
|
|
646
|
-
span.service = pin.service
|
|
647
|
-
# serve something here
|
|
648
|
-
end
|
|
649
|
-
end
|
|
650
|
-
end
|
|
651
|
-
|
|
652
|
-
### Debug Mode
|
|
653
|
-
|
|
654
|
-
If you need to check locally what traces and spans are sent after each traced block, you can enable
|
|
655
|
-
a global debug mode for all tracers so that every time a trace is ready to be sent, the content will be
|
|
656
|
-
printed in the +STDOUT+. To enable the debug logging, add this code anywhere before using the tracer
|
|
657
|
-
for the first time:
|
|
658
|
-
|
|
659
|
-
require 'ddtrace'
|
|
660
|
-
require 'sinatra'
|
|
661
|
-
require 'active_record'
|
|
662
|
-
|
|
663
|
-
# enable debug mode
|
|
664
|
-
Datadog::Tracer.debug_logging = true
|
|
665
|
-
|
|
666
|
-
# use the tracer as usual
|
|
667
|
-
tracer = Datadog.tracer
|
|
668
|
-
|
|
669
|
-
get '/' do
|
|
670
|
-
tracer.trace('web.request') do |span|
|
|
671
|
-
# ...
|
|
672
511
|
end
|
|
673
512
|
end
|
|
674
513
|
|
|
675
|
-
Remember that the debug mode may affect your application performance and so it must not be used
|
|
676
|
-
in a production environment.
|
|
677
|
-
|
|
678
|
-
### Using a custom logger
|
|
679
|
-
|
|
680
|
-
By default, all logs are processed by the default Ruby logger.
|
|
681
|
-
Typically, when using Rails, you should see the messages in your application log file.
|
|
682
|
-
Datadog client log messages are marked with ``[ddtrace]`` so you should be able
|
|
683
|
-
to isolate them from other messages.
|
|
684
|
-
|
|
685
|
-
Additionally, it is possible to override the default logger and replace it by a
|
|
686
|
-
custom one. This is done using the ``log`` attribute of the tracer.
|
|
687
|
-
|
|
688
|
-
f = File.new("my-custom.log", "w+") # Log messages should go there
|
|
689
|
-
Datadog::Tracer.log = Logger.new(f) # Overriding the default tracer
|
|
690
|
-
Datadog::Tracer.log.info { "this is typically called by tracing code" }
|
|
691
|
-
|
|
692
514
|
### Environment and tags
|
|
693
515
|
|
|
694
516
|
By default, the trace agent (not this library, but the program running in
|
|
@@ -698,7 +520,9 @@ set in the agent config file, see our
|
|
|
698
520
|
|
|
699
521
|
These values can be overridden at the tracer level:
|
|
700
522
|
|
|
701
|
-
Datadog.
|
|
523
|
+
Datadog.configure do |c|
|
|
524
|
+
c.tracer tags: { 'env' => 'prod' }
|
|
525
|
+
end
|
|
702
526
|
|
|
703
527
|
This enables you to set this value on a per tracer basis, so you can have
|
|
704
528
|
for example several applications reporting for different environments on the same host.
|
|
@@ -716,32 +540,49 @@ overhead.
|
|
|
716
540
|
|
|
717
541
|
# Sample rate is between 0 (nothing sampled) to 1 (everything sampled).
|
|
718
542
|
sampler = Datadog::RateSampler.new(0.5) # sample 50% of the traces
|
|
719
|
-
Datadog.
|
|
543
|
+
Datadog.configure do |c|
|
|
544
|
+
c.tracer sampler: sampler
|
|
545
|
+
end
|
|
720
546
|
|
|
721
547
|
#### Priority sampling
|
|
722
548
|
|
|
723
549
|
Priority sampling consists in deciding if a trace will be kept by using a priority attribute that will be propagated for distributed traces. Its value gives indication to the Agent and to the backend on how important the trace is.
|
|
724
550
|
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
*
|
|
551
|
+
The sampler can set the priority to the following values:
|
|
552
|
+
|
|
553
|
+
* `Datadog::Ext::Priority::AUTO_REJECT`: the sampler automatically decided to reject the trace.
|
|
554
|
+
* `Datadog::Ext::Priority::AUTO_KEEP`: the sampler automatically decided to keep the trace.
|
|
728
555
|
|
|
729
556
|
For now, priority sampling is disabled by default. Enabling it ensures that your sampled distributed traces will be complete. To enable the priority sampling:
|
|
730
557
|
|
|
731
558
|
```rb
|
|
732
|
-
Datadog.
|
|
559
|
+
Datadog.configure do |c|
|
|
560
|
+
c.tracer priority_sampling: true
|
|
561
|
+
end
|
|
733
562
|
```
|
|
734
563
|
|
|
735
564
|
Once enabled, the sampler will automatically assign a priority of 0 or 1 to traces, depending on their service and volume.
|
|
736
565
|
|
|
737
|
-
You can also set this priority manually to either drop a non-interesting trace or to keep an important one. For that, set the `context#sampling_priority` to
|
|
566
|
+
You can also set this priority manually to either drop a non-interesting trace or to keep an important one. For that, set the `context#sampling_priority` to:
|
|
567
|
+
|
|
568
|
+
* `Datadog::Ext::Priority::USER_REJECT`: the user asked to reject the trace.
|
|
569
|
+
* `Datadog::Ext::Priority::USER_KEEP`: the user asked to keep the trace.
|
|
570
|
+
|
|
571
|
+
When not using [distributed tracing](#Distributed_Tracing), you may change the priority at any time,
|
|
572
|
+
as long as the trace is not finished yet.
|
|
573
|
+
But it has to be done before any context propagation (fork, RPC calls) to be effective in a distributed context.
|
|
574
|
+
Changing the priority after context has been propagated causes different parts of a distributed trace
|
|
575
|
+
to use different priorities. Some parts might be kept, some parts might be rejected,
|
|
576
|
+
and this can cause the trace to be partially stored and remain incomplete.
|
|
577
|
+
|
|
578
|
+
If you change the priority, we recommend you do it as soon as possible, when the root span has just been created.
|
|
738
579
|
|
|
739
580
|
```rb
|
|
740
|
-
# Indicate to
|
|
741
|
-
span.context.sampling_priority =
|
|
581
|
+
# Indicate to reject the trace
|
|
582
|
+
span.context.sampling_priority = Datadog::Ext::Priority::USER_REJECT
|
|
742
583
|
|
|
743
584
|
# Indicate to keep the trace
|
|
744
|
-
span.context.sampling_priority =
|
|
585
|
+
span.context.sampling_priority = Datadog::Ext::Priority::USER_KEEP
|
|
745
586
|
```
|
|
746
587
|
|
|
747
588
|
### Distributed Tracing
|
|
@@ -766,9 +607,6 @@ On the client:
|
|
|
766
607
|
require 'net/http'
|
|
767
608
|
require 'ddtrace'
|
|
768
609
|
|
|
769
|
-
# Do *not* monkey patch here, we do it "manually", to demo the feature
|
|
770
|
-
# Datadog::Monkey.patch_module(:http)
|
|
771
|
-
|
|
772
610
|
uri = URI('http://localhost:4567/')
|
|
773
611
|
|
|
774
612
|
Datadog.tracer.trace('web.call') do |span|
|
|
@@ -788,9 +626,6 @@ On the server:
|
|
|
788
626
|
require 'sinatra'
|
|
789
627
|
require 'ddtrace'
|
|
790
628
|
|
|
791
|
-
# Do *not* use Sinatra integration, we do it "manually", to demo the feature
|
|
792
|
-
# require 'ddtrace/contrib/sinatra/tracer'
|
|
793
|
-
|
|
794
629
|
get '/' do
|
|
795
630
|
parent_trace_id = request.env['HTTP_X_DATADOG_TRACE_ID']
|
|
796
631
|
parent_span_id = request.env['HTTP_X_DATADOG_PARENT_ID']
|
|
@@ -807,7 +642,7 @@ On the server:
|
|
|
807
642
|
|
|
808
643
|
[Rack](#Rack) and [Net/HTTP](#Net_HTTP) have experimental support for this, they
|
|
809
644
|
can send and receive these headers automatically and tie spans together automatically,
|
|
810
|
-
provided you pass a ``:
|
|
645
|
+
provided you pass a ``:distributed_tracing`` option set to ``true``.
|
|
811
646
|
|
|
812
647
|
This is disabled by default.
|
|
813
648
|
|
|
@@ -828,34 +663,6 @@ pipeline using the method `Datadog::Pipeline.before_flush`:
|
|
|
828
663
|
|
|
829
664
|
For more information, please refer to this [link](https://github.com/DataDog/dd-trace-rb/pull/214).
|
|
830
665
|
|
|
831
|
-
### Troubleshooting
|
|
832
|
-
|
|
833
|
-
#### Logs
|
|
834
|
-
|
|
835
|
-
Your application log should contain informations and report problems
|
|
836
|
-
such as agent not being up and running. All logs generated by this
|
|
837
|
-
library should contain ``[ddtrace]``. Also see [how to use a custom logger](#Using_a_custom_logger)
|
|
838
|
-
to redirect these messages elsewhere.
|
|
839
|
-
|
|
840
|
-
The [Datadog Trace Agent](https://github.com/DataDog/datadog-trace-agent)
|
|
841
|
-
should by default be listening for traces on port 8126.
|
|
842
|
-
|
|
843
|
-
#### Hello World
|
|
844
|
-
|
|
845
|
-
Sometimes, setting up a complete application is complex, so in doubt,
|
|
846
|
-
try the small program below, which should be able to report traces
|
|
847
|
-
for a ``tracegen`` service:
|
|
848
|
-
|
|
849
|
-
require 'ddtrace'
|
|
850
|
-
|
|
851
|
-
loop do
|
|
852
|
-
Datadog.tracer.trace('hello-world') do |span|
|
|
853
|
-
span.service = 'tracegen'
|
|
854
|
-
span.resource = 'ruby'
|
|
855
|
-
sleep 1
|
|
856
|
-
end
|
|
857
|
-
end
|
|
858
|
-
|
|
859
666
|
### Supported Versions
|
|
860
667
|
|
|
861
668
|
#### Ruby interpreters
|