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. try:
  293. user = User.objects.filter(is_superuser=True)[0]
  294. except IndexError:
  295. raise Exception("No superuser exists (run `make bootstrap`)")
  296. dummy_user, _ = User.objects.get_or_create(
  297. username="dummy@example.com", defaults={"email": "dummy@example.com"}
  298. )
  299. dummy_user.set_password("dummy")
  300. dummy_user.save()
  301. mocks = (
  302. ("Massive Dynamic", ("Ludic Science",)),
  303. ("Captain Planet", ("Earth", "Fire", "Wind", "Water", "Heart")),
  304. )
  305. project_map = {}
  306. Broadcast.objects.create(
  307. title="Learn about Source Maps",
  308. message="Source maps are JSON files that contain information on how to map your transpiled source code back to their original source.",
  309. link="https://docs.sentry.io/platforms/javascript/#source-maps",
  310. )
  311. if settings.SENTRY_SINGLE_ORGANIZATION:
  312. org = Organization.get_default()
  313. print(f"Mocking org {org.name}") # NOQA
  314. else:
  315. print("Mocking org {}".format("Default")) # NOQA
  316. org, _ = Organization.objects.get_or_create(slug="default")
  317. OrganizationMember.objects.get_or_create(
  318. user=user, organization=org, role=roles.get_top_dog().id
  319. )
  320. dummy_member, _ = OrganizationMember.objects.get_or_create(
  321. user=dummy_user, organization=org, defaults={"role": roles.get_default().id}
  322. )
  323. # Allow for 0 events, if you only want transactions
  324. event1 = event2 = event3 = event4 = event5 = None
  325. if skip_default_setup:
  326. # Quickly fetch/create the teams and projects
  327. for team_name, project_names in mocks:
  328. print(f"> Mocking team {team_name}") # NOQA
  329. team, _ = Team.objects.get_or_create(name=team_name, defaults={"organization": org})
  330. for project_name in project_names:
  331. print(f" > Mocking project {project_name}") # NOQA
  332. project, _ = Project.objects.get_or_create(
  333. name=project_name,
  334. defaults={
  335. "organization": org,
  336. "first_event": timezone.now(),
  337. "flags": Project.flags.has_releases,
  338. },
  339. )
  340. project_map[project_name] = project
  341. project.add_team(team)
  342. else:
  343. for team_name, project_names in mocks:
  344. print(f"> Mocking team {team_name}") # NOQA
  345. team, _ = Team.objects.get_or_create(name=team_name, defaults={"organization": org})
  346. for project_name in project_names:
  347. print(f" > Mocking project {project_name}") # NOQA
  348. project, _ = Project.objects.get_or_create(
  349. name=project_name,
  350. defaults={
  351. "organization": org,
  352. "first_event": timezone.now(),
  353. "flags": Project.flags.has_releases,
  354. },
  355. )
  356. project_map[project_name] = project
  357. project.add_team(team)
  358. if not project.first_event:
  359. project.update(first_event=project.date_added)
  360. if not project.flags.has_releases:
  361. project.update(flags=F("flags").bitor(Project.flags.has_releases))
  362. environment = Environment.get_or_create(project=project, name=next(ENVIRONMENTS))
  363. monitor, _ = Monitor.objects.get_or_create(
  364. name=next(MONITOR_NAMES),
  365. project_id=project.id,
  366. organization_id=org.id,
  367. type=MonitorType.CRON_JOB,
  368. defaults={
  369. "status": MonitorStatus.DISABLED,
  370. "config": {"schedule": next(MONITOR_SCHEDULES)},
  371. "next_checkin": timezone.now() + timedelta(minutes=60),
  372. "last_checkin": timezone.now(),
  373. },
  374. )
  375. monitor_env, _ = MonitorEnvironment.objects.get_or_create(
  376. monitor=monitor,
  377. environment=environment,
  378. defaults={
  379. "status": MonitorStatus.DISABLED,
  380. "next_checkin": timezone.now() + timedelta(minutes=60),
  381. "last_checkin": timezone.now(),
  382. },
  383. )
  384. MonitorCheckIn.objects.create(
  385. project_id=monitor.project_id,
  386. monitor=monitor,
  387. monitor_environment=monitor_env,
  388. status=CheckInStatus.OK
  389. if monitor.status == MonitorStatus.OK
  390. else CheckInStatus.ERROR,
  391. )
  392. with transaction.atomic():
  393. has_release = Release.objects.filter(
  394. version=sha1(uuid4().bytes).hexdigest(),
  395. organization_id=project.organization_id,
  396. projects=project,
  397. ).exists()
  398. if not has_release:
  399. release = Release.objects.filter(
  400. version=sha1(uuid4().bytes).hexdigest(),
  401. organization_id=project.organization_id,
  402. ).first()
  403. if not release:
  404. release = Release.objects.create(
  405. version=sha1(uuid4().bytes).hexdigest(),
  406. organization_id=project.organization_id,
  407. )
  408. release.add_project(project)
  409. generate_tombstones(project, user)
  410. raw_commits = generate_commits(user)
  411. try:
  412. with transaction.atomic():
  413. repo, _ = Repository.objects.get_or_create(
  414. organization_id=org.id,
  415. provider="integrations:github",
  416. external_id="example/example",
  417. defaults={
  418. "name": "Example Repo",
  419. "url": "https://github.com/example/example",
  420. },
  421. )
  422. except IntegrityError:
  423. # for users with legacy github plugin
  424. # upgrade to the new integration
  425. repo = Repository.objects.get(
  426. organization_id=org.id,
  427. provider="github",
  428. external_id="example/example",
  429. name="Example Repo",
  430. )
  431. repo.provider = "integrations:github"
  432. repo.save()
  433. authors = set()
  434. for commit_index, raw_commit in enumerate(raw_commits):
  435. author = CommitAuthor.objects.get_or_create(
  436. organization_id=org.id,
  437. email=raw_commit["author"][1],
  438. defaults={"name": raw_commit["author"][0]},
  439. )[0]
  440. commit = Commit.objects.get_or_create(
  441. organization_id=org.id,
  442. repository_id=repo.id,
  443. key=raw_commit["key"],
  444. defaults={"author": author, "message": raw_commit["message"]},
  445. )[0]
  446. authors.add(author)
  447. for file in raw_commit["files"]:
  448. ReleaseFile.objects.get_or_create(
  449. organization_id=project.organization_id,
  450. release_id=release.id,
  451. name=file[0],
  452. file=File.objects.get_or_create(
  453. name=file[0], type="release.file", checksum="abcde" * 8, size=13043
  454. )[0],
  455. defaults={"organization_id": project.organization_id},
  456. )
  457. CommitFileChange.objects.get_or_create(
  458. organization_id=org.id, commit=commit, filename=file[0], type=file[1]
  459. )
  460. ReleaseCommit.objects.get_or_create(
  461. organization_id=org.id, release=release, commit=commit, order=commit_index
  462. )
  463. # create an unreleased commit
  464. Commit.objects.get_or_create(
  465. organization_id=org.id,
  466. repository_id=repo.id,
  467. key=sha1(uuid4().bytes).hexdigest(),
  468. defaults={
  469. "author": CommitAuthor.objects.get_or_create(
  470. organization_id=org.id, email=user.email, defaults={"name": user.name}
  471. )[0],
  472. "message": "feat: Do something to {}\n{}".format(
  473. random.choice(loremipsum.words) + ".js", make_sentence()
  474. ),
  475. },
  476. )[0]
  477. Activity.objects.create(
  478. type=ActivityType.RELEASE.value,
  479. project=project,
  480. ident=release.version,
  481. user_id=user.id,
  482. data={"version": release.version},
  483. )
  484. deploy = Deploy.objects.create(
  485. organization_id=project.organization_id,
  486. release=release,
  487. environment_id=environment.id,
  488. )
  489. release.update(
  490. commit_count=len(raw_commits),
  491. last_commit_id=commit.id,
  492. total_deploys=Deploy.objects.filter(release=release).count(),
  493. last_deploy_id=deploy.id,
  494. authors=[str(a.id) for a in authors],
  495. )
  496. ReleaseProjectEnvironment.objects.create_or_update(
  497. project=project,
  498. environment=environment,
  499. release=release,
  500. defaults={"last_deploy_id": deploy.id},
  501. )
  502. Activity.objects.create(
  503. type=ActivityType.DEPLOY.value,
  504. project=project,
  505. ident=release.version,
  506. data={
  507. "version": release.version,
  508. "deploy_id": deploy.id,
  509. "environment": environment.name,
  510. },
  511. datetime=deploy.date_finished,
  512. )
  513. # Add a bunch of additional dummy events to support pagination
  514. if extra_events:
  515. for _ in range(45):
  516. platform = next(PLATFORMS)
  517. create_sample_event(
  518. project=project,
  519. platform=platform,
  520. release=release.version,
  521. level=next(LEVELS),
  522. environment=next(ENVIRONMENTS),
  523. message="This is a mostly useless example %s exception" % platform,
  524. checksum=md5_text(platform + str(_)).hexdigest(),
  525. user=generate_user(),
  526. )
  527. for _ in range(num_events):
  528. event1 = create_sample_event(
  529. project=project,
  530. platform="python",
  531. release=release.version,
  532. environment=next(ENVIRONMENTS),
  533. user=generate_user(),
  534. )
  535. EventAttachment.objects.create(
  536. project_id=project.id,
  537. event_id=event1.event_id,
  538. name="example-logfile.txt",
  539. file_id=File.objects.get_or_create(
  540. name="example-logfile.txt",
  541. type="text/plain",
  542. checksum="abcde" * 8,
  543. size=13043,
  544. )[0].id,
  545. )
  546. event2 = create_sample_event(
  547. project=project,
  548. platform="javascript",
  549. release=release.version,
  550. environment=next(ENVIRONMENTS),
  551. sdk={"name": "raven-js", "version": "2.1.0"},
  552. user=generate_user(),
  553. )
  554. event3 = create_sample_event(project, "java")
  555. event4 = create_sample_event(
  556. project=project,
  557. platform="ruby",
  558. release=release.version,
  559. environment=next(ENVIRONMENTS),
  560. user=generate_user(),
  561. )
  562. event5 = create_sample_event(
  563. project=project,
  564. platform="cocoa",
  565. release=release.version,
  566. environment=next(ENVIRONMENTS),
  567. user=generate_user(),
  568. )
  569. create_sample_event(
  570. project=project,
  571. platform="php",
  572. release=release.version,
  573. environment=next(ENVIRONMENTS),
  574. message=LONG_MESSAGE,
  575. user=generate_user(),
  576. )
  577. create_sample_event(
  578. project=project,
  579. platform="cocoa",
  580. sample_name="react-native",
  581. release=release.version,
  582. environment=next(ENVIRONMENTS),
  583. user=generate_user(),
  584. )
  585. create_sample_event(
  586. project=project,
  587. platform="pii",
  588. release=release.version,
  589. environment=next(ENVIRONMENTS),
  590. user=generate_user(),
  591. )
  592. if event5:
  593. Commit.objects.get_or_create(
  594. organization_id=org.id,
  595. repository_id=repo.id,
  596. key=sha1(uuid4().bytes).hexdigest(),
  597. defaults={
  598. "author": CommitAuthor.objects.get_or_create(
  599. organization_id=org.id,
  600. email=user.email,
  601. defaults={"name": user.name},
  602. )[0],
  603. "message": f"Ooops!\nFixes {event5.group.qualified_short_id}",
  604. },
  605. )[0]
  606. create_sample_event(project=project, environment=next(ENVIRONMENTS), platform="csp")
  607. if event3:
  608. UserReport.objects.create(
  609. project_id=project.id,
  610. event_id=event3.event_id,
  611. group_id=event3.group.id,
  612. name="Jane Bloggs",
  613. email="jane@example.com",
  614. comments=make_sentence(),
  615. )
  616. # Metric alerts
  617. alert_rule = create_alert_rule(
  618. org,
  619. [project],
  620. "My Alert Rule",
  621. "level:error",
  622. "count()",
  623. 10,
  624. AlertRuleThresholdType.ABOVE,
  625. 1,
  626. )
  627. create_alert_rule_trigger(alert_rule, "critical", 10)
  628. create_incident(
  629. org,
  630. type_=IncidentType.DETECTED,
  631. title="My Incident",
  632. date_started=datetime.utcnow().replace(tzinfo=utc),
  633. alert_rule=alert_rule,
  634. projects=[project],
  635. )
  636. print(f" > Loading time series data") # NOQA
  637. if event1:
  638. create_sample_time_series(event1, release=release)
  639. if event2:
  640. create_sample_time_series(event2, release=release)
  641. if event3:
  642. create_sample_time_series(event3)
  643. if event4:
  644. create_sample_time_series(event4, release=release)
  645. if event5:
  646. create_sample_time_series(event5, release=release)
  647. if hasattr(buffer, "process_pending"):
  648. print(" > Processing pending buffers") # NOQA
  649. buffer.process_pending()
  650. mocks_loaded.send(project=project, sender=__name__)
  651. OrganizationAccessRequest.objects.create_or_update(member=dummy_member, team=team)
  652. create_mock_transactions(project_map, load_trends, load_performance_issues, slow)
  653. Activity.objects.create(
  654. type=ActivityType.RELEASE.value,
  655. project=project,
  656. ident="4f38b65c62c4565aa94bba391ff8946922a8eed4",
  657. user_id=user.id,
  658. data={"version": "4f38b65c62c4565aa94bba391ff8946922a8eed4"},
  659. )
  660. create_system_time_series()
  661. def create_mock_transactions(
  662. project_map, load_trends=False, load_performance_issues=False, slow=False
  663. ):
  664. backend_project = project_map["Earth"]
  665. frontend_project = project_map["Fire"]
  666. service_projects = [
  667. project_map["Wind"],
  668. project_map["Water"],
  669. project_map["Heart"],
  670. ]
  671. for project in project_map.values():
  672. if not project.flags.has_transactions:
  673. project.update(flags=F("flags").bitor(Project.flags.has_transactions))
  674. timestamp = timezone.now()
  675. print(f" > Loading a trace") # NOQA
  676. create_trace(
  677. slow,
  678. timestamp - timedelta(milliseconds=random_normal(4000, 250, 1000)),
  679. timestamp,
  680. generate_user(),
  681. uuid4().hex,
  682. None,
  683. {
  684. "project": frontend_project,
  685. "transaction": "/plants/:plantId/",
  686. "frontend": True,
  687. "errors": 1,
  688. "children": [
  689. {
  690. "project": backend_project,
  691. "transaction": "/api/plants/",
  692. "children": [
  693. {
  694. "project": service_projects[0],
  695. "transaction": "/products/all/",
  696. "children": [],
  697. },
  698. {
  699. "project": service_projects[1],
  700. "transaction": "/analytics/",
  701. "children": [],
  702. },
  703. {
  704. "project": service_projects[2],
  705. "transaction": "tasks.create_invoice",
  706. "children": [
  707. {
  708. "project": service_projects[2],
  709. "transaction": "tasks.process_invoice",
  710. "children": [
  711. {
  712. "project": service_projects[2],
  713. "transaction": "tasks.process_invoice",
  714. "children": [
  715. {
  716. "project": service_projects[2],
  717. "transaction": "tasks.process_invoice",
  718. "children": [
  719. {
  720. "project": service_projects[2],
  721. "transaction": "tasks.process_invoice",
  722. "children": [],
  723. },
  724. ],
  725. },
  726. ],
  727. },
  728. ],
  729. },
  730. ],
  731. },
  732. ],
  733. },
  734. ],
  735. },
  736. )
  737. if load_trends:
  738. print(f" > Loading trends data") # NOQA
  739. for day in range(14):
  740. for hour in range(24):
  741. timestamp = timezone.now() - timedelta(days=day, hours=hour)
  742. transaction_user = generate_user()
  743. trace_id = uuid4().hex
  744. frontend_span_id = uuid4().hex[:16]
  745. frontend_root_span_id = uuid4().hex[:16]
  746. frontend_duration = random_normal(2000 - 50 * day, 250, 1000)
  747. create_sample_event(
  748. project=frontend_project,
  749. platform="javascript-transaction",
  750. transaction="/trends/:frontend/",
  751. event_id=uuid4().hex,
  752. user=transaction_user,
  753. timestamp=timestamp,
  754. # start_timestamp decreases based on day so that there's a trend
  755. start_timestamp=timestamp - timedelta(milliseconds=frontend_duration),
  756. measurements={
  757. "fp": {"value": random_normal(1250 - 50 * day, 200, 500)},
  758. "fcp": {"value": random_normal(1250 - 50 * day, 200, 500)},
  759. "lcp": {"value": random_normal(2800 - 50 * day, 400, 2000)},
  760. "fid": {"value": random_normal(5 - 0.125 * day, 2, 1)},
  761. },
  762. # Root
  763. parent_span_id=None,
  764. span_id=frontend_root_span_id,
  765. trace=trace_id,
  766. spans=[
  767. {
  768. "same_process_as_parent": True,
  769. "op": "http",
  770. "description": "GET /api/plants/?all_plants=1",
  771. "data": {
  772. "duration": random_normal(
  773. 1 - 0.05 * day, 0.25, 0.01, frontend_duration / 1000
  774. ),
  775. "offset": 0.02,
  776. },
  777. "span_id": frontend_span_id,
  778. "trace_id": trace_id,
  779. }
  780. ],
  781. )
  782. # try to give clickhouse some breathing room
  783. if slow:
  784. time.sleep(0.05)
  785. backend_duration = random_normal(1500 + 50 * day, 250, 500)
  786. create_sample_event(
  787. project=backend_project,
  788. platform="transaction",
  789. transaction="/trends/backend/",
  790. event_id=uuid4().hex,
  791. user=transaction_user,
  792. timestamp=timestamp,
  793. start_timestamp=timestamp - timedelta(milliseconds=backend_duration),
  794. # match the trace from the javascript transaction
  795. trace=trace_id,
  796. parent_span_id=frontend_root_span_id,
  797. spans=[],
  798. )
  799. # try to give clickhouse some breathing room
  800. if slow:
  801. time.sleep(0.05)
  802. if load_performance_issues:
  803. def load_n_plus_one_issue():
  804. trace_id = uuid4().hex
  805. transaction_user = generate_user()
  806. frontend_root_span_id = uuid4().hex[:16]
  807. n_plus_one_db_current_offset = timestamp
  808. n_plus_one_db_duration = timedelta(milliseconds=100)
  809. parent_span_id = uuid4().hex[:16]
  810. source_span = {
  811. "timestamp": (timestamp + n_plus_one_db_duration).timestamp(),
  812. "start_timestamp": (timestamp + timedelta(milliseconds=10)).timestamp(),
  813. "description": "SELECT `books_book`.`id`, `books_book`.`title`, `books_book`.`author_id` FROM `books_book` ORDER BY `books_book`.`id` DESC LIMIT 10",
  814. "op": "db",
  815. "parent_span_id": parent_span_id,
  816. "span_id": uuid4().hex[:16],
  817. "hash": "858fea692d4d93e8",
  818. }
  819. def make_repeating_span(duration):
  820. nonlocal timestamp
  821. nonlocal n_plus_one_db_current_offset
  822. nonlocal n_plus_one_db_duration
  823. n_plus_one_db_duration += timedelta(milliseconds=duration) + timedelta(
  824. milliseconds=1
  825. )
  826. n_plus_one_db_current_offset = timestamp + n_plus_one_db_duration
  827. return {
  828. "timestamp": (
  829. n_plus_one_db_current_offset + timedelta(milliseconds=duration)
  830. ).timestamp(),
  831. "start_timestamp": (
  832. n_plus_one_db_current_offset + timedelta(milliseconds=1)
  833. ).timestamp(),
  834. "description": "SELECT `books_author`.`id`, `books_author`.`name` FROM `books_author` WHERE `books_author`.`id` = %s LIMIT 21",
  835. "op": "db",
  836. "span_id": uuid4().hex[:16],
  837. "parent_span_id": parent_span_id,
  838. "hash": "63f1e89e6a073441",
  839. }
  840. repeating_spans = [make_repeating_span(200) for _ in range(10)]
  841. parent_span = {
  842. "timestamp": (
  843. timestamp + n_plus_one_db_duration + timedelta(milliseconds=200)
  844. ).timestamp(),
  845. "start_timestamp": timestamp.timestamp(),
  846. "description": "new",
  847. "op": "django.view",
  848. "parent_span_id": uuid4().hex[:16],
  849. "span_id": parent_span_id,
  850. "hash": "0f43fb6f6e01ca52",
  851. }
  852. create_sample_event(
  853. project=backend_project,
  854. platform="transaction",
  855. transaction="/n_plus_one_db/backend/",
  856. event_id=uuid4().hex,
  857. user=transaction_user,
  858. timestamp=timestamp + n_plus_one_db_duration + timedelta(milliseconds=300),
  859. start_timestamp=timestamp,
  860. trace=trace_id,
  861. parent_span_id=frontend_root_span_id,
  862. spans=[
  863. parent_span,
  864. source_span,
  865. ]
  866. + repeating_spans,
  867. )
  868. time.sleep(1.0)
  869. create_sample_event(
  870. project=backend_project,
  871. platform="transaction",
  872. transaction="/file-io-main-thread/",
  873. event_id=uuid4().hex,
  874. user=transaction_user,
  875. timestamp=timestamp + timedelta(milliseconds=300),
  876. start_timestamp=timestamp,
  877. trace=trace_id,
  878. parent_span_id=frontend_root_span_id,
  879. spans=[
  880. parent_span,
  881. {
  882. "timestamp": (timestamp + timedelta(milliseconds=200)).timestamp(),
  883. "start_timestamp": timestamp.timestamp(),
  884. "description": "1669031858711_file.txt (4.0 kB)",
  885. "op": "file.write",
  886. "span_id": uuid4().hex[:16],
  887. "parent_span_id": parent_span_id,
  888. "status": "ok",
  889. "data": {
  890. "blocked_ui_thread": True,
  891. "call_stack": [
  892. {
  893. "function": "onClick",
  894. "in_app": True,
  895. "lineno": 2,
  896. "module": "io.sentry.samples.android.MainActivity$$ExternalSyntheticLambda6",
  897. "native": False,
  898. },
  899. {
  900. "filename": "MainActivity.java",
  901. "function": "lambda$onCreate$5$io-sentry-samples-android-MainActivity",
  902. "in_app": True,
  903. "lineno": 93,
  904. "module": "io.sentry.samples.android.MainActivity",
  905. "native": False,
  906. },
  907. ],
  908. "file.path": "/data/user/0/io.sentry.samples.android/files/1669031858711_file.txt",
  909. "file.size": 4010,
  910. },
  911. },
  912. ],
  913. )
  914. def load_uncompressed_asset_issue():
  915. time.sleep(1.0)
  916. transaction_user = generate_user()
  917. trace_id = uuid4().hex
  918. parent_span_id = uuid4().hex[:16]
  919. parent_span = {
  920. "timestamp": (timestamp + timedelta(milliseconds=300)).timestamp(),
  921. "start_timestamp": timestamp.timestamp(),
  922. "description": "new",
  923. "op": "pageload",
  924. "parent_span_id": uuid4().hex[:16],
  925. "span_id": parent_span_id,
  926. "hash": "0f43fb6f6e01ca52",
  927. }
  928. spans = [
  929. {
  930. "timestamp": (timestamp + timedelta(milliseconds=1000)).timestamp(),
  931. "start_timestamp": (timestamp + timedelta(milliseconds=300)).timestamp(),
  932. "description": "https://s1.sentry-cdn.com/_static/dist/sentry/entrypoints/app.js",
  933. "op": "resource.script",
  934. "parent_span_id": parent_span_id,
  935. "span_id": uuid4().hex[:16],
  936. "hash": "858fea692d4d93e9",
  937. "data": {
  938. "http.transfer_size": 1_000_000,
  939. "http.response_content_length": 1_000_000,
  940. "http.decoded_response_content_length": 1_000_000,
  941. },
  942. },
  943. ]
  944. create_sample_event(
  945. project=backend_project,
  946. platform="transaction",
  947. transaction="/uncompressed-asset/",
  948. event_id=uuid4().hex,
  949. user=transaction_user,
  950. timestamp=timestamp + timedelta(milliseconds=300),
  951. start_timestamp=timestamp,
  952. trace=trace_id,
  953. parent_span_id=parent_span_id,
  954. spans=[parent_span] + spans,
  955. )
  956. def load_consecutive_db_issue():
  957. time.sleep(1.0)
  958. transaction_user = generate_user()
  959. trace_id = uuid4().hex
  960. parent_span_id = uuid4().hex[:16]
  961. parent_span = {
  962. "timestamp": (timestamp + timedelta(milliseconds=300)).timestamp(),
  963. "start_timestamp": timestamp.timestamp(),
  964. "description": "new",
  965. "op": "django.view",
  966. "parent_span_id": uuid4().hex[:16],
  967. "span_id": parent_span_id,
  968. "hash": "0f43fb6f6e01ca52",
  969. }
  970. spans = [
  971. {
  972. "timestamp": (timestamp + timedelta(milliseconds=1000)).timestamp(),
  973. "start_timestamp": (timestamp + timedelta(milliseconds=300)).timestamp(),
  974. "description": "SELECT `customer`.`id` FROM `customers` WHERE `customer`.`name` = 'customerName'",
  975. "op": "db",
  976. "parent_span_id": parent_span_id,
  977. "span_id": uuid4().hex[:16],
  978. "hash": "858fea692d4d93e9",
  979. },
  980. {
  981. "timestamp": (timestamp + timedelta(milliseconds=2000)).timestamp(),
  982. "start_timestamp": (timestamp + timedelta(milliseconds=1000)).timestamp(),
  983. "description": "SELECT COUNT(*) FROM `customers`",
  984. "op": "db",
  985. "parent_span_id": parent_span_id,
  986. "span_id": uuid4().hex[:16],
  987. "hash": "858fea692d4d93e7",
  988. },
  989. {
  990. "timestamp": (timestamp + timedelta(milliseconds=3000)).timestamp(),
  991. "start_timestamp": (timestamp + timedelta(milliseconds=2000)).timestamp(),
  992. "description": "SELECT COUNT(*) FROM `items`",
  993. "op": "db",
  994. "parent_span_id": parent_span_id,
  995. "span_id": uuid4().hex[:16],
  996. "hash": "858fea692d4d93e6",
  997. },
  998. ]
  999. create_sample_event(
  1000. project=backend_project,
  1001. platform="transaction",
  1002. transaction="/consecutive-db/",
  1003. event_id=uuid4().hex,
  1004. user=transaction_user,
  1005. timestamp=timestamp + timedelta(milliseconds=300),
  1006. start_timestamp=timestamp,
  1007. trace=trace_id,
  1008. parent_span_id=parent_span_id,
  1009. spans=[parent_span] + spans,
  1010. )
  1011. def load_render_blocking_asset_issue():
  1012. transaction_user = generate_user()
  1013. trace_id = uuid4().hex
  1014. parent_span_id = uuid4().hex[:16]
  1015. spans = [
  1016. {
  1017. "timestamp": (timestamp + timedelta(milliseconds=1300)).timestamp(),
  1018. "start_timestamp": (timestamp + timedelta(milliseconds=300)).timestamp(),
  1019. "description": "https://example.com/asset.js",
  1020. "op": "resource.script",
  1021. "parent_span_id": parent_span_id,
  1022. "span_id": uuid4().hex[:16],
  1023. "hash": "858fea692d4d93e8",
  1024. "data": {"http.response_content_length": 1000001},
  1025. }
  1026. ]
  1027. create_sample_event(
  1028. project=frontend_project,
  1029. platform="transaction",
  1030. transaction="/render-blocking-asset/",
  1031. event_id=uuid4().hex,
  1032. user=transaction_user,
  1033. timestamp=timestamp + timedelta(milliseconds=300),
  1034. start_timestamp=timestamp,
  1035. trace=trace_id,
  1036. parent_span_id=parent_span_id,
  1037. spans=spans,
  1038. measurements={
  1039. "fcp": {"value": 2500.0},
  1040. },
  1041. )
  1042. def load_m_n_plus_one_issue():
  1043. trace_id = uuid4().hex
  1044. transaction_user = generate_user()
  1045. parent_span_id = uuid4().hex[:16]
  1046. duration = 200
  1047. def make_repeating_span(i):
  1048. nonlocal timestamp
  1049. nonlocal duration
  1050. start_timestamp = timestamp + timedelta(milliseconds=i * (duration + 1))
  1051. end_timestamp = start_timestamp + timedelta(milliseconds=duration)
  1052. op = "http" if i % 2 == 0 else "db"
  1053. description = "GET /" if i % 2 == 0 else "SELECT * FROM authors WHERE id = %s"
  1054. hash = "63f1e89e6a073441" if i % 2 == 0 else "a109ff3ef40f7fb3"
  1055. return {
  1056. "timestamp": end_timestamp.timestamp(),
  1057. "start_timestamp": start_timestamp.timestamp(),
  1058. "description": description,
  1059. "op": op,
  1060. "span_id": uuid4().hex[:16],
  1061. "parent_span_id": parent_span_id,
  1062. "hash": hash,
  1063. }
  1064. span_count = 10
  1065. repeating_spans = [make_repeating_span(i) for i in range(span_count)]
  1066. parent_span = {
  1067. "timestamp": (
  1068. timestamp + timedelta(milliseconds=span_count * (duration + 1))
  1069. ).timestamp(),
  1070. "start_timestamp": timestamp.timestamp(),
  1071. "description": "execute",
  1072. "op": "graphql.execute",
  1073. "parent_span_id": uuid4().hex[:16],
  1074. "span_id": parent_span_id,
  1075. "hash": "0f43fb6f6e01ca52",
  1076. }
  1077. create_sample_event(
  1078. project=backend_project,
  1079. platform="transaction",
  1080. transaction="/m_n_plus_one_db/backend/",
  1081. event_id=uuid4().hex,
  1082. user=transaction_user,
  1083. timestamp=timestamp + timedelta(milliseconds=span_count * (duration + 1) + 100),
  1084. start_timestamp=timestamp,
  1085. trace=trace_id,
  1086. spans=[parent_span] + repeating_spans,
  1087. )
  1088. def load_performance_issues():
  1089. print(f" > Loading performance issues data") # NOQA
  1090. print(f" > Loading n plus one issue") # NOQA
  1091. load_n_plus_one_issue()
  1092. print(f" > Loading consecutive db issue") # NOQA
  1093. load_consecutive_db_issue()
  1094. print(f" > Loading uncompressed asset issue") # NOQA
  1095. load_uncompressed_asset_issue()
  1096. print(f" > Loading render blocking asset issue") # NOQA
  1097. load_render_blocking_asset_issue()
  1098. print(f" > Loading MN+1 issue") # NOQA
  1099. load_m_n_plus_one_issue()
  1100. load_performance_issues()
  1101. if __name__ == "__main__":
  1102. settings.CELERY_ALWAYS_EAGER = True
  1103. from optparse import OptionParser
  1104. parser = OptionParser()
  1105. parser.add_option("--events", default=1, type=int, help="number of events to generate")
  1106. parser.add_option(
  1107. "--skip-default-setup",
  1108. default=False,
  1109. action="store_true",
  1110. help="Skips creating the default project, teams and timeseries, useful when only loading specific transactions",
  1111. )
  1112. parser.add_option(
  1113. "--extra-events",
  1114. default=False,
  1115. action="store_true",
  1116. help="add multiple events for each error group",
  1117. )
  1118. parser.add_option(
  1119. "--load-trends",
  1120. default=False,
  1121. action="store_true",
  1122. help="load multiple transactions for each id to show trends",
  1123. )
  1124. parser.add_option(
  1125. "--load-performance-issues",
  1126. default=False,
  1127. action="store_true",
  1128. help="load transactions with performance issues, still needs options/flags on for issues to appear.",
  1129. )
  1130. parser.add_option(
  1131. "--slow",
  1132. default=False,
  1133. action="store_true",
  1134. help="sleep between each transaction to let clickhouse rest",
  1135. )
  1136. (options, args) = parser.parse_args()
  1137. try:
  1138. main(
  1139. skip_default_setup=options.skip_default_setup,
  1140. num_events=options.events,
  1141. extra_events=options.extra_events,
  1142. load_trends=options.load_trends,
  1143. load_performance_issues=options.load_performance_issues,
  1144. slow=options.slow,
  1145. )
  1146. from sentry.issues.producer import get_occurrence_producer
  1147. get_occurrence_producer().close()
  1148. except Exception:
  1149. # Avoid reporting any issues recursively back into Sentry
  1150. import sys
  1151. import traceback
  1152. traceback.print_exc()
  1153. sys.exit(1)