ddtrace 0.14.2 → 0.15.0.beta1

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
- SHA256:
3
- metadata.gz: 25dde262eb6c5e6fc818787e0393798fca7c427fabe3fd83acfde68ae75d5e4d
4
- data.tar.gz: 384fc03cba261af39f3236d7ed1308ab5a706978f5ba8a0836538cd8f207cd49
2
+ SHA1:
3
+ metadata.gz: 152355917a6f63e309d2fa3c2493df04f689bae2
4
+ data.tar.gz: ffbb1cd4275783dce93875758383ac0df983ac72
5
5
  SHA512:
6
- metadata.gz: c4f348bf0337b3d820257f91bae3c8d95d0d47d6527eee841772e2beb66b7ca0679a325dc3d4d9027a53e518d437aa1522ced5dbadb865f2404c86c18c2908b6
7
- data.tar.gz: 26919c343f9ee6bed204d6b08fdd741a5bd878b11a19aba6cf970f36e7e0ee863c4708070bcf0bad4885a66d85913a4e3e87f73f9b18d54b900e02208b9b9c0c
6
+ metadata.gz: 7143e0ffc5d84ca3f8305840f299cd021281cc45df6cad2c78460d431f835a2483af3f4cc9b9a0c75557c837fc997e3151a4d5e4cb0f19c776bd1960509652bf
7
+ data.tar.gz: 4918277463d66e58a51314d268305a1529564966cdb645bd31b6e9770644ee3e0bb455cbaf05de493e9cdefacc523444ccd4680dce41994b2d59ca8fa5e2239c
data/CHANGELOG.md CHANGED
@@ -4,30 +4,15 @@
4
4
 
5
5
  ## [Unreleased (beta)]
6
6
 
7
- ## [0.14.2] - 2018-08-23
7
+ ## [0.15.0.beta1] - 2018-08-15
8
8
 
9
- Release notes: https://github.com/DataDog/dd-trace-rb/releases/tag/v0.14.2
9
+ Release notes: https://github.com/DataDog/dd-trace-rb/releases/tag/v0.15.0.beta1
10
10
 
