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
DATASETTE_TRACE_PLUGINS for tracing Pluggy calls #2274
Labels
Milestone
Comments
Prototype: diff --git a/datasette/plugins.py b/datasette/plugins.py
index f7a1905f..d7f73e7d 100644
--- a/datasette/plugins.py
+++ b/datasette/plugins.py
@@ -1,6 +1,7 @@
import importlib
import os
import pluggy
+from pprint import pprint
import sys
from . import hookspecs
@@ -33,6 +34,29 @@ DEFAULT_PLUGINS = (
pm = pluggy.PluginManager("datasette")
pm.add_hookspecs(hookspecs)
+DATASETTE_PLUGGY_TRACING = os.environ.get("DATASETTE_PLUGGY_TRACING", None)
+
+
+def before(hook_name, hook_impls, kwargs):
+ print()
+ print(f"{hook_name}:")
+ pprint(kwargs, width=40, indent=4)
+ print("Hook implementations:")
+ pprint(hook_impls, width=40, indent=4)
+
+
+def after(outcome, hook_name, hook_impls, kwargs):
+ results = outcome.get_result()
+ if not isinstance(results, list):
+ results = [results]
+ print(f"Results:")
+ pprint(results, width=40, indent=4)
+
+
+if DATASETTE_PLUGGY_TRACING:
+ pm.add_hookcall_monitoring(before, after)
+
+
DATASETTE_LOAD_PLUGINS = os.environ.get("DATASETTE_LOAD_PLUGINS", None)
if not hasattr(sys, "_called_from_test") and DATASETTE_LOAD_PLUGINS is None: Produces output like this:
|
It's a bit annoying that the
I tried to display the result of |
simonw
changed the title
DATASETTE_PLUGGY_TRACING for tracing Pluggy calls
DATASETTE_TRACE_PLUGINS for tracing Pluggy calls
Feb 16, 2024
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Pluggy has a debugging mechanism that can be used to output information about plugin calls: https://pluggy.readthedocs.io/en/stable/api_reference.html#pluggy.PluginManager.add_hookcall_monitoring
I tried this just now and it's helping debug a plugins permissions issue. It should be a feature.
The text was updated successfully, but these errors were encountered: