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.
-
#service ⇒ Object
Returns the value of attribute service.
-
#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
- #sampling_rule_name=(v) ⇒ 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.
16 17 18 19 20 21 22 23 24 |
# File 'lib/aws-xray-sdk/model/segment.rb', line 16 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 |
#service ⇒ Object
Returns the value of attribute service.
9 10 11 |
# File 'lib/aws-xray-sdk/model/segment.rb', line 9 def service @service 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
32 33 34 35 36 |
# File 'lib/aws-xray-sdk/model/segment.rb', line 32 def add_subsegment(subsegment:) super subsegment: subsegment @ref_counter += 1 @subsegment_size += 1 end |
#decrement_ref_counter ⇒ Object
49 50 51 |
# File 'lib/aws-xray-sdk/model/segment.rb', line 49 def decrement_ref_counter @ref_counter -= 1 end |
#ready_to_send? ⇒ Boolean
53 54 55 |
# File 'lib/aws-xray-sdk/model/segment.rb', line 53 def ready_to_send? closed? && ref_counter.zero? end |
#remove_subsegment(subsegment:) ⇒ Object
38 39 40 41 |
# File 'lib/aws-xray-sdk/model/segment.rb', line 38 def remove_subsegment(subsegment:) super subsegment: subsegment @subsegment_size = subsegment_size - subsegment.all_children_count - 1 end |
#sampling_rule_name=(v) ⇒ Object
43 44 45 46 47 |
# File 'lib/aws-xray-sdk/model/segment.rb', line 43 def sampling_rule_name=(v) @aws ||= {} @aws[:xray] ||= {} @aws[:xray][:sampling_rule_name] = v end |
#segment ⇒ Object
67 68 69 |
# File 'lib/aws-xray-sdk/model/segment.rb', line 67 def segment self end |
#to_h ⇒ Object
57 58 59 60 61 62 63 64 65 |
# File 'lib/aws-xray-sdk/model/segment.rb', line 57 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[:service] = service if service h end |
#trace_id ⇒ Object
26 27 28 29 30 |
# File 'lib/aws-xray-sdk/model/segment.rb', line 26 def trace_id @trace_id ||= begin %[1-#{Time.now.to_i.to_s(16)}-#{SecureRandom.hex(12)}] end end |