Comments (3)
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:
actor_from_request:
{ 'datasette': <datasette.app.Datasette object at 0x104d8bc70>,
'request': <asgi.Request method="GET" url="http://127.0.0.1:4433/fixtures/sortable">}
Hook implementations:
[ <HookImpl plugin_name='codespaces', plugin=<module 'datasette_codespaces' from '/Users/simon/.local/share/virtualenvs/datasette-AWNrQs95/lib/python3.10/site-packages/datasette_codespaces/__init__.py'>>,
<HookImpl plugin_name='datasette.actor_auth_cookie', plugin=<module 'datasette.actor_auth_cookie' from '/Users/simon/Dropbox/Development/datasette/datasette/actor_auth_cookie.py'>>,
<HookImpl plugin_name='datasette.default_permissions', plugin=<module 'datasette.default_permissions' from '/Users/simon/Dropbox/Development/datasette/datasette/default_permissions.py'>>]
Results:
[]
permission_allowed:
{ 'action': 'view-table',
'actor': None,
'datasette': <datasette.app.Datasette object at 0x104d8bc70>,
'resource': ( 'fixtures',
'sortable')}
Hook implementations:
[ <HookImpl plugin_name='datasette.default_permissions', plugin=<module 'datasette.default_permissions' from '/Users/simon/Dropbox/Development/datasette/datasette/default_permissions.py'>>,
<HookImpl plugin_name='datasette.default_permissions', plugin=<module 'datasette.default_permissions' from '/Users/simon/Dropbox/Development/datasette/datasette/default_permissions.py'>>]
Results:
[ <function permission_allowed_default.<locals>.inner at 0x1081332e0>]
permission_allowed:
{ 'action': 'view-database',
'actor': None,
'datasette': <datasette.app.Datasette object at 0x104d8bc70>,
'resource': 'fixtures'}
Hook implementations:
[ <HookImpl plugin_name='datasette.default_permissions', plugin=<module 'datasette.default_permissions' from '/Users/simon/Dropbox/Development/datasette/datasette/default_permissions.py'>>,
<HookImpl plugin_name='datasette.default_permissions', plugin=<module 'datasette.default_permissions' from '/Users/simon/Dropbox/Development/datasette/datasette/default_permissions.py'>>]
Results:
[ <function permission_allowed_default.<locals>.inner at 0x108132cb0>]
from datasette.
It's a bit annoying that the await_me_maybe
pattern produces results like this:
Results:
[ <function permission_allowed_default.<locals>.inner at 0x1081332e0>]
I tried to display the result of await_me_maybe
on them but the before
and after
hook functions aren't async and my attempts to execute that using loop.run_until_complete()
didn't work.
from datasette.
Documentation: https://docs.datasette.io/en/latest/writing_plugins.html#tracing-plugin-hooks
from datasette.
Related Issues (20)
- Using absolute URLs breaks when running behind a reverse proxy. Is it even necessary to use absolute URLs? HOT 1
- Use of md5 hash causes FIPS error, requires usedforsecurity=False HOT 14
- Move asgiref to test dependencies
- Run delete_everything inside a transaction HOT 1
- datasette.permission_allowed() should consider all checks, not just the last returned HOT 6
- Release notes for Datasette 1.0a9
- database.execute_write_fn() should default to running in a transaction HOT 6
- Incorrect display of permissions in permission testing tool HOT 2
- POST to /-/insert with "replace": true should require update-row HOT 5
- Release notes for 1.10a11 HOT 1
- Database and table action menus should appear next to the cog icon HOT 9
- `query_actions` plugin hook - like `table_actions` and `database_actions` for the query/canned query page HOT 2
- Document and make stable `derive_named_parameters` utility function HOT 2
- Ditch the "form label" styles
- New action button displayed too close to metadata HOT 1
- "does not contain" table filter HOT 2
- Bug where JavaScript cog menu doesn't fully reset HOT 5
- `internal.db` database is written to WAY too often HOT 6
- Fix httpx app shortcut deprecation warning
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from datasette.