ddtrace 0.37.0 → 0.38.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (57) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +2 -0
  3. data/Appraisals +15 -0
  4. data/CHANGELOG.md +33 -1
  5. data/Rakefile +11 -10
  6. data/docker-compose.yml +2 -2
  7. data/docs/GettingStarted.md +55 -0
  8. data/lib/ddtrace.rb +2 -0
  9. data/lib/ddtrace/configuration/settings.rb +18 -0
  10. data/lib/ddtrace/contrib/active_support/notifications/subscription.rb +1 -1
  11. data/lib/ddtrace/contrib/extensions.rb +10 -0
  12. data/lib/ddtrace/contrib/faraday/middleware.rb +5 -3
  13. data/lib/ddtrace/contrib/faraday/patcher.rb +3 -0
  14. data/lib/ddtrace/contrib/grpc/datadog_interceptor/client.rb +1 -3
  15. data/lib/ddtrace/contrib/httprb/configuration/settings.rb +27 -0
  16. data/lib/ddtrace/contrib/httprb/ext.rb +14 -0
  17. data/lib/ddtrace/contrib/httprb/instrumentation.rb +163 -0
  18. data/lib/ddtrace/contrib/httprb/integration.rb +43 -0
  19. data/lib/ddtrace/contrib/httprb/patcher.rb +35 -0
  20. data/lib/ddtrace/contrib/kafka/configuration/settings.rb +25 -0
  21. data/lib/ddtrace/contrib/kafka/consumer_event.rb +14 -0
  22. data/lib/ddtrace/contrib/kafka/consumer_group_event.rb +14 -0
  23. data/lib/ddtrace/contrib/kafka/event.rb +51 -0
  24. data/lib/ddtrace/contrib/kafka/events.rb +44 -0
  25. data/lib/ddtrace/contrib/kafka/events/connection/request.rb +34 -0
  26. data/lib/ddtrace/contrib/kafka/events/consumer/process_batch.rb +41 -0
  27. data/lib/ddtrace/contrib/kafka/events/consumer/process_message.rb +39 -0
  28. data/lib/ddtrace/contrib/kafka/events/consumer_group/heartbeat.rb +39 -0
  29. data/lib/ddtrace/contrib/kafka/events/consumer_group/join_group.rb +29 -0
  30. data/lib/ddtrace/contrib/kafka/events/consumer_group/leave_group.rb +29 -0
  31. data/lib/ddtrace/contrib/kafka/events/consumer_group/sync_group.rb +29 -0
  32. data/lib/ddtrace/contrib/kafka/events/produce_operation/send_messages.rb +32 -0
  33. data/lib/ddtrace/contrib/kafka/events/producer/deliver_messages.rb +35 -0
  34. data/lib/ddtrace/contrib/kafka/ext.rb +38 -0
  35. data/lib/ddtrace/contrib/kafka/integration.rb +39 -0
  36. data/lib/ddtrace/contrib/kafka/patcher.rb +26 -0
  37. data/lib/ddtrace/contrib/rack/middlewares.rb +15 -12
  38. data/lib/ddtrace/contrib/rest_client/request_patch.rb +2 -2
  39. data/lib/ddtrace/contrib/sidekiq/ext.rb +1 -0
  40. data/lib/ddtrace/contrib/sidekiq/patcher.rb +8 -1
  41. data/lib/ddtrace/contrib/sidekiq/server_tracer.rb +1 -0
  42. data/lib/ddtrace/diagnostics/environment_logger.rb +278 -0
  43. data/lib/ddtrace/environment.rb +5 -1
  44. data/lib/ddtrace/ext/diagnostics.rb +2 -0
  45. data/lib/ddtrace/ext/environment.rb +2 -0
  46. data/lib/ddtrace/pipeline/span_filter.rb +15 -15
  47. data/lib/ddtrace/sampler.rb +2 -0
  48. data/lib/ddtrace/span.rb +10 -0
  49. data/lib/ddtrace/tracer.rb +13 -6
  50. data/lib/ddtrace/transport/http/adapters/net.rb +8 -0
  51. data/lib/ddtrace/transport/http/adapters/test.rb +4 -0
  52. data/lib/ddtrace/transport/http/adapters/unix_socket.rb +4 -0
  53. data/lib/ddtrace/transport/response.rb +11 -0
  54. data/lib/ddtrace/version.rb +1 -1
  55. data/lib/ddtrace/workers/trace_writer.rb +3 -0
  56. data/lib/ddtrace/writer.rb +33 -12
  57. metadata +27 -3
