ddtrace 0.5.0 → 0.6.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 80f9cffb7ec1f57e9215784dd53d859b6a9ffae7
4
- data.tar.gz: 348d67544886fa8762b2c2125dd8033a766d5f62
3
+ metadata.gz: c166ccd4553aa6b0a63817846b4aca66a7d74f92
4
+ data.tar.gz: bd1cdacc971045e137b14a5714d0659747e442f2
5
5
  SHA512:
6
- metadata.gz: e6795138d773ce92ba5123d9fbbe42a84c49a66800a9ab2a487f5c73900059b5197dbae0768e055fd11b9990fed3e1c812cf5f0637c87de7f7b56fa0ec1ba242
7
- data.tar.gz: 1658c85972eb0be8ecc6941382558623d2ba54407e3d28874efe5c6e0936510e108512ee6314cf8d483796a903e71af77a4b47057441d2ff25e35e3174c4dfc5
6
+ metadata.gz: 94e7ee6857c01885d16ada253e8d6cab86704c321e8fa114e6a7fbfb716e940d5aaad62261f9486b44ecb2cdc01bd7992e0dd8d6473c23758c82d8a909344d5e
7
+ data.tar.gz: 338c3d27571dc226d6c8dede32fb497b90a6a67d7985542fb74b1f0c0dd2d40e9e914eb50e64bd85dfb2c559fe97cdcca7cbccf12c0d36a8ceab444e4009b614
@@ -50,3 +50,8 @@ Metrics/PerceivedComplexity:
50
50
 
51
51
  Lint/UnusedMethodArgument:
52
52
  Enabled: false
53
+
54
+ # Disabling advices that would lead to incompatible Ruby 1.9 code
55
+ Style/SymbolArray:
56
+ Enabled: false
57
+
data/Appraisals CHANGED
@@ -1,90 +1,113 @@
1
- if RUBY_VERSION < "2.4.0"
2
- appraise "rails3-postgres" do
3
- gem "test-unit"
4
- gem "rails", "3.2.22.5"
5
- gem "pg", platform: :ruby
6
- gem 'activerecord-jdbcpostgresql-adapter', platform: :jruby
1
+ if RUBY_VERSION < '2.4.0'
2
+ if RUBY_VERSION >= '1.9.1'
3
+ appraise 'rails3-mysql2' do
4
+ gem 'test-unit'
5
+ gem 'rails', '3.2.22.5'
6
+ gem 'mysql2', '0.3.21', platform: :ruby
7
+ gem 'activerecord-mysql-adapter', platform: :ruby
8
+ gem 'activerecord-jdbcmysql-adapter', platform: :jruby
9
+ end
7
10
  end
8
11
 
9
- appraise "rails4-postgres" do
10
- gem "rails", "4.2.7.1"
11
- gem "pg", platform: :ruby
12
- gem 'activerecord-jdbcpostgresql-adapter', platform: :jruby
13
- end
12
+ if RUBY_VERSION >= '1.9.1'
13
+ appraise 'rails3-postgres' do
14
+ gem 'test-unit'
15
+ gem 'rails', '3.2.22.5'
16
+ gem 'pg', '0.15.1', platform: :ruby
17
+ gem 'activerecord-jdbcpostgresql-adapter', platform: :jruby
18
+ end
14
19
 
15
- appraise "rails3-mysql2" do
16
- gem "test-unit"
17
- gem "rails", "3.2.22.5"
18
- gem "mysql2", "0.3.21", platform: :ruby
19
- gem "activerecord-mysql-adapter", platform: :ruby
20
- gem 'activerecord-jdbcmysql-adapter', platform: :jruby
21
- end
20
+ appraise 'rails3-postgres-redis' do
21
+ gem 'test-unit'
22
+ gem 'rails', '3.2.22.5'
23
+ gem 'pg', '0.15.1', platform: :ruby
24
+ gem 'activerecord-jdbcpostgresql-adapter', platform: :jruby
25
+ gem 'redis-rails'
26
+ end
22
27
 
23
- appraise "rails4-mysql2" do
24
- gem "rails", "4.2.7.1"
25
- gem "mysql2", platform: :ruby
26
- gem 'activerecord-jdbcmysql-adapter', platform: :jruby
28
+ appraise 'rails3-postgres-sidekiq' do
29
+ gem 'test-unit'
30
+ gem 'rails', '3.2.22.5'
31
+ gem 'pg', '0.15.1', platform: :ruby
32
+ gem 'activerecord-jdbcpostgresql-adapter', platform: :jruby
33
+ gem 'sidekiq'
34
+ end
27
35
  end
28
36
 
29
- appraise "rails3-postgres-redis" do
30
- gem "test-unit"
31
- gem "rails", "3.2.22.5"
32
- gem "pg", platform: :ruby
33
- gem 'activerecord-jdbcpostgresql-adapter', platform: :jruby
34
- gem "redis-rails"
35
- end
37
+ if RUBY_VERSION >= '2.1.10'
38
+ appraise 'rails4-mysql2' do
39
+ gem 'rails', '4.2.7.1'
40
+ gem 'mysql2', platform: :ruby
41
+ gem 'activerecord-jdbcmysql-adapter', platform: :jruby
42
+ end
36
43
 
37
- appraise "rails4-postgres-redis" do
38
- gem "rails", "4.2.7.1"
39
- gem "pg", platform: :ruby
40
- gem 'activerecord-jdbcpostgresql-adapter', platform: :jruby
41
- gem "redis-rails"
42
- end
43
- appraise "rails3-postgres-sidekiq" do
44
- gem "test-unit"
45
- gem "rails", "3.2.22.5"
46
- gem "pg", platform: :ruby
47
- gem 'activerecord-jdbcpostgresql-adapter', platform: :jruby
48
- gem "sidekiq"
49
- end
44
+ appraise 'rails4-postgres' do
45
+ gem 'rails', '4.2.7.1'
46
+ gem 'pg', platform: :ruby
47
+ gem 'activerecord-jdbcpostgresql-adapter', platform: :jruby
48
+ end
49
+
50
+ appraise 'rails4-postgres-redis' do
51
+ gem 'rails', '4.2.7.1'
52
+ gem 'pg', platform: :ruby
53
+ gem 'activerecord-jdbcpostgresql-adapter', platform: :jruby
54
+ gem 'redis-rails'
55
+ end
50
56
 
