What ammo are you shooting? Do you see triangular dents/scrapes at the case mouths of the spent casings? Some ammo will eject erratically in a Glock even if there isn't a problem with the gun.
There's a problem with a small number of recent production Gen3 and Gen4 9/40/357 models that causes erratic ejection. I've experienced it, and fixed it in my own Gen3 G27. With some, it seems the extractor is out-of-spec and replacing it fixes the problem. With others however, only the new ejector will solve the problem. Glock designed two new ejectors, stamped 30274 for 9mm and 28926 for .40/.357. They're only using the new ejectors in Gen4's, Gen4's with a test-fire date after 10/10/2011 should have the new ejector.
If your Gen4 ejects erratically with the new ejector, it likely means that the extractor is out-of-spec and should be replaced.
One way to get the new ejector is to find a local Glock Certified Armorer, ask them to order the Gen4 9mm trigger housing part number 30275, and install that ejector in your gun. If your gun is a Gen4, it's a simple trigger housing w/ejector swap. If your gun is a Gen3, the ejector has to be removed from the Gen3 trigger housing in your gun and the Gen4 trigger housing, and the new ejector must be put into your Gen3 trigger housing to use in your Gen3 gun.
Another way to get the new ejector is to send the gun back to Glock. If it's a Gen4, they'll install the new ejector without question as it's a normal "upgrade" to the latest parts for Gen4's. With a Gen3 however you have to explain to them that the gun ejects erratically with a variety of ammo, and you have to ask them to install the new ejector into your Gen3. They have done so in some cases, and refused to do so in other cases even recently.
LoneWolf Distributors recently went out of stock on their Gen4 9mm trigger housings, presumably since the old version w/336 ejector was discontinued, they'll re-stock with the one that has the 30274 ejector, but no one has yet confirmed receiving one with the new ejector from them. http://www.lonewolfdist.com/Detail.aspx?PROD=123268&CAT=200
My wifes G19 was doing the same thing yesterday... It was the first time the pistol was shot.. Put 300 rounds through it and it was still doing it... My G23 don't do it all.. You think it could be the 9mm round in general?