Sha256: e0c48dea98179336fce632de44f87138c06e5a241851f929b2922778c9b24ebf

Contents?: true

Size: 1.23 KB

Versions: 9

Compression:

Stored size: 1.23 KB

Contents

require 'ddtrace/transport/statistics'

module Datadog
  module Transport
    module HTTP
      # Tracks statistics for HTTP transports
      module Statistics
        def self.included(base)
          base.send(:include, Datadog::Transport::Statistics)
          base.send(: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

9 entries across 9 versions & 1 rubygems

Version Path
ddtrace-0.49.0 lib/ddtrace/transport/http/statistics.rb
ddtrace-0.48.0 lib/ddtrace/transport/http/statistics.rb
ddtrace-0.47.0 lib/ddtrace/transport/http/statistics.rb
ddtrace-0.46.0 lib/ddtrace/transport/http/statistics.rb
ddtrace-0.45.0 lib/ddtrace/transport/http/statistics.rb
ddtrace-0.44.0 lib/ddtrace/transport/http/statistics.rb
ddtrace-0.43.0 lib/ddtrace/transport/http/statistics.rb
ddtrace-0.42.0 lib/ddtrace/transport/http/statistics.rb
ddtrace-0.41.0 lib/ddtrace/transport/http/statistics.rb