Class: Datadog::Core::Telemetry::Client

Inherits:
Object
  • Object
show all
Includes:
Utils::Forking
Defined in:
lib/datadog/core/telemetry/client.rb

Overview

Telemetry entrypoint, coordinates sending telemetry events at various points in app lifecyle

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Utils::Forking

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

Constructor Details

#initialize(enabled: true) ⇒ Client

Returns a new instance of Client.

Parameters:

  • enabled (Boolean) (defaults to: true)

    Determines whether telemetry events should be sent to the API



19
20
21
22
23
24
25
26
27
# File 'lib/datadog/core/telemetry/client.rb', line 19

def initialize(enabled: true)
  @enabled = enabled
  @emitter = Emitter.new
  @stopped = false
  @unsupported = false
  @worker = Telemetry::Heartbeat.new(enabled: @enabled) do
    heartbeat!
  end
end

Instance Attribute Details

#emitterObject (readonly)

Returns the value of attribute emitter.



10
11
12
# File 'lib/datadog/core/telemetry/client.rb', line 10

def emitter
  @emitter
end

#enabledObject (readonly)

Returns the value of attribute enabled.



10
11
12
# File 'lib/datadog/core/telemetry/client.rb', line 10

def enabled
  @enabled
end

#unsupportedObject (readonly)

Returns the value of attribute unsupported.



10
11
12
# File 'lib/datadog/core/telemetry/client.rb', line 10

def unsupported
  @unsupported
end

#workerObject (readonly)

Returns the value of attribute worker.



10
11
12
# File 'lib/datadog/core/telemetry/client.rb', line 10

def worker
  @worker
end

Instance Method Details

#disable!Object



29
30
31
32
# File 'lib/datadog/core/telemetry/client.rb', line 29

def disable!
  @enabled = false
  @worker.enabled = false
end

#emit_closing!Object



48
49
50
51
52
# File 'lib/datadog/core/telemetry/client.rb', line 48

def emit_closing!
  return if !@enabled || forked?

  @emitter.request(:'app-closing')
end

#integrations_change!Object



61
62
63
64
65
# File 'lib/datadog/core/telemetry/client.rb', line 61

def integrations_change!
  return if !@enabled || forked?

  @emitter.request(:'app-integrations-change')
end

#started!Object



34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/datadog/core/telemetry/client.rb', line 34

def started!
  return if !@enabled || forked?

  res = @emitter.request(:'app-started')

  if res.not_found? # Telemetry is only supported by agent versions 7.34 and up
    Datadog.logger.debug('Agent does not support telemetry; disabling future telemetry events.')
    disable!
    @unsupported = true # Prevent telemetry from getting re-enabled
  end

  res
end

#stop!Object



54
55
56
57
58
59
# File 'lib/datadog/core/telemetry/client.rb', line 54

def stop!
  return if @stopped

  @worker.stop(true, 0)
  @stopped = true
end