@@ -193,6 +193,8 @@ module Datadog
193
193
  class PrioritySampler
194
194
  extend Forwardable
195
195
 
196
+ attr_reader :pre_sampler, :priority_sampler
197
+
196
198
  SAMPLE_RATE_METRIC_KEY = '_sample_rate'.freeze
197
199
 
198
200
  def initialize(opts = {})
@@ -107,6 +107,16 @@ module Datadog
107
107
  Datadog.logger.debug("Unable to set the tag #{key}, ignoring it. Caused by: #{e}")
108
108
  end
109
109
 
110
+ # Sets tags from given hash, for each key in hash it sets the tag with that key
111
+ # and associated value from the hash. It is shortcut for `set_tag`. Keys and values
112
+ # of the hash must be strings. Note that nested hashes are not supported.
113
+ # A valid example is:
114
+ #
115
+ # span.set_tags({ "http.method" => "GET", "user.id" => "234" })
116
+ def set_tags(tags)
117
+ tags.each { |k, v| set_tag(k, v) }
118
+ end
119
+
110
120
  # This method removes a tag for the given key.
111
121
  def clear_tag(key)
112
122
  @meta.delete(key)
@@ -212,8 +212,8 @@ module Datadog
212
212
  # child span
213
213
  span.parent = parent # sets service, trace_id, parent_id, sampled
214
214
  end
215
- @tags.each { |k, v| span.set_tag(k, v) } unless @tags.empty?
216
- tags.each { |k, v| span.set_tag(k, v) } unless tags.empty?
215
+ span.set_tags(@tags) unless @tags.empty?
216
+ span.set_tags(tags) unless tags.empty?
217
217
  span.start_time = start_time
218
218
 
219
219
  # this could at some point be optional (start_active_span vs start_manual_span)
@@ -255,9 +255,11 @@ module Datadog
255
255
  # * +service+: the service name for this span
256
256
  # * +resource+: the resource this span refers, or \name if it's missing
257
257
  # * +span_type+: the type of the span (such as \http, \db and so on)
258
+ # * +child_of+: a \Span or a \Context instance representing the parent for this span.
259
+ # If not set, defaults to Tracer.call_context
258
260
  # * +tags+: extra tags which should be added to the span.
259
261
  def trace(name, options = {})
260
- options[:child_of] = call_context
262
+ options[:child_of] ||= call_context
261
263
 
262
264
  # call the finish only if a block is given; this ensures
263
265
  # that a call to tracer.trace() without a block, returns
@@ -269,11 +271,16 @@ module Datadog
269
271
  begin
270
272
  begin
271
273
  span = start_span(name, options)
272
- # rubocop:disable Lint/UselessAssignment
273
274
  rescue StandardError => e
274
- Datadog.logger.debug('Failed to start span: #{e}')
275
+ Datadog.logger.debug("Failed to start span: #{e}")
275
276
  ensure
276
- return_value = yield(span)
277
+ # We should yield to the provided block when possible, as this
278
+ # block is application code that we don't want to hinder. We call:
279
+ # * `yield(span)` during normal execution.
280
+ # * `yield(nil)` if `start_span` fails with a runtime error.
281
+ # * We don't yield during a fatal error, as the application is likely trying to
282
+ # end its execution (either due to a system error or graceful shutdown).
283
+ return_value = yield(span) if span || e.is_a?(StandardError)
277
284
  end
278
285
  # rubocop:disable Lint/RescueException
279
286
  # Here we really want to catch *any* exception, not only StandardError,
@@ -47,6 +47,10 @@ module Datadog
47
47
  Response.new(http_response)
48
48
  end
49
49
 
50
+ def url
51
+ "http://#{hostname}:#{port}?timeout=#{timeout}"
52
+ end
53
+
50
54
  # Raised when called with an unknown HTTP method
51
55
  class UnknownHTTPMethod < StandardError
52
56
  attr_reader :verb
@@ -104,6 +108,10 @@ module Datadog
104
108
  return super if http_response.nil?
105
109
  code.between?(500, 599)
106
110
  end
111
+
112
+ def inspect
113
+ "#{super}, http_response:#{http_response}"
114
+ end
107
115
  end
108
116
  end
109
117
  end
@@ -69,6 +69,10 @@ module Datadog
69
69
  def server_error?
70
70
  code.between?(500, 599)
71
71
  end
72
+
73
+ def inspect
74
+ "#{super}, code:#{code}"
75
+ end
72
76
  end
73
77
  end
74
78
  end
