ddtrace 0.34.1 → 0.36.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (113) hide show
  1. checksums.yaml +5 -5
  2. data/.circleci/config.yml +58 -9
  3. data/.circleci/images/primary/Dockerfile-jruby-9.2 +77 -0
  4. data/.rubocop.yml +4 -0
  5. data/Appraisals +9 -7
  6. data/CHANGELOG.md +89 -3
  7. data/Rakefile +11 -2
  8. data/ddtrace.gemspec +5 -3
  9. data/docker-compose.yml +35 -0
  10. data/docs/DevelopmentGuide.md +1 -1
  11. data/docs/GettingStarted.md +89 -36
  12. data/lib/ddtrace.rb +1 -1
  13. data/lib/ddtrace/buffer.rb +9 -9
  14. data/lib/ddtrace/chunker.rb +34 -0
  15. data/lib/ddtrace/configuration.rb +28 -5
  16. data/lib/ddtrace/configuration/base.rb +1 -1
  17. data/lib/ddtrace/configuration/components.rb +154 -0
  18. data/lib/ddtrace/configuration/options.rb +1 -1
  19. data/lib/ddtrace/configuration/settings.rb +131 -63
  20. data/lib/ddtrace/context.rb +6 -6
  21. data/lib/ddtrace/context_flush.rb +1 -1
  22. data/lib/ddtrace/contrib/action_cable/instrumentation.rb +1 -1
  23. data/lib/ddtrace/contrib/action_pack/action_controller/instrumentation.rb +2 -2
  24. data/lib/ddtrace/contrib/action_view/events/render_partial.rb +1 -1
  25. data/lib/ddtrace/contrib/action_view/events/render_template.rb +1 -1
  26. data/lib/ddtrace/contrib/action_view/instrumentation/partial_renderer.rb +1 -1
  27. data/lib/ddtrace/contrib/action_view/instrumentation/template_renderer.rb +2 -2
  28. data/lib/ddtrace/contrib/action_view/patcher.rb +1 -1
  29. data/lib/ddtrace/contrib/active_record/events/instantiation.rb +1 -1
  30. data/lib/ddtrace/contrib/active_record/events/sql.rb +1 -1
  31. data/lib/ddtrace/contrib/active_support/cache/instrumentation.rb +2 -2
  32. data/lib/ddtrace/contrib/active_support/notifications/subscription.rb +2 -2
  33. data/lib/ddtrace/contrib/analytics.rb +1 -1
  34. data/lib/ddtrace/contrib/configuration/settings.rb +1 -1
  35. data/lib/ddtrace/contrib/dalli/patcher.rb +1 -1
  36. data/lib/ddtrace/contrib/dalli/quantize.rb +1 -1
  37. data/lib/ddtrace/contrib/elasticsearch/patcher.rb +1 -1
  38. data/lib/ddtrace/contrib/excon/middleware.rb +2 -2
  39. data/lib/ddtrace/contrib/extensions.rb +29 -5
  40. data/lib/ddtrace/contrib/faraday/patcher.rb +1 -1
  41. data/lib/ddtrace/contrib/grape/endpoint.rb +5 -5
  42. data/lib/ddtrace/contrib/grape/patcher.rb +1 -1
  43. data/lib/ddtrace/contrib/grpc/datadog_interceptor/client.rb +1 -1
  44. data/lib/ddtrace/contrib/grpc/datadog_interceptor/server.rb +2 -2
  45. data/lib/ddtrace/contrib/grpc/patcher.rb +1 -1
  46. data/lib/ddtrace/contrib/http/circuit_breaker.rb +8 -32
  47. data/lib/ddtrace/contrib/http/instrumentation.rb +2 -2
  48. data/lib/ddtrace/contrib/mongodb/subscribers.rb +2 -2
  49. data/lib/ddtrace/contrib/patchable.rb +1 -1
  50. data/lib/ddtrace/contrib/patcher.rb +3 -3
  51. data/lib/ddtrace/contrib/presto/instrumentation.rb +3 -3
  52. data/lib/ddtrace/contrib/presto/patcher.rb +1 -1
  53. data/lib/ddtrace/contrib/rack/middlewares.rb +2 -2
  54. data/lib/ddtrace/contrib/rack/patcher.rb +2 -2
  55. data/lib/ddtrace/contrib/rack/request_queue.rb +1 -1
  56. data/lib/ddtrace/contrib/rails/configuration/settings.rb +14 -0
  57. data/lib/ddtrace/contrib/rails/framework.rb +54 -48
  58. data/lib/ddtrace/contrib/rails/integration.rb +1 -1
  59. data/lib/ddtrace/contrib/rake/instrumentation.rb +2 -2
  60. data/lib/ddtrace/contrib/redis/quantize.rb +1 -1
  61. data/lib/ddtrace/contrib/resque/resque_job.rb +2 -2
  62. data/lib/ddtrace/contrib/sidekiq/tracing.rb +1 -1
  63. data/lib/ddtrace/contrib/sinatra/env.rb +20 -0
  64. data/lib/ddtrace/contrib/sinatra/ext.rb +6 -0
  65. data/lib/ddtrace/contrib/sinatra/patcher.rb +1 -0
  66. data/lib/ddtrace/contrib/sinatra/tracer.rb +98 -35
  67. data/lib/ddtrace/contrib/sinatra/tracer_middleware.rb +16 -13
  68. data/lib/ddtrace/correlation.rb +9 -6
  69. data/lib/ddtrace/diagnostics/health.rb +2 -6
  70. data/lib/ddtrace/encoding.rb +13 -39
  71. data/lib/ddtrace/event.rb +1 -1
  72. data/lib/ddtrace/ext/correlation.rb +1 -0
  73. data/lib/ddtrace/ext/diagnostics.rb +2 -0
  74. data/lib/ddtrace/ext/environment.rb +1 -0
  75. data/lib/ddtrace/ext/forced_tracing.rb +1 -1
  76. data/lib/ddtrace/logger.rb +3 -44
  77. data/lib/ddtrace/metrics.rb +5 -5
  78. data/lib/ddtrace/monkey.rb +1 -1
  79. data/lib/ddtrace/opentracer/global_tracer.rb +1 -1
  80. data/lib/ddtrace/pin.rb +18 -17
  81. data/lib/ddtrace/pipeline.rb +1 -1
  82. data/lib/ddtrace/propagation/http_propagator.rb +2 -2
  83. data/lib/ddtrace/runtime/cgroup.rb +1 -1
  84. data/lib/ddtrace/runtime/container.rb +1 -1
  85. data/lib/ddtrace/runtime/metrics.rb +5 -2
  86. data/lib/ddtrace/sampler.rb +2 -2
  87. data/lib/ddtrace/sampling/rule.rb +1 -1
  88. data/lib/ddtrace/sampling/rule_sampler.rb +1 -1
  89. data/lib/ddtrace/span.rb +4 -4
  90. data/lib/ddtrace/sync_writer.rb +3 -8
  91. data/lib/ddtrace/tracer.rb +26 -31
  92. data/lib/ddtrace/transport/http.rb +1 -1
  93. data/lib/ddtrace/transport/http/api/instance.rb +4 -0
  94. data/lib/ddtrace/transport/http/builder.rb +3 -5
  95. data/lib/ddtrace/transport/http/client.rb +7 -64
  96. data/lib/ddtrace/transport/http/response.rb +1 -1
  97. data/lib/ddtrace/transport/http/statistics.rb +1 -1
  98. data/lib/ddtrace/transport/http/traces.rb +10 -7
  99. data/lib/ddtrace/transport/io.rb +1 -1
  100. data/lib/ddtrace/transport/io/client.rb +2 -2
  101. data/lib/ddtrace/transport/io/response.rb +3 -1
  102. data/lib/ddtrace/transport/io/traces.rb +50 -3
  103. data/lib/ddtrace/transport/parcel.rb +0 -4
  104. data/lib/ddtrace/transport/statistics.rb +2 -2
  105. data/lib/ddtrace/transport/traces.rb +160 -10
  106. data/lib/ddtrace/utils.rb +1 -1
  107. data/lib/ddtrace/version.rb +2 -2
  108. data/lib/ddtrace/workers.rb +5 -13
  109. data/lib/ddtrace/workers/async.rb +2 -2
  110. data/lib/ddtrace/workers/runtime_metrics.rb +47 -0
  111. data/lib/ddtrace/workers/trace_writer.rb +199 -0
  112. data/lib/ddtrace/writer.rb +20 -27
  113. metadata +22 -32