51
- appraise "rails4-postgres-sidekiq" do
52
- gem "rails", "4.2.7.1"
53
- gem "pg", platform: :ruby
54
- gem 'activerecord-jdbcpostgresql-adapter', platform: :jruby
55
- gem "sidekiq"
57
+ appraise 'rails4-postgres-sidekiq' do
58
+ gem 'rails', '4.2.7.1'
59
+ gem 'pg', platform: :ruby
60
+ gem 'activerecord-jdbcpostgresql-adapter', platform: :jruby
61
+ gem 'sidekiq'
62
+ gem 'activejob'
63
+ end
56
64
  end
57
65
 
58
- if RUBY_VERSION >= "2.2.2" && RUBY_PLATFORM != "java"
59
- appraise "rails5-postgres" do
60
- gem "rails", "5.0.1"
61
- gem "pg", platform: :ruby
66
+ if RUBY_VERSION >= '2.2.2' && RUBY_PLATFORM != 'java'
67
+ appraise 'rails5-mysql2' do
68
+ gem 'rails', '5.0.1'
69
+ gem 'mysql2', platform: :ruby
62
70
  end
63
71
 
64
- appraise "rails5-mysql2" do
65
- gem "rails", "5.0.1"
66
- gem "mysql2", platform: :ruby
72
+ appraise 'rails5-postgres' do
73
+ gem 'rails', '5.0.1'
74
+ gem 'pg', platform: :ruby
67
75
  end
68
76
 
69
- appraise "rails5-postgres-redis" do
70
- gem "rails", "5.0.1"
71
- gem "pg", platform: :ruby
72
- gem "redis-rails"
77
+ appraise 'rails5-postgres-redis' do
78
+ gem 'rails', '5.0.1'
79
+ gem 'pg', platform: :ruby
80
+ gem 'redis-rails'
73
81
  end
74
82
 
75
- appraise "rails5-postgres-sidekiq" do
76
- gem "rails", "5.0.1"
77
- gem "pg", platform: :ruby
78
- gem "sidekiq"
83
+ appraise 'rails5-postgres-sidekiq' do
84
+ gem 'rails', '5.0.1'
85
+ gem 'pg', platform: :ruby
86
+ gem 'sidekiq'
87
+ gem "activejob"
79
88
  end
80
89
  end
81
90
  end
82
91
 
83
- appraise "contrib" do
84
- gem "elasticsearch-transport"
85
- gem "redis"
86
- gem "hiredis"
87
- gem "rack-test"
88
- gem "sinatra"
89
- gem "sidekiq"
92
+ if RUBY_VERSION >= '2.2.2'
93
+ appraise 'contrib' do
94
+ gem 'elasticsearch-transport'
95
+ gem 'redis'
96
+ gem 'hiredis'
97
+ gem 'rack-test'
98
+ gem 'sinatra'
99
+ gem 'activerecord'
100
+ gem 'sidekiq'
101
+ end
102
+ else
103
+ appraise 'contrib-old' do
104
+ gem 'elasticsearch-transport'
105
+ gem 'redis'
106
+ gem 'hiredis'
107
+ gem 'rack-test', '0.6.2'
108
+ gem 'rack', '1.4.7'
109
+ gem 'sinatra', '1.4.5'
110
+ gem 'activerecord', '3.2.22.5'
111
+ gem 'sidekiq', '4.0.0'
112
+ end
90
113
  end
data/Rakefile CHANGED
@@ -1,12 +1,14 @@
1
1
  require 'bundler/gem_tasks'
2
2
  require 'ddtrace/version'
3
- require 'rubocop/rake_task'
3
+ require 'rubocop/rake_task' if RUBY_VERSION >= '2.1.0'
4
4
  require 'rake/testtask'
5
5
  require 'appraisal'
6
6
  require 'yard'
7
7
 
8
8
  namespace :test do
9
- task all: [:main, :rails, :railsredis, :elasticsearch, :http, :redis, :sidekiq, :sinatra, :monkey]
9
+ task all: [:main,
10
+ :rails, :railsredis, :railssidekiq, :railsactivejob,
11
+ :elasticsearch, :http, :redis, :sidekiq, :sinatra, :monkey]
10
12
 
11
13
  Rake::TestTask.new(:main) do |t|
12
14
  t.libs << %w(test lib)
@@ -22,7 +24,8 @@ namespace :test do
22
24
  t.libs << %w(test lib)
23
25
  t.test_files = FileList['test/contrib/rails/**/*_test.rb'].reject do |path|
24
26
  path.include?('redis') ||
25
- path.include?('sidekiq')
27
+ path.include?('sidekiq') ||
28
+ path.include?('active_job')
26
29
  end
27
30
  end
28
31
 
@@ -36,6 +39,11 @@ namespace :test do
36
39
  t.test_files = FileList['test/contrib/rails/**/*sidekiq*_test.rb']
37
40
  end
38
41
 
42
+ Rake::TestTask.new(:railsactivejob) do |t|
43
+ t.libs << %w(test lib)
44
+ t.test_files = FileList['test/contrib/rails/**/*active_job*_test.rb']
45
+ end
46
+
39
47
  [:elasticsearch, :http, :redis, :sinatra, :sidekiq].each do |contrib|
40
48
  Rake::TestTask.new(contrib) do |t|
41
49
  t.libs << %w(test lib)
@@ -54,9 +62,11 @@ Rake::TestTask.new(:benchmark) do |t|
54
62
  t.test_files = FileList['test/benchmark_test.rb']
55
63
  end
56
64
 
57
- RuboCop::RakeTask.new(:rubocop) do |t|
58
- t.options << ['-D']
59
- t.patterns = ['lib/**/*.rb', 'test/**/*.rb', 'Gemfile', 'Rakefile']
65
+ if RUBY_VERSION >= '2.1.0'
66
+ RuboCop::RakeTask.new(:rubocop) do |t|
67
+ t.options << ['-D']
68
+ t.patterns = ['lib/**/*.rb', 'test/**/*.rb', 'Gemfile', 'Rakefile']
69
+ end
60
70
  end
61
71
 
62
72
  YARD::Rake::YardocTask.new(:docs) do |t|
@@ -113,7 +123,7 @@ task :ci do
113
123
  # check: https://circleci.com/docs/parallel-manual-setup/#env-splitting
114
124
  case ENV['CIRCLE_NODE_INDEX'].to_i
115
125
  when 0
116
- sh 'rvm $MRI_VERSIONS --verbose do rake test:main'
126
+ sh 'rvm $MRI_VERSIONS,$MRI_OLD_VERSIONS --verbose do rake test:main'
117
127
  sh 'rvm $LAST_STABLE --verbose do rake benchmark'