@@ -31,6 +31,10 @@ module Datadog
31
31
  end
32
32
  end
33
33
 
34
+ def url
35
+ "http+unix://#{filepath}?timeout=#{timeout}"
36
+ end
37
+
34
38
  # Re-implements Net:HTTP with underlying Unix socket
35
39
  class HTTP < ::Net::HTTP
36
40
  DEFAULT_TIMEOUT = 1
@@ -29,6 +29,13 @@ module Datadog
29
29
  def internal_error?
30
30
  nil
31
31
  end
32
+
33
+ def inspect
34
+ "#{self.class} ok?:#{ok?} unsupported?:#{unsupported?}, " \
35
+ "not_found?:#{not_found?}, client_error?:#{client_error?}, " \
36
+ "server_error?:#{server_error?}, internal_error?:#{internal_error?}, " \
37
+ "payload:#{payload}"
38
+ end
32
39
  end
33
40
 
34
41
  # A generic error response for internal errors
@@ -44,6 +51,10 @@ module Datadog
44
51
  def internal_error?
45
52
  true
46
53
  end
54
+
55
+ def inspect
56
+ "#{super}, error_type:#{error.class} error:#{error}"
57
+ end
47
58
  end
48
59
  end
49
60
  end
@@ -1,7 +1,7 @@
1
1
  module Datadog
2
2
  module VERSION
3
3
  MAJOR = 0
4
- MINOR = 37
4
+ MINOR = 38
5
5
  PATCH = 0
6
6
  PRE = nil
7
7
 
@@ -72,6 +72,9 @@ module Datadog
72
72
  end
73
73
  end
74
74
 
75
+ # TODO: Register `Datadog::Diagnostics::EnvironmentLogger.log!`
76
+ # TODO: as a flush_completed subscriber when the `TraceWriter`
77
+ # TODO: instantiation code is implemented.
75
78
  def flush_completed
76
79
  @flush_completed ||= FlushCompleted.new
77
80
  end
@@ -7,6 +7,7 @@ require 'ddtrace/transport/http'
7
7
  require 'ddtrace/transport/io'
8
8
  require 'ddtrace/encoding'
9
9
  require 'ddtrace/workers'
10
+ require 'ddtrace/diagnostics/environment_logger'
10
11
 
11
12
  module Datadog
12
13
  # Processor that sends traces and metadata to the agent
@@ -43,9 +44,18 @@ module Datadog
43
44
  @worker = nil
44
45
  end
45
46
 
46
- # spawns a worker for spans; they share the same transport which is thread-safe
47
47
  def start
48
- @pid = Process.pid
48
+ @mutex_after_fork.synchronize do
49
+ pid = Process.pid
50
+ return if @worker && pid == @pid
51
+ @pid = pid
52
+ start_worker
53
+ true
54
+ end
55
+ end
56
+
57
+ # spawns a worker for spans; they share the same transport which is thread-safe
58
+ def start_worker
49
59
  @trace_handler = ->(items, transport) { send_spans(items, transport) }
