alexmojaki / birdseye

Graphical Python debugger which lets you easily view the values of all evaluated expressions
https://birdseye.readthedocs.io
MIT License
1.65k stars 71 forks source link

Feature request: recursively trace calls within traced function #97

Open giladbarnea opened 2 years ago

giladbarnea commented 2 years ago

Hi, thanks for birdseye!

I often use it to trace a whole flow, e.g a web request, from endpoint to response. It's especially useful when the flow is complicated and can't be debugged locally.

It can get cumbersome to @eye the first function -> run it -> add an @eye -> run it again -> add the next @eye -> etc.

It would be great if one could e.g

def bar(): ...

def baz(): ...

@deep_eye
def foo(call_bar: bool):
    if call_bar:
        return bar()
    return baz()

Which would be equivalent to simply decorating foo, bar and baz with @eye.

To avoid exploding, maybe a @deep_eye(trace_limit=10) option could be supported.

I know birdseye can trace whole modules, but more often than not, functions call functions from other modules, so I'm imagining a trace of a call tree that spans different modules.

What are your thoughts?

Thanks, Gilad

alexmojaki commented 2 years ago

The problem is that birdseye doesn't use sys.settrace, it modifies the code, and doing that correctly at the last moment before calling a function is somewhere between difficult and impossible.

I suggest you try out https://github.com/alexmojaki/snoop, which is better suited for this kind of thing. You don't even have to choose between snoop and birdseye, you can combine them with @spy, but setting a depth will only affect the snoop part.