askrobots / foxray Public

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.

0 downloads

foxray/tests/test_sdk_any_version.py
Download zip
Clone
Clone with git
git clone https://gitstable.com/git/askrobots/foxray.git
HTTPS
https://gitstable.com/git/askrobots/foxray.git
SSH
ssh://git@gitstable.com:2222/askrobots/foxray.git

Cloning needs no sign-in. Pushing over HTTPS asks for your username and an access token. SSH needs your key under SSH keys.

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
test_sdk_any_version.py · 1.9 KB · 43 lines
1"""The parts of the Sentry protocol every SDK version uses, run with whatever sentry-sdk is installed
2(askrobots.com pins 1.9.10; the other SDK tests need 2.x for crons and new_scope)."""
3
4import json
5import subprocess
6import sys
7import time
8
9import pytest
10
11from foxray.core.sql import IssueQuery
12from foxray.standalone.store import open_store
13from tests.test_sdk_standalone import ENV, ROOT, foxray, server # noqa: F401 - the server fixture
14
15
16@pytest.mark.slow
17def test_errors_and_messages_from_any_sdk_version(server): # noqa: F811
18 dsn = foxray("--db", server["db"], "create-project", "shop", "--base-url", server["base"]).strip()
19 out = subprocess.run([sys.executable, str(ROOT / "tests" / "sdk_any_client.py"), dsn], cwd=ROOT, env=ENV,
20 capture_output=True, text=True, timeout=60, check=True).stdout
21 ids = json.loads(out.strip().splitlines()[-1])
22 store = open_store(server["db"])
23 project = store.get_project(1)
24 deadline = time.time() + 10
25 while time.time() < deadline and store.find_event(project.id, ids["msg"]) is None:
26 time.sleep(0.1)
27 issues = {i.title: i for i in store.list_issues(IssueQuery(project_id=project.id, status="all"))[0]}
28 assert issues["ZeroDivisionError: division by zero"].times_seen == 2
29 assert issues["Payment provider slow: 1234 ms"].level == "warning"
30 assert store.find_event(project.id, ids["msg"]).payload["tags"]["tenant"] == "acme"
31
32
33def test_transport_takes_plain_events_from_sdk_1x():
34 """sentry-sdk 1.x passes plain errors to Transport.capture_event, not capture_envelope."""
35 from foxray.django.sdk import FoxrayTransport
36 got = []
37 t = FoxrayTransport(deliver_fn=got.append)
38 t.capture_event({"event_id": "a" * 32, "level": "error", "message": "from 1.x"})
39 t.flush(5)
40 t.kill()
41 assert len(got) == 1
42 data = got[0] if isinstance(got[0], bytes) else got[0].encode()
43 assert b'"type":"event"' in data.replace(b" ", b"") and b"from 1.x" in data