The private key is used to sign the transaction.
Transactions are being broadcasted into the network. They simply can not contain your private key without the whole system being worthless and broken.
Additionally to what bob123 said, the
signature is broadcasted into the network, not the private key.
This is very basic cyber security. THis is why it is safe. Keys are never broadcasted, only the signature which were created by the private keys. The keys never leave the device.