module Datadog::Transport::Statistics

Tracks statistics for transports

Public Instance Methods

metrics_for_exception(_exception) click to toggle source
# File lib/ddtrace/transport/statistics.rb, line 46
def metrics_for_exception(_exception)
  { api_errors: Metrics::Metric.new(:api_errors, nil, 1) }
end
metrics_for_response(response) click to toggle source
# File lib/ddtrace/transport/statistics.rb, line 29
def metrics_for_response(response)
  {}.tap do |metrics|
    metrics[:api_errors] = Metrics::Metric.new(:api_errors, nil, 1) if response.internal_error?
    metrics[:api_responses] = Metrics::Metric.new(:api_responses, nil, 1) unless response.internal_error?
  end
end
stats() click to toggle source
# File lib/ddtrace/transport/statistics.rb, line 8
def stats
  @stats ||= Counts.new
end
update_stats_from_exception!(exception) click to toggle source
# File lib/ddtrace/transport/statistics.rb, line 36
def update_stats_from_exception!(exception)
  stats.internal_error += 1
  stats.consecutive_errors += 1

  # Send health metrics
  Datadog.health_metrics.send_metrics(
    metrics_for_exception(exception).values
  )
end
update_stats_from_response!(response) click to toggle source
# File lib/ddtrace/transport/statistics.rb, line 12
def update_stats_from_response!(response)
  if response.ok?
    stats.success += 1
    stats.consecutive_errors = 0
  else
    stats.client_error += 1 if response.client_error?
    stats.server_error += 1 if response.server_error?
    stats.internal_error += 1 if response.internal_error?
    stats.consecutive_errors += 1
  end

  # Send health metrics
  Datadog.health_metrics.send_metrics(
    metrics_for_response(response).values
  )
end