Sha256: 8ea805eeb6d5b6c43d9e9ce363129dae1d66854e7684ead317429b964a31451e

Contents?: true

Size: 1.48 KB

Versions: 20

Compression:

Stored size: 1.48 KB

Contents

# frozen_string_literal: true

require_relative 'statistics'
require_relative '../../../core/transport/http/env'
require_relative '../../../core/transport/http/response'

module Datadog
  module Tracing
    module Transport
      module HTTP
        # Routes, encodes, and sends tracer data to the trace agent via HTTP.
        class Client
          include Datadog::Tracing::Transport::HTTP::Statistics

          attr_reader :api

          def initialize(api)
            @api = api
          end

          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

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

Version data entries

20 entries across 20 versions & 2 rubygems

Version Path
datadog-2.3.0 lib/datadog/tracing/transport/http/client.rb
datadog-2.2.0 lib/datadog/tracing/transport/http/client.rb
ddtrace-1.23.3 lib/datadog/tracing/transport/http/client.rb
ddtrace-1.23.2 lib/datadog/tracing/transport/http/client.rb
datadog-2.1.0 lib/datadog/tracing/transport/http/client.rb
datadog-2.0.0 lib/datadog/tracing/transport/http/client.rb
ddtrace-1.23.1 lib/datadog/tracing/transport/http/client.rb
datadog-2.0.0.beta2 lib/datadog/tracing/transport/http/client.rb
ddtrace-1.22.0 lib/datadog/tracing/transport/http/client.rb
datadog-2.0.0.beta1 lib/datadog/tracing/transport/http/client.rb
ddtrace-1.21.1 lib/datadog/tracing/transport/http/client.rb
ddtrace-1.21.0 lib/datadog/tracing/transport/http/client.rb
ddtrace-1.20.0 lib/datadog/tracing/transport/http/client.rb
ddtrace-1.19.0 lib/datadog/tracing/transport/http/client.rb
ddtrace-1.18.0 lib/datadog/tracing/transport/http/client.rb
ddtrace-1.17.0 lib/datadog/tracing/transport/http/client.rb
ddtrace-1.16.2 lib/datadog/tracing/transport/http/client.rb
ddtrace-1.16.1 lib/datadog/tracing/transport/http/client.rb
ddtrace-1.16.0 lib/datadog/tracing/transport/http/client.rb
ddtrace-1.15.0 lib/datadog/tracing/transport/http/client.rb