11
- Git diff: https://github.com/DataDog/dd-trace-rb/compare/v0.14.1...v0.14.2
12
-
13
- ### Fixed
14
-
15
- - Sampling priority from request headers not being used (#521)
16
-
17
-
18
- ## [0.14.1] - 2018-08-21
19
-
20
- Release notes: https://github.com/DataDog/dd-trace-rb/releases/tag/v0.14.1
21
-
22
- Git diff: https://github.com/DataDog/dd-trace-rb/compare/v0.14.0...v0.14.1
11
+ Git diff: https://github.com/DataDog/dd-trace-rb/compare/v0.14.0...v0.15.0.beta1
23
12
 
24
13
  ### Changed
25
14
 
26
- - Reduce verbosity of connection errors in log (#515)
27
-
28
- ### Fixed
29
-
30
- - Sequel 'not a valid integration' error (#514, #516) (@steveh)
15
+ - Reduced locking to improve multithreaded performance (#506)
31
16
 
32
17
  ## [0.14.0] - 2018-08-14
33
18
 
@@ -485,9 +470,8 @@ Release notes: https://github.com/DataDog/dd-trace-rb/releases/tag/v0.3.1
485
470
 
486
471
  Git diff: https://github.com/DataDog/dd-trace-rb/compare/v0.3.0...v0.3.1
487
472
 
488
- [Unreleased (stable)]: https://github.com/DataDog/dd-trace-rb/compare/v0.14.1...master
489
- [Unreleased (beta)]: https://github.com/DataDog/dd-trace-rb/compare/v0.14.1...0.15-dev
490
- [0.14.1]: https://github.com/DataDog/dd-trace-rb/compare/v0.14.0...v0.14.1
473
+ [Unreleased (stable)]: https://github.com/DataDog/dd-trace-rb/compare/v0.14.0...master
474
+ [Unreleased (beta)]: https://github.com/DataDog/dd-trace-rb/compare/v0.14.0...0.15-dev
491
475
  [0.14.0]: https://github.com/DataDog/dd-trace-rb/compare/v0.13.2...v0.14.0
492
476
  [0.14.0.rc1]: https://github.com/DataDog/dd-trace-rb/compare/v0.14.0.beta2...v0.14.0.rc1
493
477
  [0.14.0.beta2]: https://github.com/DataDog/dd-trace-rb/compare/v0.14.0.beta1...v0.14.0.beta2
data/lib/ddtrace.rb CHANGED
@@ -44,29 +44,29 @@ module Datadog
44
44
  end
45
45
 
46
46
  require 'ddtrace/contrib/base'
47
+ require 'ddtrace/contrib/integration'
48
+ require 'ddtrace/contrib/rack/patcher'
49
+ require 'ddtrace/contrib/rails/patcher'
47
50
  require 'ddtrace/contrib/active_model_serializers/patcher'
48
51
  require 'ddtrace/contrib/active_record/integration'
49
- require 'ddtrace/contrib/aws/patcher'
50
- require 'ddtrace/contrib/dalli/patcher'
51
- require 'ddtrace/contrib/delayed_job/patcher'
52
+ require 'ddtrace/contrib/sequel/patcher'
52
53
  require 'ddtrace/contrib/elasticsearch/patcher'
53
- require 'ddtrace/contrib/excon/patcher'
54
54
  require 'ddtrace/contrib/faraday/patcher'
55
55
  require 'ddtrace/contrib/grape/patcher'
56
56
  require 'ddtrace/contrib/graphql/patcher'
57
57
  require 'ddtrace/contrib/grpc/patcher'
58
+ require 'ddtrace/contrib/redis/patcher'
58
59
  require 'ddtrace/contrib/http/patcher'
59
- require 'ddtrace/contrib/integration'
60
+ require 'ddtrace/contrib/aws/patcher'
61
+ require 'ddtrace/contrib/sucker_punch/patcher'
62
+ require 'ddtrace/contrib/rest_client/integration'
60
63
  require 'ddtrace/contrib/mongodb/patcher'
61
- require 'ddtrace/contrib/mysql2/patcher'
62
- require 'ddtrace/contrib/racecar/patcher'
63
- require 'ddtrace/contrib/rack/patcher'
64
- require 'ddtrace/contrib/rails/patcher'
64
+ require 'ddtrace/contrib/dalli/patcher'
65
65
  require 'ddtrace/contrib/rake/patcher'
66
- require 'ddtrace/contrib/redis/patcher'
67
66
  require 'ddtrace/contrib/resque/patcher'
68
- require 'ddtrace/contrib/rest_client/integration'
69
- require 'ddtrace/contrib/sequel/integration'
67
+ require 'ddtrace/contrib/delayed_job/patcher'
68
+ require 'ddtrace/contrib/racecar/patcher'
70
69
  require 'ddtrace/contrib/sidekiq/patcher'
71
- require 'ddtrace/contrib/sucker_punch/patcher'
70
+ require 'ddtrace/contrib/excon/patcher'
71
+ require 'ddtrace/contrib/mysql2/patcher'
72
72
  require 'ddtrace/monkey'
@@ -8,7 +8,7 @@ module Datadog
8
8
  def initialize(max_size)
9
9
  @max_size = max_size
10
10
 
11
- @mutex = Mutex.new()
11
+ @mutex = Mutex.new
12
12
  @traces = []
13
13
  @closed = false
14
14
  end
@@ -16,30 +16,20 @@ module Datadog
16
16
  # Add a new ``trace`` in the local queue. This method doesn't block the execution
17
17
  # even if the buffer is full. In that case, a random trace is discarded.
18
18
  def push(trace)
19
- @mutex.synchronize do
20
- return if @closed
21
- len = @traces.length
22
- if len < @max_size || @max_size <= 0
23
- @traces << trace
24
- else
25
- # we should replace a random trace with the new one
26
- @traces[rand(len)] = trace
27
- end
28
- end
19
+ return if @closed
20
+ len = @traces.length
21
+ @traces.delete_at(rand(len)) if len >= @max_size && @max_size > 0
22
+ @traces << trace
29
23
  end
30
24
 
31
25
  # Return the current number of stored traces.
32
26
  def length
33
- @mutex.synchronize do
34
- return @traces.length
35
- end
27
+ @traces.length
36
28
  end
37
29
 
38
30
  # Return if the buffer is empty.
39
31
  def empty?
40
- @mutex.synchronize do
41
- return @traces.empty?
42
- end
32
+ @traces.empty?
43
33
  end
44
34
 
45
35
  # Stored traces are returned and the local buffer is reset.
@@ -52,9 +42,7 @@ module Datadog
52
42
  end
53
43
 
54
44
  def close
55
- @mutex.synchronize do
56
- @closed = true
57
- end
45
+ @closed = true
58
46
  end
59
47
  end
60
48
  end
@@ -13,16 +13,14 @@ module Datadog
13
13
  # \Context, it will be related to the original trace.
14
14
  #
15
15
  # This data structure is thread-safe.
16
- # rubocop:disable Metrics/ClassLength
17
16
  class Context
18
17
  # 100k spans is about a 100Mb footprint
19
18
  DEFAULT_MAX_LENGTH = 100_000
20
19
 
21
20
  attr_reader :max_length
22
21
 
23
- # Initialize a new thread-safe \Context.
22
+ # Initialize a new \Context.
24
23
  def initialize(options = {})
25
- @mutex = Mutex.new
26
24
  # max_length is the amount of spans above which, for a given trace,
27
25
  # the context will simply drop and ignore spans, avoiding high memory usage.
28
26
  @max_length = options.fetch(:max_length, DEFAULT_MAX_LENGTH)
@@ -30,82 +28,56 @@ module Datadog
30
28
  end
31
29
 
32
30
  def trace_id
33
- @mutex.synchronize do
34
- @parent_trace_id
35
- end
31
+ @parent_trace_id
36
32
  end
37
33
 
38
34
  def span_id
39
- @mutex.synchronize do
40
- @parent_span_id
41
- end
35
+ @parent_span_id
42
36
  end
43
37
 
44
- def sampling_priority
45
- @mutex.synchronize do
46
- @sampling_priority
47
- end
48
- end
38
+ attr_reader :sampling_priority
49
39
 
50
- def sampling_priority=(priority)
51
- @mutex.synchronize do
52
- @sampling_priority = priority
53
- end
54
- end
40
+ attr_writer :sampling_priority
55
41
 
56
42
  # Return the last active span that corresponds to the last inserted
57
43
  # item in the trace list. This cannot be considered as the current active
58
44
  # span in asynchronous environments, because some spans can be closed
59
45
  # earlier while child spans still need to finish their traced execution.
60
- def current_span
61
- @mutex.synchronize do
62
- return @current_span
63
- end
64
- end
65
-
66
- def current_root_span
67
- @mutex.synchronize do
68
- return @current_root_span
69
- end
70
- end
46
+ attr_reader :current_span, :current_root_span
71
47
 
72
48
  # Add a span to the context trace list, keeping it as the last active span.
73
49
  def add_span(span)
74
- @mutex.synchronize do
75
- # If hitting the hard limit, just drop spans. This is really a rare case
76
- # as it means despite the soft limit, the hard limit is reached, so the trace
77
- # by default has 10000 spans, all of which belong to unfinished parts of a
78
- # larger trace. This is a catch-all to reduce global memory usage.
79
- if @max_length > 0 && @trace.length >= @max_length
80
- Datadog::Tracer.log.debug("context full, ignoring span #{span.name}")
81
- # Detach the span from any context, it's being dropped and ignored.
82
- span.context = nil
83
- return
84
- end
85
- set_current_span(span)
86
- @current_root_span = span if @trace.empty?
87
- @trace << span
88
- span.context = self
89
- end
50
+ # If hitting the hard limit, just drop spans. This is really a rare case
51
+ # as it means despite the soft limit, the hard limit is reached, so the trace
52
+ # by default has 10000 spans, all of which belong to unfinished parts of a
53
+ # larger trace. This is a catch-all to reduce global memory usage.
54
+ if @max_length > 0 && @trace.length >= @max_length
55
+ Datadog::Tracer.log.debug("context full, ignoring span #{span.name}")
56
+ # Detach the span from any context, it's being dropped and ignored.
57
+ span.context = nil
58
+ return
59
+ end
60
+ set_current_span(span)
61
+ @current_root_span = span if @trace.empty?
62
+ @trace << span
63
+ span.context = self
90
64
  end
91
65
 
92
66
  # Mark a span as a finished, increasing the internal counter to prevent
93
67
  # cycles inside _trace list.
94
68
  def close_span(span)
95
- @mutex.synchronize do
96
- @finished_spans += 1
97
- # Current span is only meaningful for linear tree-like traces,
98
- # in other cases, this is just broken and one should rely
99
- # on per-instrumentation code to retrieve handle parent/child relations.
100
- set_current_span(span.parent)
101
- return if span.tracer.nil?
102
- return unless Datadog::Tracer.debug_logging
103
- if span.parent.nil? && !check_finished_spans
104
- opened_spans = @trace.length - @finished_spans
105
- Datadog::Tracer.log.debug("root span #{span.name} closed but has #{opened_spans} unfinished spans:")
106
- @trace.each do |s|
107
- Datadog::Tracer.log.debug("unfinished span: #{s}") unless s.finished?
108
- end
69
+ @finished_spans += 1
70
+ # Current span is only meaningful for linear tree-like traces,
71
+ # in other cases, this is just broken and one should rely
72
+ # on per-instrumentation code to retrieve handle parent/child relations.
73
+ set_current_span(span.parent)
74
+ return if span.tracer.nil?
75
+ return unless Datadog::Tracer.debug_logging
76
+ if span.parent.nil? && !check_finished_spans
77
+ opened_spans = @trace.length - @finished_spans
78
+ Datadog::Tracer.log.debug("root span #{span.name} closed but has #{opened_spans} unfinished spans:")
79
+ @trace.each do |s|
80
+ Datadog::Tracer.log.debug("unfinished span: #{s}") unless s.finished?
109
81
  end
110
82
  end
111
83
  end
@@ -113,17 +85,13 @@ module Datadog
113
85
  # Returns if the trace for the current Context is finished or not. A \Context
114
86
  # is considered finished if all spans in this context are finished.
115
87
  def finished?
116
- @mutex.synchronize do
117
- return check_finished_spans
118
- end
88
+ check_finished_spans
119
89
  end
120
90
 
121
91
  # Returns true if the context is sampled, that is, if it should be kept
122
92
  # and sent to the trace agent.
123
93
  def sampled?
124
- @mutex.synchronize do
125
- return @sampled
126
- end
94
+ @sampled
127
95
  end
128
96
 
129
97
  # Returns both the trace list generated in the current context and
@@ -133,26 +101,22 @@ module Datadog
133
101
  #
134
102
  # This operation is thread-safe.
135
103
  def get
136
- @mutex.synchronize do
137
- trace = @trace
138
- sampled = @sampled
104
+ trace = @trace
105
+ sampled = @sampled
139
106
 
140
- attach_sampling_priority if sampled && @sampling_priority
107
+ attach_sampling_priority if sampled && @sampling_priority
141
108
 
142
- # still return sampled attribute, even if context is not finished
143
- return nil, sampled unless check_finished_spans()
109
+ # still return sampled attribute, even if context is not finished
110
+ return nil, sampled unless check_finished_spans()
144
111
 
145
- reset
146
- [trace, sampled]
147
- end
112
+ reset
113
+ [trace, sampled]
148
114
  end
149
115
 
150
116
  # Return a string representation of the context.
151
117
  def to_s
152
- @mutex.synchronize do
153
- # rubocop:disable Metrics/LineLength
154
- "Context(trace.length:#{@trace.length},sampled:#{@sampled},finished_spans:#{@finished_spans},current_span:#{@current_span})"
155
- end
118
+ # rubocop:disable Metrics/LineLength
119
+ "Context(trace.length:#{@trace.length},sampled:#{@sampled},finished_spans:#{@finished_spans},current_span:#{@current_span})"
156
120
  end
157
121
 
158
122
  private
@@ -194,45 +158,37 @@ module Datadog
194
158
 
195
159
  # Return the start time of the root span, or nil if there are no spans or this is undefined.
196
160
  def start_time
197
- @mutex.synchronize do
198
- return nil if @trace.empty?
199
- @trace[0].start_time
200
- end
161
+ return nil if @trace.empty?
162
+ @trace[0].start_time
201
163
  end
202
164
 
203
165
  # Return the length of the current trace held by this context.
204
166
  def length
205
- @mutex.synchronize do
206
- @trace.length
207
- end
167
+ @trace.length
208
168
  end
209
169
 
210
170
  # Iterate on each span within the trace. This is thread safe.
211
171
  def each_span
212
- @mutex.synchronize do
213
- @trace.each do |span|
214
- yield span
215
- end
172
+ @trace.each do |span|
173
+ yield span
216
174
  end
217
175
  end
218
176
 
219
177
  # Delete any span matching the condition. This is thread safe.
220
178
  def delete_span_if
221
- @mutex.synchronize do
222
- @trace.delete_if do |span|
223
- finished = span.finished?
224
- delete_span = yield span
225
- if delete_span
226
- # We need to detach the span from the context, else, some code
227
- # finishing it afterwards would mess up with the number of
228
- # finished_spans and possibly cause other side effects.
229
- span.context = nil
230
- # Acknowledge there's one span less to finish, if needed.
231
- # It's very important to keep this balanced.
232
- @finished_spans -= 1 if finished
233
- end
234
- delete_span
179
+ @trace.delete_if do |span|
180
+ finished = span.finished?
181
+ delete_span = yield span
182
+ if delete_span
183
+ # We need to detach the span from the context, else, some code
184
+ # finishing it afterwards would mess up with the number of
185
+ # finished_spans and possibly cause other side effects.
186
+ span.context = nil
187
+ # Acknowledge there's one span less to finish, if needed.
188
+ # It's very important to keep this balanced.
189
+ @finished_spans -= 1 if finished
235
190
  end
191
+ delete_span
236
192
  end
237
193
  end
238
194
  end
@@ -25,10 +25,8 @@ module Datadog
25
25
  end
26
26
 
27
27
  def [](name)
28
- @mutex.synchronize do
29
- entry = @data[name]
30
- entry.klass if entry
31
- end
28
+ entry = @data[name]
29
+ entry.klass if entry
32
30
  end
33
31
 
34
32
  def to_h
@@ -98,32 +98,14 @@ module Datadog
98
98
  end
99
99
 
100
100
  def sample(span)
101
- return perform_sampling(span) unless span.context
102
- return sampled_by_upstream(span) if span.context.sampling_priority
103
-
104
- perform_sampling(span).tap do |sampled|
105
- span.context.sampling_priority = if sampled
106
- Datadog::Ext::Priority::AUTO_KEEP
107
- else
108
- Datadog::Ext::Priority::AUTO_REJECT
109
- end
110
- end
111
- end
112
-
113
- def_delegators :@post_sampler, :update
114
-
115
- private
116
-
117
- def sampled_by_upstream(span)
118
- span.sampled = priority_keep?(span.context.sampling_priority)
119
- end
101
+ span.context.sampling_priority = Datadog::Ext::Priority::AUTO_REJECT if span.context
102
+ return unless @base_sampler.sample(span)
103
+ return unless @post_sampler.sample(span)
104
+ span.context.sampling_priority = Datadog::Ext::Priority::AUTO_KEEP if span.context
120
105
 
121
- def priority_keep?(sampling_priority)
122
- sampling_priority == Datadog::Ext::Priority::USER_KEEP || sampling_priority == Datadog::Ext::Priority::AUTO_KEEP
106
+ true
123
107
  end
124
108
 
125
- def perform_sampling(span)
126
- @base_sampler.sample(span) && @post_sampler.sample(span)
127
- end
109
+ def_delegators :@post_sampler, :update
128
110
  end
129
111
  end
@@ -103,7 +103,6 @@ module Datadog
103
103
 
104
104
  @context_flush = options[:partial_flush] ? Datadog::ContextFlush.new(options) : nil
105
105
 
106
- @mutex = Mutex.new
107
106
  @services = {}
108
107
  @tags = {}
109
108
  end
@@ -68,7 +68,6 @@ module Datadog
68
68
  @count_client_error = 0
69
69
  @count_server_error = 0
70
70
  @count_internal_error = 0
71
- @count_consecutive_errors = 0
72
71
  end
73
72
 
74
73
  # route the send to the right endpoint
@@ -110,7 +109,7 @@ module Datadog
110
109
  response = Net::HTTP.start(@hostname, @port, read_timeout: TIMEOUT) { |http| http.request(request) }
111
110
  handle_response(response)
112
111
  rescue StandardError => e
113
- log_error_once(e.message)
112
+ Datadog::Tracer.log.error(e.message)
114
113
  500
115
114
  end.tap do
116
115
  yield(response) if block_given?
@@ -171,22 +170,21 @@ module Datadog
171
170
 
172
171
  if success?(status_code)
173
172
  Datadog::Tracer.log.debug('Payload correctly sent to the trace agent.')
174
- @mutex.synchronize { @count_consecutive_errors = 0 }
175
173
  @mutex.synchronize { @count_success += 1 }
176
174
  elsif downgrade?(status_code)
177
175
  Datadog::Tracer.log.debug("calling the endpoint but received #{status_code}; downgrading the API")
178
176
  elsif client_error?(status_code)
179
- log_error_once("Client error: #{response.message}")
177
+ Datadog::Tracer.log.error("Client error: #{response.message}")
180
178
  @mutex.synchronize { @count_client_error += 1 }
181
179
  elsif server_error?(status_code)
182
- log_error_once("Server error: #{response.message}")
180
+ Datadog::Tracer.log.error("Server error: #{response.message}")
181
+ @mutex.synchronize { @count_server_error += 1 }
183
182
  end
184
183
 
185
184
  status_code
186
185
  rescue StandardError => e
187
- log_error_once(e.message)
186
+ Datadog::Tracer.log.error(e.message)
188
187
  @mutex.synchronize { @count_internal_error += 1 }
189
-
190
188
  500
191
189
  end
192
190
 
@@ -203,16 +201,6 @@ module Datadog
203
201
 
204
202
  private
205
203
 
206
- def log_error_once(*args)
207
- if @count_consecutive_errors > 0
208
- Datadog::Tracer.log.debug(*args)
209
- else
210
- Datadog::Tracer.log.error(*args)
211
- end
212
-
213
- @mutex.synchronize { @count_consecutive_errors += 1 }
214
- end
215
-
216
204
  def process_callback(action, response)
217
205
  return unless @response_callback && @response_callback.respond_to?(:call)
218
206
 
@@ -1,9 +1,9 @@
1
1
  module Datadog
2
2
  module VERSION
3
3
  MAJOR = 0
4
- MINOR = 14
5
- PATCH = 2
6
- PRE = nil
4
+ MINOR = 15
5
+ PATCH = 0
6
+ PRE = 'beta1'.freeze
7
7
 
8
8
  STRING = [MAJOR, MINOR, PATCH, PRE].compact.join('.')
9
9
  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.14.2
4
+ version: 0.15.0.beta1
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-08-24 00:00:00.000000000 Z
11
+ date: 2018-08-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: msgpack
@@ -435,12 +435,12 @@ required_ruby_version: !ruby/object:Gem::Requirement
435
435
  version: 1.9.1
436
436
  required_rubygems_version: !ruby/object:Gem::Requirement
437
437
  requirements:
438
- - - ">="
438
+ - - ">"
439
439
  - !ruby/object:Gem::Version
440
- version: '0'
440
+ version: 1.3.1
441
441
  requirements: []
442
442
  rubyforge_project:
443
- rubygems_version: 2.7.7
443
+ rubygems_version: 2.6.14
444
444
  signing_key:
445
445
  specification_version: 4
446
446
  summary: Datadog tracing code for your Ruby applications