118
128
  when 1
119
129
  sh 'rvm $MRI_VERSIONS --verbose do appraisal contrib rake test:monkey'
@@ -122,19 +132,28 @@ task :ci do
122
132
  sh 'rvm $MRI_VERSIONS --verbose do appraisal contrib rake test:redis'
123
133
  sh 'rvm $MRI_VERSIONS --verbose do appraisal contrib rake test:sinatra'
124
134
  sh 'rvm $MRI_VERSIONS --verbose do appraisal contrib rake test:sidekiq'
125
- sh 'rvm $RAILS_VERSIONS --verbose do appraisal rails3-postgres-sidekiq rake test:railssidekiq'
126
- sh 'rvm $RAILS_VERSIONS --verbose do appraisal rails4-postgres-sidekiq rake test:railssidekiq'
127
- sh 'rvm $RAILS5_VERSIONS --verbose do appraisal rails5-postgres-sidekiq rake test:railssidekiq'
135
+ sh 'rvm $MRI_OLD_VERSIONS --verbose do appraisal contrib-old rake test:monkey'
136
+ sh 'rvm $MRI_OLD_VERSIONS --verbose do appraisal contrib-old rake test:elasticsearch'
137
+ sh 'rvm $MRI_OLD_VERSIONS --verbose do appraisal contrib-old rake test:http'
138
+ sh 'rvm $MRI_OLD_VERSIONS --verbose do appraisal contrib-old rake test:redis'
139
+ sh 'rvm $MRI_OLD_VERSIONS --verbose do appraisal contrib-old rake test:sinatra'
140
+ sh 'rvm $SIDEKIQ_OLD_VERSIONS --verbose do appraisal contrib-old rake test:sidekiq'
128
141
  when 2
129
- sh 'rvm $RAILS_VERSIONS --verbose do appraisal rails3-postgres rake test:rails'
130
- sh 'rvm $RAILS_VERSIONS --verbose do appraisal rails3-mysql2 rake test:rails'
131
- sh 'rvm $RAILS_VERSIONS --verbose do appraisal rails4-postgres rake test:rails'
132
- sh 'rvm $RAILS_VERSIONS --verbose do appraisal rails4-mysql2 rake test:rails'
133
- sh 'rvm $RAILS5_VERSIONS --verbose do appraisal rails5-postgres rake test:rails'
142
+ sh 'rvm $RAILS3_VERSIONS --verbose do appraisal rails3-mysql2 rake test:rails'
143
+ sh 'rvm $RAILS3_VERSIONS --verbose do appraisal rails3-postgres rake test:rails'
144
+ sh 'rvm $RAILS3_VERSIONS --verbose do appraisal rails3-postgres-redis rake test:railsredis'
145
+ sh 'rvm $RAILS4_VERSIONS --verbose do appraisal rails4-mysql2 rake test:rails'
146
+ sh 'rvm $RAILS4_VERSIONS --verbose do appraisal rails4-postgres rake test:rails'
147
+ sh 'rvm $RAILS4_VERSIONS --verbose do appraisal rails4-postgres-redis rake test:railsredis'
148
+ # Test Rails3/Sidekiq with Rails4 versions (3 vs 4) as Sidekiq requires >= 2.0 and Rails3 should support 1.9
149
+ sh 'rvm $RAILS4_VERSIONS --verbose do appraisal rails3-postgres-sidekiq rake test:railssidekiq'
150
+ sh 'rvm $RAILS4_VERSIONS --verbose do appraisal rails4-postgres-sidekiq rake test:railssidekiq'
151
+ sh 'rvm $RAILS4_VERSIONS --verbose do appraisal rails4-postgres-sidekiq rake test:railsactivejob'
134
152
  sh 'rvm $RAILS5_VERSIONS --verbose do appraisal rails5-mysql2 rake test:rails'
135
- sh 'rvm $RAILS_VERSIONS --verbose do appraisal rails3-postgres-redis rake test:railsredis'
136
- sh 'rvm $RAILS_VERSIONS --verbose do appraisal rails4-postgres-redis rake test:railsredis'
153
+ sh 'rvm $RAILS5_VERSIONS --verbose do appraisal rails5-postgres rake test:rails'
137
154
  sh 'rvm $RAILS5_VERSIONS --verbose do appraisal rails5-postgres-redis rake test:railsredis'
155
+ sh 'rvm $RAILS5_VERSIONS --verbose do appraisal rails5-postgres-sidekiq rake test:railssidekiq'
156
+ sh 'rvm $RAILS5_VERSIONS --verbose do appraisal rails5-postgres-sidekiq rake test:railsactivejob'
138
157
  else
139
158
  puts 'Too many workers than parallel tasks'
140
159
  end
data/circle.yml CHANGED
@@ -4,9 +4,12 @@ machine:
4
4
  environment:
5
5
  # FIXME: Disabled $JRUBY_VERSIONS tests because of a Java incompatibility
6
6
  LAST_STABLE: 2.4.0
7
- EARLY_STABLE: 2.1.10
8
- MRI_VERSIONS: 2.4.0,2.3.3,2.2.6,2.1.10
9
- RAILS_VERSIONS: 2.3.3,2.2.6,2.1.10
7
+ EARLY_STABLE: 2.2.6
8
+ MRI_VERSIONS: 2.4.0,2.3.3,2.2.6
9
+ MRI_OLD_VERSIONS: 2.1.10,2.0.0,1.9.3
10
+ SIDEKIQ_OLD_VERSIONS: 2.1.10,2.0.0
11
+ RAILS3_VERSIONS: 2.3.3,2.2.6,2.1.10,2.0.0,1.9.3
12
+ RAILS4_VERSIONS: 2.3.3,2.2.6,2.1.10
10
13
  RAILS5_VERSIONS: 2.3.3,2.2.6
11
14
  AGENT_BUILD_PATH: "/home/ubuntu/agent"
12
15
  TEST_DATADOG_INTEGRATION: 1
@@ -29,10 +32,10 @@ dependencies:
29
32
  - rvm get head
30
33
  - rvm install $MRI_VERSIONS
31
34
  override:
32
- - rvm $MRI_VERSIONS --verbose do gem update --system
33
- - rvm $MRI_VERSIONS --verbose do gem install bundler
34
- - rvm $MRI_VERSIONS --verbose do bundle install
35
- - rvm $MRI_VERSIONS --verbose do appraisal install
35
+ - rvm $MRI_VERSIONS,$MRI_OLD_VERSIONS --verbose do gem update --system
36
+ - rvm $MRI_VERSIONS,$MRI_OLD_VERSIONS --verbose do gem install bundler
37
+ - rvm $MRI_VERSIONS,$MRI_OLD_VERSIONS --verbose do bundle install
38
+ - rvm $MRI_VERSIONS,$MRI_OLD_VERSIONS --verbose do appraisal install
36
39
 
37
40
  test:
38
41
  override:
@@ -4,38 +4,38 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
4
  require 'ddtrace/version'
5
5
 
6
6
  Gem::Specification.new do |spec|
7
- spec.name = "ddtrace"
7
+ spec.name = 'ddtrace'
8
8
  spec.version = "#{Datadog::VERSION::STRING}#{ENV['VERSION_SUFFIX']}"
9
- spec.required_ruby_version = '>= 2.1.0'
10
- spec.authors = ["Datadog, Inc."]
11
- spec.email = ["dev@datadoghq.com"]
9
+ spec.required_ruby_version = '>= 1.9.1'
10
+ spec.authors = ['Datadog, Inc.']
11
+ spec.email = ['dev@datadoghq.com']
12
12
 
13
- spec.summary = "Datadog tracing code for your Ruby applications"
13
+ spec.summary = 'Datadog tracing code for your Ruby applications'
14
14
  spec.description = <<-EOS
15
15
  ddtrace is Datadog’s tracing client for Ruby. It is used to trace requests
16
16
  as they flow across web servers, databases and microservices so that developers
17
17
  have great visiblity into bottlenecks and troublesome requests.
18
18
  EOS
19
19
 
20
- spec.homepage = "https://github.com/DataDog/dd-trace-rb"
21
- spec.license = "BSD-3-Clause"
20
+ spec.homepage = 'https://github.com/DataDog/dd-trace-rb'
21
+ spec.license = 'BSD-3-Clause'
22
22
 
23
23
  if spec.respond_to?(:metadata)
24
- spec.metadata['allowed_push_host'] = "https://rubygems.org"
24
+ spec.metadata['allowed_push_host'] = 'https://rubygems.org'
25
25
  else
26
- raise "RubyGems 2.0 or newer is required to protect against public gem pushes."
26
+ raise 'RubyGems 2.0 or newer is required to protect against public gem pushes.'
27
27
  end
28
28
 
29
29
  spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
30
- spec.bindir = "exe"
30
+ spec.bindir = 'exe'
31
31
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
32
- spec.require_paths = ["lib"]
32
+ spec.require_paths = ['lib']
33
33
 
34
- spec.add_dependency "msgpack"
34
+ spec.add_dependency 'msgpack'
35
35
 
36
- spec.add_development_dependency "rake", "~> 12.0"
37
- spec.add_development_dependency "rubocop", "~> 0.47"
38
- spec.add_development_dependency "minitest", "~> 5.10"
39
- spec.add_development_dependency "appraisal", "~> 2.1"
40
- spec.add_development_dependency "yard", "~> 0.9"
36
+ spec.add_development_dependency 'rake', '~> 10.5'
37
+ spec.add_development_dependency('rubocop', '~> 0.47') if RUBY_VERSION >= '2.1.0'
38
+ spec.add_development_dependency 'minitest', '~> 5.10'
39
+ spec.add_development_dependency 'appraisal', '~> 2.1'
40
+ spec.add_development_dependency 'yard', '~> 0.9'
41
41
  end
@@ -403,6 +403,9 @@ overhead.
403
403
 
404
404
  The Datadog Trace Client has been tested with the following Ruby versions:
405
405
 
406
+ * Ruby MRI 1.9.1 (experimental)
407
+ * Ruby MRI 1.9.3
408
+ * Ruby MRI 2.0
406
409
  * Ruby MRI 2.1
407
410
  * Ruby MRI 2.2
408
411
  * Ruby MRI 2.3
@@ -7,6 +7,7 @@ gem "redis"
7
7
  gem "hiredis"
8
8
  gem "rack-test"
9
9
  gem "sinatra"
10
+ gem "activerecord"
10
11
  gem "sidekiq"
11
12
 
12
13
  gemspec :path => "../"
@@ -0,0 +1,14 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gem "elasticsearch-transport"
6
+ gem "redis"
7
+ gem "hiredis"
8
+ gem "rack-test", "0.6.2"
9
+ gem "rack", "1.4.7"
10
+ gem "sinatra", "1.4.5"
11
+ gem "activerecord", "3.2.22.5"
12
+ gem "sidekiq", "4.0.0"
13
+
14
+ gemspec :path => "../"
@@ -4,7 +4,7 @@ source "https://rubygems.org"
4
4
 
5
5
  gem "test-unit"
6
6
  gem "rails", "3.2.22.5"
7
- gem "pg", :platform => :ruby
7
+ gem "pg", "0.15.1", :platform => :ruby
8
8
  gem "activerecord-jdbcpostgresql-adapter", :platform => :jruby
9
9
 
10
10
  gemspec :path => "../"
@@ -4,7 +4,7 @@ source "https://rubygems.org"
4
4
 
5
5
  gem "test-unit"
6
6
  gem "rails", "3.2.22.5"
7
- gem "pg", :platform => :ruby
7
+ gem "pg", "0.15.1", :platform => :ruby
8
8
  gem "activerecord-jdbcpostgresql-adapter", :platform => :jruby
9
9
  gem "redis-rails"
10
10
 
@@ -4,7 +4,7 @@ source "https://rubygems.org"
4
4
 
5
5
  gem "test-unit"
6
6
  gem "rails", "3.2.22.5"
7
- gem "pg", :platform => :ruby
7
+ gem "pg", "0.15.1", :platform => :ruby
8
8
  gem "activerecord-jdbcpostgresql-adapter", :platform => :jruby
9
9
  gem "sidekiq"
10
10
 
@@ -6,5 +6,6 @@ gem "rails", "4.2.7.1"
6
6
  gem "pg", :platform => :ruby
7
7
  gem "activerecord-jdbcpostgresql-adapter", :platform => :jruby
8
8
  gem "sidekiq"
9
+ gem "activejob"
9
10
 
10
11
  gemspec :path => "../"
@@ -5,5 +5,6 @@ source "https://rubygems.org"
5
5
  gem "rails", "5.0.1"
6
6
  gem "pg", :platform => :ruby
7
7
  gem "sidekiq"
8
+ gem "activejob"
8
9
 
9
10
  gemspec :path => "../"
