datadog 2.0.0.beta1 → 2.0.0.beta2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (63) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +125 -1
  3. data/ext/datadog_profiling_native_extension/collectors_cpu_and_wall_time_worker.c +32 -12
  4. data/ext/datadog_profiling_native_extension/collectors_thread_context.c +5 -2
  5. data/ext/datadog_profiling_native_extension/heap_recorder.c +45 -3
  6. data/ext/datadog_profiling_native_extension/heap_recorder.h +7 -1
  7. data/ext/datadog_profiling_native_extension/http_transport.c +5 -5
  8. data/ext/datadog_profiling_native_extension/native_extension_helpers.rb +1 -1
  9. data/ext/datadog_profiling_native_extension/stack_recorder.c +7 -9
  10. data/lib/datadog/appsec/contrib/rack/request_middleware.rb +43 -13
  11. data/lib/datadog/appsec/event.rb +2 -2
  12. data/lib/datadog/core/configuration/components.rb +2 -1
  13. data/lib/datadog/core/configuration/option.rb +7 -5
  14. data/lib/datadog/core/configuration/settings.rb +38 -14
  15. data/lib/datadog/core/configuration.rb +20 -4
  16. data/lib/datadog/core/environment/platform.rb +7 -1
  17. data/lib/datadog/core/remote/client/capabilities.rb +2 -1
  18. data/lib/datadog/core/remote/transport/http/config.rb +5 -5
  19. data/lib/datadog/core/telemetry/client.rb +18 -10
  20. data/lib/datadog/core/telemetry/emitter.rb +9 -13
  21. data/lib/datadog/core/telemetry/event.rb +247 -57
  22. data/lib/datadog/core/telemetry/ext.rb +1 -0
  23. data/lib/datadog/core/telemetry/heartbeat.rb +1 -3
  24. data/lib/datadog/core/telemetry/http/ext.rb +4 -1
  25. data/lib/datadog/core/telemetry/http/transport.rb +9 -4
  26. data/lib/datadog/core/telemetry/request.rb +59 -0
  27. data/lib/datadog/core/utils/base64.rb +22 -0
  28. data/lib/datadog/opentelemetry/sdk/span_processor.rb +1 -1
  29. data/lib/datadog/opentelemetry/sdk/trace/span.rb +3 -17
  30. data/lib/datadog/profiling/collectors/code_provenance.rb +10 -4
  31. data/lib/datadog/profiling/collectors/cpu_and_wall_time_worker.rb +25 -0
  32. data/lib/datadog/profiling/component.rb +23 -15
  33. data/lib/datadog/profiling/load_native_extension.rb +14 -1
  34. data/lib/datadog/profiling.rb +11 -0
  35. data/lib/datadog/tracing/contrib/action_pack/integration.rb +1 -1
  36. data/lib/datadog/tracing/contrib/action_view/integration.rb +1 -1
  37. data/lib/datadog/tracing/contrib/active_record/integration.rb +1 -1
  38. data/lib/datadog/tracing/contrib/active_support/integration.rb +1 -1
  39. data/lib/datadog/tracing/contrib/grape/endpoint.rb +43 -5
  40. data/lib/datadog/tracing/correlation.rb +3 -4
  41. data/lib/datadog/tracing/sampling/matcher.rb +23 -3
  42. data/lib/datadog/tracing/sampling/rule.rb +18 -2
  43. data/lib/datadog/tracing/sampling/rule_sampler.rb +2 -0
  44. data/lib/datadog/tracing/span.rb +7 -2
  45. data/lib/datadog/tracing/span_link.rb +86 -0
  46. data/lib/datadog/tracing/trace_operation.rb +12 -0
  47. data/lib/datadog/tracing/tracer.rb +4 -3
  48. data/lib/datadog/tracing/transport/serializable_trace.rb +3 -1
  49. data/lib/datadog/tracing/utils.rb +16 -0
  50. data/lib/datadog/version.rb +1 -1
  51. metadata +7 -30
  52. data/lib/datadog/core/telemetry/collector.rb +0 -248
  53. data/lib/datadog/core/telemetry/v1/app_event.rb +0 -59
  54. data/lib/datadog/core/telemetry/v1/application.rb +0 -94
  55. data/lib/datadog/core/telemetry/v1/configuration.rb +0 -27
  56. data/lib/datadog/core/telemetry/v1/dependency.rb +0 -45
  57. data/lib/datadog/core/telemetry/v1/host.rb +0 -59
  58. data/lib/datadog/core/telemetry/v1/install_signature.rb +0 -38
  59. data/lib/datadog/core/telemetry/v1/integration.rb +0 -66
  60. data/lib/datadog/core/telemetry/v1/product.rb +0 -36
  61. data/lib/datadog/core/telemetry/v1/telemetry_request.rb +0 -108
  62. data/lib/datadog/core/telemetry/v2/app_client_configuration_change.rb +0 -41
  63. data/lib/datadog/core/telemetry/v2/request.rb +0 -29
