code: func getSegment(name string, ctx context.Context) *awsxray.Segment {
  	md, _ := metadata.FromContext(ctx)
  	parentId := getParentId(md)
  	traceId := getTraceId(md)
  
  	// try get existing segment for parent Id
  	if s, ok := awsxray.FromContext(ctx); ok {
  		// only set existing segment as parent if its not a subsegment itself
  		if len(parentId) == 0 && len(s.Type) == 0 {
  			parentId = s.Id
  		}
  		if len(traceId) == 0 {
  			traceId = s.TraceId
  		}
  	}
  
  	// create segment
  	s := &awsxray.Segment{
  		Id:        fmt.Sprintf("%x", getRandom(8)),
  		Name:      name,
  		TraceId:   traceId,
  		StartTime: float64(time.Now().Truncate(time.Millisecond).UnixNano()) / 1e9,
  	}
  
  	// we have a parent so subsegment
  	if len(parentId) > 0 {
  		s.ParentId = parentId
  		s.Type = "subsegment"
  	}
  
  	return s
  }
docs: // getSegment creates a new segment based on whether we're part of an existing flow