@@ -3,6 +3,14 @@
3
3
  module Datadog
4
4
  module Contrib
5
5
  module Elasticsearch
6
+ URL = 'elasticsearch.url'.freeze
7
+ METHOD = 'elasticsearch.method'.freeze
8
+ PARAMS = 'elasticsearch.params'.freeze
9
+ BODY = 'elasticsearch.body'.freeze
10
+
11
+ SERVICE = 'elasticsearch'.freeze
12
+ SPAN_TYPE = 'elasticsearch'.freeze
13
+
6
14
  # Patcher enables patching of 'elasticsearch/transport' module.
7
15
  # This is used in monkey.rb to automatically apply patches
8
16
  module Patcher
@@ -15,8 +23,15 @@ module Datadog
15
23
  if !@patched && (defined?(::Elasticsearch::Transport::VERSION) && \
16
24
  Gem::Version.new(::Elasticsearch::Transport::VERSION) >= Gem::Version.new('1.0.0'))
17
25
  begin
18
- require 'ddtrace/contrib/elasticsearch/core'
19
- ::Elasticsearch::Transport::Client.prepend Datadog::Contrib::Elasticsearch::TracedClient
26
+ require 'uri'
27
+ require 'json'
28
+ require 'ddtrace/monkey'
29
+ require 'ddtrace/pin'
30
+ require 'ddtrace/ext/app_types'
31
+ require 'ddtrace/contrib/elasticsearch/quantize'
32
+
33
+ patch_elasticsearch_transport_client()
34
+
20
35
  @patched = true
21
36
  rescue StandardError => e
22
37
  Datadog::Tracer.log.error("Unable to apply Elastic Search integration: #{e}")
@@ -25,6 +40,63 @@ module Datadog
25
40
  @patched
26
41
  end
27
42
 
43
+ # rubocop:disable Metrics/MethodLength
44
+ def patch_elasticsearch_transport_client
45
+ ::Elasticsearch::Transport::Client.class_eval do
46
+ alias_method :initialize_without_datadog, :initialize
47
+ Datadog::Monkey.without_warnings do
48
+ remove_method :initialize
49
+ end
50
+
51
+ def initialize(*args)
52
+ pin = Datadog::Pin.new(SERVICE, app: 'elasticsearch', app_type: Datadog::Ext::AppTypes::DB)
53
+ pin.onto(self)
54
+ initialize_without_datadog(*args)
55
+ end
56
+
57
+ alias_method :perform_request_without_datadog, :perform_request
58
+ remove_method :perform_request
59
+
60
+ def perform_request(*args)
61
+ pin = Datadog::Pin.get_from(self)
62
+ return perform_request_without_datadog(*args) unless pin && pin.tracer
63
+
64
+ method = args[0]
65
+ path = args[1]
66
+ params = args[2]
67
+ body = args[3]
68
+ full_url = URI.parse(path)
69
+
70
+ url = full_url.path
71
+ response = nil
72
+ pin.tracer.trace('elasticsearch.query') do |span|
73
+ begin
74
+ span.service = pin.service
75
+ span.span_type = SPAN_TYPE
76
+
77
+ # load JSON for the following fields unless they're already strings
78
+ params = JSON.generate(params) if params && !params.is_a?(String)
79
+ body = JSON.generate(body) if body && !body.is_a?(String)
80
+
81
+ span.set_tag(METHOD, method)
82
+ span.set_tag(URL, url)
83
+ span.set_tag(PARAMS, params) if params
84
+ span.set_tag(BODY, body) if body
85
+
86
+ quantized_url = Datadog::Contrib::Elasticsearch::Quantize.format_url(url)
87
+ span.resource = "#{method} #{quantized_url}"
88
+ rescue StandardError => e
89
+ Datadog::Tracer.log.error(e.message)
90
+ ensure
91
+ # the call is still executed
92
+ response = perform_request_without_datadog(*args)
93
+ end
94
+ end
95
+ response
96
+ end
97
+ end
98
+ end
99
+
28
100
  # patched? tells wether patch has been successfully applied
29
101
  def patched?
30
102
  @patched
@@ -18,7 +18,7 @@ module Datadog
18
18
  # we don't want to trace our own call to the API (they use net/http)
19
19
  # when we know the host & port (from the URI) we use it, else (most-likely
20
20
  # called with a block) rely on the URL at the end.
21
- if req.uri
21
+ if req.respond_to?(:uri) && req.uri
22
22
  if req.uri.host.to_s == transport.hostname.to_s &&
23
23
  req.uri.port.to_i == transport.port.to_i
24
24
  return true
@@ -96,14 +96,14 @@ module Datadog
96
96
  span.service = pin.service
97
97
  span.span_type = Datadog::Ext::HTTP::TYPE
98
98
 
99
- span.resource = req.path
100
- # *NOT* filling Datadog::Ext::HTTP::URL as it's already in resource.
101
- # The agent can then decide to quantize the URL and store the original,
102
- # untouched data in http.url but the client should not send redundant fields.
99
+ span.resource = req.method
100
+ # Using the method as a resource, as URL/path can trigger
101
+ # a possibly infinite number of resources.
102
+ span.set_tag(Datadog::Ext::HTTP::URL, req.path)
103
103
  span.set_tag(Datadog::Ext::HTTP::METHOD, req.method)
104
104
  response = request_without_datadog(req, body, &block)
105
105
  span.set_tag(Datadog::Ext::HTTP::STATUS_CODE, response.code)
106
- if req.uri
106
+ if req.respond_to?(:uri) && req.uri
107
107
  span.set_tag(Datadog::Ext::NET::TARGET_HOST, req.uri.host)
108
108
  span.set_tag(Datadog::Ext::NET::TARGET_PORT, req.uri.port.to_s)
109
109
  else
@@ -51,17 +51,22 @@ module Datadog
51
51
  if payload[:exception].nil?
52
52
  # [christian] in some cases :status is not defined,
53
53
  # rather than firing an error, simply acknowledge we don't know it.
54
- span.set_tag(Datadog::Ext::HTTP::STATUS_CODE, payload.fetch(:status, '?').to_s)
54
+ status = payload.fetch(:status, '?').to_s
55
+ if status.starts_with?('5')
56
+ span.status = 1
57
+ span.set_tag(Datadog::Ext::Errors::STACK, caller().join('\n'))
58
+ end
59
+ span.set_tag(Datadog::Ext::HTTP::STATUS_CODE, status)
55
60
  else
56
61
  error = payload[:exception]
