Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save jordanlewis/b5acf853de13f616761c79728f12a87e to your computer and use it in GitHub Desktop.
Save jordanlewis/b5acf853de13f616761c79728f12a87e to your computer and use it in GitHub Desktop.
sentry zap
import re
if "stacktrace" in input_data:
s = input_data["stacktrace"]
lines = s.split("\n")
l = ""
for line in lines:
if line.startswith("stacktrace: "):
l = line.lstrip("stacktrace: ")
break
out = []
dq = False
sq = False
lastWasEsc = False
for c in l:
out.append(c)
if c == "'":
if sq:
if dq:
if not lastWasEsc:
out[-1] = "\\'"
else:
sq = False
else:
sq = True
elif c == '"':
dq = not dq
if c == "\\":
lastWasEsc = True
else:
lastWasEsc = False
d = eval("".join(out))
else:
d = {"frames": []}
pkg_re = re.compile(".*(github.com\/cockroachdb\/cockroach\/)")
taglist = input_data.get("tags","notag,novalue").split(",")
tags = {taglist[i*2]: taglist[i*2 + 1] for i in range(len(taglist) / 2)}
rev = tags.get("rev", "unknown")
# Make two stack traces: one compact, without hooks for GitHub to expand, and one verbose, with all stack frames linked to GitHub so that they auto-expand to code snippets.
compact = "\n".join(("%s in %s.%s at line %d" % (pkg_re.sub("", x["abs_path"]), pkg_re.sub("", x["module"]), x["function"], x["lineno"]) for x in reversed(d["frames"])))
ret = "\n".join(("%s#L%d-L%d in %s.%s" % (pkg_re.sub(r"https://\1blob/"+rev+"/", x["abs_path"]), x["lineno"]-1, x["lineno"]+1, pkg_re.sub("", x["module"]), x["function"]) for x in reversed(d["frames"])))
return {"stacktrace": compact, "expanded_stacktrace": ret, "tags": tags}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment