Module: HTTP::Tracer
- Defined in:
- lib/http/tracer.rb,
lib/http/tracer/version.rb
Constant Summary collapse
- IngoreRequest =
->(_request, ) { false }
- VERSION =
'0.4.0'
Class Attribute Summary collapse
-
.ignore_request ⇒ Object
Returns the value of attribute ignore_request.
-
.tracer ⇒ Object
Returns the value of attribute tracer.
Class Method Summary collapse
- .compatible_version? ⇒ Boolean
- .instrument(tracer: OpenTracing.global_tracer, ignore_request: IngoreRequest) ⇒ Object
- .patch_perform ⇒ Object
- .remove ⇒ Object
Class Attribute Details
.ignore_request ⇒ Object
Returns the value of attribute ignore_request.
9 10 11 |
# File 'lib/http/tracer.rb', line 9 def ignore_request @ignore_request end |
.tracer ⇒ Object
Returns the value of attribute tracer.
9 10 11 |
# File 'lib/http/tracer.rb', line 9 def tracer @tracer end |
Class Method Details
.compatible_version? ⇒ Boolean
26 27 28 |
# File 'lib/http/tracer.rb', line 26 def compatible_version? Gem::Version.new(HTTP::VERSION) >= Gem::Version.new("0.1.0") end |
.instrument(tracer: OpenTracing.global_tracer, ignore_request: IngoreRequest) ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/http/tracer.rb', line 13 def instrument(tracer: OpenTracing.global_tracer, ignore_request: IngoreRequest) begin require 'http' rescue LoadError return end raise IncompatibleGemVersion unless compatible_version? @ignore_request = ignore_request @tracer = tracer patch_perform end |
.patch_perform ⇒ Object
40 41 42 43 44 45 46 47 48 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/http/tracer.rb', line 40 def patch_perform ::HTTP::Client.class_eval do def perform_with_tracing(request, ) if ::HTTP::Tracer.ignore_request.call(request, ) res = perform_without_tracing(request, ) else path, host, port, verb = nil path = request.uri.path if request.uri.respond_to?(:path) host = request.uri.host if request.uri.respond_to?(:host) port = request.uri.port if request.uri.respond_to?(:port) verb = request.verb.to_s.upcase if request.respond_to?(:verb) = { 'component' => 'ruby-httprb', 'span.kind' => 'client', 'http.method' => verb, 'http.url' => path, 'peer.host' => host, 'peer.port' => port }.compact tracer = ::HTTP::Tracer.tracer tracer.start_active_span('http.request', tags: ) do |scope| OpenTracing.inject(scope.span.context, OpenTracing::FORMAT_RACK, .headers) res = perform_without_tracing(request, ) scope.span.set_tag('http.status_code', res.status) scope.span.set_tag('error', true) if res.is_a?(StandardError) end end res end alias perform_without_tracing perform alias perform perform_with_tracing end end |
.remove ⇒ Object
30 31 32 33 34 35 36 37 38 |
# File 'lib/http/tracer.rb', line 30 def remove return unless ::HTTP::Client.method_defined?(:perform_without_tracing) ::HTTP::Client.class_eval do remove_method :perform alias_method :perform, :perform_without_tracing remove_method :perform_without_tracing end end |