Sha256: 2706813de1300c28efdfe915e23b2db53ea499a4bd795332b4064ad1cdc24018

Contents?: true

Size: 1.48 KB

Versions: 16

Compression:

Stored size: 1.48 KB

Contents

# This file is distributed under New Relic's license terms.
# See https://github.com/newrelic/newrelic-ruby-agent/blob/main/LICENSE for complete details.
# frozen_string_literal: true

module NewRelic::Agent
  NewRelic::Agent.logger.debug('Installing Infinite Tracer in Agent')

  Agent.class_eval do
    def new_infinite_tracer
      # We must start streaming in a thread or we block/deadlock the
      # entire start-up process for the Agent.
      InfiniteTracing::Client.new.tap do |client|
        @infinite_tracer_thread = InfiniteTracing::Worker.new(:infinite_tracer) do
          NewRelic::Agent.logger.debug('Opening Infinite Tracer Stream with gRPC server')
          client.start_streaming
        end
      end
    end

    # Handles the case where the server tells us to restart -
    # this clears the data, clears connection attempts, and
    # waits a while to reconnect.
    def handle_force_restart(error)
      ::NewRelic::Agent.logger.debug(error.message)
      drop_buffered_data
      @service&.force_restart
      @connect_state = :pending
      close_infinite_tracer
      sleep(30)
    end

    # Whenever we reconnect, close and restart
    def close_infinite_tracer
      NewRelic::Agent.logger.debug('Closing infinite tracer threads')
      return unless @infinite_tracer_thread

      @infinite_tracer_thread.join
      @infinite_tracer_thread.stop
      @infinite_tracer_thread = nil
    end

    def infinite_tracer
      @infinite_tracer ||= new_infinite_tracer
    end
  end
end

Version data entries

16 entries across 16 versions & 1 rubygems

Version Path
newrelic-infinite_tracing-9.17.0 lib/infinite_tracing/agent_integrations/agent.rb
newrelic-infinite_tracing-9.16.1 lib/infinite_tracing/agent_integrations/agent.rb
newrelic-infinite_tracing-9.16.0 lib/infinite_tracing/agent_integrations/agent.rb
newrelic-infinite_tracing-9.15.0 lib/infinite_tracing/agent_integrations/agent.rb
newrelic-infinite_tracing-9.14.0 lib/infinite_tracing/agent_integrations/agent.rb
newrelic-infinite_tracing-9.13.0 lib/infinite_tracing/agent_integrations/agent.rb
newrelic-infinite_tracing-9.12.0 lib/infinite_tracing/agent_integrations/agent.rb
newrelic-infinite_tracing-9.11.0 lib/infinite_tracing/agent_integrations/agent.rb
newrelic-infinite_tracing-9.10.2 lib/infinite_tracing/agent_integrations/agent.rb
newrelic-infinite_tracing-9.10.1 lib/infinite_tracing/agent_integrations/agent.rb
newrelic-infinite_tracing-9.10.0 lib/infinite_tracing/agent_integrations/agent.rb
newrelic-infinite_tracing-9.9.0 lib/infinite_tracing/agent_integrations/agent.rb
newrelic-infinite_tracing-9.8.0 lib/infinite_tracing/agent_integrations/agent.rb
newrelic-infinite_tracing-9.7.1 lib/infinite_tracing/agent_integrations/agent.rb
newrelic-infinite_tracing-9.7.0 lib/infinite_tracing/agent_integrations/agent.rb
newrelic-infinite_tracing-9.6.0 lib/infinite_tracing/agent_integrations/agent.rb