Melt 2 tablespoons of butter in a large skillet over medium heat. Add the sliced onions and a pinch of salt, then cook slowly for 20 minutes until they turn deep golden brown. Remove half the onions to a plate and set aside.
In a large bowl, combine the ground beef, breadcrumbs, egg, minced garlic, Worcestershire sauce, thyme, the remaining caramelized onions, and salt and pepper. Mix just until evenly blended.
Press half the meat mixture into a loaf pan. Scatter the Gruyere cubes over the center, then cover with the remaining meat mixture. Press the edges to seal the cheese inside.
Bake at 375°F for 50 to 55 minutes until the internal temperature reaches 160°F. Let the meatloaf rest for 10 minutes before slicing.
While the meatloaf rests, return the skillet with the reserved onions to medium heat. Sprinkle in the flour and stir for one minute. Slowly whisk in the beef broth, scraping up any browned bits. Simmer until the gravy thickens, then season with salt and pepper.