Class: TRACING_MODULE::Contrib::HTTPX::Plugin::RequestTracer
- Inherits:
-
Object
- Object
- TRACING_MODULE::Contrib::HTTPX::Plugin::RequestTracer
- Includes:
- Contrib::HttpAnnotationHelper
- Defined in:
- lib/httpx/adapters/datadog.rb
Constant Summary collapse
- SPAN_REQUEST =
"httpx.request"
Instance Method Summary collapse
- #call ⇒ Object
- #finish(response) ⇒ Object
-
#initialize(request) ⇒ RequestTracer
constructor
A new instance of RequestTracer.
Constructor Details
#initialize(request) ⇒ RequestTracer
Returns a new instance of RequestTracer.
62 63 64 |
# File 'lib/httpx/adapters/datadog.rb', line 62 def initialize(request) @request = request end |
Instance Method Details
#call ⇒ Object
66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 |
# File 'lib/httpx/adapters/datadog.rb', line 66 def call return unless tracing_enabled? @request.on(:response, &method(:finish)) verb = @request.verb uri = @request.uri @span = build_span @span.resource = verb # Add additional request specific tags to the span. @span.set_tag(TAG_URL, @request.path) @span.set_tag(TAG_METHOD, verb) @span.set_tag(TAG_TARGET_HOST, uri.host) @span.set_tag(TAG_TARGET_PORT, uri.port.to_s) # Tag as an external peer service @span.set_tag(TAG_PEER_SERVICE, @span.service) propagate_headers if @configuration[:distributed_tracing] # Set analytics sample rate if Contrib::Analytics.enabled?(@configuration[:analytics_enabled]) Contrib::Analytics.set_sample_rate(@span, @configuration[:analytics_sample_rate]) end rescue StandardError => e Datadog.logger.error("error preparing span for http request: #{e}") Datadog.logger.error(e.backtrace) end |
#finish(response) ⇒ Object
100 101 102 103 104 105 106 107 108 109 110 111 112 |
# File 'lib/httpx/adapters/datadog.rb', line 100 def finish(response) return unless @span if response.is_a?(::HTTPX::ErrorResponse) @span.set_error(response.error) else @span.set_tag(TAG_STATUS_CODE, response.status.to_s) @span.set_error(::HTTPX::HTTPError.new(response)) if response.status >= 400 && response.status <= 599 end @span.finish end |