Class: LogBrew::HttpClientTraceOperation
- Inherits:
-
Object
- Object
- LogBrew::HttpClientTraceOperation
- Defined in:
- lib/logbrew/http_client_tracing.rb
Instance Attribute Summary collapse
-
#context ⇒ Object
readonly
Returns the value of attribute context.
-
#traceparent ⇒ Object
readonly
Returns the value of attribute traceparent.
Instance Method Summary collapse
- #around ⇒ Object
- #capture_error(error) ⇒ Object
- #finish(status_code: nil, error: nil) ⇒ Object
-
#initialize(client:, parent:, source:, method:, host:, on_capture_error:) ⇒ HttpClientTraceOperation
constructor
A new instance of HttpClientTraceOperation.
Constructor Details
#initialize(client:, parent:, source:, method:, host:, on_capture_error:) ⇒ HttpClientTraceOperation
Returns a new instance of HttpClientTraceOperation.
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/logbrew/http_client_tracing.rb', line 9 def initialize(client:, parent:, source:, method:, host:, on_capture_error:) @client = client @context = Trace.create( trace_id: parent.trace_id, span_id: Trace.generate_span_id, parent_span_id: parent.span_id, trace_flags: parent.trace_flags ) @traceparent = Trace.create_headers(@context).fetch("traceparent") @source = source @method = HttpClientTracing.normalize_method(method) @host = HttpClientTracing.normalize_host(host) @on_capture_error = on_capture_error @timestamp = Time.now.utc.iso8601(6) @started_at = HttpClientTracing.monotonic_time @mutex = Mutex.new @finished = false end |
Instance Attribute Details
#context ⇒ Object (readonly)
Returns the value of attribute context.
7 8 9 |
# File 'lib/logbrew/http_client_tracing.rb', line 7 def context @context end |
#traceparent ⇒ Object (readonly)
Returns the value of attribute traceparent.
7 8 9 |
# File 'lib/logbrew/http_client_tracing.rb', line 7 def traceparent @traceparent end |
Instance Method Details
#around ⇒ Object
28 29 30 |
# File 'lib/logbrew/http_client_tracing.rb', line 28 def around HttpClientTracing.with_operation(self) { yield } end |
#capture_error(error) ⇒ Object
44 45 46 |
# File 'lib/logbrew/http_client_tracing.rb', line 44 def capture_error(error) HttpClientTracing.report_capture_error(@on_capture_error, error) end |
#finish(status_code: nil, error: nil) ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/logbrew/http_client_tracing.rb', line 32 def finish(status_code: nil, error: nil) should_capture = @mutex.synchronize do next false if @finished @finished = true true end return unless should_capture capture(status_code, error) end |