Class: Datadog::Tracing::Transport::HTTP::Client

Inherits:
Object
  • Object
show all
Includes:
Statistics, Traces::Client
Defined in:
lib/datadog/tracing/transport/http/client.rb

Overview

Routes, encodes, and sends tracer data to the trace agent via HTTP.

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Traces::Client

#send_traces_payload

Methods included from Statistics

included

Constructor Details

#initialize(api) ⇒ Client

Returns a new instance of Client.



17
18
19
# File 'lib/datadog/tracing/transport/http/client.rb', line 17

def initialize(api)
  @api = api
end

Instance Attribute Details

#apiObject (readonly)

Returns the value of attribute api.



15
16
17
# File 'lib/datadog/tracing/transport/http/client.rb', line 15

def api
  @api
end

Instance Method Details

#build_env(request) ⇒ Object



50
51
52
# File 'lib/datadog/tracing/transport/http/client.rb', line 50

def build_env(request)
  Datadog::Core::Transport::HTTP::Env.new(request)
end

#send_request(request, &block) ⇒ Object



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/datadog/tracing/transport/http/client.rb', line 21

def send_request(request, &block)
  # Build request into env
  env = build_env(request)

  # Get responses from API
  response = yield(api, env)

  # Update statistics
  update_stats_from_response!(response)

  response
rescue StandardError => e
  message =
    "Internal error during #{self.class.name} request. Cause: #{e.class.name} #{e.message} " \
      "Location: #{Array(e.backtrace).first}"

  # Log error
  if stats.consecutive_errors > 0
    Datadog.logger.debug(message)
  else
    Datadog.logger.error(message)
  end

  # Update statistics
  update_stats_from_exception!(e)

  Datadog::Core::Transport::InternalErrorResponse.new(e)
end