ddtrace 0.9.0 → 0.9.1

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: 3896d5d634a6a65d95f815955b5e62108562a55c
4
- data.tar.gz: a4d606173f9f92749e757bccc17a8524a91a916e
3
+ metadata.gz: b0875d09844d2557b344cda645c3a378d0b33a1b
4
+ data.tar.gz: dd0bfd29b724ae66809b769512d971379cc56853
5
5
  SHA512:
6
- metadata.gz: 9ef525976240577dd0d39692749416765ace3b5542202d6b9db4674c8467c2d76c3bcfa8a4755e62b79fc31d4478c49960b10aba4607d3963d71754518fac240
7
- data.tar.gz: 9eaf559a0c2d59798e8441c45342f3d3084358955e318677e42c506a95f548ad5b688eee4b0edf649e7f638befa6ee621337e6dd591fc9d12ebe011de30d8283
6
+ metadata.gz: cf0a24f6e5dc2198f8108fbb6f477295d73db47bd439d1f9b10b4b8b01e9aa006e9922180976b7a851b5bb6474558ccd950543944e343e332c00e77de7a503b3
7
+ data.tar.gz: 48410c488ae9fdaec44b519e702badf58ccc651bfb4204988b11e078598b6c4f6bc61c607a97ee313fcc708d562e9bf035045c13beb463fae6e1beb94cb46cea
data/Rakefile CHANGED
@@ -92,6 +92,8 @@ end
92
92
 
93
93
  YARD::Rake::YardocTask.new(:docs) do |t|
94
94
  t.options += ['--title', "ddtrace #{Datadog::VERSION::STRING} documentation"]
95
+ t.options += ['--markup', 'markdown']
96
+ t.options += ['--markup-provider', 'redcarpet']
95
97
  end
96
98
 
97
99
  # Deploy tasks
data/ddtrace.gemspec CHANGED
@@ -39,4 +39,5 @@ EOS
39
39
  spec.add_development_dependency 'minitest', '= 5.10.1'
40
40
  spec.add_development_dependency 'appraisal', '~> 2.2'
41
41
  spec.add_development_dependency 'yard', '~> 0.9'
42
+ spec.add_development_dependency 'redcarpet', '~> 3.4' if RUBY_PLATFORM != 'java'
42
43
  end
@@ -24,17 +24,18 @@ The easiest way to get started with the tracing client is to instrument your web
24
24
  provides auto instrumentation for the following web frameworks and libraries:
25
25
 
