Sha256: c7c1069682f04c72d0c1c220aa0445a2f5a45bb47c645f59f9ff9aa202b3a3eb

Contents?: true

Size: 1.84 KB

Versions: 11

Compression:

Stored size: 1.84 KB

Contents

# typed: true

require_relative 'emitter'
require_relative 'heartbeat'
require_relative '../utils/forking'

module Datadog
  module Core
    module Telemetry
      # Telemetry entrypoint, coordinates sending telemetry events at various points in app lifecyle
      class Client
        attr_reader \
          :emitter,
          :enabled,
          :unsupported,
          :worker

        include Core::Utils::Forking

        # @param enabled [Boolean] Determines whether telemetry events should be sent to the API
        def initialize(enabled: true)
          @enabled = enabled
          @emitter = Emitter.new
          @stopped = false
          @unsupported = false
          @worker = Telemetry::Heartbeat.new(enabled: @enabled) do
            heartbeat!
          end
        end

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

        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

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

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

        def stop!
          return if @stopped

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

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

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

        private

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

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

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
ddtrace-1.9.0 lib/datadog/core/telemetry/client.rb
ddtrace-1.8.0 lib/datadog/core/telemetry/client.rb
ddtrace-1.7.0 lib/datadog/core/telemetry/client.rb
ddtrace-1.6.1 lib/datadog/core/telemetry/client.rb
ddtrace-1.6.0 lib/datadog/core/telemetry/client.rb
ddtrace-1.5.2 lib/datadog/core/telemetry/client.rb
ddtrace-1.5.1 lib/datadog/core/telemetry/client.rb
ddtrace-1.5.0 lib/datadog/core/telemetry/client.rb
ddtrace-1.4.2 lib/datadog/core/telemetry/client.rb
ddtrace-1.4.1 lib/datadog/core/telemetry/client.rb
ddtrace-1.4.0 lib/datadog/core/telemetry/client.rb