Bug — A problem which impairs or prevents the functions of the product.
Improvement — An enhancement to an existing feature.
New Feature — A new feature of the product.
Task — A task that needs to be done.
Custom Issue — A custom issue type, as defined by your organization if required.
But in the end it all comes down to your own interpretation. You get to decide what's a bug and what's a story, you can choose that for yourself with your company. Some things will be stories, some things will be bugs and some things might be issue types only your company uses. JIRA is flexible in this regard and you can play with it until it works for your company.
"Whenever you find a bug" is the basic answer.
Exactly how you handle it is up to your processes. Some places simply accept new bugs as they're found, with them all going into the backlog. Some places differentiate between a "bug" and a "defect" by saying that bugs are found in production, and defects in testing, and then they handle defects differently.
Your question about "in or out of the sprint" is quite important though. In Agile, a new bug or defect simply gets raised and planned in the next sprint, like any other piece of work. If you don't take that approach, there is no way you can reliably plan anything and you might as well forget doing sprints. A more amiable approach is to over-estimate your stories, allowing a bit more time for "defects" to be created as sub-tasks on stories in the sprint and then dealt with as part of the story.
But, just as Bart says. It's up to you how you do it.
Try not to alter the content of a sprint once it has been created. So add bugs to a sprint beforehand.
And "when to create a bug?" My answer is: when you are surprised.
The difference between a feature and a bug is that you didn't expect the bug.
Hi there! Shannon from Statuspage here. 👋 With Cyber Monday quickly approaching, we're looking to hear from Atlassian customers – specifically from teams who touch incident response li...
Connect with like-minded Atlassian users at free events near you!Find a group
Connect with like-minded Atlassian users at free events near you!
Unfortunately there are no AUG chapters near you at the moment.Start an AUG
You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs