CControxity Docs
GuidesReferenceHTTP APIOpen Controxity
Reference

Python SDK

Every function in controxity for Python 3.9 and newer (SDK 0.14.1), what it takes and what it sends. No dependencies.

init(key, url, *, version, every, root, capture_uncaught, heartbeat, capture_input, breadcrumbs)#

Starts reporting. Call it once, as early as you can.

ArgumentDefaultMeaning
keyrequiredThe place's server key (dep_…).
urlrequiredYour Controxity's address.
version""The version this runs: 1.4.2, or a git commit. Left out: CONTROXITY_VERSION, else the controxity-release.json that controxity deploy writes (0.13.0).
every60Seconds between sends.
rootthe working folderPaths in frames are made relative to it.
capture_uncaughtTrueReport uncaught exceptions, also in threads.
heartbeatTrueA heartbeat each minute; False for a script that isn't a server.
breadcrumbsTrueKeep the last 20 steps to send with an error.
capture_inputTrueWith an error, send the shape of its input: key names and types, never values.
controxity.init(os.environ["CONTROXITY_KEY"], os.environ["CONTROXITY_URL"], version="1.4.2")

check()#

(ok, why): whether this key works, and what's wrong in words when it doesn't.

ok, why = controxity.check()

capture_error(error, where="", crash=False, input=…)#

Reports an error you caught. Sent: its type, frames, where, its code (see code_of), whether it crashed, and, when you pass input (what the failing code was given), its shape. Never its message, never a value.

try:
    charge(order)
except Exception as error:
    controxity.capture_error(error, where="orders", input={"order": order})
    raise

flag(name, default=False, id=None)#

A switch: is it on? It's off until someone turns it on in Controxity (the product's page → Switches), and it turns itself off when errors are plainly worse where it's on. id: a steady id, so a switch on for a share gives each the same answer (only a hash of it is used, nothing is sent). See Switches.

if controxity.flag("new-checkout", id=user.id):
    return new_checkout(cart)

step(name), new_trail()#

step(name) notes a step, so an error after it shows how the app got there. A short code, never a value. Routes, calls out (requests, urllib, httpx: method, site, answer and time), event(), failing health checks and earlier errors are noted by themselves. The framework hooks give each request its own steps; new_trail() starts fresh ones for a job of your own. See Steps before an error.

r = requests.post(STRIPE, ...)
controxity.step(f"stripe.charge {r.status_code}")

expect(name, condition, where="", input=…)#

Says what must always be true. When condition is falsy, that's a problem in Controxity, like an error, but nothing is raised: the app carries on. Every check is counted, held or broken, so the problem says how rare it is. Returns bool(condition). See Expectations.

controxity.expect("total-not-negative", total >= 0, input={"cart": cart})

shape(value)#

What capture_error sends for input: key names and types. Dicts, lists, dataclasses and plain objects are followed; strings are string (or "" when empty), None is null.

controxity.shape({"items": None, "lines": [Line("A-1", 2)]})
# {"items": "null", "lines": [{"sku": "string", "qty": "number"}]}

code_of(error)#

The short code sent for an error: its own code, pgcode or sqlstate (23505), else http-<status> from status, status_code or its response (requests, httpx, urllib), else timeout, else the errno's name (ECONNREFUSED), else the code of the error that caused it (requests wraps a refused connection in its own ConnectionError). "" when there's none.

controxity.code_of(requests_error)   # "http-429"

flask(app), fastapi(app), Django#

Connects a framework, so a route's error is reported, with the shape of the request's route params and query (Flask and Django: its body too; with FastAPI, pass the body to capture_error yourself if you want it).

controxity.flask(app)        # Flask
controxity.fastapi(app)      # FastAPI or Starlette
# Django: "controxity.Django" in MIDDLEWARE

health(code, ok, severity="medium", reason="")#

Something you depend on is working or failing. reason is sent only when failing.

controxity.health("stripe", False, "high", "http-503")

event(name, count=1)#

Counts something that happened.

controxity.event("payment_failed")

client_version(platform, version, count=1, native="", runtime="")#

A phone or browser on that version talked to your server.

controxity.client_version("ios", app_version, native=store_build, runtime=runtime)

problems(), problem_for(found, error)#

Where your errors stand, and which one an error belongs to.

found = controxity.problems()["problems"]
p = controxity.problem_for(found, error)

report(title, what, expected, steps)#

What a person told you went wrong, as a bug report. Returns its id. The one call that sends text you give it.

controxity.report(title="Booking failed", what=text)

verify_update(body, signature, secret)#

Checks that a post to your server really came from Controxity.

if not controxity.verify_update(raw_body, request.headers["X-Controxity-Signature"], secret):
    abort(401)

flush(), shutdown()#

flush() sends what's waiting. shutdown() (called by itself when Python exits normally) sends it and says the server is stopping on purpose.

controxity.shutdown()
Controxity 1.132.0These pages are in the repository: docs/site