module Datadog::Contrib::RestClient::RequestPatch::InstanceMethods
InstanceMethods
- implementing instrumentation
Public Instance Methods
datadog_tag_request(uri, span)
click to toggle source
# File lib/ddtrace/contrib/rest_client/request_patch.rb, line 31 def datadog_tag_request(uri, span) span.resource = method.to_s.upcase # Set analytics sample rate Contrib::Analytics.set_sample_rate(span, analytics_sample_rate) if analytics_enabled? span.set_tag(Datadog::Ext::HTTP::URL, uri.path) span.set_tag(Datadog::Ext::HTTP::METHOD, method.to_s.upcase) span.set_tag(Datadog::Ext::NET::TARGET_HOST, uri.host) span.set_tag(Datadog::Ext::NET::TARGET_PORT, uri.port) end
datadog_trace_request(uri) { |span| ... }
click to toggle source
# File lib/ddtrace/contrib/rest_client/request_patch.rb, line 43 def datadog_trace_request(uri) span = datadog_configuration[:tracer].trace(Ext::SPAN_REQUEST, service: datadog_configuration[:service_name], span_type: Datadog::Ext::HTTP::TYPE_OUTBOUND) datadog_tag_request(uri, span) yield(span).tap do |response| # Verify return value is a response # If so, add additional tags. if response.is_a?(::RestClient::Response) span.set_tag(Datadog::Ext::HTTP::STATUS_CODE, response.code) end end rescue ::RestClient::ExceptionWithResponse => e span.set_error(e) if Datadog::Ext::HTTP::ERROR_RANGE.cover?(e.http_code) span.set_tag(Datadog::Ext::HTTP::STATUS_CODE, e.http_code) raise e # rubocop:disable Lint/RescueException rescue Exception => e # rubocop:enable Lint/RescueException span.set_error(e) if span raise e ensure span.finish if span end
execute(&block)
click to toggle source
Calls superclass method
# File lib/ddtrace/contrib/rest_client/request_patch.rb, line 17 def execute(&block) uri = URI.parse(url) return super(&block) unless datadog_configuration[:tracer].enabled datadog_trace_request(uri) do |span| if datadog_configuration[:distributed_tracing] Datadog::HTTPPropagator.inject!(span.context, processed_headers) end super(&block) end end
Private Instance Methods
analytics_enabled?()
click to toggle source
# File lib/ddtrace/contrib/rest_client/request_patch.rb, line 78 def analytics_enabled? Contrib::Analytics.enabled?(datadog_configuration[:analytics_enabled]) end
analytics_sample_rate()
click to toggle source
# File lib/ddtrace/contrib/rest_client/request_patch.rb, line 82 def analytics_sample_rate datadog_configuration[:analytics_sample_rate] end
datadog_configuration()
click to toggle source
# File lib/ddtrace/contrib/rest_client/request_patch.rb, line 74 def datadog_configuration Datadog.configuration[:rest_client] end