Ssauté the onions over medium heat for 20-25 minutes until they are soft and golden brown. Be patient as this is where the onions develop their rich flavour.
When the onions are golden brown, add the sugar, thyme and salt and cook for another 10 minutes over low-medium heat.
Remove from the heat and allow to cool.
Pre-heat the oven to 180°C/350°F and spray a muffin tray with cooking spray.
Roll out the puff pastry slightly then cut squares of approximately 5cm x 5cm.
Fill each with a spoonful of the caramelized onions followed by some grated Gruyère. Take care not to overload with filling as it can burst open when baking.
Pinch the sides together to encase the filling.
Brush with the egg wash. Place in the oven and allow to bake for 15-20 minutes until golden brown and puffed.
Remove from the oven and allow to cool slightly then serve.