ddtrace 0.11.3 → 0.11.4

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: f346610fe35749be53eaf03db7fc190790e39e7a
4
- data.tar.gz: c4ec02969569dd14ddde32e0018e870872efd491
3
+ metadata.gz: 31d6da2597a1d5479adcaf45268088c482e72d30
4
+ data.tar.gz: e36b2dcb51d0f780ab15f365c9e5ad3989509e81
5
5
  SHA512:
6
- metadata.gz: 7ef4b64aca16574394a2cb94b2c601a69e01f81563b2ca3db981714e19635dbfba3457827747a1f88ccba2b215ef3c891172f6e12a1d4f0075288401a460018e
7
- data.tar.gz: 232e89d0f09f137fbdef9ee286526a73d92bb2294cb0909d705cae20eddeaa0da1e04b2ae6cc6f4db8f22949e5d263c6972149bedcb2fca3171409ce830a674b
6
+ metadata.gz: 91cae89a7b193e57861cbb78bc456bae57c1edfe5d3e65869245be105e826fabe604477c34f21c95846f1173b3df80de4889da780b91854c9dd69589766eb1a7
7
+ data.tar.gz: 2323a8f95dd92228c607f92550dccf30268369444f2595dcb52673da74cb4a548c363ab46b631a81ddd3d812f2ed0e8f4abafe91d63fb90caca64ea91cde55ef
data/Appraisals CHANGED
@@ -57,7 +57,7 @@ if RUBY_VERSION < '2.4.0' && RUBY_PLATFORM != 'java'
57
57
  if RUBY_VERSION >= '2.1.10'
58
58
  appraise 'rails4-mysql2' do
59
59
  gem 'rails', '4.2.7.1'
60
- gem 'mysql2', platform: :ruby
60
+ gem 'mysql2', '< 0.5', platform: :ruby
61
61
  gem 'activerecord-jdbcmysql-adapter', platform: :jruby
62
62
  end
63
63
 
@@ -79,7 +79,7 @@ if RUBY_VERSION < '2.4.0' && RUBY_PLATFORM != 'java'
79
79
  if RUBY_VERSION >= '2.2.2'
80
80
  appraise 'rails5-mysql2' do
81
81
  gem 'rails', '5.0.1'
82
- gem 'mysql2', platform: :ruby
82
+ gem 'mysql2', '< 0.5', platform: :ruby
83
83
  end
84
84
 
85
85
  appraise 'rails5-postgres' do
@@ -129,7 +129,7 @@ if RUBY_VERSION >= '2.2.2' && RUBY_PLATFORM != 'java'
129
129
  gem 'dalli'
130
130
  gem 'resque', '< 2.0'
131
131
  gem 'racecar', '>= 0.3.5'
132
- gem 'mysql2', platform: :ruby
132
+ gem 'mysql2', '< 0.5', platform: :ruby
133
133
  end
134
134
  else
135
135
  appraise 'contrib-old' do
