class XRay::Segment

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.

Attributes

origin[RW]
ref_counter[RW]
service[RW]
subsegment_size[RW]
user[RW]

Public Class Methods

new(trace_id: nil, name: nil, parent_id: nil) click to toggle source

@param [String] trace_id Manually crafted trace id. @param [String] name Must be specified either on object creation or

on environment variable `AWS_TRACING_NAME`. The latter has higher precedence.

@param [String] parent_id ID of the segment/subsegment representing the upstream caller.

# 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

Public Instance Methods

add_subsegment(subsegment:) click to toggle source
Calls superclass method XRay::Entity#add_subsegment
# 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() click to toggle source
# File lib/aws-xray-sdk/model/segment.rb, line 49
def decrement_ref_counter
  @ref_counter -= 1
end
ready_to_send?() click to toggle source
# File lib/aws-xray-sdk/model/segment.rb, line 53
def ready_to_send?
  closed? && ref_counter.zero?
end
remove_subsegment(subsegment:) click to toggle source
Calls superclass method XRay::Entity#remove_subsegment
# 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) click to toggle source
# 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() click to toggle source
# File lib/aws-xray-sdk/model/segment.rb, line 67
def segment
  self
end
to_h() click to toggle source
Calls superclass method XRay::Entity#to_h
# 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() click to toggle source
# 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