@@ -61,7 +61,7 @@ module Datadog
61
61
  break
62
62
  end
63
63
  rescue StandardError => e
64
- Datadog::Logger.log.error(
64
+ Datadog.logger.error(
65
65
  "Error while parsing container info. Cause: #{e.message} Location: #{e.backtrace.first}"
66
66
  )
67
67
  end
@@ -14,8 +14,9 @@ module Datadog
14
14
  super
15
15
 
16
16
  # Initialize service list
17
- @services = Set.new
17
+ @services = Set.new(options.fetch(:services, []))
18
18
  @service_tags = nil
19
+ compile_service_tags!
19
20
  end
20
21
 
21
22
  def associate_with_span(span)
@@ -55,6 +56,8 @@ module Datadog
55
56
  def gc_metrics
56
57
  Hash[
57
58
  GC.stat.map do |k, v|
59
+ next if v.is_a?(Hash) # TODO: JRuby supports additional nested metrics
60
+
58
61
  ["#{Ext::Runtime::Metrics::METRIC_GC_PREFIX}.#{k}", v]
59
62
  end
60
63
  ]
@@ -63,7 +66,7 @@ module Datadog
63
66
  def try_flush
64
67
  yield
65
68
  rescue StandardError => e
66
- Datadog::Logger.log.error("Error while sending runtime metric. Cause: #{e.message}")
69
+ Datadog.logger.error("Error while sending runtime metric. Cause: #{e.message}")
67
70
  end
68
71
 
69
72
  def default_metric_options
@@ -48,7 +48,7 @@ module Datadog
48
48
  # sampled.
49
49
  def initialize(sample_rate = 1.0)
50
50
  unless sample_rate > 0.0 && sample_rate <= 1.0
51
- Datadog::Logger.log.error('sample rate is not between 0 and 1, disabling the sampler')
51
+ Datadog.logger.error('sample rate is not between 0 and 1, disabling the sampler')
52
52
  sample_rate = 1.0
53
53
  end
54
54
 
@@ -176,7 +176,7 @@ module Datadog
176
176
  update_all(rate_by_service)
177
177
 
178
178
  # Emit metric for service cache size
179
- Diagnostics::Health.metrics.sampling_service_cache_length(length)
179
+ Datadog.health_metrics.sampling_service_cache_length(length)
180
180
  end
181
181
 
182
182
  private
@@ -28,7 +28,7 @@ module Datadog
28
28
  def match?(span)
29
29
  @matcher.match?(span)
30
30
  rescue => e
31
- Datadog::Logger.log.error("Matcher failed. Cause: #{e.message} Source: #{e.backtrace.first}")
31
+ Datadog.logger.error("Matcher failed. Cause: #{e.message} Source: #{e.backtrace.first}")
32
32
  nil
33
33
  end
34
34
 
@@ -109,7 +109,7 @@ module Datadog
109
109
  set_limiter_metrics(span, rate_limiter.effective_rate)
110
110
  end
111
111
  rescue StandardError => e
112
- Datadog::Logger.log.error("Rule sampling failed. Cause: #{e.message} Source: #{e.backtrace.first}")
112
+ Datadog.logger.error("Rule sampling failed. Cause: #{e.message} Source: #{e.backtrace.first}")
113
113
  yield(span)
114
114
  end
115
115
 
@@ -104,7 +104,7 @@ module Datadog
104
104
  @meta[key] = value.to_s
105
105
  end
106
106
  rescue StandardError => e
107
- Datadog::Logger.log.debug("Unable to set the tag #{key}, ignoring it. Caused by: #{e}")
107
+ Datadog.logger.debug("Unable to set the tag #{key}, ignoring it. Caused by: #{e}")
108
108
  end
109
109
 
110
110
  # This method removes a tag for the given key.
@@ -127,7 +127,7 @@ module Datadog
127
127
  value = Float(value)
128
128
  @metrics[key] = value
129
129
  rescue StandardError => e
130
- Datadog::Logger.log.debug("Unable to set the metric #{key}, ignoring it. Caused by: #{e}")
130
+ Datadog.logger.debug("Unable to set the metric #{key}, ignoring it. Caused by: #{e}")
131
131
  end
132
132
 
133
133
  # This method removes a metric for the given key. It acts like {#remove_tag}.
@@ -179,8 +179,8 @@ module Datadog
179
179
  @context.close_span(self)
180
180
  @tracer.record(self)
181
181
  rescue StandardError => e
182
- Datadog::Logger.log.debug("error recording finished trace: #{e}")
183
- Diagnostics::Health.metrics.error_span_finish(1, tags: ["error:#{e.class.name}"])
182
+ Datadog.logger.debug("error recording finished trace: #{e}")
183
+ Datadog.health_metrics.error_span_finish(1, tags: ["error:#{e.class.name}"])
184
184
  end
185
185
  self
186
186
  end
@@ -4,10 +4,10 @@ require 'ddtrace/runtime/metrics'
4
4
 
5
5
  module Datadog
6
6
  # SyncWriter flushes both services and traces synchronously
7
+ # DEV: To be replaced by Datadog::Workers::TraceWriter.
7
8
  class SyncWriter
8
9
  attr_reader \
9
10
  :priority_sampler,
10
- :runtime_metrics,
11
11
  :transport
12
12
 
13
13
  def initialize(options = {})
@@ -16,18 +16,13 @@ module Datadog
16
16
  Transport::HTTP.default(transport_options)
17
17
  end
18
18
 
19
- # Runtime metrics
20
- @runtime_metrics = options.fetch(:runtime_metrics) do
21
- Runtime::Metrics.new
22
- end
23
-
24
19
  @priority_sampler = options.fetch(:priority_sampler, nil)
25
20
  end
26
21
 
27
22
  def write(trace, services = nil)
28
23
  unless services.nil?
29
24
  Datadog::Patcher.do_once('SyncWriter#write') do
30
- Datadog::Logger.log.warn(%(
25
+ Datadog.logger.warn(%(
31
26
  write: Writing services has been deprecated and no longer need to be provided.
32
27
  write(traces, services) can be updted to write(traces)
33
28
  ))
@@ -38,7 +33,7 @@ module Datadog
38
33
  proc { flush_trace(trace) }
39
34
  )
40
35
  rescue => e
41
- Logger.log.debug(e)
36
+ Datadog.logger.debug(e)
42
37
  end
43
38
 
44
39
  # Added for interface completeness
@@ -30,7 +30,7 @@ module Datadog
30
30
  def services
31
31
  # Only log each deprecation warning once (safeguard against log spam)
32
32
  Datadog::Patcher.do_once('Tracer#set_service_info') do
33
- Datadog::Logger.log.warn('services: Usage of Tracer.services has been deprecated')
33
+ Datadog.logger.warn('services: Usage of Tracer.services has been deprecated')
34
34
  end
35
35
 
36
36
  {}
@@ -70,22 +70,23 @@ module Datadog
70
70
  # * +enabled+: set if the tracer submits or not spans to the local agent. It's enabled
71
71
  # by default.
72
72
  def initialize(options = {})
73
- @enabled = options.fetch(:enabled, true)
74
- @writer = options.fetch(:writer, Datadog::Writer.new)
75
- @sampler = options.fetch(:sampler, Datadog::AllSampler.new)
76
-
77
- @provider = options.fetch(:context_provider, Datadog::DefaultContextProvider.new)
78
- @provider ||= Datadog::DefaultContextProvider.new # @provider should never be nil
79
-
73
+ # Configurable options
80
74
  @context_flush = if options[:partial_flush]
81
75
  Datadog::ContextFlush::Partial.new(options)
82
76
  else
83
77
  Datadog::ContextFlush::Finished.new
84
78
  end
85
79
 
80
+ @default_service = options[:default_service]
81
+ @enabled = options.fetch(:enabled, true)
82
+ @provider = options.fetch(:context_provider, Datadog::DefaultContextProvider.new)
83
+ @sampler = options.fetch(:sampler, Datadog::AllSampler.new)
84
+ @tags = options.fetch(:tags, {})
85
+ @writer = options.fetch(:writer, Datadog::Writer.new)
86
+
87
+ # Instance variables
86
88
  @mutex = Mutex.new
87
- @tags = options.fetch(:tags, Datadog.configuration.tags)
88
- @default_service = options.fetch(:default_service, Datadog.configuration.service)
89
+ @provider ||= Datadog::DefaultContextProvider.new # @provider should never be nil
89
90
 
90
91
  # Enable priority sampling by default
91
92
  activate_priority_sampling!(@sampler)
@@ -114,11 +115,13 @@ module Datadog
114
115
 
115
116
  configure_writer(options)
116
117
 
117
- @context_flush = if options[:partial_flush]
118
- Datadog::ContextFlush::Partial.new(options)
119
- else
120
- Datadog::ContextFlush::Finished.new
121
- end
118
+ if options.key?(:partial_flush)
119
+ @context_flush = if options[:partial_flush]
120
+ Datadog::ContextFlush::Partial.new(options)
121
+ else
122
+ Datadog::ContextFlush::Finished.new
123
+ end
124
+ end
122
125
  end
123
126
 
124
127
  # Set the information about the given service. A valid example is:
@@ -129,7 +132,7 @@ module Datadog
129
132
  def set_service_info(service, app, app_type)
130
133
  # Only log each deprecation warning once (safeguard against log spam)
131
134
  Datadog::Patcher.do_once('Tracer#set_service_info') do
132
- Datadog::Logger.log.warn(%(
135
+ Datadog.logger.warn(%(
133
136
  set_service_info: Usage of set_service_info has been deprecated,
134
137
  service information no longer needs to be reported to the trace agent.
135
138
  ))
@@ -144,7 +147,7 @@ module Datadog
144
147
  begin
145
148
  @default_service = File.basename($PROGRAM_NAME, '.*')
146
149
  rescue StandardError => e
147
- Datadog::Logger.log.error("unable to guess default service: #{e}")
150
+ Datadog.logger.error("unable to guess default service: #{e}")
148
151
  @default_service = 'ruby'.freeze
149
152
  end
150
153
  @default_service
@@ -268,7 +271,7 @@ module Datadog
268
271
  span = start_span(name, options)
269
272
  # rubocop:disable Lint/UselessAssignment
270
273
  rescue StandardError => e
271
- Datadog::Logger.log.debug('Failed to start span: #{e}')
274
+ Datadog.logger.debug('Failed to start span: #{e}')
272
275
  ensure
273
276
  return_value = yield(span)
274
277
  end
@@ -334,11 +337,11 @@ module Datadog
334
337
  def write(trace)
335
338
  return if @writer.nil? || !@enabled
336
339
 
337
- if Datadog::Logger.debug_logging
338
- Datadog::Logger.log.debug("Writing #{trace.length} spans (enabled: #{@enabled})")
340
+ if Datadog.configuration.diagnostics.debug
341
+ Datadog.logger.debug("Writing #{trace.length} spans (enabled: #{@enabled})")
339
342
  str = String.new('')
340
343
  PP.pp(trace, str)
341
- Datadog::Logger.log.debug(str)
344
+ Datadog.logger.debug(str)
342
345
  end
343
346
 
344
347
  @writer.write(trace)
@@ -355,10 +358,10 @@ module Datadog
355
358
  sampler = options.fetch(:sampler, nil)
356
359
  priority_sampling = options.fetch(:priority_sampling, nil)
357
360
  writer = options.fetch(:writer, nil)
358
- transport_options = options.fetch(:transport_options, {})
361
+ transport_options = options.fetch(:transport_options, {}).dup
359
362
 
360
363
  # Compile writer options
361
- writer_options = options.fetch(:writer_options, {})
364
+ writer_options = options.fetch(:writer_options, {}).dup
362
365
  rebuild_writer = !writer_options.empty?
363
366
 
364
367
  # Re-build the sampler and writer if priority sampling is enabled,
@@ -395,14 +398,6 @@ module Datadog
395
398
 
396
399
  writer_options[:transport_options] = transport_options
397
400
 
398
- # ensure any configuration to runtime_metrics statsd client is
399
- # passed on when writer gets rebuilt
400
- unless writer_options.key?(:runtime_metrics)
401
- if @writer && !@writer.runtime_metrics.nil?
402
- writer_options[:runtime_metrics] = @writer.runtime_metrics
403
- end
404
- end
405
-
406
401
  if rebuild_writer || writer
407
402
  # Make sure old writer is shut down before throwing away.
408
403
  # Don't want additional threads running...
@@ -19,7 +19,7 @@ module Datadog
19
19
 
20
20
  # Builds a new Transport::HTTP::Client
21
21
  def new(&block)
22
- Builder.new(&block).to_client
22
+ Builder.new(&block).to_transport
23
23
  end
24
24
 
25
25
  # Builds a new Transport::HTTP::Client with default settings
@@ -15,6 +15,10 @@ module Datadog
15
15
  @headers = options.fetch(:headers, {})
16
16
  end
17
17
 
18
+ def encoder
19
+ spec.encoder
20
+ end
21
+
18
22
  def call(env)
19
23
  # Add headers to request env, unless empty.
20
24
  env.headers.merge!(headers) unless headers.empty?
@@ -70,13 +70,11 @@ module Datadog
70
70
  @default_api = key
71
71
  end
72
72
 
73
- def to_client
73
+ def to_transport
74
74
  raise NoDefaultApiError if @default_api.nil?
75
75
 
76
- @client ||= Client.new(
77
- to_api_instances,
78
- @default_api
79
- )
76
+ # DEV: Should not be specific to traces
77
+ Transport::Traces::Transport.new(to_api_instances, @default_api)
80
78
  end
81
79
 
82
80
  def to_api_instances
@@ -8,42 +8,31 @@ module Datadog
8
8
  class Client
9
9
  include Transport::HTTP::Statistics
10
10
 
11
- attr_reader \
12
- :apis,
13
- :current_api_id
11
+ attr_reader :api
14
12
 
15
- def initialize(apis, current_api_id)
16
- @apis = apis
17
-
18
- # Activate initial API
19
- change_api!(current_api_id)
13
+ def initialize(api)
14
+ @api = api
20
15
  end
21
16
 
22
17
  def send_request(request, &block)
23
18
  # Build request into env
24
19
  env = build_env(request)
25
20
 
26
- # Get response from API
27
- response = yield(current_api, env)
21
+ # Get responses from API
22
+ response = yield(api, env)
28
23
 
29
24
  # Update statistics
30
25
  update_stats_from_response!(response)
31
26
 
32
- # If API should be downgraded, downgrade and try again.
33
- if downgrade?(response)
34
- downgrade!
35
- response = send_request(request, &block)
36
- end
37
-
38
27
  response
39
28
  rescue StandardError => e
40
29
  message = "Internal error during HTTP transport request. Cause: #{e.message} Location: #{e.backtrace.first}"
41
30
 
42
31
  # Log error
43
32
  if stats.consecutive_errors > 0
44
- Datadog::Logger.log.debug(message)
33
+ Datadog.logger.debug(message)
45
34
  else
46
- Datadog::Logger.log.error(message)
35
+ Datadog.logger.error(message)
47
36
  end
48
37
 
49
38
  # Update statistics
@@ -55,52 +44,6 @@ module Datadog
55
44
  def build_env(request)
56
45
  Env.new(request)
57
46
  end
58
-
59
- def downgrade?(response)
60
- return false unless apis.fallbacks.key?(current_api_id)
61
- response.not_found? || response.unsupported?
62
- end
63
-
64
- def current_api
65
- apis[current_api_id]
66
- end
67
-
68
- def change_api!(api_id)
69
- raise UnknownApiVersionError, api_id unless apis.key?(api_id)
70
- @current_api_id = api_id
71
- end
72
-
73
- def downgrade!
74
- downgrade_api_id = apis.fallbacks[current_api_id]
75
- raise NoDowngradeAvailableError, current_api_id if downgrade_api_id.nil?
76
- change_api!(downgrade_api_id)
77
- end
78
-
79
- # Raised when configured with an unknown API version
80
- class UnknownApiVersionError < StandardError
81
- attr_reader :version
82
-
83
- def initialize(version)
84
- @version = version
85
- end
86
-
87
- def message
88
- "No matching transport API for version #{version}!"
89
- end
90
- end
91
-
92
- # Raised when configured with an unknown API version
93
- class NoDowngradeAvailableError < StandardError
94
- attr_reader :version
95
-
96
- def initialize(version)
97
- @version = version
98
- end
99
-
100
- def message
101
- "No downgrade from transport API version #{version} is available!"
102
- end
103
- end
104
47
  end
105
48
  end
106
49
  end
@@ -15,7 +15,7 @@ module Datadog
15
15
  @http_response = http_response
16
16
  end
17
17
 
18
- def_delegators :@http_response, *Transport::Response.instance_methods
18
+ def_delegators :@http_response, *Datadog::Transport::Response.instance_methods
19
19
 
20
20
  def code
21
21
  @http_response.respond_to?(:code) ? @http_response.code : nil
@@ -6,7 +6,7 @@ module Datadog
6
6
  # Tracks statistics for HTTP transports
7
7
  module Statistics
8
8
  def self.included(base)
9
- base.send(:include, Transport::Statistics)
9
+ base.send(:include, Datadog::Transport::Statistics)
10
10
  base.send(:include, InstanceMethods)
11
11
  end
12
12
 
@@ -12,19 +12,18 @@ module Datadog
12
12
  # Response from HTTP transport for traces
13
13
  class Response
14
14
  include HTTP::Response
15
- include Transport::Traces::Response
15
+ include Datadog::Transport::Traces::Response
16
16
 
17
17
  def initialize(http_response, options = {})
18
18
  super(http_response)
19
19
  @service_rates = options.fetch(:service_rates, nil)
20
+ @trace_count = options.fetch(:trace_count, 0)
20
21
  end
21
22
  end
22
23
 
23
24
  # Extensions for HTTP client
24
25
  module Client
25
- def send_traces(traces)
26
- request = Transport::Traces::Request.new(traces)
27
-
26
+ def send_payload(request)
28
27
  send_request(request) do |api, env|
29
28
  api.send_traces(env)
30
29
  end
@@ -45,6 +44,10 @@ module Datadog
45
44
  traces.call(env, &block)
46
45
  end
47
46
 
47
+ def encoder
48
+ traces.encoder
49
+ end
50
+
48
51
  # Raised when traces sent but no traces endpoint is defined
49
52
  class NoTraceEndpointDefinedError < StandardError
50
53
  attr_reader :spec
@@ -104,17 +107,17 @@ module Datadog
104
107
 
105
108
  def call(env, &block)
106
109
  # Add trace count header
107
- env.headers[HEADER_TRACE_COUNT] = env.request.parcel.count.to_s
110
+ env.headers[HEADER_TRACE_COUNT] = env.request.parcel.trace_count.to_s
108
111
 
109
112
  # Encode body & type
110
113
  env.headers[HEADER_CONTENT_TYPE] = encoder.content_type
111
- env.body = env.request.parcel.encode_with(encoder)
114
+ env.body = env.request.parcel.data
112
115
 
113
116
  # Query for response
114
117
  http_response = super(env, &block)
115
118
 
116
119
  # Process the response
117
- response_options = {}.tap do |options|
120
+ response_options = { trace_count: env.request.parcel.trace_count }.tap do |options|
118
121
  # Parse service rates, if configured to do so.
119
122
  if service_rates? && !http_response.payload.to_s.empty?
120
123
  body = JSON.parse(http_response.payload)