In a large skillet, melt butter over medium-low heat and add sliced onions. Sauté for 30-35 minutes, stirring occasionally, until deeply caramelized. Deglaze the pan with 1 tablespoon of balsamic vinegar and set aside to cool.
Preheat oven to 375°F (190°C) and line a baking sheet with parchment paper.
In a large mixing bowl, combine ground beef, breadcrumbs, milk, egg, Worcestershire sauce, thyme, salt, pepper, and half of the caramelized onions. Mix by hand until just combined.
Place half of the meat mixture onto the prepared baking sheet, shaping it into a 9x5-inch rectangle.
Layer the remaining caramelized onions and the shredded Gruyère cheese over the center of the meat, leaving a 1-inch border on all sides.
Place the remaining meat mixture on top and pinch the edges firmly to seal the cheese and onions inside the loaf.
In a small bowl, whisk together the beef stock and brown sugar. Brush half of this glaze over the top and sides of the meatloaf.
Bake for 55 minutes, brushing with the remaining glaze after the first 30 minutes, until the internal temperature reaches 160°F (71°C).
Allow the meatloaf to rest for 10 minutes before slicing to ensure the cheese filling remains intact.