load-mocks 52 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294
  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.tsdb.base import TSDBModel
  60. from sentry.utils import loremipsum
  61. from sentry.utils.hashlib import md5_text
  62. from sentry.utils.samples import create_sample_event as _create_sample_event
  63. from sentry.utils.samples import create_trace, generate_user, random_normal
  64. PLATFORMS = itertools.cycle(["ruby", "php", "python", "java", "javascript"])
  65. LEVELS = itertools.cycle(["error", "error", "error", "fatal", "warning"])
  66. ENVIRONMENTS = itertools.cycle(["production", "production", "staging", "alpha", "beta", ""])
  67. MONITOR_NAMES = itertools.cycle(settings.CELERYBEAT_SCHEDULE.keys())
  68. MONITOR_SCHEDULES = itertools.cycle(["* * * * *", "0 * * * *", "0 0 * * *"])
  69. LONG_MESSAGE = """Code: 0.
  70. DB::Exception: String is too long for DateTime: 2018-10-26T19:14:18+00:00. Stack trace:
  71. 0. clickhouse-server(StackTrace::StackTrace()+0x16) [0x99e9626]
  72. 1. clickhouse-server(DB::Exception::Exception(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, int)+0x22) [0x3087172]
  73. 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]
  74. 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]
  75. 4. clickhouse-server(DB::PreparedFunctionImpl::defaultImplementationForNulls(DB::Block&, std::vector<unsigned long, std::allocator<unsigned long> > const&, unsigned long, unsigned long)+0x174) [0x7953cd4]
  76. 5. clickhouse-server(DB::PreparedFunctionImpl::executeWithoutLowCardinalityColumns(DB::Block&, std::vector<unsigned long, std::allocator<unsigned long> > const&, unsigned long, unsigned long)+0x54) [0x7953b04]
  77. 6. clickhouse-server(DB::PreparedFunctionImpl::execute(DB::Block&, std::vector<unsigned long, std::allocator<unsigned long> > const&, unsigned long, unsigned long)+0x3e2) [0x7954222]
  78. 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]
  79. 8. clickhouse-server(DB::ExpressionActions::execute(DB::Block&) const+0xe6) [0x7b03676]
  80. 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]
  81. 10. clickhouse-server() [0x75e9443]
  82. 11. clickhouse-server(DB::InterpreterSelectQuery::executeImpl(DB::InterpreterSelectQuery::Pipeline&, std::shared_ptr<DB::IBlockInputStream> const&, bool)+0x118f) [0x75f212f]
  83. 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]
  84. 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]
  85. 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]
  86. 15. clickhouse-server(DB::InterpreterFactory::get(std::shared_ptr<DB::IAST>&, DB::Context&, DB::QueryProcessingStage::Enum)+0x3a8) [0x75dc138]
  87. 16. clickhouse-server() [0x768fad9]
  88. 17. clickhouse-server(DB::executeQuery(std::__cxx11::basic..."""
  89. def make_sentence(words=None):
  90. if words is None:
  91. words = int(random.weibullvariate(8, 3))
  92. return " ".join(random.choice(loremipsum.words) for _ in range(words))
  93. def create_sample_event(*args, **kwargs):
  94. try:
  95. event = _create_sample_event(*args, **kwargs)
  96. except HashDiscarded as e:
  97. print(f"> Skipping Event: {e.message}") # NOQA
  98. else:
  99. if event is not None:
  100. features.record([event])
  101. return event
  102. def generate_commits(user):
  103. commits = []
  104. for i in range(random.randint(1, 20)):
  105. if i == 1:
  106. filename = "raven/base.py"
  107. else:
  108. filename = random.choice(loremipsum.words) + ".js"
  109. if random.randint(0, 5) == 1:
  110. author = (user.name, user.email)
  111. else:
  112. author = (
  113. f"{random.choice(loremipsum.words)} {random.choice(loremipsum.words)}",
  114. f"{random.choice(loremipsum.words)}@example.com",
  115. )
  116. commits.append(
  117. {
  118. "key": sha1(uuid4().bytes).hexdigest(),
  119. "message": f"feat: Do something to {filename}\n{make_sentence()}",
  120. "author": author,
  121. "files": [(filename, "M")],
  122. }
  123. )
  124. return commits
  125. def generate_tombstones(project, user):
  126. # attempt to create a high enough previous_group_id
  127. # that it won't conflict with any group ids
  128. prev_group_id = 100000
  129. try:
  130. prev_group_id = (
  131. max(
  132. GroupTombstone.objects.order_by("-previous_group_id")[0].previous_group_id,
  133. prev_group_id,
  134. )
  135. + 1
  136. )
  137. except IndexError:
  138. pass
  139. for group in Group.objects.filter(project=project)[:5]:
  140. GroupTombstone.objects.create(
  141. previous_group_id=prev_group_id,
  142. actor_id=user.id,
  143. **{name: getattr(group, name) for name in TOMBSTONE_FIELDS_FROM_GROUP},
  144. )
  145. prev_group_id += 1
  146. def create_system_time_series():
  147. now = datetime.utcnow().replace(tzinfo=utc)
  148. for _ in range(60):
  149. count = randint(1, 10)
  150. tsdb.incr_multi(
  151. (
  152. (TSDBModel.internal, "client-api.all-versions.responses.2xx"),
  153. (TSDBModel.internal, "client-api.all-versions.requests"),
  154. ),
  155. now,
  156. int(count * 0.9),
  157. )
  158. tsdb.incr_multi(
  159. ((TSDBModel.internal, "client-api.all-versions.responses.4xx"),),
  160. now,
  161. int(count * 0.05),
  162. )
  163. tsdb.incr_multi(
  164. ((TSDBModel.internal, "client-api.all-versions.responses.5xx"),),
  165. now,
  166. int(count * 0.1),
  167. )
  168. now = now - timedelta(seconds=1)
  169. for _ in range(24 * 30):
  170. count = randint(100, 1000)
  171. tsdb.incr_multi(
  172. (
  173. (TSDBModel.internal, "client-api.all-versions.responses.2xx"),
  174. (TSDBModel.internal, "client-api.all-versions.requests"),
  175. ),
  176. now,
  177. int(count * 4.9),
  178. )
  179. tsdb.incr_multi(
  180. ((TSDBModel.internal, "client-api.all-versions.responses.4xx"),),
  181. now,
  182. int(count * 0.05),
  183. )
  184. tsdb.incr_multi(
  185. ((TSDBModel.internal, "client-api.all-versions.responses.5xx"),),
  186. now,
  187. int(count * 0.1),
  188. )
  189. now = now - timedelta(hours=1)
  190. def create_sample_time_series(event, release=None):
  191. if event is None:
  192. return
  193. group = event.group
  194. project = group.project
  195. key = project.key_set.all()[0]
  196. now = datetime.utcnow().replace(tzinfo=utc)
  197. environment = Environment.get_or_create(
  198. project=project, name=Environment.get_name_or_default(event.get_tag("environment"))
  199. )
  200. if release:
  201. ReleaseEnvironment.get_or_create(
  202. project=project, release=release, environment=environment, datetime=now
  203. )
  204. grouprelease = GroupRelease.get_or_create(
  205. group=group, release=release, environment=environment, datetime=now
  206. )
  207. for _ in range(60):
  208. count = randint(1, 10)
  209. tsdb.incr_multi(
  210. ((TSDBModel.project, project.id), (TSDBModel.group, group.id)),
  211. now,
  212. count,
  213. environment_id=environment.id,
  214. )
  215. tsdb.incr_multi(
  216. (
  217. (TSDBModel.organization_total_received, project.organization_id),
  218. (TSDBModel.project_total_received, project.id),
  219. (TSDBModel.key_total_received, key.id),
  220. ),
  221. now,
  222. int(count * 1.1),
  223. )
  224. tsdb.incr(
  225. TSDBModel.project_total_forwarded,
  226. project.id,
  227. now,
  228. int(count * 1.1),
  229. )
  230. tsdb.incr_multi(
  231. (
  232. (TSDBModel.organization_total_rejected, project.organization_id),
  233. (TSDBModel.project_total_rejected, project.id),
  234. (TSDBModel.key_total_rejected, key.id),
  235. ),
  236. now,
  237. int(count * 0.1),
  238. )
  239. frequencies = [
  240. (TSDBModel.frequent_issues_by_project, {project.id: {group.id: count}}),
  241. (TSDBModel.frequent_environments_by_group, {group.id: {environment.id: count}}),
  242. ]
  243. if release:
  244. frequencies.append(
  245. (TSDBModel.frequent_releases_by_group, {group.id: {grouprelease.id: count}})
  246. )
  247. tsdb.record_frequency_multi(frequencies, now)
  248. now = now - timedelta(seconds=1)
  249. for _ in range(24 * 30):
  250. count = randint(100, 1000)
  251. tsdb.incr_multi(
  252. ((TSDBModel.project, group.project.id), (TSDBModel.group, group.id)),
  253. now,
  254. count,
  255. environment_id=environment.id,
  256. )
  257. tsdb.incr_multi(
  258. (
  259. (TSDBModel.organization_total_received, project.organization_id),
  260. (TSDBModel.project_total_received, project.id),
  261. (TSDBModel.key_total_received, key.id),
  262. ),
  263. now,
  264. int(count * 1.1),
  265. )
  266. tsdb.incr_multi(
  267. (
  268. (TSDBModel.organization_total_rejected, project.organization_id),
  269. (TSDBModel.project_total_rejected, project.id),
  270. (TSDBModel.key_total_rejected, key.id),
  271. ),
  272. now,
  273. int(count * 0.1),
  274. )
  275. frequencies = [
  276. (TSDBModel.frequent_issues_by_project, {project.id: {group.id: count}}),
  277. (TSDBModel.frequent_environments_by_group, {group.id: {environment.id: count}}),
  278. ]
  279. if release:
  280. frequencies.append(
  281. (TSDBModel.frequent_releases_by_group, {group.id: {grouprelease.id: count}})
  282. )
  283. tsdb.record_frequency_multi(frequencies, now)
  284. now = now - timedelta(hours=1)
  285. def main(
  286. skip_default_setup=False,
  287. num_events=1,
  288. extra_events=False,
  289. load_trends=False,
  290. load_performance_issues=False,
  291. slow=False,
  292. ):
  293. from sentry.constants import ObjectStatus
  294. try:
  295. user = User.objects.filter(is_superuser=True)[0]
  296. except IndexError:
  297. raise Exception("No superuser exists (run `make bootstrap`)")
  298. dummy_user, _ = User.objects.get_or_create(
  299. username="dummy@example.com", defaults={"email": "dummy@example.com"}
  300. )
  301. dummy_user.set_password("dummy")
  302. dummy_user.save()
  303. mocks = (
  304. ("Massive Dynamic", ("Ludic Science",)),
  305. ("Captain Planet", ("Earth", "Fire", "Wind", "Water", "Heart")),
  306. )
  307. project_map = {}
  308. Broadcast.objects.create(
  309. title="Learn about Source Maps",
  310. message="Source maps are JSON files that contain information on how to map your transpiled source code back to their original source.",
  311. link="https://docs.sentry.io/platforms/javascript/#source-maps",
  312. )
  313. if settings.SENTRY_SINGLE_ORGANIZATION:
  314. org = Organization.get_default()
  315. print(f"Mocking org {org.name}") # NOQA
  316. else:
  317. print("Mocking org {}".format("Default")) # NOQA
  318. org, _ = Organization.objects.get_or_create(slug="default")
  319. OrganizationMember.objects.get_or_create(
  320. user_id=user.id, organization=org, role=roles.get_top_dog().id
  321. )
  322. dummy_member, _ = OrganizationMember.objects.get_or_create(
  323. user_id=dummy_user.id, organization=org, defaults={"role": roles.get_default().id}
  324. )
  325. # Allow for 0 events, if you only want transactions
  326. event1 = event2 = event3 = event4 = event5 = None
  327. if skip_default_setup:
  328. # Quickly fetch/create the teams and projects
  329. for team_name, project_names in mocks:
  330. print(f"> Mocking team {team_name}") # NOQA
  331. team, _ = Team.objects.get_or_create(name=team_name, defaults={"organization": org})
  332. for project_name in project_names:
  333. print(f" > Mocking project {project_name}") # NOQA
  334. project, _ = Project.objects.get_or_create(
  335. name=project_name,
  336. defaults={
  337. "organization": org,
  338. "first_event": timezone.now(),
  339. "flags": Project.flags.has_releases,
  340. },
  341. )
  342. project_map[project_name] = project
  343. project.add_team(team)
  344. else:
  345. for team_name, project_names in mocks:
  346. print(f"> Mocking team {team_name}") # NOQA
  347. team, _ = Team.objects.get_or_create(name=team_name, defaults={"organization": org})
  348. for project_name in project_names:
  349. print(f" > Mocking project {project_name}") # NOQA
  350. project, _ = Project.objects.get_or_create(
  351. name=project_name,
  352. defaults={
  353. "organization": org,
  354. "first_event": timezone.now(),
  355. "flags": Project.flags.has_releases,
  356. },
  357. )
  358. project_map[project_name] = project
  359. project.add_team(team)
  360. if not project.first_event:
  361. project.update(first_event=project.date_added)
  362. if not project.flags.has_releases:
  363. project.update(flags=F("flags").bitor(Project.flags.has_releases))
  364. environment = Environment.get_or_create(project=project, name=next(ENVIRONMENTS))
  365. monitor, _ = Monitor.objects.get_or_create(
  366. name=next(MONITOR_NAMES),
  367. project_id=project.id,
  368. organization_id=org.id,
  369. type=MonitorType.CRON_JOB,
  370. defaults={
  371. "status": ObjectStatus.DISABLED,
  372. "config": {"schedule": next(MONITOR_SCHEDULES)},
  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_env.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. except Exception:
  1147. # Avoid reporting any issues recursively back into Sentry
  1148. import sys
  1149. import traceback
  1150. traceback.print_exc()
  1151. sys.exit(1)