57
- # TODO[manu]: it's right to have a 500? there are cases in Rails that let
58
- # user to recover the error after this point?
59
62
  span.status = 1
60
63
  span.set_tag(Datadog::Ext::Errors::TYPE, error[0])
61
64
  span.set_tag(Datadog::Ext::Errors::MSG, error[1])
62
- span.set_tag(Datadog::Ext::HTTP::STATUS_CODE, '500')
65
+ span.set_tag(Datadog::Ext::Errors::STACK, caller().join('\n'))
66
+ # [manu,christian]: it's right to have a 500? there are cases in Rails that let
67
+ # user to recover the error after this point?
68
+ span.set_tag(Datadog::Ext::HTTP::STATUS_CODE, payload.fetch(:status, '500').to_s)
63
69
  end
64
-
65
70
  ensure
66
71
  span.start_time = start
67
72
  span.finish_at(finish)
@@ -81,7 +81,6 @@ module Datadog
81
81
  span.set_tag(Datadog::Ext::Errors::TYPE, error[0])
82
82
  span.set_tag(Datadog::Ext::Errors::MSG, error[1])
83
83
  end
84
-
85
84
  ensure
86
85
  span.start_time = start
87
86
  span.finish_at(finish)
@@ -110,7 +109,6 @@ module Datadog
110
109
  span.set_tag(Datadog::Ext::Errors::TYPE, error[0])
111
110
  span.set_tag(Datadog::Ext::Errors::MSG, error[1])
112
111
  end
113
-
114
112
  ensure
115
113
  span.start_time = start
116
114
  span.finish_at(finish)
@@ -31,11 +31,20 @@ module Datadog
31
31
  span_type: span_type
32
32
  )
33
33
 
34
+ # find out if the SQL query has been cached in this request. This meta is really
35
+ # helpful to users because some spans may have 0ns of duration because the query
36
+ # is simply cached from memory, so the notification is fired with start == finish.
37
+ # TODO[manu]: this feature has been merged into master but has not yet released.
38
+ # We're supporting this action as a best effort, but we should add a test after
39
+ # a new version of Rails is out.
40
+ cached = payload[:cached]
41
+
34
42
  # the span should have the query ONLY in the Resource attribute,
35
43
  # so that the ``sql.query`` tag will be set in the agent with an
36
44
  # obfuscated version
37
45
  span.span_type = Datadog::Ext::SQL::TYPE
38
46
  span.set_tag('rails.db.vendor', adapter_name)
47
+ span.set_tag('rails.db.cached', cached) if cached
39
48
  span.start_time = start
40
49
  span.finish_at(finish)
41
50
  rescue StandardError => e
@@ -104,7 +104,6 @@ module Datadog
104
104
  span.set_tag(Datadog::Ext::Errors::TYPE, error[0])
105
105
  span.set_tag(Datadog::Ext::Errors::MSG, error[1])
106
106
  end
107
-
108
107
  ensure
109
108
  span.start_time = start
110
109
  span.finish_at(finish)
@@ -1,106 +1,112 @@
1
1
  module Datadog
2
- # TODO[manu]: write docs
3
- module RendererExtension
4
- def render_template(*args)
5
- ActiveSupport::Notifications.instrument('start_render_template.action_view')
6
- super(*args)
7
- end
8
- end
9
-
10
- # TODO[manu]: write docs
11
- module PartialRendererExtension
12
- def render_partial(*args)
13
- ActiveSupport::Notifications.instrument('start_render_partial.action_view')
14
- super(*args)
15
- end
16
- end
17
-
18
- # CacheStoreReadExtension contains a new read function that notifies
19
- # the framework of a read, then calls read.
20
- module CacheStoreReadExtension
21
- def read(*args)
22
- ActiveSupport::Notifications.instrument('start_cache_read.active_support')
23
- super(*args)
24
- end
25
- end
26
-
27
- # CacheStoreFetchExtension contains a new fetch function that notifies
28
- # the framework of a fetch, then calls fetch.
29
- module CacheStoreFetchExtension
30
- # It might seem redundant to instrument both read and fetch since
31
- # fetch very often calls read. But there's no garantee of this, in
32
- # some cases fetch can call directly read_entry without calling read.
33
- def fetch(*args)
34
- ActiveSupport::Notifications.instrument('start_cache_fetch.active_support')
35
- super(*args)
36
- end
37
- end
2
+ # RailsPatcher contains function to patch the Rails libraries.
3
+ module RailsPatcher
4
+ module_function
38
5
 
39
- # CacheWriteReadExtension contains a new read function that notifies
40
- # the framework of a write, then calls write.
41
- module CacheStoreWriteExtension
42
- def write(*args)
43
- ActiveSupport::Notifications.instrument('start_cache_write.active_support')
44
- super(*args)
6
+ def patch_renderer
7
+ patch_renderer_render_template
8
+ patch_renderer_render_partial
45
9
  end
46
- end
47
10
 
48
- # CacheDeleteExtension contains a new read function that notifies
49
- # the framework of a delete, then calls delete.
50
- module CacheStoreDeleteExtension
51
- def delete(*args)
52
- ActiveSupport::Notifications.instrument('start_cache_delete.active_support')
53
- super(*args)
11
+ def patch_cache_store
12
+ patch_cache_store_read
13
+ patch_cache_store_fetch
14
+ patch_cache_store_write
15
+ patch_cache_store_delete
16
+ patch_cache_store_instrument
54
17
  end
55
- end
56
18
 
57
- # CacheInstrumentExtension prepends the instrument function that Rails 3.x uses
58
- # to know if the underlying cache should be instrumented or not. By default,
59
- # we force that instrumentation if the Rails application is auto instrumented.
60
- module CacheInstrumentExtension
61
- def instrument
62
- true
19
+ def patch_renderer_render_template
20
+ ::ActionView::Renderer.class_eval do
21
+ alias_method :render_template_without_datadog, :render_template
22
+ def render_template(*args, &block)
23
+ ActiveSupport::Notifications.instrument('start_render_template.action_view')
24
+ render_template_without_datadog(*args, &block)
25
+ end
26
+ end
63
27
  end
64
- end
65
28
 
66
- # RailsPatcher contains function to patch the Rails libraries.
67
- module RailsPatcher
68
- module_function
69
-
70
- def patch_renderer
71
- ::ActionView::Renderer.prepend Datadog::RendererExtension
72
- ::ActionView::PartialRenderer.prepend Datadog::PartialRendererExtension
29
+ def patch_renderer_render_partial
30
+ ::ActionView::PartialRenderer.class_eval do
31
+ alias_method :render_partial_without_datadog, :render_partial
32
+ def render_partial(*args, &block)
33
+ ActiveSupport::Notifications.instrument('start_render_partial.action_view')
34
+ render_partial_without_datadog(*args, &block)
35
+ end
36
+ end
73
37
  end
