Sha256: ae8a01c2ae6d95f63f67884de7a3690537baf4ba7000281472261a3f1a027a9c

Contents?: true

Size: 1.23 KB

Versions: 12

Compression:

Stored size: 1.23 KB

Contents

# typed: true

require_relative '../statistics'

module Datadog
  module Transport
    module HTTP
      # Tracks statistics for HTTP transports
      module Statistics
        def self.included(base)
          base.include(Datadog::Transport::Statistics)
          base.include(InstanceMethods)
        end

        # Instance methods for HTTP statistics
        module InstanceMethods
          # Decorate metrics for HTTP responses
          def metrics_for_response(response)
            super.tap do |metrics|
              # Add status code tag to api.responses metric
              if metrics.key?(:api_responses)
                (metrics[:api_responses].options[:tags] ||= []).tap do |tags|
                  tags << metrics_tag_value(response.code)
                end
              end
            end
          end

          private

          # The most common status code on a healthy tracer
          STATUS_CODE_200 = 'status_code:200'.freeze

          def metrics_tag_value(status_code)
            if status_code == 200
              STATUS_CODE_200 # DEV Saves string concatenation/creation for common case
            else
              "status_code:#{status_code}"
            end
          end
        end
      end
    end
  end
end

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
ddtrace-1.9.0 lib/ddtrace/transport/http/statistics.rb
ddtrace-1.8.0 lib/ddtrace/transport/http/statistics.rb
ddtrace-1.7.0 lib/ddtrace/transport/http/statistics.rb
ddtrace-1.6.1 lib/ddtrace/transport/http/statistics.rb
ddtrace-1.6.0 lib/ddtrace/transport/http/statistics.rb
ddtrace-1.5.2 lib/ddtrace/transport/http/statistics.rb
ddtrace-1.5.1 lib/ddtrace/transport/http/statistics.rb
ddtrace-1.5.0 lib/ddtrace/transport/http/statistics.rb
ddtrace-1.4.2 lib/ddtrace/transport/http/statistics.rb
ddtrace-1.4.1 lib/ddtrace/transport/http/statistics.rb
ddtrace-1.4.0 lib/ddtrace/transport/http/statistics.rb
ddtrace-1.3.0 lib/ddtrace/transport/http/statistics.rb