Foxray: a light error tracker for the Sentry SDKs. Runs inside Django (the admin is the UI) or on its own; SQLite or Postgres, nothing else. Not affiliated with Sentry.
danq9
0.1.2: the first PyPI release (v0.1.1 is already tagged at 05cc354, before the PyPI metadata)
58507e3
4 weeks ago
History
sdk_checks.py · 2.8 KB · 54 lines
| 1 | """What a run of tests/sdk_client.py must leave in a store, whichever kind.""" |
| 2 | |
| 3 | from foxray.core.sql import IssueQuery |
| 4 | |
| 5 | |
| 6 | def check_sdk_run(store, project, ids: dict) -> None: |
| 7 | issues = {i.title: i for i in store.list_issues(IssueQuery(project_id=project.id, status="all"))[0]} |
| 8 | titles = set(issues) |
| 9 | assert "ZeroDivisionError: division by zero" in titles, titles |
| 10 | assert "KeyError: 'missing'" in titles, titles |
| 11 | assert "Payment provider slow: 1234 ms" in titles, titles |
| 12 | assert "db timeout on shard 3" in titles or "db timeout on shard 7" in titles, titles |
| 13 | assert "RuntimeError: job failed" in titles, titles |
| 14 | |
| 15 | # grouping: the same place twice is one issue; logging calls group by their template |
| 16 | zero = issues["ZeroDivisionError: division by zero"] |
| 17 | assert zero.times_seen == 2 and store.count_events(zero.id) == 2 |
| 18 | shard = [i for t, i in issues.items() if t.startswith("db timeout on shard")] |
| 19 | assert len(shard) == 1 and shard[0].times_seen == 2 |
| 20 | |
| 21 | # the stored event: frames with context, release/environment, PII cut down |
| 22 | ev = store.find_event(project.id, ids["exc"][0]).payload |
| 23 | frame = ev["exception"]["values"][-1]["stacktrace"]["frames"][-1] |
| 24 | assert frame["function"] == "checkout" and frame["in_app"] is True |
| 25 | assert "10 / n" in frame["context_line"] |
| 26 | assert ev["release"] == "shop@1.2.3" and ev["environment"] == "test" and ev["server_name"] == "client-1" |
| 27 | assert zero.culprit.endswith("in checkout") |
| 28 | |
| 29 | key = store.find_event(project.id, ids["keyerror"]).payload |
| 30 | assert key["user"] == {"id": "42"} |
| 31 | assert key["tags"]["tenant"] == "acme" |
| 32 | assert key["extra"]["api_token"] == "[Filtered]" |
| 33 | |
| 34 | msg = issues["Payment provider slow: 1234 ms"] |
| 35 | assert msg.level == "warning" |
| 36 | tags = store.issue_tags(zero.id) |
| 37 | assert tags["environment"] == [("test", 2)] and tags["release"] == [("shop@1.2.3", 2)] |
| 38 | |
| 39 | # monitors and check-ins |
| 40 | nightly = store.get_monitor(project.id, "nightly-report") |
| 41 | assert (nightly.schedule_type, nightly.schedule_value, nightly.timezone) == ("crontab", "0 3 * * *", "America/Chicago") |
| 42 | assert nightly.checkin_margin == 10 and nightly.max_runtime == 30 and nightly.status == "ok" |
| 43 | assert nightly.next_due_at is not None |
| 44 | runs = store.list_checkins(nightly.id) |
| 45 | assert len(runs) == 1 and runs[0].status == "ok" and runs[0].duration and runs[0].duration > 0 |
| 46 | broken = store.get_monitor(project.id, "broken-job") |
| 47 | assert broken.status == "error" and [c.status for c in store.list_checkins(broken.id)] == ["error"] |
| 48 | hourly = store.get_monitor(project.id, "hourly-sync") |
| 49 | assert (hourly.schedule_type, hourly.schedule_value, hourly.schedule_unit) == ("interval", "1", "hour") |
| 50 | |
| 51 | # alerts were decided and queued |
| 52 | kinds = [a.kind for a in store.list_alerts(100)] |
| 53 | assert kinds.count("new_issue") == len(issues) |
| 54 | assert kinds.count("monitor_error") == 1 |