load-mocks 52 KB

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