Class: BrightData::LiveTrace Private
- Inherits:
-
Object
- Object
- BrightData::LiveTrace
- Defined in:
- lib/brightdata/live_trace.rb
Overview
This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.
Optional request/response recorder, enabled by the ‘BRIGHTDATA_LIVE` env var. Writes one JSON file per request, response, and error under `tmp/live` so live API calls can be inspected after the fact.
HTTP asks for a recorder via LiveTrace.for; when tracing is disabled it gets a Null recorder whose methods are no-ops, keeping the HTTP request path free of conditionals.
Defined Under Namespace
Class Method Summary collapse
-
.for(request) ⇒ LiveTrace, LiveTrace::Null
private
Build a recorder and persist the request, or return a no-op recorder when ‘BRIGHTDATA_LIVE` is unset.
Instance Method Summary collapse
-
#initialize(request) ⇒ LiveTrace
constructor
private
A new instance of LiveTrace.
- #record_error(error) ⇒ Object private
- #record_request ⇒ Object private
- #record_response(response:, duration:) ⇒ Object private
Constructor Details
#initialize(request) ⇒ LiveTrace
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns a new instance of LiveTrace.
41 42 43 44 |
# File 'lib/brightdata/live_trace.rb', line 41 def initialize(request) @request = request @trace_id = build_trace_id end |
Class Method Details
.for(request) ⇒ LiveTrace, LiveTrace::Null
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Build a recorder and persist the request, or return a no-op recorder when ‘BRIGHTDATA_LIVE` is unset.
26 27 28 29 30 |
# File 'lib/brightdata/live_trace.rb', line 26 def self.for(request) return Null.new unless ENV["BRIGHTDATA_LIVE"] new(request).tap(&:record_request) end |
Instance Method Details
#record_error(error) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
57 58 59 60 |
# File 'lib/brightdata/live_trace.rb', line 57 def record_error(error) save("error", { error_class: error.class.name, message: error. }) announce("error saved #{error.class}: #{error.}") end |
#record_request ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
46 47 48 49 |
# File 'lib/brightdata/live_trace.rb', line 46 def record_request save("request", request_payload) announce("request saved") end |
#record_response(response:, duration:) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
51 52 53 54 55 |
# File 'lib/brightdata/live_trace.rb', line 51 def record_response(response:, duration:) payload = response_payload(response, duration) save("response", payload) announce("response saved status=#{payload.fetch(:status)} duration=#{payload.fetch(:duration_seconds)}s") end |