@@ -24,6 +24,17 @@ Git diff: https://github.com/DataDog/dd-trace-rb/compare/v0.11.2...v0.12.0.beta1
24
24
  - ActiveRecord object instantiation tracing (#311, #334)
25
25
  - `http.request_id` tag to Rack spans (#335)
26
26
 
27
+ ## [0.11.4] - 2018-03-29
28
+
29
+ Release notes: https://github.com/DataDog/dd-trace-rb/releases/tag/v0.11.4
30
+
31
+ Git diff: https://github.com/DataDog/dd-trace-rb/compare/v0.11.3...v0.11.4
32
+
33
+ ### Fixed
34
+ - Transport body parsing when downgrading (#369)
35
+ - Transport incorrectly attempting to apply sampling to service metadata (#370)
36
+ - `sql.active_record` traces showing incorrect adapter settings when non-default adapter used (#383)
37
+
27
38
  ## [0.11.3] - 2018-03-06
28
39
 
29
40
  Release notes: https://github.com/DataDog/dd-trace-rb/releases/tag/v0.11.3
@@ -214,6 +225,7 @@ Git diff: https://github.com/DataDog/dd-trace-rb/compare/v0.3.0...v0.3.1
214
225
  [Unreleased (beta)]: https://github.com/DataDog/dd-trace-rb/compare/v0.12.0.beta2...0.12-dev
215
226
  [0.12.0.beta2]: https://github.com/DataDog/dd-trace-rb/compare/v0.12.0.beta1...v0.12.0.beta2
216
227
  [0.12.0.beta1]: https://github.com/DataDog/dd-trace-rb/compare/v0.11.2...v0.12.0.beta1
228
+ [0.11.4]: https://github.com/DataDog/dd-trace-rb/compare/v0.11.3...v0.11.4
217
229
  [0.11.3]: https://github.com/DataDog/dd-trace-rb/compare/v0.11.2...v0.11.3
218
230
  [0.11.2]: https://github.com/DataDog/dd-trace-rb/compare/v0.11.1...v0.11.2
219
231
  [0.11.1]: https://github.com/DataDog/dd-trace-rb/compare/v0.11.0...v0.11.1
@@ -19,6 +19,6 @@ gem "sucker_punch"
19
19
  gem "dalli"
20
20
  gem "resque", "< 2.0"
21
21
  gem "racecar", ">= 0.3.5"
22
- gem "mysql2", platform: :ruby
22
+ gem "mysql2", "< 0.5", platform: :ruby
23
23
 
24
24
  gemspec path: "../"
@@ -4,7 +4,7 @@ source "https://rubygems.org"
4
4
 
5
5
  gem "pry-nav", git: "https://github.com/nixme/pry-nav.git", branch: "master"
6
6
  gem "rails", "4.2.7.1"
7
- gem "mysql2", platform: :ruby
7
+ gem "mysql2", "< 0.5", platform: :ruby
8
8
  gem "activerecord-jdbcmysql-adapter", platform: :jruby
9
9
 
10
10
  gemspec path: "../"
@@ -4,6 +4,6 @@ source "https://rubygems.org"
4
4
 
5
5
  gem "pry-nav", git: "https://github.com/nixme/pry-nav.git", branch: "master"
6
6
  gem "rails", "5.0.1"
7
- gem "mysql2", platform: :ruby
7
+ gem "mysql2", "< 0.5", platform: :ruby
8
8
 
9
9
  gemspec path: "../"
@@ -42,35 +42,20 @@ module Datadog
42
42
  end
43
43
  end
44
44
 
45
- def self.adapter_name
46
- @adapter_name ||= Datadog::Contrib::Rails::Utils.adapter_name
47
- end
48
-
49
- def self.database_name
50
- @database_name ||= Datadog::Contrib::Rails::Utils.database_name
51
- end
52
-
53
- def self.adapter_host
54
- @adapter_host ||= Datadog::Contrib::Rails::Utils.adapter_host
55
- end
56
-
57
- def self.adapter_port
58
- @adapter_port ||= Datadog::Contrib::Rails::Utils.adapter_port
59
- end
60
-
61
45
  def self.database_service
62
46
  return @database_service if defined?(@database_service)
63
47
 
64
- @database_service = get_option(:service_name) || adapter_name
48
+ @database_service = get_option(:service_name) || Datadog::Contrib::Rails::Utils.adapter_name
65
49
  get_option(:tracer).set_service_info(@database_service, 'active_record', Ext::AppTypes::DB)
66
50
  @database_service
67
51
  end
68
52
 
69
53
  def self.sql(_name, start, finish, _id, payload)
70
54
  span_type = Datadog::Ext::SQL::TYPE
55
+ connection_config = Datadog::Contrib::Rails::Utils.connection_config(payload[:connection_id])
71
56
 
72
57
  span = get_option(:tracer).trace(
73
- "#{adapter_name}.query",
58
+ "#{connection_config[:adapter_name]}.query",
74
59
  resource: payload.fetch(:sql),
75
60
  service: database_service,
76
61
  span_type: span_type
@@ -85,11 +70,11 @@ module Datadog
85
70
  # so that the ``sql.query`` tag will be set in the agent with an
86
71
  # obfuscated version
87
72
  span.span_type = Datadog::Ext::SQL::TYPE
88
- span.set_tag('active_record.db.vendor', adapter_name)
89
- span.set_tag('active_record.db.name', database_name)
73
+ span.set_tag('active_record.db.vendor', connection_config[:adapter_name])
74
+ span.set_tag('active_record.db.name', connection_config[:database_name])
90
75
  span.set_tag('active_record.db.cached', cached) if cached
91
- span.set_tag('out.host', adapter_host)
92
- span.set_tag('out.port', adapter_port)
76
+ span.set_tag('out.host', connection_config[:adapter_host])
77
+ span.set_tag('out.port', connection_config[:adapter_port])
93
78
  span.start_time = start
94
79
  span.finish(finish)
95
80
  rescue StandardError => e
@@ -24,14 +24,11 @@ module Datadog
24
24
  def self.sql(_name, start, finish, _id, payload)
25
25
  tracer = Datadog.configuration[:rails][:tracer]
26
26
  database_service = Datadog.configuration[:rails][:database_service]
27
- adapter_name = Datadog::Contrib::Rails::Utils.adapter_name
28
- database_name = Datadog::Contrib::Rails::Utils.database_name
29
- adapter_host = Datadog::Contrib::Rails::Utils.adapter_host
30
- adapter_port = Datadog::Contrib::Rails::Utils.adapter_port
27
+ connection_config = Datadog::Contrib::Rails::Utils.connection_config(payload[:connection_id])
31
28
  span_type = Datadog::Ext::SQL::TYPE
32
29
 
33
30
  span = tracer.trace(
34
- "#{adapter_name}.query",
31
+ "#{connection_config[:adapter_name]}.query",
35
32
  resource: payload.fetch(:sql),
36
33
  service: database_service,
37
34
  span_type: span_type
@@ -46,11 +43,11 @@ module Datadog
46
43
  # so that the ``sql.query`` tag will be set in the agent with an
47
44
  # obfuscated version
48
45
  span.span_type = Datadog::Ext::SQL::TYPE
49
- span.set_tag('rails.db.vendor', adapter_name)
50
- span.set_tag('rails.db.name', database_name)
46
+ span.set_tag('rails.db.vendor', connection_config[:adapter_name])
47
+ span.set_tag('rails.db.name', connection_config[:database_name])
51
48
  span.set_tag('rails.db.cached', cached) if cached
52
- span.set_tag('out.host', adapter_host)
53
- span.set_tag('out.port', adapter_port)
49
+ span.set_tag('out.host', connection_config[:adapter_host])
50
+ span.set_tag('out.port', connection_config[:adapter_port])
54
51
  span.start_time = start
55
52
  span.finish(finish)
56
53
  rescue StandardError => e
@@ -47,31 +47,66 @@ module Datadog
47
47
  end
48
48
 
49
49
  def self.adapter_name
50
- normalize_vendor(connection_config[:adapter])
50
+ connection_config[:adapter_name]
51
51
  end
52
52
 
53
53
  def self.database_name
54
- connection_config[:database]
54
+ connection_config[:database_name]
55
55
  end
56
56
 
57
57
  def self.adapter_host
58
- connection_config[:host]
58
+ connection_config[:adapter_host]
59
59
  end
60
60
 
61
61
  def self.adapter_port
62
- connection_config[:port]
62
+ connection_config[:adapter_port]
63
63
  end
64
64
 
65
- def self.connection_config
66
- @connection_config ||= begin
67
- if defined?(::ActiveRecord::Base.connection_config)
68
- ::ActiveRecord::Base.connection_config
69
- else
70
- ::ActiveRecord::Base.connection_pool.spec.config
71
- end
65
+ def self.connection_config(object_id = nil)
66
+ config = object_id.nil? ? default_connection_config : connection_config_by_id(object_id)
67
+ {
68
+ adapter_name: normalize_vendor(config[:adapter]),
69
+ adapter_host: config[:host],
70
+ adapter_port: config[:port],
71
+ database_name: config[:database]
72
+ }
73
+ end
74
+
75
+ # Attempt to retrieve the connection from an object ID.
76
+ def self.connection_by_id(object_id)
77
+ return nil if object_id.nil?
78
+ ObjectSpace._id2ref(object_id)
79
+ rescue StandardError
80
+ nil
81
+ end
82
+
83
+ # Attempt to retrieve the connection config from an object ID.
84
+ # Typical of ActiveSupport::Notifications `sql.active_record`
85
+ def self.connection_config_by_id(object_id)
86
+ connection = connection_by_id(object_id)
87
+ return {} if connection.nil?
88
+
89
+ if connection.instance_variable_defined?(:@config)
90
+ connection.instance_variable_get(:@config)
91
+ else
92
+ {}
72
93
  end
73
94
  end
74
95
 
96
+ def self.default_connection_config
97
+ return @default_connection_config unless @default_connection_config.nil?
98
+ current_connection_name = if ::ActiveRecord::Base.respond_to?(:connection_specification_name)
99
+ ::ActiveRecord::Base.connection_specification_name
100
+ else
101
+ ::ActiveRecord::Base
102
+ end
103
+
104
+ connection_pool = ::ActiveRecord::Base.connection_handler.retrieve_connection_pool(current_connection_name)
105
+ connection_pool.nil? ? {} : (@default_connection_config = connection_pool.spec.config)
106
+ rescue StandardError
107
+ {}
108
+ end
109
+
75
110
  def self.exception_is_error?(exception)
76
111
  if defined?(::ActionDispatch::ExceptionWrapper)
77
112
  # Gets the equivalent status code for the exception (not all are 5XX)
@@ -83,8 +118,6 @@ module Datadog
83
118
  true
84
119
  end
85
120
  end
86
-
87
- private_class_method :connection_config
88
121
  end
89
122
  end
90
123
  end
@@ -8,6 +8,7 @@ module Datadog
8
8
  # Transport class that handles the spans delivery to the
9
9
  # local trace-agent. The class wraps a Net:HTTP instance
10
10
  # so that the Transport is thread-safe.
11
+ # rubocop:disable Metrics/ClassLength
11
12
  class HTTPTransport
12
13
  attr_accessor :hostname, :port
13
14
  attr_reader :traces_endpoint, :services_endpoint
@@ -21,18 +22,21 @@ module Datadog
21
22
 
22
23
  API = {
23
24
  V4 = 'v0.4'.freeze => {
25
+ version: V4,
24
26
  traces_endpoint: '/v0.4/traces'.freeze,
25
27
  services_endpoint: '/v0.4/services'.freeze,
26
28
  encoder: Encoding::MsgpackEncoder,
27
29
  fallback: 'v0.3'.freeze
28
30
  }.freeze,
29
31
  V3 = 'v0.3'.freeze => {
32
+ version: V3,
30
33
  traces_endpoint: '/v0.3/traces'.freeze,
31
34
  services_endpoint: '/v0.3/services'.freeze,
32
35
  encoder: Encoding::MsgpackEncoder,
33
36
  fallback: 'v0.2'.freeze
34
37
  }.freeze,
35
38
  V2 = 'v0.2'.freeze => {
39
+ version: V2,
36
40
  traces_endpoint: '/v0.2/traces'.freeze,
37
41
  services_endpoint: '/v0.2/services'.freeze,
38
42
  encoder: Encoding::JSONEncoder
@@ -71,34 +75,45 @@ module Datadog
71
75
  case endpoint
72
76
  when :services
73
77
  payload = @encoder.encode_services(data)
74
- status_code = post(@api[:services_endpoint], payload)
78
+ status_code = post(@api[:services_endpoint], payload) do |response|
79
+ process_callback(:services, response)
80
+ end
75
81
  when :traces
76
82
  count = data.length
77
83
  payload = @encoder.encode_traces(data)
78
- status_code = post(@api[:traces_endpoint], payload, count)
84
+ status_code = post(@api[:traces_endpoint], payload, count) do |response|
85
+ process_callback(:traces, response)
86
+ end
79
87
  else
80
88
  Datadog::Tracer.log.error("Unsupported endpoint: #{endpoint}")
81
89
  return nil
82
90
  end
83
91
 
84
- downgrade! && send(endpoint, data) if downgrade?(status_code)
85
-
86
- status_code
92
+ if downgrade?(status_code)
93
+ downgrade!
94
+ send(endpoint, data)
95
+ else
96
+ status_code
97
+ end
87
98
  end
88
99
 
89
100
  # send data to the trace-agent; the method is thread-safe
90
101
  def post(url, data, count = nil)
91
- Datadog::Tracer.log.debug("Sending data from process: #{Process.pid}")
92
- headers = count.nil? ? {} : { TRACE_COUNT_HEADER => count.to_s }
93
- headers = headers.merge(@headers)
94
- request = Net::HTTP::Post.new(url, headers)
95
- request.body = data
96
-
97
- response = Net::HTTP.start(@hostname, @port, read_timeout: TIMEOUT) { |http| http.request(request) }
98
- handle_response(response)
99
- rescue StandardError => e
100
- Datadog::Tracer.log.error(e.message)
101
- 500
102
+ begin
103
+ Datadog::Tracer.log.debug("Sending data from process: #{Process.pid}")
104
+ headers = count.nil? ? {} : { TRACE_COUNT_HEADER => count.to_s }
105
+ headers = headers.merge(@headers)
106
+ request = Net::HTTP::Post.new(url, headers)
107
+ request.body = data
108
+
109
+ response = Net::HTTP.start(@hostname, @port, read_timeout: TIMEOUT) { |http| http.request(request) }
110
+ handle_response(response)
111
+ rescue StandardError => e
112
+ Datadog::Tracer.log.error(e.message)
113
+ 500
114
+ end.tap do
115
+ yield(response) if block_given?
116
+ end
102
117
  end
103
118
 
104
119
  # Downgrade the connection to a compatibility version of the HTTPTransport;
@@ -166,8 +181,6 @@ module Datadog
166
181
  @mutex.synchronize { @count_server_error += 1 }
167
182
  end
168
183
 
169
- process_callback(response)
170
-
171
184
  status_code
172
185
  rescue StandardError => e
173
186
  Datadog::Tracer.log.error(e.message)
@@ -188,10 +201,10 @@ module Datadog
188
201
 
189
202
  private
190
203
 
191
- def process_callback(response)
204
+ def process_callback(action, response)
192
205
  return unless @response_callback && @response_callback.respond_to?(:call)
193
206
 
194
- @response_callback.call(response)
207
+ @response_callback.call(action, response, @api)
195
208
  rescue => e
196
209
  Tracer.log.debug("Error processing callback: #{e}")
197
210
  end
@@ -2,7 +2,7 @@ module Datadog
2
2
  module VERSION
3
3
  MAJOR = 0
4
4
  MINOR = 11
5
- PATCH = 3
5
+ PATCH = 4
6
6
 
7
7
  STRING = [MAJOR, MINOR, PATCH].compact.join('.')
8
8
  end
@@ -5,7 +5,7 @@ require 'ddtrace/workers'
5
5
  module Datadog
6
6
  # Traces and services writer that periodically sends data to the trace-agent
7
7
  class Writer
8
- attr_reader :transport, :worker
8
+ attr_reader :transport, :worker, :priority_sampler
9
9
 
10
10
  HOSTNAME = 'localhost'.freeze
11
11
  PORT = '8126'.freeze
@@ -117,10 +117,16 @@ module Datadog
117
117
 
118
118
  private
119
119
 
120
- def sampling_updater(response)
121
- return unless response.is_a?(Net::HTTPOK)
122
- service_rates = JSON.parse(response.body)
123
- @priority_sampler.update(service_rates)
120
+ def sampling_updater(action, response, api)
121
+ return unless action == :traces && response.is_a?(Net::HTTPOK)
122
+
123
+ if api[:version] == HTTPTransport::V4
124
+ service_rates = JSON.parse(response.body)
125
+ @priority_sampler.update(service_rates)
126
+ true
127
+ else
128
+ false
129
+ end
124
130
  end
125
131
  end
126
132
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ddtrace
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.11.3
4
+ version: 0.11.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Datadog, Inc.
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2018-03-12 00:00:00.000000000 Z
11
+ date: 2018-03-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: msgpack