def announce_sensor
      unless @discovered
        ::Instana.logger.debug("#{__method__} called but discovery hasn't run yet!")
        return false
      end

      # Always re-collect process info before announce in case the process name has been
      # re-written (looking at you puma!)
      @process = ::Instana::Util.collect_process_info

      announce_payload = {}
      announce_payload[:pid] = pid_namespace? ? get_real_pid : Process.pid
      announce_payload[:name] = @process[:name]
      announce_payload[:args] = @process[:arguments]

      if @is_linux && !::Instana.test?
        # We create an open socket to the host agent in case we are running in a container
        # and the real pid needs to be detected.
        socket = TCPSocket.new @discovered[:agent_host], @discovered[:agent_port]
        announce_payload[:fd] = socket.fileno
        announce_payload[:inode] = File.readlink("/proc/#{Process.pid}/fd/#{socket.fileno}")
      end

      uri = URI.parse("http://#{@discovered[:agent_host]}:#{@discovered[:agent_port]}/#{DISCOVERY_PATH}")
      req = Net::HTTP::Put.new(uri)
      req.body = Oj.dump(announce_payload, OJ_OPTIONS)

      ::Instana.logger.debug "Announce: http://#{@discovered[:agent_host]}:#{@discovered[:agent_port]}/#{DISCOVERY_PATH} - payload: #{req.body}"

      response = make_host_agent_request(req)

      if response && (response.code.to_i == 200)
        data = Oj.load(response.body, OJ_OPTIONS)
        @process[:report_pid] = data['pid']
        @agent_uuid = data['agentUuid']

        if data.key?('extraHeaders')
          @extra_headers = data['extraHeaders']
        end
        true
      else
        false
      end
    rescue => e
      Instana.logger.info "#{__method__}:#{File.basename(__FILE__)}:#{__LINE__}: #{e.message}"
      Instana.logger.debug e.backtrace.join("\r\n")
      return false
    ensure
      socket.close if socket
    end
def announce_sensor
      unless @discovered
        ::Instana.logger.debug("#{__method__} called but discovery hasn't run yet!")
        return false
      end

      # Always re-collect process info before announce in case the process name has been
      # re-written (looking at you puma!)
      @process = ::Instana::Util.collect_process_info

      announce_payload = {}
      announce_payload[:pid] = pid_namespace? ? get_real_pid : Process.pid
      announce_payload[:name] = @process[:name]
      announce_payload[:args] = @process[:arguments]

      if @is_linux && !::Instana.test?
        # We create an open socket to the host agent in case we are running in a container
        # and the real pid needs to be detected.
        socket = TCPSocket.new @discovered[:agent_host], @discovered[:agent_port]
        announce_payload[:fd] = socket.fileno
        announce_payload[:inode] = File.readlink("/proc/#{Process.pid}/fd/#{socket.fileno}")
      end

      uri = URI.parse("http://#{@discovered[:agent_host]}:#{@discovered[:agent_port]}/#{DISCOVERY_PATH}")
      req = Net::HTTP::Put.new(uri)
      req.body = Oj.dump(announce_payload, OJ_OPTIONS)

      ::Instana.logger.debug "Announce: http://#{@discovered[:agent_host]}:#{@discovered[:agent_port]}/#{DISCOVERY_PATH} - payload: #{req.body}"

      response = make_host_agent_request(req)

      if response && (response.code.to_i == 200)
        data = Oj.load(response.body, OJ_OPTIONS)
        @process[:report_pid] = data['pid']
        @agent_uuid = data['agentUuid']

        if data.key?('extraHeaders')
          @extra_headers = data['extraHeaders']
        end
        true
      else
        false
      end
    rescue => e
      Instana.logger.info "#{__method__}:#{File.basename(__FILE__)}:#{__LINE__}: #{e.message}"
      Instana.logger.debug e.backtrace.join("\r\n")
      return false
    ensure
      socket.close if socket
    end
Collect process ID, name and arguments to notify
 the host agent.