@@ -15,6 +15,18 @@ module Datadog
15
15
  module AppSec
16
16
  module Contrib
17
17
  module Rack
18
+ # Create an array of lowercased headers
19
+ WAF_VENDOR_HEADERS_TAGS = %w[
20
+ X-Amzn-Trace-Id
21
+ Cloudfront-Viewer-Ja3-Fingerprint
22
+ Cf-Ray
23
+ X-Cloud-Trace-Context
24
+ X-Appgw-Trace-id
25
+ X-SigSci-RequestID
26
+ X-SigSci-Tags
27
+ Akamai-User-Risk
28
+ ].map(&:downcase).freeze
29
+
18
30
  # Topmost Rack middleware for AppSec
19
31
  # This should be inserted just below Datadog::Tracing::Contrib::Rack::TraceMiddleware
20
32
  class RequestMiddleware
@@ -22,6 +34,7 @@ module Datadog
22
34
  @app = app
23
35
 
24
36
  @oneshot_tags_sent = false
37
+ @rack_headers = {}
25
38
  end
26
39
 
27
40
  # rubocop:disable Metrics/AbcSize,Metrics/PerceivedComplexity,Metrics/CyclomaticComplexity,Metrics/MethodLength
@@ -56,7 +69,8 @@ module Datadog
56
69
 
57
70
  gateway_request = Gateway::Request.new(env)
58
71
 
59
- add_appsec_tags(processor, scope, env)
72
+ add_appsec_tags(processor, scope)
73
+ add_request_tags(scope, env)
60
74
 
61
75
  request_return, request_response = catch(::Datadog::AppSec::Ext::INTERRUPT) do
62
76
  Instrumentation.gateway.push('rack.request', gateway_request) do
@@ -131,7 +145,7 @@ module Datadog
131
145
  Datadog::Tracing.active_span
132
146
  end
133
147
 
134
- def add_appsec_tags(processor, scope, env)
148
+ def add_appsec_tags(processor, scope)
135
149
  span = scope.service_entry_span
136
150
  trace = scope.trace
137
151
 
@@ -141,17 +155,6 @@ module Datadog
141
155
  span.set_tag('_dd.runtime_family', 'ruby')
142
156
  span.set_tag('_dd.appsec.waf.version', Datadog::AppSec::WAF::VERSION::BASE_STRING)
143
157
 
144
- if span && span.get_tag(Tracing::Metadata::Ext::HTTP::TAG_CLIENT_IP).nil?
145
- request_header_collection = Datadog::Tracing::Contrib::Rack::Header::RequestHeaderCollection.new(env)
146
-
147
- # always collect client ip, as this is part of AppSec provided functionality
148
- Datadog::Tracing::ClientIp.set_client_ip_tag!(
149
- span,
150
- headers: request_header_collection,
151
- remote_ip: env['REMOTE_ADDR']
152
- )
153
- end
154
-
155
158
  if processor.diagnostics
