Class: Aws::Xray::SubSegment

Inherits:
Segment
  • Object
show all
Defined in:
lib/aws/xray/sub_segment.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

Instance Method Summary collapse

Methods inherited from Segment

#add_annotation, #add_metadata, #finish, #set_error, #set_http_response, #set_http_response_with_error, #to_json

Constructor Details

#initialize(name:, trace:, parent_id:, remote:) ⇒ SubSegment

Returns a new instance of SubSegment.



14
15
16
17
18
# File 'lib/aws/xray/sub_segment.rb', line 14

def initialize(name:, trace:, parent_id:, remote:)
  super(name: name, trace_id: trace.root, parent_id: parent_id)
  @trace = trace
  @remote = !!remote
end

Class Method Details

.build(trace, parent_id, remote:, name:) ⇒ Object

Parameters:

  • remote (Boolean)


8
9
10
# File 'lib/aws/xray/sub_segment.rb', line 8

def self.build(trace, parent_id, remote:, name:)
  new(name: name, trace: trace, parent_id: parent_id, remote: remote)
end

Instance Method Details

#generate_traceObject



40
41
42
# File 'lib/aws/xray/sub_segment.rb', line 40

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



23
24
25
26
# File 'lib/aws/xray/sub_segment.rb', line 23

def set_http_request(env, traced: false)
  super(env)
  @http_request.traced = traced
end

#to_hObject



28
29
30
31
32
33
34
35
36
37
38
# File 'lib/aws/xray/sub_segment.rb', line 28

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
end