Module: Datadog::Tracing::Contrib::Ethon::EasyPatch::InstanceMethods
- Includes:
- HttpAnnotationHelper
- Defined in:
- lib/datadog/tracing/contrib/ethon/easy_patch.rb
Overview
InstanceMethods - implementing instrumentation
Instance Method Summary collapse
- #complete ⇒ Object
-
#datadog_before_request(continue_from: nil) ⇒ Object
Starts or retrieves the already started Easy request span.
- #datadog_span_started? ⇒ Boolean
- #headers=(headers) ⇒ Object
- #http_request(url, action_name, options = {}) ⇒ Object
- #perform ⇒ Object
- #reset ⇒ Object
Methods included from HttpAnnotationHelper
Instance Method Details
#complete ⇒ Object
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 |
# File 'lib/datadog/tracing/contrib/ethon/easy_patch.rb', line 49 def complete return super unless Tracing.enabled? 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" ("Request has failed: #{}") else @datadog_span.set_tag(Tracing::Metadata::Ext::HTTP::TAG_STATUS_CODE, response_code) # DEV-3.0: This was previously checking against a 500..599 range. # To not introduce breaking change, this was changed to use `http_error_statuses.server`, # but `ethon` is a client library, this check should use `http_error_statuses.client` instead. if Datadog.configuration.tracing.http_error_statuses.server.include?(response_code) ("Request has failed with HTTP error: #{response_code}") end end @datadog_span.( Datadog.configuration.tracing..( Core::Utils::Hash::CaseInsensitiveWrapper.new(parse_response_headers), ), ) ensure @datadog_span.finish @datadog_span = nil end super end |
#datadog_before_request(continue_from: nil) ⇒ Object
Starts or retrieves the already started Easy request span.
When tracing in Multi request context, child spans for each Easy
request are created early, and then finished as their HTTP response
becomes available. Because many Easy requests are open at the same time,
many Datadog::Tracing::Spans are also open at the same time. To avoid each separate
Easy request becoming the parented to the previous open request we set
the parent_span parameter with the parent Multi span. This correctly
assigns all open Easy spans to the currently executing Multi context.
101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 |
# File 'lib/datadog/tracing/contrib/ethon/easy_patch.rb', line 101 def datadog_before_request(continue_from: nil) load_datadog_configuration_for(url) = continue_from ? {continue_from: continue_from} : {} uri = try_parse_uri @datadog_span = Tracing.trace( Ext::SPAN_REQUEST, service: uri ? service_name(uri.host, datadog_configuration) : datadog_configuration[:service_name], type: Tracing::Metadata::Ext::HTTP::TYPE_OUTBOUND, **, ) datadog_trace = Tracing.active_trace datadog_tag_request(uri) if Tracing::Distributed::PropagationPolicy.enabled?( global_config: datadog_configuration, trace: datadog_trace, ) @datadog_original_headers ||= {} Contrib::HTTP.inject(datadog_trace, @datadog_original_headers) self.headers = @datadog_original_headers end end |
#datadog_span_started? ⇒ Boolean
127 128 129 |
# File 'lib/datadog/tracing/contrib/ethon/easy_patch.rb', line 127 def datadog_span_started? instance_variable_defined?(:@datadog_span) && !@datadog_span.nil? end |
#headers=(headers) ⇒ Object
35 36 37 38 39 |
# File 'lib/datadog/tracing/contrib/ethon/easy_patch.rb', line 35 def headers=(headers) # Store headers to call this method again when span is ready @datadog_original_headers = headers super end |
#http_request(url, action_name, options = {}) ⇒ Object
26 27 28 29 30 31 32 33 |
# File 'lib/datadog/tracing/contrib/ethon/easy_patch.rb', line 26 def http_request(url, action_name, = {}) load_datadog_configuration_for(url) return super unless Tracing.enabled? # It's tricky to get HTTP method from libcurl @datadog_method = action_name.to_s.upcase super end |
#perform ⇒ Object
41 42 43 44 45 46 47 |
# File 'lib/datadog/tracing/contrib/ethon/easy_patch.rb', line 41 def perform load_datadog_configuration_for(url) return super unless Tracing.enabled? datadog_before_request super end |
#reset ⇒ Object
81 82 83 84 85 86 87 88 |
# File 'lib/datadog/tracing/contrib/ethon/easy_patch.rb', line 81 def reset super ensure @datadog_span = nil @datadog_method = nil @datadog_original_headers = nil @datadog_configuration = nil end |