156
159
  diagnostics = processor.diagnostics
157
160
 
@@ -177,6 +180,29 @@ module Datadog
177
180
  end
178
181
  end
179
182
 
183
+ def add_request_tags(scope, env)
184
+ span = scope.service_entry_span
185
+
186
+ return unless span
187
+
188
+ # Always add WAF vendors headers
189
+ WAF_VENDOR_HEADERS_TAGS.each do |lowercase_header|
190
+ rack_header = to_rack_header(lowercase_header)
191
+ span.set_tag("http.request.headers.#{lowercase_header}", env[rack_header]) if env[rack_header]
192
+ end
193
+
194
+ if span && span.get_tag(Tracing::Metadata::Ext::HTTP::TAG_CLIENT_IP).nil?
195
+ request_header_collection = Datadog::Tracing::Contrib::Rack::Header::RequestHeaderCollection.new(env)
196
+
197
+ # always collect client ip, as this is part of AppSec provided functionality
198
+ Datadog::Tracing::ClientIp.set_client_ip_tag!(
199
+ span,
200
+ headers: request_header_collection,
201
+ remote_ip: env['REMOTE_ADDR']
202
+ )
203
+ end
204
+ end
205
+
180
206
  def add_waf_runtime_tags(scope)
181
207
  span = scope.service_entry_span
182
208
  context = scope.processor_context
@@ -189,6 +215,10 @@ module Datadog
189
215
  span.set_tag('_dd.appsec.waf.duration', context.time_ns / 1000.0)
190
216
  span.set_tag('_dd.appsec.waf.duration_ext', context.time_ext_ns / 1000.0)
191
217
  end
218
+
219
+ def to_rack_header(header)
220
+ @rack_headers[header] ||= Datadog::Tracing::Contrib::Rack::Header.to_rack_header(header)
221
+ end
192
222
  end
193
223
  end
194
224
  end
@@ -2,9 +2,9 @@
2
2
 
3
3
  require 'json'
4
4
  require 'zlib'
5
- require 'base64'
6
5
 
7
6
  require_relative 'rate_limiter'
7
+ require_relative '../core/utils/base64'
8
8
 
9
9
  module Datadog
10
10
  module AppSec
@@ -140,7 +140,7 @@ module Datadog
140
140
  private
141
141
 
142
142
  def compressed_and_base64_encoded(value)
143
- Base64.encode64(gzip(value))
143
+ Datadog::Core::Utils::Base64.strict_encode64(gzip(value))
144
144
  rescue TypeError => e
145
145
  Datadog.logger.debug do
146
146
  "Failed to compress and encode value when populating AppSec::Event. Error: #{e.message}"
@@ -64,7 +64,8 @@ module Datadog
64
64
 
65
65
  Telemetry::Client.new(
66
66
  enabled: enabled,
67
- heartbeat_interval_seconds: settings.telemetry.heartbeat_interval_seconds
67
+ heartbeat_interval_seconds: settings.telemetry.heartbeat_interval_seconds,
68
+ dependency_collection: settings.telemetry.dependency_collection
68
69
  )
69
70
  end
70
71
  end
@@ -8,7 +8,13 @@ module Datadog
8
8
  # Represents an instance of an integration configuration option
9
9
  # @public_api
10
10
  class Option
11
- attr_reader :definition
11
+ # @!attribute [r] definition
12
+ # The definition object that matches this option.
13
+ # @return [Configuration::OptionDefinition]
14
+ # @!attribute [r] precedence_set
15
+ # When this option was last set, what was the value precedence used?
16
+ # @return [Precedence::Value]
17
+ attr_reader :definition, :precedence_set
12
18
 
13
19
  # Option setting precedence.
14
20
  module Precedence
