Class: Aws::Xray::Subsegment
- Defined in:
- lib/aws/xray/subsegment.rb
Overview
Constant Summary collapse
- TYPE_NAME =
'subsegment'.freeze
Instance Attribute Summary
Attributes inherited from Segment
#id, #name, #parent_id, #trace_id
Class Method Summary collapse
- .build(trace, parent_id, remote:, name:) ⇒ Object
-
.build_null ⇒ Object
Build a subsegment as null object.
Instance Method Summary collapse
- #generate_trace ⇒ Object
-
#initialize(name:, trace:, parent_id:, remote:) ⇒ Subsegment
constructor
A new instance of Subsegment.
-
#set_http_request(env, traced: false) ⇒ Object
Set traced=false if the downstream call is not traced app.
- #set_sql(sql) ⇒ Object
- #to_h ⇒ Object
Methods inherited from Segment
#add_annotation, #add_metadata, #finish, #finished?, #set_error, #set_http_response, #set_http_response_with_error, #start, #to_json
Constructor Details
#initialize(name:, trace:, parent_id:, remote:) ⇒ Subsegment
Returns a new instance of Subsegment.
20 21 22 23 24 25 |
# File 'lib/aws/xray/subsegment.rb', line 20 def initialize(name:, trace:, parent_id:, remote:) super(name: name, trace_id: trace.root, parent_id: parent_id) @trace = trace @remote = !!remote @sql = nil end |
Class Method Details
.build(trace, parent_id, remote:, name:) ⇒ Object
9 10 11 |
# File 'lib/aws/xray/subsegment.rb', line 9 def self.build(trace, parent_id, remote:, name:) new(name: name, trace: trace, parent_id: parent_id, remote: remote) end |
Instance Method Details
#generate_trace ⇒ Object
53 54 55 |
# File 'lib/aws/xray/subsegment.rb', line 53 def generate_trace @trace.copy(parent: @id) end |
#set_http_request(env, traced: false) ⇒ Object
Set traced=false if the downstream call is not traced app. e.g. Third-party Web API call. docs.aws.amazon.com/xray/latest/devguide/xray-api-segmentdocuments.html
30 31 32 33 |
# File 'lib/aws/xray/subsegment.rb', line 30 def set_http_request(env, traced: false) super(env) @http_request.traced = traced end |
#set_sql(sql) ⇒ Object
36 37 38 |
# File 'lib/aws/xray/subsegment.rb', line 36 def set_sql(sql) @sql = sql end |
#to_h ⇒ Object
40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/aws/xray/subsegment.rb', line 40 def to_h h = super # x_forwarded_for is Segment only. if h[:http] && h[:http][:request] h[:http][:request].delete(:x_forwarded_for) h[:http][:request][:traced] = @http_request.traced end h[:type] = TYPE_NAME h[:namespace] = 'remote' if @remote h[:sql] = @sql.to_h if @sql h end |