Class: Datadog::Core::Telemetry::Emitter

Inherits:
Object
  • Object
show all
Extended by:
Utils::Forking
Defined in:
lib/datadog/core/telemetry/emitter.rb

Overview

Class that emits telemetry events

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Utils::Forking

after_fork!, extended, fork_pid, forked?, included, update_fork_pid!

Constructor Details

#initialize(http_transport:) ⇒ Emitter

Returns a new instance of Emitter.

Parameters:



19
20
21
# File 'lib/datadog/core/telemetry/emitter.rb', line 19

def initialize(http_transport:)
  @http_transport = http_transport
end

Instance Attribute Details

#http_transportObject (readonly)

Returns the value of attribute http_transport.



13
14
15
# File 'lib/datadog/core/telemetry/emitter.rb', line 13

def http_transport
  @http_transport
end

Class Method Details

.sequenceObject

Initializes a Sequence object to track seq_id if not already initialized; else returns stored Sequence object



37
38
39
40
# File 'lib/datadog/core/telemetry/emitter.rb', line 37

def self.sequence
  after_fork! { @sequence = Datadog::Core::Utils::Sequence.new(1) }
  @sequence ||= Datadog::Core::Utils::Sequence.new(1)
end

Instance Method Details

#request(event) ⇒ Object

Retrieves and emits a TelemetryRequest object based on the request type specified



24
25
26
27
28
29
30
31
32
33
# File 'lib/datadog/core/telemetry/emitter.rb', line 24

def request(event)
  seq_id = self.class.sequence.next
  payload = Request.build_payload(event, seq_id)
  res = @http_transport.request(request_type: event.type, payload: payload.to_json)
  Datadog.logger.debug { "Telemetry sent for event `#{event.type}` (code: #{res.code.inspect})" }
  res
rescue => e
  Datadog.logger.debug("Unable to send telemetry request for event `#{event.type rescue 'unknown'}`: #{e}")
  Telemetry::Http::InternalErrorResponse.new(e)
end