74
38
 
75
- def patch_cache_store
39
+ def cache_store_class(k)
76
40
  # When Redis is used, we can't only patch Cache::Store as it is
77
41
  # Cache::RedisStore, a sub-class of it that is used, in practice.
78
42
  # We need to do a per-method monkey patching as some of them might
79
43
  # be redefined, and some of them not. The latest version of redis-activesupport
80
44
  # redefines write but leaves untouched read and delete:
81
45
  # https://github.com/redis-store/redis-activesupport/blob/master/lib/active_support/cache/redis_store.rb
46
+ c = if defined?(::ActiveSupport::Cache::RedisStore) &&
47
+ ::ActiveSupport::Cache::RedisStore.instance_methods(false).include?(k)
48
+ ::ActiveSupport::Cache::RedisStore
49
+ else
50
+ ::ActiveSupport::Cache::Store
51
+ end
52
+ c
53
+ end
82
54
 
83
- { read: Datadog::CacheStoreReadExtension,
84
- fetch: Datadog::CacheStoreFetchExtension,
85
- write: Datadog::CacheStoreWriteExtension,
86
- delete: Datadog::CacheStoreDeleteExtension }.each do |k, v|
87
- c = if defined?(::ActiveSupport::Cache::RedisStore) &&
88
- ::ActiveSupport::Cache::RedisStore.instance_methods(false).include?(k)
89
- ::ActiveSupport::Cache::RedisStore
90
- else
91
- ::ActiveSupport::Cache::Store
92
- end
93
- Datadog::Tracer.log.debug("monkey patching #{c}.#{k} with #{v}.#{k}")
94
- c.prepend v
55
+ def patch_cache_store_read
56
+ cache_store_class(:read).class_eval do
57
+ alias_method :read_without_datadog, :read
58
+ def read(*args, &block)
59
+ ActiveSupport::Notifications.instrument('start_cache_read.active_support')
60
+ read_without_datadog(*args, &block)
61
+ end
95
62
  end
63
+ end
96
64
 
65
+ def patch_cache_store_fetch
66
+ cache_store_class(:fetch).class_eval do
67
+ alias_method :fetch_without_datadog, :fetch
68
+ def fetch(*args, &block)
69
+ ActiveSupport::Notifications.instrument('start_cache_fetch.active_support')
70
+ fetch_without_datadog(*args, &block)
71
+ end
72
+ end
73
+ end
74
+
75
+ def patch_cache_store_write
76
+ cache_store_class(:write).class_eval do
77
+ alias_method :write_without_datadog, :write
78
+ def write(*args, &block)
79
+ ActiveSupport::Notifications.instrument('start_cache_write.active_support')
80
+ write_without_datadog(*args, &block)
81
+ end
82
+ end
83
+ end
84
+
85
+ def patch_cache_store_delete
86
+ cache_store_class(:delete).class_eval do
87
+ alias_method :delete_without_datadog, :delete
88
+ def delete(*args, &block)
89
+ ActiveSupport::Notifications.instrument('start_cache_delete.active_support')
90
+ delete_without_datadog(*args, &block)
91
+ end
92
+ end
93
+ end
94
+
95
+ def patch_cache_store_instrument
97
96
  # by default, Rails 3 doesn't instrument the cache system so we should turn it on
98
97
  # using the ActiveSupport::Cache::Store.instrument= function. Unfortunately, early
99
98
  # versions of Rails use a Thread.current store that is not compatible with some
100
99
  # application servers like Passenger.
101
100
  # More details: https://github.com/rails/rails/blob/v3.2.22.5/activesupport/lib/active_support/cache.rb#L175-L177
102
101
  return unless ::Rails::VERSION::MAJOR.to_i == 3
103
- ::ActiveSupport::Cache::Store.singleton_class.prepend Datadog::CacheInstrumentExtension
102
+ ::ActiveSupport::Cache::Store.singleton_class.class_eval do
103
+ # Add the instrument function that Rails 3.x uses
104
+ # to know if the underlying cache should be instrumented or not. By default,
105
+ # we force that instrumentation if the Rails application is auto instrumented.
106
+ def instrument
107
+ true
108
+ end
109
+ end
104
110
  end
105
111
  end
106
112
  end
@@ -23,6 +23,7 @@ module Datadog
23
23
  return name.to_s
24
24
  end
25
25
 
26
+ # TODO: Consider moving this out of Rails.
26
27
  # Return a canonical name for a type of database
27
28
  def self.normalize_vendor(vendor)
28
29
  case vendor
@@ -25,7 +25,7 @@ module Datadog
25
25
 
26
26
  # Middleware is a Sidekiq server-side middleware which traces executed jobs
27
27
  class Tracer
28
- def initialize(options)
28
+ def initialize(options = {})
29
29
  # check if Rails configuration is available and use it to override
30
30
  # Sidekiq defaults
31
31
  rails_config = ::Rails.configuration.datadog_trace rescue {}
@@ -54,7 +54,14 @@ module Datadog
54
54
 
55
55
  def call(worker, job, queue)
56
56
  @tracer.trace('sidekiq.job', service: @sidekiq_service, span_type: 'job') do |span|
57
- span.resource = job['class']
57
+ if job['wrapped']
58
+ # If class is wrapping something else, the interesting resource info
59
+ # is the underlying, wrapped class, and not the wrapper.
60
+ span.resource = job['wrapped']
61
+ span.set_tag('sidekiq.job.wrapper', job['class'])
62
+ else
63
+ span.resource = job['class']
64
+ end
58
65
  span.set_tag('sidekiq.job.id', job['jid'])
59
66
  span.set_tag('sidekiq.job.retry', job['retry'])
60
67
  span.set_tag('sidekiq.job.queue', job['queue'])
@@ -35,7 +35,7 @@ module Datadog
35
35
  @cfg = DEFAULT_CFG.dup()
36
36
  end
37
37
 
38
- def configure(**args)
38
+ def configure(args = {})
39
39
  args.each do |name, value|
40
40
  self[name] = value
41
41
  end
@@ -48,7 +48,7 @@ module Datadog
48
48
 
49
49
  def get_patched_modules
50
50
  patched = autopatch_modules
