How can I get the active menu trail for the current page?
MenuLinkTreeInterface::getCurrentRouteMenuTreeParameters() is what you want. To use the example above:

$menu_tree = Drupal::menuTree();
$parameters = $menu_tree-&gt;getCurrentRouteMenuTreeParameters('main');
$parameters-&gt;setTopLevelOnly();
$main_menu_top_level = $menu_tree-&gt;load('main', $parameters);


The resulting menu tree should have inActiveTrail flagged.