Sha256: 0de409b047b2450f4c802655b765215b625e0c08bacddcb218fd3969fed6dae9

Contents?: true

Size: 1.34 KB

Versions: 25

Compression:

Stored size: 1.34 KB

Contents

# frozen_string_literal: true

require_relative '../statistics'

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

            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
end

Version data entries

25 entries across 25 versions & 2 rubygems

Version Path
datadog-2.7.1 lib/datadog/tracing/transport/http/statistics.rb
datadog-2.7.0 lib/datadog/tracing/transport/http/statistics.rb
datadog-2.6.0 lib/datadog/tracing/transport/http/statistics.rb
datadog-2.5.0 lib/datadog/tracing/transport/http/statistics.rb
datadog-2.4.0 lib/datadog/tracing/transport/http/statistics.rb
datadog-2.3.0 lib/datadog/tracing/transport/http/statistics.rb
datadog-2.2.0 lib/datadog/tracing/transport/http/statistics.rb
ddtrace-1.23.3 lib/datadog/tracing/transport/http/statistics.rb
ddtrace-1.23.2 lib/datadog/tracing/transport/http/statistics.rb
datadog-2.1.0 lib/datadog/tracing/transport/http/statistics.rb
datadog-2.0.0 lib/datadog/tracing/transport/http/statistics.rb
ddtrace-1.23.1 lib/datadog/tracing/transport/http/statistics.rb
datadog-2.0.0.beta2 lib/datadog/tracing/transport/http/statistics.rb
ddtrace-1.22.0 lib/datadog/tracing/transport/http/statistics.rb
datadog-2.0.0.beta1 lib/datadog/tracing/transport/http/statistics.rb
ddtrace-1.21.1 lib/datadog/tracing/transport/http/statistics.rb
ddtrace-1.21.0 lib/datadog/tracing/transport/http/statistics.rb
ddtrace-1.20.0 lib/datadog/tracing/transport/http/statistics.rb
ddtrace-1.19.0 lib/datadog/tracing/transport/http/statistics.rb
ddtrace-1.18.0 lib/datadog/tracing/transport/http/statistics.rb