Sha256: 1be210930575e23a81d7495306cbee28d5a9e589d39e53c90b7c4b5e7286af97

Contents?: true

Size: 1.1 KB

Versions: 21

Compression:

Stored size: 1.1 KB

Contents

module Datadog
  module Contrib
    module Rack
      # QueueTime simply...
      module QueueTime
        REQUEST_START = 'HTTP_X_REQUEST_START'.freeze
        QUEUE_START = 'HTTP_X_QUEUE_START'.freeze

        module_function

        def get_request_start(env, now = Time.now.utc)
          header = env[REQUEST_START] || env[QUEUE_START]
          return unless header

          # nginx header is in the format "t=1512379167.574"
          # TODO: this should be generic enough to work with any
          # frontend web server or load balancer
          time_string = header.split('t=')[1]
          return if time_string.nil?

          # return the request_start only if it's lesser than
          # current time, to avoid significant clock skew
          request_start = Time.at(time_string.to_f)
          request_start.utc > now ? nil : request_start
        rescue StandardError => e
          # in case of an Exception we don't create a
          # `request.queuing` span
          Datadog::Tracer.log.debug("[rack] unable to parse request queue headers: #{e}")
          nil
        end
      end
    end
  end
end

Version data entries

21 entries across 21 versions & 1 rubygems

Version Path
ddtrace-0.17.3 lib/ddtrace/contrib/rack/request_queue.rb
ddtrace-0.17.2 lib/ddtrace/contrib/rack/request_queue.rb
ddtrace-0.17.1 lib/ddtrace/contrib/rack/request_queue.rb
ddtrace-0.17.0 lib/ddtrace/contrib/rack/request_queue.rb
ddtrace-0.16.1 lib/ddtrace/contrib/rack/request_queue.rb
ddtrace-0.15.0.internaltracinfeature1 lib/ddtrace/contrib/rack/request_queue.rb
ddtrace-0.16.0 lib/ddtrace/contrib/rack/request_queue.rb
ddtrace-0.14.2.disableprotocolversion4 lib/ddtrace/contrib/rack/request_queue.rb
ddtrace-0.15.0 lib/ddtrace/contrib/rack/request_queue.rb
ddtrace-0.14.2.withoutpriorityparsing1 lib/ddtrace/contrib/rack/request_queue.rb
ddtrace-0.14.2 lib/ddtrace/contrib/rack/request_queue.rb
ddtrace-0.14.1 lib/ddtrace/contrib/rack/request_queue.rb
ddtrace-0.15.0.beta1 lib/ddtrace/contrib/rack/request_queue.rb
ddtrace-0.14.0 lib/ddtrace/contrib/rack/request_queue.rb
ddtrace-0.14.0.rc1 lib/ddtrace/contrib/rack/request_queue.rb
ddtrace-0.13.2 lib/ddtrace/contrib/rack/request_queue.rb
ddtrace-0.14.0.beta2 lib/ddtrace/contrib/rack/request_queue.rb
ddtrace-0.14.0.beta1 lib/ddtrace/contrib/rack/request_queue.rb
ddtrace-0.13.1 lib/ddtrace/contrib/rack/request_queue.rb
ddtrace-0.13.0 lib/ddtrace/contrib/rack/request_queue.rb