26
26
  * [Ruby on Rails](#Ruby_on_Rails)
27
- * [Sidekiq](#Sidekiq)
28
27
  * [Sinatra](#Sinatra)
29
28
  * [Rack](#Rack)
30
29
  * [Grape](#Grape)
31
30
  * [Active Record](#Active_Record)
32
31
  * [Elastic Search](#Elastic_Search)
33
32
  * [MongoDB](#MongoDB)
34
- * [Dalli](#Dalli)
35
- * [Faraday](#Faraday)
33
+ * [Sidekiq](#Sidekiq)
34
+ * [Resque](#Resque)
36
35
  * [SuckerPunch](#SuckerPunch)
37
36
  * [Net/HTTP](#Net_HTTP)
37
+ * [Faraday](#Faraday)
38
+ * [Dalli](#Dalli)
38
39
  * [Redis](#Redis)
39
40
 
40
41
  ## Web Frameworks
@@ -365,6 +366,23 @@ The `faraday` integration is available through the `ddtrace` middleware:
365
366
 
366
367
  connection.get('/foo')
367
368
 
369
+ Where `options` is an optional `Hash` that accepts the following parameters:
370
+
371
+ | Key | Type | Default | Description |
372
+ | --- | --- | --- | --- |
373
+ | `split_by_domain` | Boolean | `false` | Uses the request domain as the service name when set to `true`. |
374
+ | `distributed_tracing` | Boolean | `false` | Propagates tracing context along the HTTP request when set to `true`. |
375
+ | `error_handler` | Callable | ``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. |
376
+
377
+ It's worth mentioning that `ddtrace` also supports instrumentation for the
378
+ `net/http` library, so if you're using it as farady's backend you might see
379
+ instrumentation both on `faraday` and `net/http` levels. If you want to avoid
380
+ multiple levels of instrumentation for your HTTP requests, remember that you can
381
+ always fine tune which libraries are patched by calling:
382
+
383
+ Datadog::Monkey.patch([:faraday, :redis])
384
+ # instead of using Datadog::Monkey.patch_all
385
+
368
386
  ### AWS
369
387
 
370
388
  The AWS integration will trace every interaction (e.g. API calls) with AWS
@@ -422,21 +440,6 @@ executions. It can be added as any other Sidekiq middleware:
422
440
  end
423
441
  end
424
442
 
425
- ### SuckerPunch
426
-
427
- The `sucker_punch` integration traces all scheduled jobs:
428
-
429
- require 'ddtrace'
430
-
431
- Datadog::Monkey.patch_module(:sucker_punch)
432
-
433
- # the execution of this job is traced
434
- LogJob.perform_async('login')
435
-
436
- # to change SuckerPunch service name, use the Pin class
437
- pin = Datadog::Pin.get_from(::SuckerPunch)
438
- pin.service = 'deploy-queues'
439
-
440
443
  #### Configure the tracer middleware
441
444
 
442
445
  To modify the default configuration, simply pass arguments to the middleware.
@@ -475,22 +478,41 @@ giving precedence to the middleware settings. Inherited configurations are:
475
478
  * ``trace_agent_hostname``
476
479
  * ``trace_agent_port``
477
480
 
478
- Where `options` is an optional `Hash` that accepts the following parameters:
481
+ ### Resque
479
482
 
480
- | Key | Type | Default | Description |
481
- | --- | --- | --- | --- |
482
- | `split_by_domain` | Boolean | `false` | Uses the request domain as the service name when set to `true`. |
483
- | `distributed_tracing` | Boolean | `false` | Propagates tracing context along the HTTP request when set to `true`. |
484
- | `error_handler` | Callable | [Click Here](https://github.com/DataDog/dd-trace-rb/blob/4fe3bc9df032eac3cd294b0bebcc866080dbe04f/lib/ddtrace/contrib/faraday/middleware.rb#L11-L13) | 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. By default, only server-side errors (e.g. `5xx`) are flagged as errors. |
483
+ The Resque integration uses Resque hooks that wraps the ``perform`` method.
484
+ To add tracing to a Resque job, extend your base class with the provided
485
+ one:
485
486
 
486
- It's worth mentioning that `ddtrace` also supports instrumentation for the
487
- `net/http` library, so if you're using it as farady's backend you might see
488
- instrumentation both on `faraday` and `net/http` levels. If you want to avoid
489
- multiple levels of instrumentation for your HTTP requests, remember that you can
490
- always fine tune witch libraries are patched by calling:
487
+ require 'ddtrace'
488
+ require 'ddtrace/contrib/resque/resque_job'
489
+
490
+ # patch Resque
491
+ Datadog::Monkey.patch_module(:resque)
492
+
493
+ class MyJob
494
+ # extend MyJob with integration hooks
495
+ extend Datadog::Contrib::Resque::ResqueJob
496
+
497
+ def self.perform(*args)
498
+ # do_something
499
+ end
500
+ end
501
+
502
+ ### SuckerPunch
503
+
504
+ The `sucker_punch` integration traces all scheduled jobs:
505
+
506
+ require 'ddtrace'
507
+
508
+ Datadog::Monkey.patch_module(:sucker_punch)
509
+
510
+ # the execution of this job is traced
511
+ LogJob.perform_async('login')
491
512
 
492
- Datadog::Monkey.patch([:foo, :bar])
493
- # instead of Datadog::Monkey.patch_all
513
+ # to change SuckerPunch service name, use the Pin class
514
+ pin = Datadog::Pin.get_from(::SuckerPunch)
515
+ pin.service = 'deploy-queues'
494
516
 
495
517
  ## Advanced usage
496
518
 
@@ -771,8 +793,11 @@ sent upstream. To achieve that, you can hook custom *processors* into the
771
793
  pipeline using the method `Datadog::Pipeline.before_flush`:
772
794
 
773
795
  Datadog::Pipeline.before_flush(
796
+ # filter the Span if the given block evaluates true
774
797
  Datadog::Pipeline::SpanFilter.new { |span| span.resource =~ /PingController/ },
775
798
  Datadog::Pipeline::SpanFilter.new { |span| span.get_tag('host') == 'localhost' }
799
+
800
+ # alter the Span updating fields or tags
776
801
  Datadog::Pipeline::SpanProcessor.new { |span| span.resource.gsub!(/password=.*/, '') }
777
802
  )
778
803
 
@@ -844,11 +869,6 @@ Currently we are supporting Sinatra >= 1.4.0.
844
869
 
845
870
  Currently we are supporting Sidekiq >= 4.0.0.
846
871
 
847
- ### Glossary
872
+ ### Terminology
848
873
 
849
- * ``Service``: The name of a set of processes that do the same job. Some examples are ``datadog-web-app`` or ``datadog-metrics-db``.
850
- * ``Resource``: A particular query to a service. For a web application, some examples might be a URL stem like ``/user/home`` or a
851
- handler function like ``web.user.home``. For a SQL database, a resource would be the SQL of the query itself like ``select * from users where id = ?``.
852
- You can track thousands (not millions or billions) of unique resources per services, so prefer resources like ``/user/home`` rather than ``/user/home?id=123456789``.
853
- * ``Span``: A span tracks a unit of work in a service, like querying a database or rendering a template. Spans are associated
854
- with a service and optionally a resource. Spans have names, start times, durations and optional tags.
874
+ If you need more context about the terminology used in the APM, take a look at the [official documentation](https://docs.datadoghq.com/tracing/terminology/).
@@ -9,19 +9,9 @@ module Datadog
9
9
  def self.instrument
10
10
  # patch Rails core components
11
11
  Datadog::RailsActionPatcher.patch_action_controller
12
-
13
- # subscribe when the request processing starts
14
- ::ActiveSupport::Notifications.subscribe('!datadog.start_processing.action_controller') do |*args|
15
- start_processing(*args)
16
- end
17
-
18
- # subscribe when the request processing has been completed
19
- ::ActiveSupport::Notifications.subscribe('!datadog.finish_processing.action_controller') do |*args|
20
- finish_processing(*args)
21
- end
22
12
  end
23
13
 
24
- def self.start_processing(_name, _start, _finish, _id, payload)
14
+ def self.start_processing(payload)
25
15
  # trace the execution
26
16
  tracer = ::Rails.configuration.datadog_trace.fetch(:tracer)
27
17
  service = ::Rails.configuration.datadog_trace.fetch(:default_controller_service)
@@ -35,7 +25,7 @@ module Datadog
35
25
  Datadog::Tracer.log.error(e.message)
36
26
  end
37
27
 
38
- def self.finish_processing(_name, start, finish, _id, payload)
28
+ def self.finish_processing(payload)
39
29
  # retrieve the tracing context and the latest active span
40
30
  tracing_context = payload.fetch(:tracing_context)
41
31
  span = tracing_context[:dd_request_span]
@@ -7,30 +7,10 @@ module Datadog
7
7
  module ActionView
8
8
  def self.instrument
9
9
  # patch Rails core components
10
- Datadog::RailsRendererPatcher.patch_renderer()
11
-
12
- # subscribe when the template rendering starts
13
- ::ActiveSupport::Notifications.subscribe('!datadog.start_render_template.action_view') do |*args|
14
- start_render_template(*args)
15
- end
16
-
17
- # subscribe when the template rendering has been processed
18
- ::ActiveSupport::Notifications.subscribe('!datadog.finish_render_template.action_view') do |*args|
19
- finish_render_template(*args)
20
- end
21
-
22
- # subscribe when the partial rendering starts
23
- ::ActiveSupport::Notifications.subscribe('!datadog.start_render_partial.action_view') do |*args|
24
- start_render_partial(*args)
25
- end
26
-
27
- # subscribe when the partial rendering has been processed
28
- ::ActiveSupport::Notifications.subscribe('!datadog.finish_render_partial.action_view') do |*args|
29
- finish_render_partial(*args)
30
- end
10
+ Datadog::RailsRendererPatcher.patch_renderer
31
11
  end
32
12
 
33
- def self.start_render_template(_name, _start, _finish, _id, payload)
13
+ def self.start_render_template(payload)
34
14
  # retrieve the tracing context
35
15
  tracing_context = payload.fetch(:tracing_context)
36
16
 
@@ -42,7 +22,7 @@ module Datadog
42
22
  Datadog::Tracer.log.debug(e.message)
43
23
  end
44
24
 
45
- def self.finish_render_template(_name, _start, _finish, _id, payload)
25
+ def self.finish_render_template(payload)
46
26
  # retrieve the tracing context and the latest active span
47
27
  tracing_context = payload.fetch(:tracing_context)
48
28
  span = tracing_context[:dd_rails_template_span]
@@ -64,7 +44,7 @@ module Datadog
64
44
  Datadog::Tracer.log.debug(e.message)
65
45
  end
66
46
 
67
- def self.start_render_partial(_name, _start, _finish, _id, payload)
47
+ def self.start_render_partial(payload)
68
48
  # retrieve the tracing context
69
49
  tracing_context = payload.fetch(:tracing_context)
70
50
 
@@ -75,7 +55,7 @@ module Datadog
75
55
  Datadog::Tracer.log.debug(e.message)
76
56
  end
77
57
 
78
- def self.finish_render_partial(_name, start, finish, _id, payload)
58
+ def self.finish_render_partial(payload)
79
59
  # retrieve the tracing context and the latest active span
80
60
  tracing_context = payload.fetch(:tracing_context)
81
61
  span = tracing_context[:dd_rails_partial_span]
@@ -8,20 +8,10 @@ module Datadog
8
8
  module ActiveSupport
9
9
  def self.instrument
10
10
  # patch Rails core components
11
- Datadog::RailsCachePatcher.patch_cache_store()
12
-
13
- # subscribe when a cache read starts being processed
14
- ::ActiveSupport::Notifications.subscribe('!datadog.start_cache_tracing.active_support') do |*args|
15
- start_trace_cache(*args)
16
- end
17
-
18
- # subscribe when a cache read has been processed
19
- ::ActiveSupport::Notifications.subscribe('!datadog.finish_cache_tracing.active_support') do |*args|
20
- finish_trace_cache(*args)
21
- end
11
+ Datadog::RailsCachePatcher.patch_cache_store
22
12
  end
23
13
 
24
- def self.start_trace_cache(_name, _start, _finish, _id, payload)
14
+ def self.start_trace_cache(payload)
25
15
  tracer = ::Rails.configuration.datadog_trace.fetch(:tracer)
26
16
  tracing_context = payload.fetch(:tracing_context)
27
17
 
@@ -45,7 +35,7 @@ module Datadog
45
35
  Datadog::Tracer.log.debug(e.message)
46
36
  end
47
37
 
48
- def self.finish_trace_cache(_name, _start, _finish, _id, payload)
38
+ def self.finish_trace_cache(payload)
49
39
  # retrieve the tracing context and continue the trace
50
40
  tracing_context = payload.fetch(:tracing_context)
51
41
  span = tracing_context[:dd_cache_span]
@@ -2,7 +2,7 @@ module Datadog
2
2
  # RailsRendererPatcher contains function to patch Rails rendering libraries.
3
3
  # rubocop:disable Lint/RescueException
4
4
  # rubocop:disable Metrics/MethodLength
5
- # rubocop:disable Metrics/BlockLength
5
+ # rubocop:disable Metrics/ModuleLength
6
6
  module RailsRendererPatcher
7
7
  module_function
8
8
 
@@ -27,11 +27,9 @@ module Datadog
27
27
  # context when a partial is rendered
28
28
  @tracing_context ||= {}
29
29
  if @tracing_context.empty?
30
- ::ActiveSupport::Notifications.instrument(
31
- '!datadog.start_render_template.action_view',
32
- tracing_context: @tracing_context
33
- )
30
+ Datadog::Contrib::Rails::ActionView.start_render_template(tracing_context: @tracing_context)
34
31
  end
32
+
35
33
  render_without_datadog(*args)
36
34
  rescue Exception => e
37
35
  # attach the exception to the tracing context if any
@@ -39,10 +37,7 @@ module Datadog
39
37
  raise e
40
38
  ensure
41
39
  # ensure that the template `Span` is finished even during exceptions
42
- ::ActiveSupport::Notifications.instrument(
43
- '!datadog.finish_render_template.action_view',
44
- tracing_context: @tracing_context
45
- )
40
+ Datadog::Contrib::Rails::ActionView.finish_render_template(tracing_context: @tracing_context)
46
41
  end
47
42
 
48
43
  def render_template_with_datadog(*args)
@@ -90,10 +85,7 @@ module Datadog
90
85
  def render_with_datadog(*args, &block)
91
86
  # create a tracing context and start the rendering span
92
87
  @tracing_context = {}
93
- ::ActiveSupport::Notifications.instrument(
94
- '!datadog.start_render_partial.action_view',
95
- tracing_context: @tracing_context
96
- )
88
+ Datadog::Contrib::Rails::ActionView.start_render_partial(tracing_context: @tracing_context)
97
89
  render_without_datadog(*args)
98
90
  rescue Exception => e
99
91
  # attach the exception to the tracing context if any
@@ -101,10 +93,7 @@ module Datadog
101
93
  raise e
102
94
  ensure
103
95
  # ensure that the template `Span` is finished even during exceptions
104
- ::ActiveSupport::Notifications.instrument(
105
- '!datadog.finish_render_partial.action_view',
106
- tracing_context: @tracing_context
107
- )
96
+ Datadog::Contrib::Rails::ActionView.finish_render_partial(tracing_context: @tracing_context)
108
97
  end
109
98
 
110
99
  def render_partial_with_datadog(*args)
@@ -143,24 +132,25 @@ module Datadog
143
132
  # mutable payload with a tracing context that is used in two different
144
133
  # signals; it propagates the request span so that it can be finished
145
134
  # no matter what
146
- raw_payload = {
135
+ payload = {
147
136
  controller: self.class.name,
148
137
  action: action_name,
149
138
  tracing_context: {}
150
139
  }
151
140
 
152
- # emits two different signals that start and finish the trace; this approach
153
- # mimics the original behavior that is available since Rails 3.0:
154
- # - https://github.com/rails/rails/blob/3-0-stable/actionpack/lib/action_controller/metal/instrumentation.rb#L17-L35
155
- # - https://github.com/rails/rails/blob/5-1-stable/actionpack/lib/action_controller/metal/instrumentation.rb#L17-L39
156
- ActiveSupport::Notifications.instrument('!datadog.start_processing.action_controller', raw_payload)
157
-
158
- # process the request and finish the trace
159
- ActiveSupport::Notifications.instrument('!datadog.finish_processing.action_controller', raw_payload) do |payload|
141
+ begin
142
+ # process and catch request exceptions
143
+ Datadog::Contrib::Rails::ActionController.start_processing(payload)
160
144
  result = process_action_without_datadog(*args)
161
145
  payload[:status] = response.status
162
146
  result
147
+ rescue Exception => e
148
+ payload[:exception] = [e.class.name, e.message]
149
+ payload[:exception_object] = e
150
+ raise e
163
151
  end
152
+ ensure
153
+ Datadog::Contrib::Rails::ActionController.finish_processing(payload)
164
154
  end
165
155
 
166
156
  alias_method :process_action_without_datadog, :process_action
@@ -206,11 +196,17 @@ module Datadog
206
196
  tracing_context: {}
207
197
  }
208
198
 
209
- ActiveSupport::Notifications.instrument('!datadog.start_cache_tracing.active_support', raw_payload)
210
-
211
- ActiveSupport::Notifications.instrument('!datadog.finish_cache_tracing.active_support', raw_payload) do
199
+ begin
200
+ # process and catch cache exceptions
201
+ Datadog::Contrib::Rails::ActiveSupport.start_trace_cache(raw_payload)
212
202
  read_without_datadog(*args, &block)
203
+ rescue Exception => e
204
+ payload[:exception] = [e.class.name, e.message]
205
+ payload[:exception_object] = e
206
+ raise e
213
207
  end
208
+ ensure
209
+ Datadog::Contrib::Rails::ActiveSupport.finish_trace_cache(raw_payload)
214
210
  end
215
211
  end
216
212
  end
@@ -225,11 +221,17 @@ module Datadog
225
221
  tracing_context: {}
226
222
  }
227
223
 
228
- ActiveSupport::Notifications.instrument('!datadog.start_cache_tracing.active_support', raw_payload)
229
-
230
- ActiveSupport::Notifications.instrument('!datadog.finish_cache_tracing.active_support', raw_payload) do
224
+ begin
225
+ # process and catch cache exceptions
226
+ Datadog::Contrib::Rails::ActiveSupport.start_trace_cache(raw_payload)
231
227
  fetch_without_datadog(*args, &block)
228
+ rescue Exception => e
229
+ payload[:exception] = [e.class.name, e.message]
230
+ payload[:exception_object] = e
231
+ raise e
232
232
  end
233
+ ensure
234
+ Datadog::Contrib::Rails::ActiveSupport.finish_trace_cache(raw_payload)
233
235
  end
234
236
  end
235
237
  end
@@ -244,11 +246,17 @@ module Datadog
244
246
  tracing_context: {}
245
247
  }
246
248
 
247
- ActiveSupport::Notifications.instrument('!datadog.start_cache_tracing.active_support', raw_payload)
248
-
249
- ActiveSupport::Notifications.instrument('!datadog.finish_cache_tracing.active_support', raw_payload) do
249
+ begin
250
+ # process and catch cache exceptions
251
+ Datadog::Contrib::Rails::ActiveSupport.start_trace_cache(raw_payload)
250
252
  write_without_datadog(*args, &block)
253
+ rescue Exception => e
254
+ payload[:exception] = [e.class.name, e.message]
255
+ payload[:exception_object] = e
256
+ raise e
251
257
  end
258
+ ensure
259
+ Datadog::Contrib::Rails::ActiveSupport.finish_trace_cache(raw_payload)
252
260
  end
253
261
  end
254
262
  end
@@ -263,11 +271,17 @@ module Datadog
263
271
  tracing_context: {}
264
272
  }
265
273
 
266
- ActiveSupport::Notifications.instrument('!datadog.start_cache_tracing.active_support', raw_payload)
267
-
268
- ActiveSupport::Notifications.instrument('!datadog.finish_cache_tracing.active_support', raw_payload) do
274
+ begin
275
+ # process and catch cache exceptions
276
+ Datadog::Contrib::Rails::ActiveSupport.start_trace_cache(raw_payload)
269
277
  delete_without_datadog(*args, &block)
278
+ rescue Exception => e
279
+ payload[:exception] = [e.class.name, e.message]
280
+ payload[:exception_object] = e
281
+ raise e
270
282
  end
283
+ ensure
284
+ Datadog::Contrib::Rails::ActiveSupport.finish_trace_cache(raw_payload)
271
285
  end
272
286
  end
273
287
  end
@@ -8,6 +8,7 @@ module Datadog
8
8
  module ResqueJob
9
9
  def around_perform(*args)
10
10
  pin = Pin.get_from(::Resque)
11
+ return yield unless pin && pin.tracer
11
12
  pin.tracer.trace('resque.job', service: pin.service) do |span|
12
13
  span.resource = name
13
14
  span.span_type = pin.app_type
@@ -18,7 +19,7 @@ module Datadog
18
19
 
19
20
  def after_perform(*args)
20
21
  pin = Pin.get_from(::Resque)
21
- pin.tracer.shutdown!
22
+ pin.tracer.shutdown! if pin && pin.tracer
22
23
  end
23
24
  end
24
25
  end
@@ -27,5 +28,15 @@ end
27
28
 
28
29
  Resque.before_first_fork do
29
30
  pin = Datadog::Pin.get_from(Resque)
31
+ next unless pin && pin.tracer
30
32
  pin.tracer.set_service_info(pin.service, 'resque', Datadog::Ext::AppTypes::WORKER)
31
33
  end
34
+
35
+ Resque.after_fork do
36
+ # get the current tracer
37
+ pin = Datadog::Pin.get_from(Resque)
38
+ next unless pin && pin.tracer
39
+ # clean the state so no CoW happens
40
+ pin.tracer.provider.context = nil
41
+ pin.tracer.writer.start
42
+ end
data/lib/ddtrace/pin.rb CHANGED
@@ -34,11 +34,11 @@ module Datadog
34
34
  false
35
35
  end
36
36
 
37
+ # rubocop:disable Style/TrivialAccessors
37
38
  def onto(obj)
38
39
  unless obj.respond_to? :datadog_pin=
39
40
  obj.instance_exec do
40
41
  def datadog_pin=(pin)
41
- Datadog::Tracer.log.debug("Set pin #{pin.service} on #{self.class}.")
42
42
  @datadog_pin = pin
43
43
  end
44
44
  end
@@ -47,7 +47,6 @@ module Datadog
47
47
  unless obj.respond_to? :datadog_pin
48
48
  obj.instance_exec do
49
49
  def datadog_pin
50
- Datadog::Tracer.log.debug("Get pin from #{self.class}.")
51
50
  @datadog_pin
52
51
  end
53
52
  end
@@ -259,13 +259,8 @@ module Datadog
259
259
  # * +span_type+: the type of the span (such as \http, \db and so on)
260
260
  # * +tags+: extra tags which should be added to the span.
261
261
  def trace(name, options = {})
262
- opts = options.select do |k, _v|
263
- # Filter options, we want no side effects with unexpected args.
264
- # Plus, this documents the code (Ruby 2 named args would be better but we're Ruby 1.9 compatible)
265
- [:service, :resource, :span_type, :tags].include?(k)
266
- end
267
- opts[:child_of] = call_context
268
- span = start_span(name, opts)
262
+ options[:child_of] = call_context
263
+ span = start_span(name, options)
269
264
 
270
265
  # call the finish only if a block is given; this ensures
271
266
  # that a call to tracer.trace() without a block, returns
@@ -2,7 +2,7 @@ module Datadog
2
2
  module VERSION
3
3
  MAJOR = 0
4
4
  MINOR = 9
5
- PATCH = 0
5
+ PATCH = 1
6
6
 
7
7
  STRING = [MAJOR, MINOR, PATCH].compact.join('.')
8
8
  end
@@ -10,6 +10,8 @@ module Datadog
10
10
  # with the +stop()+ method and can start with the +start()+ method.
11
11
  class AsyncTransport
12
12
  DEFAULT_TIMEOUT = 5
13
+ BACK_OFF_RATIO = 1.2
14
+ BACK_OFF_MAX = 5
13
15
 
14
16
  attr_reader :trace_buffer, :service_buffer, :shutting_down
15
17
 
@@ -17,6 +19,7 @@ module Datadog
17
19
  @trace_task = trace_task
18
20
  @service_task = service_task
19
21
  @flush_interval = interval
22
+ @back_off = interval
20
23
  @trace_buffer = TraceBuffer.new(buff_size)
21
24
  @service_buffer = TraceBuffer.new(buff_size)
22
25
  @transport = transport
@@ -28,7 +31,7 @@ module Datadog
28
31
 
29
32
  # Callback function that process traces and executes the +send_traces()+ method.
30
33
  def callback_traces
31
- return if @trace_buffer.empty?
34
+ return true if @trace_buffer.empty?
32
35
 
33
36
  begin
34
37
  traces = @trace_buffer.pop()
@@ -44,7 +47,7 @@ module Datadog
44
47
 
45
48
  # Callback function that process traces and executes the +send_services()+ method.
46
49
  def callback_services
47
- return if @service_buffer.empty?
50
+ return true if @service_buffer.empty?
48
51
 
49
52
  begin
50
53
  services = @service_buffer.pop()
@@ -65,9 +68,11 @@ module Datadog
65
68
  Datadog::Tracer.log.debug("Starting thread in the process: #{Process.pid}")
66
69
 
67
70
  while @run
68
- callback_traces
71
+ @back_off = callback_traces ? @flush_interval : [@back_off * BACK_OFF_RATIO, BACK_OFF_MAX].min
72
+
69
73
  callback_services
70
- sleep(@flush_interval) if @run
74
+
75
+ sleep(@back_off) if @run
71
76
  end
72
77
  end
73
78
  end
@@ -33,6 +33,7 @@ module Datadog
33
33
  # spawns two different workers for spans and services;
34
34
  # they share the same transport which is thread-safe
35
35
  def start
36
+ @pid = Process.pid
36
37
  @trace_handler = ->(items, transport) { send_spans(items, transport) }
37
38
  @service_handler = ->(items, transport) { send_services(items, transport) }
38
39
  @worker = Datadog::Workers::AsyncTransport.new(@transport,
@@ -55,16 +56,10 @@ module Datadog
55
56
  return true if traces.empty?
56
57
 
57
58
  code = transport.send(:traces, traces)
59
+ status = !transport.server_error?(code)
60
+ @traces_flushed += traces.length if status
58
61
 
59
- if transport.server_error? code # requeue on server error, skip on success or client error
60
- traces[0..@buff_size].each do |trace|
61
- @worker.enqueue_trace trace
62
- end
63
- return false
64
- end
65
-
66
- @traces_flushed += traces.length()
67
- true
62
+ status
68
63
  end
69
64
 
70
65
  # flush services to the trace-agent, handles services only
@@ -72,13 +67,10 @@ module Datadog
72
67
  return true if services.empty?
73
68
 
74
69
  code = transport.send(:services, services)
75
- if transport.server_error? code # requeue on server error, skip on success or client error
76
- @worker.enqueue_service services
77
- return false
78
- end
70
+ status = !transport.server_error?(code)
71
+ @services_flushed += 1 if status
79
72
 
80
- @services_flushed += 1
81
- true
73
+ status
82
74
  end
83
75
 
84
76
  # enqueue the trace for submission to the API
@@ -94,7 +86,6 @@ module Datadog
94
86
  pid = Process.pid
95
87
  @mutex_after_fork.synchronize do
96
88
  if pid != @pid
97
- @pid = pid
98
89
  # we should start threads because the worker doesn't own this
99
90
  start()
100
91
  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.9.0
4
+ version: 0.9.1
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-10-06 00:00:00.000000000 Z
11
+ date: 2017-11-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: msgpack
@@ -94,6 +94,20 @@ dependencies:
94
94
  - - "~>"
95
95
  - !ruby/object:Gem::Version
96
96
  version: '0.9'
97
+ - !ruby/object:Gem::Dependency
98
+ name: redcarpet
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: '3.4'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: '3.4'
97
111
  description: |
98
112
  ddtrace is Datadog’s tracing client for Ruby. It is used to trace requests
99
113
  as they flow across web servers, databases and microservices so that developers