load-mocks 52 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297
  1. #!/usr/bin/env python
  2. import time
  3. from sentry.runner import configure
  4. from sentry.types.activity import ActivityType
  5. configure()
  6. import itertools
  7. import random
  8. from datetime import datetime, timedelta
  9. from hashlib import sha1
  10. from random import randint
  11. from uuid import uuid4
  12. from django.conf import settings
  13. from django.db import IntegrityError, transaction
  14. from django.db.models import F
  15. from django.utils import timezone
  16. from pytz import utc
  17. from sentry import buffer, roles, tsdb
  18. from sentry.event_manager import HashDiscarded
  19. from sentry.incidents.logic import create_alert_rule, create_alert_rule_trigger, create_incident
  20. from sentry.incidents.models import AlertRuleThresholdType, IncidentType
  21. from sentry.models import (
  22. TOMBSTONE_FIELDS_FROM_GROUP,
  23. Activity,
  24. Broadcast,
  25. Commit,
  26. CommitAuthor,
  27. CommitFileChange,
  28. Deploy,
  29. Environment,
  30. EventAttachment,
  31. File,
  32. Group,
  33. GroupRelease,
  34. GroupTombstone,
  35. Organization,
  36. OrganizationAccessRequest,
  37. OrganizationMember,
  38. Project,
  39. Release,
  40. ReleaseCommit,
  41. ReleaseEnvironment,
  42. ReleaseFile,
  43. ReleaseProjectEnvironment,
  44. Repository,
  45. Team,
  46. User,
  47. UserReport,
  48. )
  49. from sentry.monitors.models import (
  50. CheckInStatus,
  51. Monitor,
  52. MonitorCheckIn,
  53. MonitorEnvironment,
  54. MonitorStatus,
  55. MonitorType,
  56. )
  57. from sentry.signals import mocks_loaded
  58. from sentry.similarity import features
  59. from sentry.utils import loremipsum
  60. from sentry.utils.hashlib import md5_text
  61. from sentry.utils.samples import create_sample_event as _create_sample_event
  62. from sentry.utils.samples import create_trace, generate_user, random_normal
  63. PLATFORMS = itertools.cycle(["ruby", "php", "python", "java", "javascript"])
  64. LEVELS = itertools.cycle(["error", "error", "error", "fatal", "warning"])
  65. ENVIRONMENTS = itertools.cycle(["production", "production", "staging", "alpha", "beta", ""])
  66. MONITOR_NAMES = itertools.cycle(settings.CELERYBEAT_SCHEDULE.keys())
  67. MONITOR_SCHEDULES = itertools.cycle(["* * * * *", "0 * * * *", "0 0 * * *"])
  68. LONG_MESSAGE = """Code: 0.
  69. DB::Exception: String is too long for DateTime: 2018-10-26T19:14:18+00:00. Stack trace:
  70. 0. clickhouse-server(StackTrace::StackTrace()+0x16) [0x99e9626]
  71. 1. clickhouse-server(DB::Exception::Exception(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, int)+0x22) [0x3087172]
  72. 2. clickhouse-server(DB::FunctionComparison<DB::EqualsOp, DB::NameEquals>::executeDateOrDateTimeOrEnumOrUUIDWithConstString(DB::Block&, unsigned long, DB::IColumn const*, DB::IColumn const*, std::shared_ptr<DB::IDataType const> const&, std::shared_ptr<DB::IDataType const> const&, bool, unsigned long)+0x13c8) [0x3b233d8]
  73. 3. clickhouse-server(DB::FunctionComparison<DB::EqualsOp, DB::NameEquals>::executeImpl(DB::Block&, std::vector<unsigned long, std::allocator<unsigned long> > const&, unsigned long, unsigned long)+0x576) [0x3bafc86]
  74. 4. clickhouse-server(DB::PreparedFunctionImpl::defaultImplementationForNulls(DB::Block&, std::vector<unsigned long, std::allocator<unsigned long> > const&, unsigned long, unsigned long)+0x174) [0x7953cd4]
  75. 5. clickhouse-server(DB::PreparedFunctionImpl::executeWithoutLowCardinalityColumns(DB::Block&, std::vector<unsigned long, std::allocator<unsigned long> > const&, unsigned long, unsigned long)+0x54) [0x7953b04]
  76. 6. clickhouse-server(DB::PreparedFunctionImpl::execute(DB::Block&, std::vector<unsigned long, std::allocator<unsigned long> > const&, unsigned long, unsigned long)+0x3e2) [0x7954222]
  77. 7. clickhouse-server(DB::ExpressionAction::execute(DB::Block&, std::unordered_map<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, unsigned long, std::hash<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > >, std::equal_to<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > >, std::allocator<std::pair<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const, unsigned long> > >&) const+0x69b) [0x7b021fb]
  78. 8. clickhouse-server(DB::ExpressionActions::execute(DB::Block&) const+0xe6) [0x7b03676]
  79. 9. clickhouse-server(DB::FilterBlockInputStream::FilterBlockInputStream(std::shared_ptr<DB::IBlockInputStream> const&, std::shared_ptr<DB::ExpressionActions> const&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, bool)+0x711) [0x79b7e31]
  80. 10. clickhouse-server() [0x75e9443]
  81. 11. clickhouse-server(DB::InterpreterSelectQuery::executeImpl(DB::InterpreterSelectQuery::Pipeline&, std::shared_ptr<DB::IBlockInputStream> const&, bool)+0x118f) [0x75f212f]
  82. 12. clickhouse-server(DB::InterpreterSelectQuery::InterpreterSelectQuery(std::shared_ptr<DB::IAST> const&, DB::Context const&, std::shared_ptr<DB::IBlockInputStream> const&, std::shared_ptr<DB::IStorage> const&, std::vector<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::allocator<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > > > const&, DB::QueryProcessingStage::Enum, unsigned long, bool)+0x5e6) [0x75f2d46]
  83. 13. clickhouse-server(DB::InterpreterSelectQuery::InterpreterSelectQuery(std::shared_ptr<DB::IAST> const&, DB::Context const&, std::vector<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::allocator<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > > > const&, DB::QueryProcessingStage::Enum, unsigned long, bool)+0x56) [0x75f3aa6]
  84. 14. clickhouse-server(DB::InterpreterSelectWithUnionQuery::InterpreterSelectWithUnionQuery(std::shared_ptr<DB::IAST> const&, DB::Context const&, std::vector<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::allocator<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > > > const&, DB::QueryProcessingStage::Enum, unsigned long, bool)+0x7e7) [0x75ffab7]
  85. 15. clickhouse-server(DB::InterpreterFactory::get(std::shared_ptr<DB::IAST>&, DB::Context&, DB::QueryProcessingStage::Enum)+0x3a8) [0x75dc138]
  86. 16. clickhouse-server() [0x768fad9]
  87. 17. clickhouse-server(DB::executeQuery(std::__cxx11::basic..."""
  88. def make_sentence(words=None):
  89. if words is None:
  90. words = int(random.weibullvariate(8, 3))
  91. return " ".join(random.choice(loremipsum.words) for _ in range(words))
  92. def create_sample_event(*args, **kwargs):
  93. try:
  94. event = _create_sample_event(*args, **kwargs)
  95. except HashDiscarded as e:
  96. print(f"> Skipping Event: {e.message}") # NOQA
  97. else:
  98. if event is not None:
  99. features.record([event])
  100. return event
  101. def generate_commits(user):
  102. commits = []
  103. for i in range(random.randint(1, 20)):
  104. if i == 1:
  105. filename = "raven/base.py"
  106. else:
  107. filename = random.choice(loremipsum.words) + ".js"
  108. if random.randint(0, 5) == 1:
  109. author = (user.name, user.email)
  110. else:
  111. author = (
  112. f"{random.choice(loremipsum.words)} {random.choice(loremipsum.words)}",
  113. f"{random.choice(loremipsum.words)}@example.com",
  114. )
  115. commits.append(
  116. {
  117. "key": sha1(uuid4().bytes).hexdigest(),
  118. "message": f"feat: Do something to {filename}\n{make_sentence()}",
  119. "author": author,
  120. "files": [(filename, "M")],
  121. }
  122. )
  123. return commits
  124. def generate_tombstones(project, user):
  125. # attempt to create a high enough previous_group_id
  126. # that it won't conflict with any group ids
  127. prev_group_id = 100000
  128. try:
  129. prev_group_id = (
  130. max(
  131. GroupTombstone.objects.order_by("-previous_group_id")[0].previous_group_id,
  132. prev_group_id,
  133. )
  134. + 1
  135. )
  136. except IndexError:
  137. pass
  138. for group in Group.objects.filter(project=project)[:5]:
  139. GroupTombstone.objects.create(
  140. previous_group_id=prev_group_id,
  141. actor_id=user.id,
  142. **{name: getattr(group, name) for name in TOMBSTONE_FIELDS_FROM_GROUP},
  143. )
  144. prev_group_id += 1
  145. def create_system_time_series():
  146. now = datetime.utcnow().replace(tzinfo=utc)
  147. for _ in range(60):
  148. count = randint(1, 10)
  149. tsdb.incr_multi(
  150. (
  151. (tsdb.models.internal, "client-api.all-versions.responses.2xx"),
  152. (tsdb.models.internal, "client-api.all-versions.requests"),
  153. ),
  154. now,
  155. int(count * 0.9),
  156. )
  157. tsdb.incr_multi(
  158. ((tsdb.models.internal, "client-api.all-versions.responses.4xx"),),
  159. now,
  160. int(count * 0.05),
  161. )
  162. tsdb.incr_multi(
  163. ((tsdb.models.internal, "client-api.all-versions.responses.5xx"),),
  164. now,
  165. int(count * 0.1),
  166. )
  167. now = now - timedelta(seconds=1)
  168. for _ in range(24 * 30):
  169. count = randint(100, 1000)
  170. tsdb.incr_multi(
  171. (
  172. (tsdb.models.internal, "client-api.all-versions.responses.2xx"),
  173. (tsdb.models.internal, "client-api.all-versions.requests"),
  174. ),
  175. now,
  176. int(count * 4.9),
  177. )
  178. tsdb.incr_multi(
  179. ((tsdb.models.internal, "client-api.all-versions.responses.4xx"),),
  180. now,
  181. int(count * 0.05),
  182. )
  183. tsdb.incr_multi(
  184. ((tsdb.models.internal, "client-api.all-versions.responses.5xx"),),
  185. now,
  186. int(count * 0.1),
  187. )
  188. now = now - timedelta(hours=1)
  189. def create_sample_time_series(event, release=None):
  190. if event is None:
  191. return
  192. group = event.group
  193. project = group.project
  194. key = project.key_set.all()[0]
  195. now = datetime.utcnow().replace(tzinfo=utc)
  196. environment = Environment.get_or_create(
  197. project=project, name=Environment.get_name_or_default(event.get_tag("environment"))
  198. )
  199. if release:
  200. ReleaseEnvironment.get_or_create(
  201. project=project, release=release, environment=environment, datetime=now
  202. )
  203. grouprelease = GroupRelease.get_or_create(
  204. group=group, release=release, environment=environment, datetime=now
  205. )
  206. for _ in range(60):
  207. count = randint(1, 10)
  208. tsdb.incr_multi(
  209. ((tsdb.models.project, project.id), (tsdb.models.group, group.id)),
  210. now,
  211. count,
  212. environment_id=environment.id,
  213. )
  214. tsdb.incr_multi(
  215. (
  216. (tsdb.models.organization_total_received, project.organization_id),
  217. (tsdb.models.project_total_received, project.id),
  218. (tsdb.models.key_total_received, key.id),
  219. ),
  220. now,
  221. int(count * 1.1),
  222. )
  223. tsdb.incr(
  224. tsdb.models.project_total_forwarded,
  225. project.id,
  226. now,
  227. int(count * 1.1),
  228. )
  229. tsdb.incr_multi(
  230. (
  231. (tsdb.models.organization_total_rejected, project.organization_id),
  232. (tsdb.models.project_total_rejected, project.id),
  233. (tsdb.models.key_total_rejected, key.id),
  234. ),
  235. now,
  236. int(count * 0.1),
  237. )
  238. frequencies = [
  239. (tsdb.models.frequent_issues_by_project, {project.id: {group.id: count}}),
  240. (tsdb.models.frequent_environments_by_group, {group.id: {environment.id: count}}),
  241. ]
  242. if release:
  243. frequencies.append(
  244. (tsdb.models.frequent_releases_by_group, {group.id: {grouprelease.id: count}})
  245. )
  246. tsdb.record_frequency_multi(frequencies, now)
  247. now = now - timedelta(seconds=1)
  248. for _ in range(24 * 30):
  249. count = randint(100, 1000)
  250. tsdb.incr_multi(
  251. ((tsdb.models.project, group.project.id), (tsdb.models.group, group.id)),
  252. now,
  253. count,
  254. environment_id=environment.id,
  255. )
  256. tsdb.incr_multi(
  257. (
  258. (tsdb.models.organization_total_received, project.organization_id),
  259. (tsdb.models.project_total_received, project.id),
  260. (tsdb.models.key_total_received, key.id),
  261. ),
  262. now,
  263. int(count * 1.1),
  264. )
  265. tsdb.incr_multi(
  266. (
  267. (tsdb.models.organization_total_rejected, project.organization_id),
  268. (tsdb.models.project_total_rejected, project.id),
  269. (tsdb.models.key_total_rejected, key.id),
  270. ),
  271. now,
  272. int(count * 0.1),
  273. )
  274. frequencies = [
  275. (tsdb.models.frequent_issues_by_project, {project.id: {group.id: count}}),
  276. (tsdb.models.frequent_environments_by_group, {group.id: {environment.id: count}}),
  277. ]
  278. if release:
  279. frequencies.append(
  280. (tsdb.models.frequent_releases_by_group, {group.id: {grouprelease.id: count}})
  281. )
  282. tsdb.record_frequency_multi(frequencies, now)
  283. now = now - timedelta(hours=1)
  284. def main(
  285. skip_default_setup=False,
  286. num_events=1,
  287. extra_events=False,
  288. load_trends=False,
  289. load_performance_issues=False,
  290. slow=False,
  291. ):
  292. from sentry.constants import ObjectStatus
  293. try:
  294. user = User.objects.filter(is_superuser=True)[0]
  295. except IndexError:
  296. raise Exception("No superuser exists (run `make bootstrap`)")
  297. dummy_user, _ = User.objects.get_or_create(
  298. username="dummy@example.com", defaults={"email": "dummy@example.com"}
  299. )
  300. dummy_user.set_password("dummy")
  301. dummy_user.save()
  302. mocks = (
  303. ("Massive Dynamic", ("Ludic Science",)),
  304. ("Captain Planet", ("Earth", "Fire", "Wind", "Water", "Heart")),
  305. )
  306. project_map = {}
  307. Broadcast.objects.create(
  308. title="Learn about Source Maps",
  309. message="Source maps are JSON files that contain information on how to map your transpiled source code back to their original source.",
  310. link="https://docs.sentry.io/platforms/javascript/#source-maps",
  311. )
  312. if settings.SENTRY_SINGLE_ORGANIZATION:
  313. org = Organization.get_default()
  314. print(f"Mocking org {org.name}") # NOQA
  315. else:
  316. print("Mocking org {}".format("Default")) # NOQA
  317. org, _ = Organization.objects.get_or_create(slug="default")
  318. OrganizationMember.objects.get_or_create(
  319. user=user, organization=org, role=roles.get_top_dog().id
  320. )
  321. dummy_member, _ = OrganizationMember.objects.get_or_create(
  322. user=dummy_user, organization=org, defaults={"role": roles.get_default().id}
  323. )
  324. # Allow for 0 events, if you only want transactions
  325. event1 = event2 = event3 = event4 = event5 = None
  326. if skip_default_setup:
  327. # Quickly fetch/create the teams and projects
  328. for team_name, project_names in mocks:
  329. print(f"> Mocking team {team_name}") # NOQA
  330. team, _ = Team.objects.get_or_create(name=team_name, defaults={"organization": org})
  331. for project_name in project_names:
  332. print(f" > Mocking project {project_name}") # NOQA
  333. project, _ = Project.objects.get_or_create(
  334. name=project_name,
  335. defaults={
  336. "organization": org,
  337. "first_event": timezone.now(),
  338. "flags": Project.flags.has_releases,
  339. },
  340. )
  341. project_map[project_name] = project
  342. project.add_team(team)
  343. else:
  344. for team_name, project_names in mocks:
  345. print(f"> Mocking team {team_name}") # NOQA
  346. team, _ = Team.objects.get_or_create(name=team_name, defaults={"organization": org})
  347. for project_name in project_names:
  348. print(f" > Mocking project {project_name}") # NOQA
  349. project, _ = Project.objects.get_or_create(
  350. name=project_name,
  351. defaults={
  352. "organization": org,
  353. "first_event": timezone.now(),
  354. "flags": Project.flags.has_releases,
  355. },
  356. )
  357. project_map[project_name] = project
  358. project.add_team(team)
  359. if not project.first_event:
  360. project.update(first_event=project.date_added)
  361. if not project.flags.has_releases:
  362. project.update(flags=F("flags").bitor(Project.flags.has_releases))
  363. environment = Environment.get_or_create(project=project, name=next(ENVIRONMENTS))
  364. monitor, _ = Monitor.objects.get_or_create(
  365. name=next(MONITOR_NAMES),
  366. project_id=project.id,
  367. organization_id=org.id,
  368. type=MonitorType.CRON_JOB,
  369. defaults={
  370. "status": ObjectStatus.DISABLED,
  371. "config": {"schedule": next(MONITOR_SCHEDULES)},
  372. },
  373. )
  374. monitor_env, _ = MonitorEnvironment.objects.get_or_create(
  375. monitor=monitor,
  376. environment=environment,
  377. defaults={
  378. "status": MonitorStatus.DISABLED,
  379. "next_checkin": timezone.now() + timedelta(minutes=60),
  380. "last_checkin": timezone.now(),
  381. },
  382. )
  383. MonitorCheckIn.objects.create(
  384. project_id=monitor.project_id,
  385. monitor=monitor,
  386. monitor_environment=monitor_env,
  387. status=CheckInStatus.OK
  388. if monitor_env.status == MonitorStatus.OK
  389. else CheckInStatus.ERROR,
  390. )
  391. with transaction.atomic():
  392. has_release = Release.objects.filter(
  393. version=sha1(uuid4().bytes).hexdigest(),
  394. organization_id=project.organization_id,
  395. projects=project,
  396. ).exists()
  397. if not has_release:
  398. release = Release.objects.filter(
  399. version=sha1(uuid4().bytes).hexdigest(),
  400. organization_id=project.organization_id,
  401. ).first()
  402. if not release:
  403. release = Release.objects.create(
  404. version=sha1(uuid4().bytes).hexdigest(),
  405. organization_id=project.organization_id,
  406. )
  407. release.add_project(project)
  408. generate_tombstones(project, user)
  409. raw_commits = generate_commits(user)
  410. try:
  411. with transaction.atomic():
  412. repo, _ = Repository.objects.get_or_create(
  413. organization_id=org.id,
  414. provider="integrations:github",
  415. external_id="example/example",
  416. defaults={
  417. "name": "Example Repo",
  418. "url": "https://github.com/example/example",
  419. },
  420. )
  421. except IntegrityError:
  422. # for users with legacy github plugin
  423. # upgrade to the new integration
  424. repo = Repository.objects.get(
  425. organization_id=org.id,
  426. provider="github",
  427. external_id="example/example",
  428. name="Example Repo",
  429. )
  430. repo.provider = "integrations:github"
  431. repo.save()
  432. authors = set()
  433. for commit_index, raw_commit in enumerate(raw_commits):
  434. author = CommitAuthor.objects.get_or_create(
  435. organization_id=org.id,
  436. email=raw_commit["author"][1],
  437. defaults={"name": raw_commit["author"][0]},
  438. )[0]
  439. commit = Commit.objects.get_or_create(
  440. organization_id=org.id,
  441. repository_id=repo.id,
  442. key=raw_commit["key"],
  443. defaults={"author": author, "message": raw_commit["message"]},
  444. )[0]
  445. authors.add(author)
  446. for file in raw_commit["files"]:
  447. ReleaseFile.objects.get_or_create(
  448. organization_id=project.organization_id,
  449. release_id=release.id,
  450. name=file[0],
  451. file=File.objects.get_or_create(
  452. name=file[0], type="release.file", checksum="abcde" * 8, size=13043
  453. )[0],
  454. defaults={"organization_id": project.organization_id},
  455. )
  456. CommitFileChange.objects.get_or_create(
  457. organization_id=org.id, commit=commit, filename=file[0], type=file[1]
  458. )
  459. ReleaseCommit.objects.get_or_create(
  460. organization_id=org.id, release=release, commit=commit, order=commit_index
  461. )
  462. # create an unreleased commit
  463. Commit.objects.get_or_create(
  464. organization_id=org.id,
  465. repository_id=repo.id,
  466. key=sha1(uuid4().bytes).hexdigest(),
  467. defaults={
  468. "author": CommitAuthor.objects.get_or_create(
  469. organization_id=org.id, email=user.email, defaults={"name": user.name}
  470. )[0],
  471. "message": "feat: Do something to {}\n{}".format(
  472. random.choice(loremipsum.words) + ".js", make_sentence()
  473. ),
  474. },
  475. )[0]
  476. Activity.objects.create(
  477. type=ActivityType.RELEASE.value,
  478. project=project,
  479. ident=release.version,
  480. user_id=user.id,
  481. data={"version": release.version},
  482. )
  483. deploy = Deploy.objects.create(
  484. organization_id=project.organization_id,
  485. release=release,
  486. environment_id=environment.id,
  487. )
  488. release.update(
  489. commit_count=len(raw_commits),
  490. last_commit_id=commit.id,
  491. total_deploys=Deploy.objects.filter(release=release).count(),
  492. last_deploy_id=deploy.id,
  493. authors=[str(a.id) for a in authors],
  494. )
  495. ReleaseProjectEnvironment.objects.create_or_update(
  496. project=project,
  497. environment=environment,
  498. release=release,
  499. defaults={"last_deploy_id": deploy.id},
  500. )
  501. Activity.objects.create(
  502. type=ActivityType.DEPLOY.value,
  503. project=project,
  504. ident=release.version,
  505. data={
  506. "version": release.version,
  507. "deploy_id": deploy.id,
  508. "environment": environment.name,
  509. },
  510. datetime=deploy.date_finished,
  511. )
  512. # Add a bunch of additional dummy events to support pagination
  513. if extra_events:
  514. for _ in range(45):
  515. platform = next(PLATFORMS)
  516. create_sample_event(
  517. project=project,
  518. platform=platform,
  519. release=release.version,
  520. level=next(LEVELS),
  521. environment=next(ENVIRONMENTS),
  522. message="This is a mostly useless example %s exception" % platform,
  523. checksum=md5_text(platform + str(_)).hexdigest(),
  524. user=generate_user(),
  525. )
  526. for _ in range(num_events):
  527. event1 = create_sample_event(
  528. project=project,
  529. platform="python",
  530. release=release.version,
  531. environment=next(ENVIRONMENTS),
  532. user=generate_user(),
  533. )
  534. EventAttachment.objects.create(
  535. project_id=project.id,
  536. event_id=event1.event_id,
  537. name="example-logfile.txt",
  538. file_id=File.objects.get_or_create(
  539. name="example-logfile.txt",
  540. type="text/plain",
  541. checksum="abcde" * 8,
  542. size=13043,
  543. )[0].id,
  544. )
  545. event2 = create_sample_event(
  546. project=project,
  547. platform="javascript",
  548. release=release.version,
  549. environment=next(ENVIRONMENTS),
  550. sdk={"name": "raven-js", "version": "2.1.0"},
  551. user=generate_user(),
  552. )
  553. event3 = create_sample_event(project, "java")
  554. event4 = create_sample_event(
  555. project=project,
  556. platform="ruby",
  557. release=release.version,
  558. environment=next(ENVIRONMENTS),
  559. user=generate_user(),
  560. )
  561. event5 = create_sample_event(
  562. project=project,
  563. platform="cocoa",
  564. release=release.version,
  565. environment=next(ENVIRONMENTS),
  566. user=generate_user(),
  567. )
  568. create_sample_event(
  569. project=project,
  570. platform="php",
  571. release=release.version,
  572. environment=next(ENVIRONMENTS),
  573. message=LONG_MESSAGE,
  574. user=generate_user(),
  575. )
  576. create_sample_event(
  577. project=project,
  578. platform="cocoa",
  579. sample_name="react-native",
  580. release=release.version,
  581. environment=next(ENVIRONMENTS),
  582. user=generate_user(),
  583. )
  584. create_sample_event(
  585. project=project,
  586. platform="pii",
  587. release=release.version,
  588. environment=next(ENVIRONMENTS),
  589. user=generate_user(),
  590. )
  591. if event5:
  592. Commit.objects.get_or_create(
  593. organization_id=org.id,
  594. repository_id=repo.id,
  595. key=sha1(uuid4().bytes).hexdigest(),
  596. defaults={
  597. "author": CommitAuthor.objects.get_or_create(
  598. organization_id=org.id,
  599. email=user.email,
  600. defaults={"name": user.name},
  601. )[0],
  602. "message": f"Ooops!\nFixes {event5.group.qualified_short_id}",
  603. },
  604. )[0]
  605. create_sample_event(project=project, environment=next(ENVIRONMENTS), platform="csp")
  606. if event3:
  607. UserReport.objects.create(
  608. project_id=project.id,
  609. event_id=event3.event_id,
  610. group_id=event3.group.id,
  611. name="Jane Bloggs",
  612. email="jane@example.com",
  613. comments=make_sentence(),
  614. )
  615. # Metric alerts
  616. alert_rule = create_alert_rule(
  617. org,
  618. [project],
  619. "My Alert Rule",
  620. "level:error",
  621. "count()",
  622. 10,
  623. AlertRuleThresholdType.ABOVE,
  624. 1,
  625. )
  626. create_alert_rule_trigger(alert_rule, "critical", 10)
  627. create_incident(
  628. org,
  629. type_=IncidentType.DETECTED,
  630. title="My Incident",
  631. date_started=datetime.utcnow().replace(tzinfo=utc),
  632. alert_rule=alert_rule,
  633. projects=[project],
  634. )
  635. print(f" > Loading time series data") # NOQA
  636. if event1:
  637. create_sample_time_series(event1, release=release)
  638. if event2:
  639. create_sample_time_series(event2, release=release)
  640. if event3:
  641. create_sample_time_series(event3)
  642. if event4:
  643. create_sample_time_series(event4, release=release)
  644. if event5:
  645. create_sample_time_series(event5, release=release)
  646. if hasattr(buffer, "process_pending"):
  647. print(" > Processing pending buffers") # NOQA
  648. buffer.process_pending()
  649. mocks_loaded.send(project=project, sender=__name__)
  650. OrganizationAccessRequest.objects.create_or_update(member=dummy_member, team=team)
  651. create_mock_transactions(project_map, load_trends, load_performance_issues, slow)
  652. Activity.objects.create(
  653. type=ActivityType.RELEASE.value,
  654. project=project,
  655. ident="4f38b65c62c4565aa94bba391ff8946922a8eed4",
  656. user_id=user.id,
  657. data={"version": "4f38b65c62c4565aa94bba391ff8946922a8eed4"},
  658. )
  659. create_system_time_series()
  660. def create_mock_transactions(
  661. project_map, load_trends=False, load_performance_issues=False, slow=False
  662. ):
  663. backend_project = project_map["Earth"]
  664. frontend_project = project_map["Fire"]
  665. service_projects = [
  666. project_map["Wind"],
  667. project_map["Water"],
  668. project_map["Heart"],
  669. ]
  670. for project in project_map.values():
  671. if not project.flags.has_transactions:
  672. project.update(flags=F("flags").bitor(Project.flags.has_transactions))
  673. timestamp = timezone.now()
  674. print(f" > Loading a trace") # NOQA
  675. create_trace(
  676. slow,
  677. timestamp - timedelta(milliseconds=random_normal(4000, 250, 1000)),
  678. timestamp,
  679. generate_user(),
  680. uuid4().hex,
  681. None,
  682. {
  683. "project": frontend_project,
  684. "transaction": "/plants/:plantId/",
  685. "frontend": True,
  686. "errors": 1,
  687. "children": [
  688. {
  689. "project": backend_project,
  690. "transaction": "/api/plants/",
  691. "children": [
  692. {
  693. "project": service_projects[0],
  694. "transaction": "/products/all/",
  695. "children": [],
  696. },
  697. {
  698. "project": service_projects[1],
  699. "transaction": "/analytics/",
  700. "children": [],
  701. },
  702. {
  703. "project": service_projects[2],
  704. "transaction": "tasks.create_invoice",
  705. "children": [
  706. {
  707. "project": service_projects[2],
  708. "transaction": "tasks.process_invoice",
  709. "children": [
  710. {
  711. "project": service_projects[2],
  712. "transaction": "tasks.process_invoice",
  713. "children": [
  714. {
  715. "project": service_projects[2],
  716. "transaction": "tasks.process_invoice",
  717. "children": [
  718. {
  719. "project": service_projects[2],
  720. "transaction": "tasks.process_invoice",
  721. "children": [],
  722. },
  723. ],
  724. },
  725. ],
  726. },
  727. ],
  728. },
  729. ],
  730. },
  731. ],
  732. },
  733. ],
  734. },
  735. )
  736. if load_trends:
  737. print(f" > Loading trends data") # NOQA
  738. for day in range(14):
  739. for hour in range(24):
  740. timestamp = timezone.now() - timedelta(days=day, hours=hour)
  741. transaction_user = generate_user()
  742. trace_id = uuid4().hex
  743. frontend_span_id = uuid4().hex[:16]
  744. frontend_root_span_id = uuid4().hex[:16]
  745. frontend_duration = random_normal(2000 - 50 * day, 250, 1000)
  746. create_sample_event(
  747. project=frontend_project,
  748. platform="javascript-transaction",
  749. transaction="/trends/:frontend/",
  750. event_id=uuid4().hex,
  751. user=transaction_user,
  752. timestamp=timestamp,
  753. # start_timestamp decreases based on day so that there's a trend
  754. start_timestamp=timestamp - timedelta(milliseconds=frontend_duration),
  755. measurements={
  756. "fp": {"value": random_normal(1250 - 50 * day, 200, 500)},
  757. "fcp": {"value": random_normal(1250 - 50 * day, 200, 500)},
  758. "lcp": {"value": random_normal(2800 - 50 * day, 400, 2000)},
  759. "fid": {"value": random_normal(5 - 0.125 * day, 2, 1)},
  760. },
  761. # Root
  762. parent_span_id=None,
  763. span_id=frontend_root_span_id,
  764. trace=trace_id,
  765. spans=[
  766. {
  767. "same_process_as_parent": True,
  768. "op": "http",
  769. "description": "GET /api/plants/?all_plants=1",
  770. "data": {
  771. "duration": random_normal(
  772. 1 - 0.05 * day, 0.25, 0.01, frontend_duration / 1000
  773. ),
  774. "offset": 0.02,
  775. },
  776. "span_id": frontend_span_id,
  777. "trace_id": trace_id,
  778. }
  779. ],
  780. )
  781. # try to give clickhouse some breathing room
  782. if slow:
  783. time.sleep(0.05)
  784. backend_duration = random_normal(1500 + 50 * day, 250, 500)
  785. create_sample_event(
  786. project=backend_project,
  787. platform="transaction",
  788. transaction="/trends/backend/",
  789. event_id=uuid4().hex,
  790. user=transaction_user,
  791. timestamp=timestamp,
  792. start_timestamp=timestamp - timedelta(milliseconds=backend_duration),
  793. # match the trace from the javascript transaction
  794. trace=trace_id,
  795. parent_span_id=frontend_root_span_id,
  796. spans=[],
  797. )
  798. # try to give clickhouse some breathing room
  799. if slow:
  800. time.sleep(0.05)
  801. if load_performance_issues:
  802. def load_n_plus_one_issue():
  803. trace_id = uuid4().hex
  804. transaction_user = generate_user()
  805. frontend_root_span_id = uuid4().hex[:16]
  806. n_plus_one_db_current_offset = timestamp
  807. n_plus_one_db_duration = timedelta(milliseconds=100)
  808. parent_span_id = uuid4().hex[:16]
  809. source_span = {
  810. "timestamp": (timestamp + n_plus_one_db_duration).timestamp(),
  811. "start_timestamp": (timestamp + timedelta(milliseconds=10)).timestamp(),
  812. "description": "SELECT `books_book`.`id`, `books_book`.`title`, `books_book`.`author_id` FROM `books_book` ORDER BY `books_book`.`id` DESC LIMIT 10",
  813. "op": "db",
  814. "parent_span_id": parent_span_id,
  815. "span_id": uuid4().hex[:16],
  816. "hash": "858fea692d4d93e8",
  817. }
  818. def make_repeating_span(duration):
  819. nonlocal timestamp
  820. nonlocal n_plus_one_db_current_offset
  821. nonlocal n_plus_one_db_duration
  822. n_plus_one_db_duration += timedelta(milliseconds=duration) + timedelta(
  823. milliseconds=1
  824. )
  825. n_plus_one_db_current_offset = timestamp + n_plus_one_db_duration
  826. return {
  827. "timestamp": (
  828. n_plus_one_db_current_offset + timedelta(milliseconds=duration)
  829. ).timestamp(),
  830. "start_timestamp": (
  831. n_plus_one_db_current_offset + timedelta(milliseconds=1)
  832. ).timestamp(),
  833. "description": "SELECT `books_author`.`id`, `books_author`.`name` FROM `books_author` WHERE `books_author`.`id` = %s LIMIT 21",
  834. "op": "db",
  835. "span_id": uuid4().hex[:16],
  836. "parent_span_id": parent_span_id,
  837. "hash": "63f1e89e6a073441",
  838. }
  839. repeating_spans = [make_repeating_span(200) for _ in range(10)]
  840. parent_span = {
  841. "timestamp": (
  842. timestamp + n_plus_one_db_duration + timedelta(milliseconds=200)
  843. ).timestamp(),
  844. "start_timestamp": timestamp.timestamp(),
  845. "description": "new",
  846. "op": "django.view",
  847. "parent_span_id": uuid4().hex[:16],
  848. "span_id": parent_span_id,
  849. "hash": "0f43fb6f6e01ca52",
  850. }
  851. create_sample_event(
  852. project=backend_project,
  853. platform="transaction",
  854. transaction="/n_plus_one_db/backend/",
  855. event_id=uuid4().hex,
  856. user=transaction_user,
  857. timestamp=timestamp + n_plus_one_db_duration + timedelta(milliseconds=300),
  858. start_timestamp=timestamp,
  859. trace=trace_id,
  860. parent_span_id=frontend_root_span_id,
  861. spans=[
  862. parent_span,
  863. source_span,
  864. ]
  865. + repeating_spans,
  866. )
  867. time.sleep(1.0)
  868. create_sample_event(
  869. project=backend_project,
  870. platform="transaction",
  871. transaction="/file-io-main-thread/",
  872. event_id=uuid4().hex,
  873. user=transaction_user,
  874. timestamp=timestamp + timedelta(milliseconds=300),
  875. start_timestamp=timestamp,
  876. trace=trace_id,
  877. parent_span_id=frontend_root_span_id,
  878. spans=[
  879. parent_span,
  880. {
  881. "timestamp": (timestamp + timedelta(milliseconds=200)).timestamp(),
  882. "start_timestamp": timestamp.timestamp(),
  883. "description": "1669031858711_file.txt (4.0 kB)",
  884. "op": "file.write",
  885. "span_id": uuid4().hex[:16],
  886. "parent_span_id": parent_span_id,
  887. "status": "ok",
  888. "data": {
  889. "blocked_ui_thread": True,
  890. "call_stack": [
  891. {
  892. "function": "onClick",
  893. "in_app": True,
  894. "lineno": 2,
  895. "module": "io.sentry.samples.android.MainActivity$$ExternalSyntheticLambda6",
  896. "native": False,
  897. },
  898. {
  899. "filename": "MainActivity.java",
  900. "function": "lambda$onCreate$5$io-sentry-samples-android-MainActivity",
  901. "in_app": True,
  902. "lineno": 93,
  903. "module": "io.sentry.samples.android.MainActivity",
  904. "native": False,
  905. },
  906. ],
  907. "file.path": "/data/user/0/io.sentry.samples.android/files/1669031858711_file.txt",
  908. "file.size": 4010,
  909. },
  910. },
  911. ],
  912. )
  913. def load_uncompressed_asset_issue():
  914. time.sleep(1.0)
  915. transaction_user = generate_user()
  916. trace_id = uuid4().hex
  917. parent_span_id = uuid4().hex[:16]
  918. parent_span = {
  919. "timestamp": (timestamp + timedelta(milliseconds=300)).timestamp(),
  920. "start_timestamp": timestamp.timestamp(),
  921. "description": "new",
  922. "op": "pageload",
  923. "parent_span_id": uuid4().hex[:16],
  924. "span_id": parent_span_id,
  925. "hash": "0f43fb6f6e01ca52",
  926. }
  927. spans = [
  928. {
  929. "timestamp": (timestamp + timedelta(milliseconds=1000)).timestamp(),
  930. "start_timestamp": (timestamp + timedelta(milliseconds=300)).timestamp(),
  931. "description": "https://s1.sentry-cdn.com/_static/dist/sentry/entrypoints/app.js",
  932. "op": "resource.script",
  933. "parent_span_id": parent_span_id,
  934. "span_id": uuid4().hex[:16],
  935. "hash": "858fea692d4d93e9",
  936. "data": {
  937. "http.transfer_size": 1_000_000,
  938. "http.response_content_length": 1_000_000,
  939. "http.decoded_response_content_length": 1_000_000,
  940. },
  941. },
  942. ]
  943. create_sample_event(
  944. project=backend_project,
  945. platform="transaction",
  946. transaction="/uncompressed-asset/",
  947. event_id=uuid4().hex,
  948. user=transaction_user,
  949. timestamp=timestamp + timedelta(milliseconds=300),
  950. start_timestamp=timestamp,
  951. trace=trace_id,
  952. parent_span_id=parent_span_id,
  953. spans=[parent_span] + spans,
  954. )
  955. def load_consecutive_db_issue():
  956. time.sleep(1.0)
  957. transaction_user = generate_user()
  958. trace_id = uuid4().hex
  959. parent_span_id = uuid4().hex[:16]
  960. parent_span = {
  961. "timestamp": (timestamp + timedelta(milliseconds=300)).timestamp(),
  962. "start_timestamp": timestamp.timestamp(),
  963. "description": "new",
  964. "op": "django.view",
  965. "parent_span_id": uuid4().hex[:16],
  966. "span_id": parent_span_id,
  967. "hash": "0f43fb6f6e01ca52",
  968. }
  969. spans = [
  970. {
  971. "timestamp": (timestamp + timedelta(milliseconds=1000)).timestamp(),
  972. "start_timestamp": (timestamp + timedelta(milliseconds=300)).timestamp(),
  973. "description": "SELECT `customer`.`id` FROM `customers` WHERE `customer`.`name` = 'customerName'",
  974. "op": "db",
  975. "parent_span_id": parent_span_id,
  976. "span_id": uuid4().hex[:16],
  977. "hash": "858fea692d4d93e9",
  978. },
  979. {
  980. "timestamp": (timestamp + timedelta(milliseconds=2000)).timestamp(),
  981. "start_timestamp": (timestamp + timedelta(milliseconds=1000)).timestamp(),
  982. "description": "SELECT COUNT(*) FROM `customers`",
  983. "op": "db",
  984. "parent_span_id": parent_span_id,
  985. "span_id": uuid4().hex[:16],
  986. "hash": "858fea692d4d93e7",
  987. },
  988. {
  989. "timestamp": (timestamp + timedelta(milliseconds=3000)).timestamp(),
  990. "start_timestamp": (timestamp + timedelta(milliseconds=2000)).timestamp(),
  991. "description": "SELECT COUNT(*) FROM `items`",
  992. "op": "db",
  993. "parent_span_id": parent_span_id,
  994. "span_id": uuid4().hex[:16],
  995. "hash": "858fea692d4d93e6",
  996. },
  997. ]
  998. create_sample_event(
  999. project=backend_project,
  1000. platform="transaction",
  1001. transaction="/consecutive-db/",
  1002. event_id=uuid4().hex,
  1003. user=transaction_user,
  1004. timestamp=timestamp + timedelta(milliseconds=300),
  1005. start_timestamp=timestamp,
  1006. trace=trace_id,
  1007. parent_span_id=parent_span_id,
  1008. spans=[parent_span] + spans,
  1009. )
  1010. def load_render_blocking_asset_issue():
  1011. transaction_user = generate_user()
  1012. trace_id = uuid4().hex
  1013. parent_span_id = uuid4().hex[:16]
  1014. spans = [
  1015. {
  1016. "timestamp": (timestamp + timedelta(milliseconds=1300)).timestamp(),
  1017. "start_timestamp": (timestamp + timedelta(milliseconds=300)).timestamp(),
  1018. "description": "https://example.com/asset.js",
  1019. "op": "resource.script",
  1020. "parent_span_id": parent_span_id,
  1021. "span_id": uuid4().hex[:16],
  1022. "hash": "858fea692d4d93e8",
  1023. "data": {"http.response_content_length": 1000001},
  1024. }
  1025. ]
  1026. create_sample_event(
  1027. project=frontend_project,
  1028. platform="transaction",
  1029. transaction="/render-blocking-asset/",
  1030. event_id=uuid4().hex,
  1031. user=transaction_user,
  1032. timestamp=timestamp + timedelta(milliseconds=300),
  1033. start_timestamp=timestamp,
  1034. trace=trace_id,
  1035. parent_span_id=parent_span_id,
  1036. spans=spans,
  1037. measurements={
  1038. "fcp": {"value": 2500.0},
  1039. },
  1040. )
  1041. def load_m_n_plus_one_issue():
  1042. trace_id = uuid4().hex
  1043. transaction_user = generate_user()
  1044. parent_span_id = uuid4().hex[:16]
  1045. duration = 200
  1046. def make_repeating_span(i):
  1047. nonlocal timestamp
  1048. nonlocal duration
  1049. start_timestamp = timestamp + timedelta(milliseconds=i * (duration + 1))
  1050. end_timestamp = start_timestamp + timedelta(milliseconds=duration)
  1051. op = "http" if i % 2 == 0 else "db"
  1052. description = "GET /" if i % 2 == 0 else "SELECT * FROM authors WHERE id = %s"
  1053. hash = "63f1e89e6a073441" if i % 2 == 0 else "a109ff3ef40f7fb3"
  1054. return {
  1055. "timestamp": end_timestamp.timestamp(),
  1056. "start_timestamp": start_timestamp.timestamp(),
  1057. "description": description,
  1058. "op": op,
  1059. "span_id": uuid4().hex[:16],
  1060. "parent_span_id": parent_span_id,
  1061. "hash": hash,
  1062. }
  1063. span_count = 10
  1064. repeating_spans = [make_repeating_span(i) for i in range(span_count)]
  1065. parent_span = {
  1066. "timestamp": (
  1067. timestamp + timedelta(milliseconds=span_count * (duration + 1))
  1068. ).timestamp(),
  1069. "start_timestamp": timestamp.timestamp(),
  1070. "description": "execute",
  1071. "op": "graphql.execute",
  1072. "parent_span_id": uuid4().hex[:16],
  1073. "span_id": parent_span_id,
  1074. "hash": "0f43fb6f6e01ca52",
  1075. }
  1076. create_sample_event(
  1077. project=backend_project,
  1078. platform="transaction",
  1079. transaction="/m_n_plus_one_db/backend/",
  1080. event_id=uuid4().hex,
  1081. user=transaction_user,
  1082. timestamp=timestamp + timedelta(milliseconds=span_count * (duration + 1) + 100),
  1083. start_timestamp=timestamp,
  1084. trace=trace_id,
  1085. spans=[parent_span] + repeating_spans,
  1086. )
  1087. def load_performance_issues():
  1088. print(f" > Loading performance issues data") # NOQA
  1089. print(f" > Loading n plus one issue") # NOQA
  1090. load_n_plus_one_issue()
  1091. print(f" > Loading consecutive db issue") # NOQA
  1092. load_consecutive_db_issue()
  1093. print(f" > Loading uncompressed asset issue") # NOQA
  1094. load_uncompressed_asset_issue()
  1095. print(f" > Loading render blocking asset issue") # NOQA
  1096. load_render_blocking_asset_issue()
  1097. print(f" > Loading MN+1 issue") # NOQA
  1098. load_m_n_plus_one_issue()
  1099. load_performance_issues()
  1100. if __name__ == "__main__":
  1101. settings.CELERY_ALWAYS_EAGER = True
  1102. from optparse import OptionParser
  1103. parser = OptionParser()
  1104. parser.add_option("--events", default=1, type=int, help="number of events to generate")
  1105. parser.add_option(
  1106. "--skip-default-setup",
  1107. default=False,
  1108. action="store_true",
  1109. help="Skips creating the default project, teams and timeseries, useful when only loading specific transactions",
  1110. )
  1111. parser.add_option(
  1112. "--extra-events",
  1113. default=False,
  1114. action="store_true",
  1115. help="add multiple events for each error group",
  1116. )
  1117. parser.add_option(
  1118. "--load-trends",
  1119. default=False,
  1120. action="store_true",
  1121. help="load multiple transactions for each id to show trends",
  1122. )
  1123. parser.add_option(
  1124. "--load-performance-issues",
  1125. default=False,
  1126. action="store_true",
  1127. help="load transactions with performance issues, still needs options/flags on for issues to appear.",
  1128. )
  1129. parser.add_option(
  1130. "--slow",
  1131. default=False,
  1132. action="store_true",
  1133. help="sleep between each transaction to let clickhouse rest",
  1134. )
  1135. (options, args) = parser.parse_args()
  1136. try:
  1137. main(
  1138. skip_default_setup=options.skip_default_setup,
  1139. num_events=options.events,
  1140. extra_events=options.extra_events,
  1141. load_trends=options.load_trends,
  1142. load_performance_issues=options.load_performance_issues,
  1143. slow=options.slow,
  1144. )
  1145. from sentry.issues.producer import get_occurrence_producer
  1146. get_occurrence_producer().close()
  1147. except Exception:
  1148. # Avoid reporting any issues recursively back into Sentry
  1149. import sys
  1150. import traceback
  1151. traceback.print_exc()
  1152. sys.exit(1)