51
- @autopatch_modules.each do |k, v|
51
+ @patchers.each do |k, v|
52
52
  @mutex.synchronize do
53
53
  if v
54
54
  patcher = @patchers[k]
@@ -17,13 +17,14 @@ module Datadog
17
17
  attr_accessor :name
18
18
  attr_accessor :tracer
19
19
 
20
- def initialize(service, app: nil, tags: nil, app_type: nil, tracer: Datadog.tracer)
20
+ # [ruby19] named parameters would be more idiomatic here, but would break backward compatibility
21
+ def initialize(service, options = { app: nil, tags: nil, app_type: nil, tracer: nil })
21
22
  @service = service
22
- @app = app
23
- @tags = tags
24
- @app_type = app_type
23
+ @app = options[:app]
24
+ @tags = options[:tags]
25
+ @app_type = options[:app_type]
25
26
  @name = nil # this would rarely be overriden as it's really span-specific
26
- @tracer = tracer
27
+ @tracer = options[:tracer] || Datadog.tracer
27
28
  end
28
29
 
29
30
  def enabled?
@@ -86,7 +86,7 @@ module Datadog
86
86
  @status = 1
87
87
  @meta[Datadog::Ext::Errors::MSG] = e.message if e.respond_to?(:message) && e.message
88
88
  @meta[Datadog::Ext::Errors::TYPE] = e.class.to_s
89
- @meta[Datadog::Ext::Errors::STACK] = e.backtrace.join("\n") if e.respond_to?(:backtrace) && e.backtrace
89
+ @meta[Datadog::Ext::Errors::STACK] = e.backtrace.join('\n') if e.respond_to?(:backtrace) && e.backtrace
90
90
  end
91
91
 
92
92
  # Mark the span finished at the current time and submit it.
@@ -1,7 +1,7 @@
1
1
  module Datadog
2
2
  module VERSION
3
3
  MAJOR = 0
4
- MINOR = 5
4
+ MINOR = 6
5
5
  PATCH = 0
6
6
 
7
7
  STRING = [MAJOR, MINOR, PATCH].compact.join('.')
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.5.0
4
+ version: 0.6.0
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-03-08 00:00:00.000000000 Z
11
+ date: 2017-03-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: msgpack
@@ -30,14 +30,14 @@ dependencies:
30
30
  requirements:
31
31
  - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: '12.0'
33
+ version: '10.5'
34
34
  type: :development
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
- version: '12.0'
40
+ version: '10.5'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: rubocop
43
43
  requirement: !ruby/object:Gem::Requirement
@@ -118,6 +118,7 @@ files:
118
118
  - docker-compose.yml
119
119
  - docs/GettingStarted.md
120
120
  - gemfiles/contrib.gemfile
121
+ - gemfiles/contrib_old.gemfile
121
122
  - gemfiles/rails3_mysql2.gemfile
122
123
  - gemfiles/rails3_postgres.gemfile
123
124
  - gemfiles/rails3_postgres_redis.gemfile
@@ -132,7 +133,6 @@ files:
132
133
  - gemfiles/rails5_postgres_sidekiq.gemfile
133
134
  - lib/ddtrace.rb
134
135
  - lib/ddtrace/buffer.rb
135
- - lib/ddtrace/contrib/elasticsearch/core.rb
136
136
  - lib/ddtrace/contrib/elasticsearch/patcher.rb
137
137
  - lib/ddtrace/contrib/elasticsearch/quantize.rb
138
138
  - lib/ddtrace/contrib/http/patcher.rb
@@ -179,7 +179,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
179
179
  requirements:
180
180
  - - ">="
181
181
  - !ruby/object:Gem::Version
182
- version: 2.1.0
182
+ version: 1.9.1
183
183
  required_rubygems_version: !ruby/object:Gem::Requirement
184
184
  requirements:
185
185
  - - ">="
@@ -187,7 +187,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
187
187
  version: '0'
188
188
  requirements: []
189
189
  rubyforge_project:
190
- rubygems_version: 2.5.1
190
+ rubygems_version: 2.6.11
191
191
  signing_key:
192
192
  specification_version: 4
193
193
  summary: Datadog tracing code for your Ruby applications
@@ -1,66 +0,0 @@
1
- require 'uri'
2
- require 'ddtrace/pin'
3
- require 'ddtrace/ext/app_types'
4
- require 'json'
5
- require 'ddtrace/contrib/elasticsearch/quantize'
6
-
7
- module Datadog
8
- module Contrib
9
- module Elasticsearch
10
- URL = 'elasticsearch.url'.freeze
11
- METHOD = 'elasticsearch.method'.freeze
12
- PARAMS = 'elasticsearch.params'.freeze
13
- BODY = 'elasticsearch.body'.freeze
14
-
15
- SERVICE = 'elasticsearch'.freeze
16
- SPAN_TYPE = 'elasticsearch'.freeze
17
-
18
- # Datadog APM Elastic Search integration.
19
- module TracedClient
20
- def initialize(*)
21
- pin = Datadog::Pin.new(SERVICE, app: 'elasticsearch', app_type: Datadog::Ext::AppTypes::DB)
22
- pin.onto(self)
23
- super
24
- end
25
-
26
- def perform_request(*args)
27
- pin = Datadog::Pin.get_from(self)
28
- return super unless pin && pin.tracer
29
-
30
- method = args[0]
31
- path = args[1]
32
- params = args[2]
33
- body = args[3]
34
- full_url = URI.parse(path)
35
-
36
- url = full_url.path
37
- response = nil
38
- pin.tracer.trace('elasticsearch.query') do |span|
39
- begin
40
- span.service = pin.service
41
- span.span_type = SPAN_TYPE
42
-
43
- # load JSON for the following fields unless they're already strings
44
- params = JSON.generate(params) if params && !params.is_a?(String)
45
- body = JSON.generate(body) if body && !body.is_a?(String)
46
-
47
- span.set_tag(METHOD, method)
48
- span.set_tag(URL, url)
49
- span.set_tag(PARAMS, params) if params
50
- span.set_tag(BODY, body) if body
51
-
52
- quantized_url = Datadog::Contrib::Elasticsearch::Quantize.format_url(url)
53
- span.resource = "#{method} #{quantized_url}"
54
- rescue StandardError => e
55
- Datadog::Tracer.log.error(e.message)
56
- ensure
57
- # the call is still executed
58
- response = super(*args)
59
- end
60
- end
61
- response
62
- end
63
- end
64
- end
65
- end
66
- end