@@ -305,10 +311,6 @@ module Datadog
305
311
  "but '#{ENV[effective_env]}' was provided"
306
312
  end
307
313
 
308
- # Used for testing
309
- attr_reader :precedence_set
310
- private :precedence_set
311
-
312
314
  # Anchor object that represents a value that is not set.
313
315
  # This is necessary because `nil` is a valid value to be set.
314
316
  UNSET = Object.new
@@ -271,29 +271,43 @@ module Datadog
271
271
 
272
272
  # Can be used to disable the gathering of names and versions of gems in use by the service, used to power
273
273
  # grouping and categorization of stack traces.
274
- option :code_provenance_enabled, default: true
274
+ option :code_provenance_enabled do |o|
275
+ o.type :bool
276
+ o.default true
277
+ end
275
278
 
276
279
  # Forces enabling of profiling of time/resources spent in Garbage Collection.
277
280
  #
278
281
  # Note that setting this to "false" (or not setting it) will not prevent the feature from being
279
282
  # being automatically enabled in the future.
280
283
  #
281
- # This feature defaults to off for two reasons:
282
- # 1. Currently this feature can add a lot of overhead for GC-heavy workloads.
283
- # 2. Although this feature is safe on Ruby 2.x, on Ruby 3.x it can break in applications that make use of
284
- # Ractors due to two Ruby VM bugs:
285
- # https://bugs.ruby-lang.org/issues/19112 AND https://bugs.ruby-lang.org/issues/18464.
286
- # If you use Ruby 3.x and your application does not use Ractors (or if your Ruby has been patched), the
287
- # feature is fully safe to enable and this toggle can be used to do so.
284
+ # GC profiling is now on by default and controlled by {:gc_enabled}.
285
+ option :force_enable_gc_profiling do |o|
286
+ o.after_set do |_, _, precedence|
287
+ unless precedence == Datadog::Core::Configuration::Option::Precedence::DEFAULT
288
+ Datadog.logger.warn(
289
+ 'The profiling.advanced.force_enable_gc_profiling setting has been deprecated for removal and no ' \
290
+ 'longer does anything (the feature is now on by default). ' \
291
+ 'Please remove this setting from your Datadog.configure block.'
292
+ )
293
+ end
294
+ end
295
+ end
296
+
297
+ # Can be used to enable/disable garbage collection profiling.
288
298
  #
289
- # We expect the once the above issues are overcome, we'll automatically enable the feature on fixed Ruby
290
- # versions.
299
+ # @warn To avoid https://bugs.ruby-lang.org/issues/18464 even when enabled, GC profiling is only started
300
+ # for Ruby versions 2.x, 3.1.4+, 3.2.3+ and 3.3.0+
301
+ # (more details in {Datadog::Profiling::Component.enable_gc_profiling?})
291
302
  #
292
- # @default `DD_PROFILING_FORCE_ENABLE_GC` environment variable, otherwise `false`
293
- option :force_enable_gc_profiling do |o|
294
- o.env 'DD_PROFILING_FORCE_ENABLE_GC'
303
+ # @warn Due to a VM bug in the Ractor implementation (https://bugs.ruby-lang.org/issues/19112) this feature
304
+ # stops working when Ractors get garbage collected.
305
+ #
306
+ # @default `DD_PROFILING_GC_ENABLED` environment variable, otherwise `true`
307
+ option :gc_enabled do |o|
295
308
  o.type :bool
296
- o.default false
309
+ o.env 'DD_PROFILING_GC_ENABLED'
310
+ o.default true
297
311
  end
298
312
 
299
313
  # Can be used to enable/disable the Datadog::Profiling.allocation_count feature.
@@ -646,6 +660,16 @@ module Datadog
646
660
  # Client-side telemetry configuration
647
661
  # @public_api
648
662
  settings :telemetry do