50
60
  @worker = Datadog::Workers::AsyncTransport.new(
51
61
  transport: @transport,
@@ -57,14 +67,19 @@ module Datadog
57
67
  @worker.start
58
68
  end
59
69
 
60
- # stops worker for spans.
61
70
  def stop
62
- return if worker.nil?
71
+ @mutex_after_fork.synchronize { stop_worker }
72
+ end
73
+
74
+ def stop_worker
75
+ return if @worker.nil?
63
76
  @worker.stop
64
77
  @worker = nil
65
78
  true
66
79
  end
67
80
 
81
+ private :start_worker, :stop_worker
82
+
68
83
  # flush spans to the trace-agent, handles spans only
69
84
  def send_spans(traces, transport)
70
85
  return true if traces.empty?
@@ -83,6 +98,8 @@ module Datadog
83
98
  # Update priority sampler
84
99
  update_priority_sampler(responses.last)
85
100
 
101
+ record_environment_information!(responses)
102
+
86
103
  # Return if server error occurred.
87
104
  !responses.find(&:server_error?)
88
105
  end
@@ -106,13 +123,7 @@ module Datadog
106
123
  #
107
124
  # This check ensures that if a process doesn't own the current +Writer+, async workers
108
125
  # will be initialized again (but only once for each process).
109
- pid = Process.pid
110
- if pid != @pid # avoid using Mutex when pids are equal
111
- @mutex_after_fork.synchronize do
112
- # we should start threads because the worker doesn't own this
113
- start if pid != @pid
114
- end
115
- end
126
+ start if @worker.nil? || @pid != Process.pid
116
127
 
117
128
  # TODO: Remove this, and have the tracer pump traces directly to runtime metrics
118
129
  # instead of working through the trace writer.
@@ -121,7 +132,13 @@ module Datadog
121
132
  Datadog.runtime_metrics.associate_with_span(trace.first)
122
133
  end
123
134
 
124
- @worker.enqueue_trace(trace)
135
+ worker_local = @worker
136
+
137
+ if worker_local
138
+ worker_local.enqueue_trace(trace)
139
+ else
140
+ Datadog.logger.debug('Writer either failed to start or was stopped before #write could complete')
141
+ end
125
142
  end
126
143
 
127
144
  # stats returns a dictionary of stats about the writer.
@@ -150,5 +167,9 @@ module Datadog
150
167
 
151
168
  priority_sampler.update(response.service_rates)
152
169
  end
170
+
171
+ def record_environment_information!(responses)
172
+ Diagnostics::EnvironmentLogger.log!(responses)
173
+ end
153
174
  end
154
175
  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.37.0
4
+ version: 0.38.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: 2020-06-24 00:00:00.000000000 Z
11
+ date: 2020-07-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: msgpack
@@ -546,7 +546,29 @@ files:
546
546
  - lib/ddtrace/contrib/http/integration.rb
547
547
  - lib/ddtrace/contrib/http/patcher.rb
548
548
  - lib/ddtrace/contrib/http_annotation_helper.rb
549
+ - lib/ddtrace/contrib/httprb/configuration/settings.rb
550
+ - lib/ddtrace/contrib/httprb/ext.rb
551
+ - lib/ddtrace/contrib/httprb/instrumentation.rb
552
+ - lib/ddtrace/contrib/httprb/integration.rb
553
+ - lib/ddtrace/contrib/httprb/patcher.rb
549
554
  - lib/ddtrace/contrib/integration.rb
555
+ - lib/ddtrace/contrib/kafka/configuration/settings.rb
556
+ - lib/ddtrace/contrib/kafka/consumer_event.rb
557
+ - lib/ddtrace/contrib/kafka/consumer_group_event.rb
558
+ - lib/ddtrace/contrib/kafka/event.rb
559
+ - lib/ddtrace/contrib/kafka/events.rb
560
+ - lib/ddtrace/contrib/kafka/events/connection/request.rb
561
+ - lib/ddtrace/contrib/kafka/events/consumer/process_batch.rb
562
+ - lib/ddtrace/contrib/kafka/events/consumer/process_message.rb
563
+ - lib/ddtrace/contrib/kafka/events/consumer_group/heartbeat.rb
564
+ - lib/ddtrace/contrib/kafka/events/consumer_group/join_group.rb
565
+ - lib/ddtrace/contrib/kafka/events/consumer_group/leave_group.rb
566
+ - lib/ddtrace/contrib/kafka/events/consumer_group/sync_group.rb
567
+ - lib/ddtrace/contrib/kafka/events/produce_operation/send_messages.rb
568
+ - lib/ddtrace/contrib/kafka/events/producer/deliver_messages.rb
569
+ - lib/ddtrace/contrib/kafka/ext.rb
570
+ - lib/ddtrace/contrib/kafka/integration.rb
571
+ - lib/ddtrace/contrib/kafka/patcher.rb
550
572
  - lib/ddtrace/contrib/mongodb/configuration/settings.rb
551
573
  - lib/ddtrace/contrib/mongodb/ext.rb
552
574
  - lib/ddtrace/contrib/mongodb/instrumentation.rb
@@ -647,6 +669,7 @@ files:
647
669
  - lib/ddtrace/contrib/sucker_punch/integration.rb
648
670
  - lib/ddtrace/contrib/sucker_punch/patcher.rb
649
671
  - lib/ddtrace/correlation.rb
672
+ - lib/ddtrace/diagnostics/environment_logger.rb
650
673
  - lib/ddtrace/diagnostics/health.rb
651
674
  - lib/ddtrace/distributed_tracing/headers/b3.rb
652
675
  - lib/ddtrace/distributed_tracing/headers/b3_single.rb
@@ -784,7 +807,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
784
807
  - !ruby/object:Gem::Version
785
808
  version: 2.0.0
786
809
  requirements: []
787
- rubygems_version: 3.0.3
810
+ rubyforge_project:
811
+ rubygems_version: 2.7.6.2
788
812
  signing_key:
789
813
  specification_version: 4
790
814
  summary: Datadog tracing code for your Ruby applications