Repository navigation
Closed
Description
Hi! I've recently created a few libraries that are helpful for extracting information from frames and tracebacks, and I think they could be very useful to sentry.
executingcan identify the exact AST node being executed by a frame in many cases. It's always disappointed me that Python only points to a line in each frame in tracebacks, especially when the expression/statement at fault spans many lines. Sometimes it can be really hard to interpret. Currently executing is used in IPython (in master, unreleased) to highlight the node, here's what it looks like:
executingcan also infer a function__qualname__from a code object, meaning your traceback can saylorem/ipsum.py in MyClass.__init__ at line 123instead of just__init__, which is much more informative.pure_evalcan safely evaluate certain AST nodes without side effects, so that if the source for a frame contains expressions likeself.fooandbar[key]their values can often be shown alongside plain variables.stack_datacollects data from tracebacks for the purpose of formatting and displaying them. It usesexecutingandpure_evaland also provides a lot of functionality of its own. For example, in this frame:
there are lines from complex_filter which the user doesn't need to see, and stack_data knows how to filter those out by only collecting lines which belong in the current scope. I integratedstack_data into IPython which allowed removing a lot of flaky custom introspection code, fixing several bugs and making the code more maintainable.
stack_dataidentifies the locations of variables and evaluated expressions in the source lines. An intelligent UI could use this, for example, to allow the user to hover over a variable in source code to see its value rather than scroll through a list to find it.
Overall there are lots of possibilities. What would interest you? I'm willing to make a PR and make any necessary changes to the libraries.
Metadata
Metadata
Assignees
Labels
No labels


Activity
untitaker commentedon Jun 28, 2020
Hey @alexmojaki, this seems like a nice library!
I'm only going to comment on the ideas you presented.
Please keep in mind that you have no guarantee of the filename containing valid sourcecode, for example in Jinja templates that isn't the case (it's also one of the reasons we have refrained from adding syntax highlighting to Sentry, the other reason being laziness).
We would have to establish how to send this kind of information to the server in a way that makes sense for other languages than Python.
I believe an initial PoC, of whichever feature you're thinking of implementing, should pull those libraries in as optional dependency only. before_send seems like a very cheap way to hook into the SDK since its
hintobject will contain exc_info and you have access to the entire payload that is sent to sentry.Hope that helps,
Markus
alexmojaki commentedon Jun 28, 2020
OK, if these are going to be optional dependencies, I'm going to avoid stack_data, as that would just make the code more complicated.
I've made PRs for a couple of the features mentioned. There's some finicky details I haven't handled - for example the tests currently assume that the optional libraries are installed. But you can see the general idea well enough for a PoC as you said. Before I polish things up, can you confirm if the concept is proven?
The feature that would interest me the most is the first one I listed - highlighting the executing node. This would require changes on the server side in order to render the information. Shall I just ignore that complication for now and make another PoC PR which adds the data to the frame and we can worry about rendering later?
untitaker commentedon Jul 9, 2020
Yes, preferrably behind an integration like mentioned in #749. The server can handle superfluous attributes, sort of.
Use executing to infer code qualname (#749)
untitaker commentedon Jul 15, 2020
@alexmojaki did I get it right if I say that pure_eval is py3-only?
alexmojaki commentedon Jul 15, 2020
Yes.
untitaker commentedon Jul 15, 2020
Ok cool. Just so you know you're in charge of creating the sentry-docs PRs. There should be one per integration so one for executing and one for pure_eval, unless you plan to refactor those further.
alexmojaki commentedon Jul 18, 2020
I'm going to make a docs PR for pure_eval. I don't know how I can add an integration suggestion for it when the integration has three dependencies: pure_eval, executing, and asttokens.
For executing, I don't think there's much point in people using it unless the feature for highlighting the node range goes through. I've made a server side PR which I don't think I can complete on my own.
Add setup.py extra for pure_eval (#763)
untitaker commentedon Jul 19, 2020
Makes sense. I think pure-eval has most value anyway. Still unsure what to do about the server-side changes. We would probably need to review the exact protocol changes with others in the company.
Add page for pure_eval integration (#1907)
github-actions commentedon Dec 23, 2021
This issue has gone three weeks without activity. In another week, I will close it.
But! If you comment or otherwise update it, I will reset the clock, and if you label it
Status: BacklogorStatus: In Progress, I will leave it alone ... forever!"A weed is but an unloved flower." ― Ella Wheeler Wilcox 🥀