Module: Bugwatch::HttpTracker
- Defined in:
- lib/bugwatch/http_tracker.rb
Defined Under Namespace
Modules: NetHttpPatch
Constant Summary collapse
- THREAD_KEY =
:bugwatch_http_tracker- CALLER_FILTER =
%r{/(bugwatch|ruby/gems)/}
Class Method Summary collapse
- .clear ⇒ Object
- .collecting? ⇒ Boolean
- .finish_request ⇒ Object
- .handle_call(http, req, response, duration_ms) ⇒ Object
- .start_request(collecting:) ⇒ Object
- .subscribe! ⇒ Object
Class Method Details
.clear ⇒ Object
46 47 48 |
# File 'lib/bugwatch/http_tracker.rb', line 46 def clear Thread.current[THREAD_KEY] = nil end |
.collecting? ⇒ Boolean
50 51 52 53 |
# File 'lib/bugwatch/http_tracker.rb', line 50 def collecting? state = Thread.current[THREAD_KEY] state && state[:collecting] end |
.finish_request ⇒ Object
40 41 42 43 44 |
# File 'lib/bugwatch/http_tracker.rb', line 40 def finish_request state = Thread.current[THREAD_KEY] Thread.current[THREAD_KEY] = nil state end |
.handle_call(http, req, response, duration_ms) ⇒ Object
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/bugwatch/http_tracker.rb', line 55 def handle_call(http, req, response, duration_ms) state = Thread.current[THREAD_KEY] return unless state return unless state[:collecting] config = Bugwatch.configuration return if state[:calls].size >= config.max_http_calls_per_request state[:calls] << { host: http.address, port: http.port, method: req.method, path: extract_path(req.path), status_code: response.code.to_i, duration_ms: duration_ms, library: detect_library, caller_location: extract_caller } rescue StandardError # Never let tracking break the app end |
.start_request(collecting:) ⇒ Object
33 34 35 36 37 38 |
# File 'lib/bugwatch/http_tracker.rb', line 33 def start_request(collecting:) Thread.current[THREAD_KEY] = { calls: [], collecting: collecting } end |
.subscribe! ⇒ Object
27 28 29 30 31 |
# File 'lib/bugwatch/http_tracker.rb', line 27 def subscribe! return if Net::HTTP.ancestors.include?(NetHttpPatch) Net::HTTP.prepend(NetHttpPatch) end |