def begin_segment(name, trace_id: nil, parent_id: nil, sampled: nil)
      seg_name = name || config.name
      raise SegmentNameMissingError if seg_name.to_s.empty?

      # sampling decision comes from outside has higher precedence.
      sample = sampled.nil? ? config.sample? : sampled
      if sample
        segment = Segment.new name: seg_name, trace_id: trace_id, parent_id: parent_id
        populate_runtime_context(segment, sample)
      else
        segment = DummySegment.new name: seg_name, trace_id: trace_id, parent_id: parent_id
      end
      context.store_entity entity: segment
      segment
    end
def begin_segment(name, trace_id: nil, parent_id: nil, sampled: nil)
      seg_name = name || config.name
      raise SegmentNameMissingError if seg_name.to_s.empty?

      # sampling decision comes from outside has higher precedence.
      sample = sampled.nil? ? config.sample? : sampled
      if sample
        segment = Segment.new name: seg_name, trace_id: trace_id, parent_id: parent_id
        populate_runtime_context(segment, sample)
      else
        segment = DummySegment.new name: seg_name, trace_id: trace_id, parent_id: parent_id
      end
      context.store_entity entity: segment
      segment
    end
Begin a segment for the current context. The recorder
 only keeps one segment at a time. Create a second one without
 closing existing one will overwrite the existing one.
 @return [Segment] thew newly created segment.