New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Spans: capture code snippets #7930
Conversation
Unit Test ResultsSee test report for an extended history of previous test failures. This is useful for diagnosing flaky tests. 20 files + 1 20 suites +1 12h 56m 41s ⏱️ + 40m 1s For more details on these failures, see this check. Results for commit 7f8c0fd. ± Comparison against base commit 49437c2. ♻️ This comment has been updated with latest results. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm OK moving forward even without the "split code by span" hack I mentioned in the thread. @crusaderky up to you
distributed/tests/test_spans.py
Outdated
assert "def _run(self)" in code[0][-2].code | ||
# Code snippets are in first-seen order | ||
assert "inc, 1" in code[0][-1].code | ||
assert "inc, 2" in code[1][-1].code | ||
assert "inc, 3" in code[2][-1].code |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Based on my testing, all spans have the same code. This is not a blocker but a bit unforunate.
I played briefly with ast
to see if we can improve this. This code is a bit of a hack but works and we could apply something like this on a best-effort basis to only attach the code that is relevant to the given span.
I'm basing this on the span
function name in the contextmanager. This could be refined further but should be good enough for most cases.
import ast
def parse_frame_by_span(frame):
code_by_span = {}
ast_fr = ast.parse(inspect.getsource(fr))
for node in ast.walk(ast_fr):
if isinstance(node, ast.With) and node.items[0].context_expr.func.id == "span":
try:
# This is a literal
label = node.items[0].context_expr.args[0].value
except:
# This is a variable. We can't get all of them, only whatever
# is stored in the locals at the time. Still, nice.
label = node.items[0].context_expr.args[0].id
label = fr.f_locals[label]
code_by_span[label] = ast.unparse(node)
return code_by_span
Disclaimer: I haven't looked at this PR at all, so sorry for the potentially uninformed comment. I'm pretty ok capturing more code than we need to if we can also capture the line number. Getting line numbers would, I think, help in many cases that I've seen. Often a big frame has many different compute calls within it (such as in a script or a large Jupyter cell). Getting line numbers would help us to disambiguate. This is an expansion of scope, so maybe it makes sense to defer to another PR, but I thought I'd mention it as an alternative (or addition to) Florian's suggestion above (although I like Florian's thought as well). |
We should be capturing the line of code already since #7786 (The fact that this is not shown on the Coiled UI, yet, is a Coiled issue) |
Ah ok, grand. Sorry for the distraction
…On Tue, Jun 20, 2023, 8:22 AM Florian Jetter ***@***.***> wrote:
Getting line numbers would help us to disambiguate.
We should be capturing the line of code already since #7786
<#7786> (The fact that this is
not shown on the Coiled UI, yet, is a Coiled issue)
—
Reply to this email directly, view it on GitHub
<#7930 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AACKZTA26RP4ULS4YQLQQMLXMGP3DANCNFSM6AAAAAAZLSAARU>
.
You are receiving this because you commented.Message ID:
***@***.***>
|
I would rather keep the scope as small as possible and just ensure that spans receive the same code as computations here. I think that the AST code snippet above is quite fragile. Namely, it wouldn't work with the |
I've updated the test to reflect that the three frames are different in line number |
Part of #7860