663
+ # Whether the bundled Ruby gems as reported through telemetry.
664
+ #
665
+ # @default `DD_TELEMETRY_DEPENDENCY_COLLECTION_ENABLED` environment variable, otherwise `true`.
666
+ # @return [Boolean]
667
+ option :dependency_collection do |o|
668
+ o.type :bool
669
+ o.env Core::Telemetry::Ext::ENV_DEPENDENCY_COLLECTION
670
+ o.default true
671
+ end
672
+
649
673
  # Enable telemetry collection. This allows telemetry events to be emitted to the telemetry API.
650
674
  #
651
675
  # @default `DD_INSTRUMENTATION_TELEMETRY_ENABLED` environment variable, otherwise `true`.
@@ -84,18 +84,23 @@ module Datadog
84
84
  configuration = self.configuration
85
85
  yield(configuration)
86
86
 
87
- safely_synchronize do |write_components|
87
+ built_components = false
88
+
89
+ components = safely_synchronize do |write_components|
88
90
  write_components.call(
89
91
  if components?
90
92
  replace_components!(configuration, @components)
91
93
  else
92
94
  components = build_components(configuration)
93
- components.telemetry.started!
95
+ built_components = true
94
96
  components
95
97
  end
96
98
  )
97
99
  end
98
100
 
101
+ # Should only be called the first time components are built
102
+ components.telemetry.started! if built_components
103
+
99
104
  configuration
100
105
  end
101
106
 
@@ -195,9 +200,20 @@ module Datadog
195
200
  current_components = COMPONENTS_READ_LOCK.synchronize { defined?(@components) && @components }
196
201
  return current_components if current_components || !allow_initialization
197
202
 
198
- safely_synchronize do |write_components|
199
- (defined?(@components) && @components) || write_components.call(build_components(configuration))
203
+ built_components = false
204
+
205
+ components = safely_synchronize do |write_components|
206
+ if defined?(@components) && @components
207
+ @components
208
+ else
209
+ built_components = true
210
+ write_components.call(build_components(configuration))
211
+ end
200
212
  end
213
+
214
+ # Should only be called the first time components are built
215
+ components&.telemetry&.started! if built_components
216
+ components
201
217
  end
202
218
 
203
219
  private
@@ -11,12 +11,18 @@ module Datadog
11
11
  module Platform
12
12
  module_function
13
13
 
14
+ # @return [String] ISA of host; `uname -m`
15
+ def architecture
16
+ Identity.lang_version >= '2.2' ? Etc.uname[:machine] : Gem::Platform.local.cpu
17
+ end
18
+
14
19
  # @return [String] name of host; `uname -n`
15
20
  def hostname
16
21
  Identity.lang_version >= '2.2' ? Etc.uname[:nodename] : nil
17
22
  end
18
23
 
19
- # @return [String] name of kernel; `uname -s`
24
+ # System name, normally `Linux` or `Darwin` (but 'Mac OS X' on JRuby);
25
+ # @return [String] name of kernel; `uname -s`.
20
26
  def kernel_name
21
27
  Identity.lang_version >= '2.2' ? Etc.uname[:sysname] : Gem::Platform.local.os.capitalize
22
28
  end
@@ -1,5 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require_relative '../../utils/base64'
3
4
  require_relative '../../../appsec/remote'
4
5
  require_relative '../../../tracing/remote'
5
6
 
@@ -53,7 +54,7 @@ module Datadog
53
54
  cap_to_hexs = capabilities.reduce(:|).to_s(16).tap { |s| s.size.odd? && s.prepend('0') }.scan(/\h\h/)
54
55
  binary = cap_to_hexs.each_with_object([]) { |hex, acc| acc << hex }.map { |e| e.to_i(16) }.pack('C*')
55
56
 
56
- Base64.encode64(binary).chomp
57
+ Datadog::Core::Utils::Base64.strict_encode64(binary)
57
58
  end
58
59
  end
59
60
  end
@@ -1,10 +1,10 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require 'json'
4
- require 'base64'
5
4
 
