Re:Show HN: Httpdbg – A tool to trace the HTTP requests sent...
by mcoliver on Wednesday September 25, 2024 @10:50PM
(#41654059)
If on Linux or windows you can use Procmon or Instruments on macos.
Re:Show HN: Httpdbg – A tool to trace the HTTP requests sent...
by zerocool2750 on Wednesday September 25, 2024 @09:48PM
(#41653714)
Went spelunking through the source. I think you absolutely could!
There's actually not a whole lot I found that's really http-library specific. It uses the traceback module in a decorator that ends up being manually wrapped around all of the functions of the specific libraries the author cared about.
https://github.com/cle-b/httpdbg/blob/main/httpdbg/hooks
Should be easy enough to extend this to other libraries.
Super cool tool thanks for sharing @dmurray!
Re:Show HN: Httpdbg – A tool to trace the HTTP requests sent...
by sYnfo on Thursday September 26, 2024 @03:41AM
(#41655577)
You might find the syscall tracing functionality of Cirron useful: https://github.com/s7nfo/Cirron
Re:Show HN: Httpdbg – A tool to trace the HTTP requests sent...
by oefrha on Thursday September 26, 2024 @07:19AM
(#41657048)
CPython since 3.8 already has built-in audit events, including open, so you don't need to patch anything or use anything external. Just add an audit hook with sys.addaudithook().
Quick example:
import inspect
import pathlib
import sys
def callsite():
try:
pathlib.Path("/tmp/file").open()
except:
pass
def audit_hook(event, args):
if event == "open":
path, mode, flags = args
print(f"audit: open({path!r}, {mode!r}, 0o{flags:o})")
# Not using traceback here because traceback will attempt to read the
# source file, causing an infinite recursion of audit events.
f = inspect.currentframe()
while f := f.f_back:
print(
f'File "{f.f_code.co_filename}", line {f.f_lineno}, in {f.f_code.co_name}'
)
def main():
sys.addaudithook(audit_hook)
callsite()
if __name__ == "__main__":
main()
Prints: audit: open('/tmp/file', 'r', 0o100000000)
File "/path/to/python/lib/python3.12/pathlib.py", line 1013, in open
File "/tmp/audit.py", line 10, in callsite
File "/tmp/audit.py", line 26, in main
File "/tmp/audit.py", line 30, in <module>
https://docs.python.org/3/library/audit_events.html
I usually use strace(1) to track these down, but it's nowhere near as ergonomic as this tool. I'm wondering now if I could patch the `open` built-in instead.