Module: Datadog::Tracing::Transport::Statistics

Included in:
IO::Client
Defined in:
lib/datadog/tracing/transport/statistics.rb

Overview

Tracks statistics for transports

Defined Under Namespace

Classes: Counts

Instance Method Summary collapse

Instance Method Details

#metrics_for_exception(_exception) ⇒ Object



49
50
51
# File 'lib/datadog/tracing/transport/statistics.rb', line 49

def metrics_for_exception(_exception)
  { api_errors: Core::Metrics::Metric.new(:api_errors, nil, 1) }
end

#metrics_for_response(response) ⇒ Object



32
33
34
35
36
37
# File 'lib/datadog/tracing/transport/statistics.rb', line 32

def metrics_for_response(response)
  {}.tap do |metrics|
    metrics[:api_errors] = Core::Metrics::Metric.new(:api_errors, nil, 1) if response.internal_error?
    metrics[:api_responses] = Core::Metrics::Metric.new(:api_responses, nil, 1) unless response.internal_error?
  end
end

#statsObject



11
12
13
# File 'lib/datadog/tracing/transport/statistics.rb', line 11

def stats
  @stats ||= Counts.new
end

#update_stats_from_exception!(exception) ⇒ Object



39
40
41
42
43
44
45
46
47
# File 'lib/datadog/tracing/transport/statistics.rb', line 39

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) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/datadog/tracing/transport/statistics.rb', line 15

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