6
5
  require_relative '../config'
7
6
  require_relative 'client'
7
+ require_relative '../../../utils/base64'
8
8
  require_relative '../../../transport/http/response'
9
9
  require_relative '../../../transport/http/api/endpoint'
10
10
 
@@ -51,7 +51,7 @@ module Datadog
51
51
 
52
52
  # TODO: these fallbacks should be improved
53
53
  roots = payload[:roots] || []
54
- targets = payload[:targets] || Base64.encode64('{}').chomp
54
+ targets = payload[:targets] || Datadog::Core::Utils::Base64.strict_encode64('{}')
55
55
  target_files = payload[:target_files] || []
56
56
  client_configs = payload[:client_configs] || []
57
57
 
@@ -61,7 +61,7 @@ module Datadog
61
61
  raise TypeError.new(String, root) unless root.is_a?(String)
62
62
 
63
63
  decoded = begin
64
- Base64.strict_decode64(root) # TODO: unprocessed, don't symbolize_names
64
+ Datadog::Core::Utils::Base64.strict_decode64(root) # TODO: unprocessed, don't symbolize_names
65
65
  rescue ArgumentError
66
66
  raise DecodeError.new(:roots, root)
67
67
  end
@@ -81,7 +81,7 @@ module Datadog
81
81
 
82
82
  @targets = begin
83
83
  decoded = begin
84
- Base64.strict_decode64(targets)
84
+ Datadog::Core::Utils::Base64.strict_decode64(targets)
85
85
  rescue ArgumentError
86
86
  raise DecodeError.new(:targets, targets)
87
87
  end
@@ -109,7 +109,7 @@ module Datadog
109
109
  raise TypeError.new(String, raw) unless raw.is_a?(String)
110
110
 
111
111
  content = begin
112
- Base64.strict_decode64(raw)
112
+ Datadog::Core::Utils::Base64.strict_decode64(raw)
113
113
  rescue ArgumentError
114
114
  raise DecodeError.new(:target_files, raw)
115
115
  end
@@ -1,6 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require_relative 'emitter'
4
+ require_relative 'event'
4
5
  require_relative 'heartbeat'
5
6
  require_relative '../utils/forking'
6
7
 
@@ -10,21 +11,25 @@ module Datadog
10
11
  # Telemetry entrypoint, coordinates sending telemetry events at various points in app lifecycle.
11
12
  class Client
12
13
  attr_reader \
13
- :emitter,
14
14
  :enabled,
15
- :unsupported,
16
- :worker
15
+ :unsupported
17
16
 
18
17
  include Core::Utils::Forking
19
18
 
20
19
  # @param enabled [Boolean] Determines whether telemetry events should be sent to the API
21
20
  # @param heartbeat_interval_seconds [Float] How frequently heartbeats will be reported, in seconds.
22
- def initialize(heartbeat_interval_seconds:, enabled: true)
21
+ # @param [Boolean] dependency_collection Whether to send the `app-dependencies-loaded` event
22
+ def initialize(heartbeat_interval_seconds:, dependency_collection:, enabled: true)
23
23
  @enabled = enabled
24
24
  @emitter = Emitter.new
25
25
  @stopped = false
26
26
  @unsupported = false
27
+ @started = false
28
+ @dependency_collection = dependency_collection
29
+
27
30
  @worker = Telemetry::Heartbeat.new(enabled: @enabled, heartbeat_interval_seconds: heartbeat_interval_seconds) do
31
+ next unless @started # `started!` should be the first event, thus ensure that `heartbeat!` is not sent first.
32
+
28
33
  heartbeat!
29
34
  end
30
35
  end
@@ -37,21 +42,24 @@ module Datadog
37
42
  def started!
38
43
  return if !@enabled || forked?
39
44
 
40
- res = @emitter.request(:'app-started')
45
+ res = @emitter.request(Event::AppStarted.new)
41
46
 
