Class: XRay::Segment
- Inherits:
-
Object
- Object
- XRay::Segment
- Includes:
- Entity
- Defined in:
- lib/aws-xray-sdk/model/segment.rb
Overview
The compute resources running your application logic send data about their work as segments. A segment provides the resource’s name, details about the request, and details about the work done.
Direct Known Subclasses
Constant Summary
Constants included from Entity
Entity::HTTP_REQUEST_KEY, Entity::HTTP_RESPONSE_KEY
Instance Attribute Summary collapse
-
#origin ⇒ Object
Returns the value of attribute origin.
-
#ref_counter ⇒ Object
Returns the value of attribute ref_counter.
-
#subsegment_size ⇒ Object
Returns the value of attribute subsegment_size.
-
#user ⇒ Object
Returns the value of attribute user.
Attributes included from Entity
#aws, #cause, #end_time, #error, #exception, #fault, #http_request, #http_response, #name, #namespace, #parent, #sampled, #start_time, #throttle
Instance Method Summary collapse
- #add_subsegment(subsegment:) ⇒ Object
- #decrement_ref_counter ⇒ Object
-
#initialize(trace_id: nil, name: nil, parent_id: nil) ⇒ Segment
constructor
A new instance of Segment.
- #ready_to_send? ⇒ Boolean
- #remove_subsegment(subsegment:) ⇒ Object
- #segment ⇒ Object
- #to_h ⇒ Object
- #trace_id ⇒ Object
Methods included from Entity
#add_exception, #annotations, #apply_status_code, #cause_id, #close, #closed?, #id, #merge_http_request, #merge_http_response, #metadata, #subsegments, #to_json
Constructor Details
#initialize(trace_id: nil, name: nil, parent_id: nil) ⇒ Segment
Returns a new instance of Segment.
15 16 17 18 19 20 21 22 23 |
# File 'lib/aws-xray-sdk/model/segment.rb', line 15 def initialize(trace_id: nil, name: nil, parent_id: nil) @trace_id = trace_id @name = ENV['AWS_TRACING_NAME'] || name @parent_id = parent_id @start_time = Time.now.to_f @ref_counter = 0 @subsegment_size = 0 @sampled = true end |
Instance Attribute Details
#origin ⇒ Object
Returns the value of attribute origin.
9 10 11 |
# File 'lib/aws-xray-sdk/model/segment.rb', line 9 def origin @origin end |
#ref_counter ⇒ Object
Returns the value of attribute ref_counter.
9 10 11 |
# File 'lib/aws-xray-sdk/model/segment.rb', line 9 def ref_counter @ref_counter end |
#subsegment_size ⇒ Object
Returns the value of attribute subsegment_size.
9 10 11 |
# File 'lib/aws-xray-sdk/model/segment.rb', line 9 def subsegment_size @subsegment_size end |
#user ⇒ Object
Returns the value of attribute user.
9 10 11 |
# File 'lib/aws-xray-sdk/model/segment.rb', line 9 def user @user end |
Instance Method Details
#add_subsegment(subsegment:) ⇒ Object
31 32 33 34 35 |
# File 'lib/aws-xray-sdk/model/segment.rb', line 31 def add_subsegment(subsegment:) super subsegment: subsegment @ref_counter += 1 @subsegment_size += 1 end |
#decrement_ref_counter ⇒ Object
42 43 44 |
# File 'lib/aws-xray-sdk/model/segment.rb', line 42 def decrement_ref_counter @ref_counter -= 1 end |
#ready_to_send? ⇒ Boolean
46 47 48 |
# File 'lib/aws-xray-sdk/model/segment.rb', line 46 def ready_to_send? closed? && ref_counter.zero? end |
#remove_subsegment(subsegment:) ⇒ Object
37 38 39 40 |
# File 'lib/aws-xray-sdk/model/segment.rb', line 37 def remove_subsegment(subsegment:) super subsegment: subsegment @subsegment_size = subsegment_size - subsegment.all_children_count - 1 end |
#segment ⇒ Object
59 60 61 |
# File 'lib/aws-xray-sdk/model/segment.rb', line 59 def segment self end |
#to_h ⇒ Object
50 51 52 53 54 55 56 57 |
# File 'lib/aws-xray-sdk/model/segment.rb', line 50 def to_h h = super h[:trace_id] = trace_id h[:origin] = origin if origin h[:parent_id] = @parent_id if @parent_id h[:user] = user if user h end |
#trace_id ⇒ Object
25 26 27 28 29 |
# File 'lib/aws-xray-sdk/model/segment.rb', line 25 def trace_id @trace_id ||= begin %[1-#{Time.now.to_i.to_s(16)}-#{SecureRandom.hex(12)}] end end |