lib/ddtrace/contrib/http/instrumentation.rb in ddtrace-0.45.0 vs lib/ddtrace/contrib/http/instrumentation.rb in ddtrace-0.46.0
- old
+ new
@@ -17,11 +17,11 @@
base.send(:prepend, InstanceMethods)
end
# Span hook invoked after request is completed.
def self.after_request(&block)
- if block_given?
+ if block
# Set hook
@after_request = block
else
# Get hook
@after_request ||= nil
@@ -30,19 +30,18 @@
# InstanceMethods - implementing instrumentation
module InstanceMethods
include Datadog::Contrib::HttpAnnotationHelper
- def request(req, body = nil, &block) # :yield: +response+
+ # :yield: +response+
+ def request(req, body = nil, &block)
host, = host_and_port(req)
request_options = datadog_configuration(host)
pin = datadog_pin(request_options)
return super(req, body, &block) unless pin && pin.tracer
- if Datadog::Contrib::HTTP.should_skip_tracing?(req, pin.tracer)
- return super(req, body, &block)
- end
+ return super(req, body, &block) if Datadog::Contrib::HTTP.should_skip_tracing?(req, pin.tracer)
pin.tracer.trace(Ext::SPAN_REQUEST, on_error: method(:annotate_span_with_error!)) do |span|
begin
# even though service_name might already be in request_options,
# we need to capture the name from the pin since it could be
@@ -106,9 +105,10 @@
span.set_error(error)
end
def set_analytics_sample_rate(span, request_options)
return unless analytics_enabled?(request_options)
+
Contrib::Analytics.set_sample_rate(span, analytics_sample_rate(request_options))
end
def datadog_pin(config = Datadog.configuration[:http])
service = config[:service_name]