I do almost all of my flying in California, so the procedure might be different back east, but any time I am going to leave the traffic pattern, I get flight following.
At Class C airports they will give you a squawk and frequency when you call ground or clearance delivery. At every Class C I have flown out of, they will give you headings and altitude restrictions. Very shortly after takeoff they will switch you over to departure control. At some point they will tell you that altitude and heading are at pilot’s discretion. I always continue with Flight Following, but once leaving the Class C area, you can cancel if you want.
At almost every Class D, ground control will give you the flight following squawk and frequency. I usually ask for flight following after being given my taxi instructions. The call goes something like this, “Cherokee 7290J is a PA28/U requesting flight following to Salinas at 7,500” or if I am going to just do maneuvers or sight-seeing I’ll ask for ‘Local Flight Following’. Ground control will call up departure and in a few minutes come back to me with a squawk and frequency. The only airport that I fly out of that won’t give you flight following on the ground is Oxnard.
They generally hand you off to departure control when you are nearing the edge of their airspace but if they are busy, you should call departure when leaving the Class D.
Your first call to Departure Control should contain your call sign, current altitude, final altitude, and distance/direction from the airport. e.g. “Cherokee 7290J 3 miles south-east of San Luis Obispo, leaving 2,200 climbing 3,500”. They’ll usually ask you to ident and then call back with your location e.g. “Cherokee 90J radar contact 4 miles south-east of San Luis Obispo, altimeter 29.92”. I then respond with the altimeter setting, but after watching, Stevo1Kinevo on YouTube, I think the correct response is to say “Position checks”.