42
47
  if res.not_found? # Telemetry is only supported by agent versions 7.34 and up
43
48
  Datadog.logger.debug('Agent does not support telemetry; disabling future telemetry events.')
44
49
  disable!
45
50
  @unsupported = true # Prevent telemetry from getting re-enabled
51
+ return res
46
52
  end
47
53
 
48
- res
54
+ @emitter.request(Event::AppDependenciesLoaded.new) if @dependency_collection
55
+
56
+ @started = true
49
57
  end
50
58
 
51
59
  def emit_closing!
52
60
  return if !@enabled || forked?
53
61
 
54
- @emitter.request(:'app-closing')
62
+ @emitter.request(Event::AppClosing.new)
55
63
  end
56
64
 
57
65
  def stop!
@@ -64,14 +72,14 @@ module Datadog
64
72
  def integrations_change!
65
73
  return if !@enabled || forked?
66
74
 
67
- @emitter.request(:'app-integrations-change')
75
+ @emitter.request(Event::AppIntegrationsChange.new)
68
76
  end
69
77
 
70
78
  # Report configuration changes caused by Remote Configuration.
71
79
  def client_configuration_change!(changes)
72
80
  return if !@enabled || forked?
73
81
 
74
- @emitter.request('app-client-configuration-change', data: { changes: changes, origin: 'remote_config' })
82
+ @emitter.request(Event::AppClientConfigurationChange.new(changes, 'remote_config'))
75
83
  end
76
84
 
77
85
  private
@@ -79,7 +87,7 @@ module Datadog
79
87
  def heartbeat!
80
88
  return if !@enabled || forked?
81
89
 
82
- @emitter.request(:'app-heartbeat')
90
+ @emitter.request(Event::AppHeartbeat.new)
83
91
  end
84
92
  end
85
93
  end
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require_relative 'event'
3
+ require_relative 'request'
4
4
  require_relative 'http/transport'
5
5
  require_relative '../utils/sequence'
6
6
  require_relative '../utils/forking'
@@ -14,7 +14,6 @@ module Datadog
14
14
 
15
15
  extend Core::Utils::Forking
16
16
 
17
- # @param sequence [Datadog::Core::Utils::Sequence] Sequence object that stores and increments a counter
18
17
  # @param http_transport [Datadog::Core::Telemetry::Http::Transport] Transport object that can be used to send
19
18
  # telemetry requests via the agent
20
19
  def initialize(http_transport: Datadog::Core::Telemetry::Http::Transport.new)
@@ -22,18 +21,15 @@ module Datadog
22
21
  end
23
22
 
24
23
  # Retrieves and emits a TelemetryRequest object based on the request type specified
25
- # @param request_type [String] the type of telemetry request to collect data for
26
- # @param data [Object] arbitrary object to be passed to the respective `request_type` handler
27
- def request(request_type, data: nil)
24
+ def request(event)
28
25
  begin
29
- request = Datadog::Core::Telemetry::Event.new.telemetry_request(
30
- request_type: request_type,
31
- seq_id: self.class.sequence.next,
32
- data: data,
33
- ).to_h
34
- @http_transport.request(request_type: request_type.to_s, payload: request.to_json)
35
- rescue StandardError => e
36
- Datadog.logger.debug("Unable to send telemetry request for event `#{request_type}`: #{e}")
26
+ seq_id = self.class.sequence.next
27
+ payload = Request.build_payload(event, seq_id)
28
+ res = @http_transport.request(request_type: event.type, payload: payload.to_json)
29
+ Datadog.logger.debug { "Telemetry sent for event `#{event.type}` (status code: #{res.code})" }
30
+ res
31
+ rescue => e
32
+ Datadog.logger.debug("Unable to send telemetry request for event `#{event.type rescue 'unknown'}`: #{e}")
37
33
  Telemetry::Http::InternalErrorResponse.new(e)
38
34
  end
39
35
  end