Module: OpenTelemetry::Instrumentation::Ethon::Patches::Easy
- Defined in:
- lib/opentelemetry/instrumentation/ethon/patches/easy.rb
Overview
Ethon::Easy patch for instrumentation
Constant Summary collapse
- ACTION_NAMES_TO_HTTP_METHODS =
Hash.new do |h, k| # #to_s is required because user input could be symbol or string h[k] = k.to_s.upcase end
- HTTP_METHODS_TO_SPAN_NAMES =
Hash.new { |h, k| h[k] = "HTTP #{k}" }
Instance Method Summary collapse
- #complete ⇒ Object
- #headers=(headers) ⇒ Object
- #http_request(url, action_name, options = {}) ⇒ Object
- #otel_before_request ⇒ Object
- #otel_span_started? ⇒ Boolean
- #perform ⇒ Object
- #reset ⇒ Object
Instance Method Details
#complete ⇒ Object
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/opentelemetry/instrumentation/ethon/patches/easy.rb', line 35 def complete begin = mirror. response_code = ([:response_code] || [:code]).to_i if response_code.zero? return_code = [:return_code] = return_code ? ::Ethon::Curl.easy_strerror(return_code) : 'unknown reason' @otel_span.status = OpenTelemetry::Trace::Status.error("Request has failed: #{}") else @otel_span.set_attribute('http.status_code', response_code) @otel_span.status = OpenTelemetry::Trace::Status.error unless (100..399).cover?(response_code.to_i) end ensure @otel_span&.finish @otel_span = nil end super end |
#headers=(headers) ⇒ Object
24 25 26 27 28 |
# File 'lib/opentelemetry/instrumentation/ethon/patches/easy.rb', line 24 def headers=(headers) # Store headers to call this method again when span is ready @otel_original_headers = headers super end |
#http_request(url, action_name, options = {}) ⇒ Object
19 20 21 22 |
# File 'lib/opentelemetry/instrumentation/ethon/patches/easy.rb', line 19 def http_request(url, action_name, = {}) @otel_method = ACTION_NAMES_TO_HTTP_METHODS[action_name] super end |
#otel_before_request ⇒ Object
62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 |
# File 'lib/opentelemetry/instrumentation/ethon/patches/easy.rb', line 62 def otel_before_request method = 'N/A' # Could be GET or not HTTP at all method = @otel_method if instance_variable_defined?(:@otel_method) && !@otel_method.nil? @otel_span = tracer.start_span( HTTP_METHODS_TO_SPAN_NAMES[method], attributes: span_creation_attributes(method), kind: :client ) @otel_original_headers ||= {} OpenTelemetry::Trace.with_span(@otel_span) do OpenTelemetry.propagation.inject(@otel_original_headers) end self.headers = @otel_original_headers end |
#otel_span_started? ⇒ Boolean
79 80 81 |
# File 'lib/opentelemetry/instrumentation/ethon/patches/easy.rb', line 79 def otel_span_started? instance_variable_defined?(:@otel_span) && !@otel_span.nil? end |
#perform ⇒ Object
30 31 32 33 |
# File 'lib/opentelemetry/instrumentation/ethon/patches/easy.rb', line 30 def perform otel_before_request super end |
#reset ⇒ Object
54 55 56 57 58 59 60 |
# File 'lib/opentelemetry/instrumentation/ethon/patches/easy.rb', line 54 def reset super ensure @otel_span = nil @otel_method = nil @otel_original_headers = nil end |