lib/scalyr/common/client.rb
def post_add_events(body, is_status, body_serialization_duration = 0)
    post_body, post_headers, compression_duration = prepare_post_object @add_events_uri.path, body
    fail_count = 1  # putative assume failure
    start_time = Time.now
    uncompressed_bytes_sent = 0
    compressed_bytes_sent = 0
    bytes_received = 0
    begin
      response = client.send(:post, @add_events_uri, body: post_body, headers: post_headers)
      handle_response(response)

      fail_count -= 1  # success means we negate the putative failure
      uncompressed_bytes_sent = (body.bytesize + @add_events_uri.path.bytesize)
      compressed_bytes_sent = (post_body.bytesize + @add_events_uri.path.bytesize)
      bytes_received = response.body.bytesize  # echee: double check
        # echee TODO add more statistics

    rescue Manticore::ManticoreException => e
      # The underlying persistent-connection library automatically retries when there are network-related errors.
      # Eventually, it will give up and raise this generic error, at which time, we convert it to a ClientError
      raise ClientError.new(e.message, @add_events_uri, e.class.name)

    ensure
      if @record_stats_for_status or !is_status
        @stats_lock.synchronize do
          @stats[:total_requests_sent] += 1
          @stats[:total_requests_failed] += fail_count
          @stats[:total_request_bytes_sent] += uncompressed_bytes_sent
          @stats[:total_compressed_request_bytes_sent] += compressed_bytes_sent
          @stats[:total_response_bytes_received] += bytes_received
          @stats[:total_serialization_duration_secs] += body_serialization_duration
          @stats[:total_compression_duration_secs] += compression_duration
          end_time = Time.now
          @stats[:total_request_latency_secs] += (end_time - start_time)
          @latency_stats[:request_latency_secs].observe(end_time - start_time)
          @latency_stats[:serialization_duration_secs].observe(body_serialization_duration)
          @latency_stats[:compression_duration_secs].observe(compression_duration)
          @latency_stats[:bytes_sent].observe(uncompressed_bytes_sent)
        end
      end
    end
  end
# Upload data to Scalyr. Assumes that the body size complies with Scalyr limits
Upload data to Scalyr. Assumes that the body size complies with Scalyr limits
Upload data to Scalyr . Assumes that the body size complies with Scalyr limits
def post_add_events(body, is_status, body_serialization_duration = 0)
    post_body, post_headers, compression_duration = prepare_post_object @add_events_uri.path, body
    fail_count = 1  
    start_time = Time.now
    uncompressed_bytes_sent = 0
    compressed_bytes_sent = 0
    bytes_received = 0
    begin
      response = client.send(:post, @add_events_uri, body: post_body, headers: post_headers)
      handle_response(response)
      fail_count -= 1  
      uncompressed_bytes_sent = (body.bytesize + @add_events_uri.path.bytesize)
      compressed_bytes_sent = (post_body.bytesize + @add_events_uri.path.bytesize)
      bytes_received = response.body.bytesize  
    rescue Manticore::ManticoreException => e
      raise ClientError.new(e.message, @add_events_uri, e.class.name)
    ensure
      if @record_stats_for_status or !is_status
        @stats_lock.synchronize do
          @stats[:total_requests_sent] += 1
          @stats[:total_requests_failed] += fail_count
          @stats[:total_request_bytes_sent] += uncompressed_bytes_sent
          @stats[:total_compressed_request_bytes_sent] += compressed_bytes_sent
          @stats[:total_response_bytes_received] += bytes_received
          @stats[:total_serialization_duration_secs] += body_serialization_duration
          @stats[:total_compression_duration_secs] += compression_duration
          end_time = Time.now
          @stats[:total_request_latency_secs] += (end_time - start_time)
          @latency_stats[:request_latency_secs].observe(end_time - start_time)
          @latency_stats[:serialization_duration_secs].observe(body_serialization_duration)
          @latency_stats[:compression_duration_secs].observe(compression_duration)
          @latency_stats[:bytes_sent].observe(uncompressed_bytes_sent)
        end
      end
    end
  end
def post_add_events ( body , is_status , body_serialization_duration = 0 ) post_body , post_headers , compression_duration = prepare_post_object @add_events_uri . path , body fail_count = 1 start_time = Time . now uncompressed_bytes_sent = 0 compressed_bytes_sent = 0 bytes_received = 0 begin response = client . send ( :post , @add_events_uri , body : post_body , headers : post_headers ) handle_response ( response ) fail_count -= 1 uncompressed_bytes_sent = ( body . bytesize + @add_events_uri . path . bytesize ) compressed_bytes_sent = ( post_body . bytesize + @add_events_uri . path . bytesize ) bytes_received = response . body . bytesize rescue Manticore :: ManticoreException => e raise ClientError . new ( e . message , @add_events_uri , e . class . name ) ensure if @record_stats_for_status or ! is_status @stats_lock . synchronize do @stats [ :total_requests_sent ] += 1 @stats [ :total_requests_failed ] += fail_count @stats [ :total_request_bytes_sent ] += uncompressed_bytes_sent @stats [ :total_compressed_request_bytes_sent ] += compressed_bytes_sent @stats [ :total_response_bytes_received ] += bytes_received @stats [ :total_serialization_duration_secs ] += body_serialization_duration @stats [ :total_compression_duration_secs ] += compression_duration end_time = Time . now @stats [ :total_request_latency_secs ] += ( end_time - start_time ) @latency_stats [ :request_latency_secs ] . observe ( end_time - start_time ) @latency_stats [ :serialization_duration_secs ] . observe ( body_serialization_duration ) @latency_stats [ :compression_duration_secs ] . observe ( compression_duration ) @latency_stats [ :bytes_sent ] . observe ( uncompressed_bytes_sent ) end end end end
Upload data to Scalyr.
Upload data to Scalyr .
# putative assume failure # success means we negate the putative failure # echee: double check # echee TODO add more statistics # The underlying persistent-connection library automatically retries when there are network-related errors. # Eventually, it will give up and raise this generic error, at which time, we convert it to a ClientError
body
is_status
body_serialization_duration