Add hook "context" information #22495
WoLfulus
started this conversation in
Feature Requests
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Summary
It's been hard to correlate hook calls (in my case filters and actions) without using hacky stuff and/or modifying the Directus core.
It would be nice to have some kind of "ID" to identify which context a hook is running. Think of it like a "request id" that you can filter in logs to debug something and/or trace its path.
Basic Example
Motivation
I'm developing tools to improve DX regarding debugging, tracing and history, and being able to correlate those hooks makes it possible to group things together for better visualization and aggregation. It also enables grouping of related operations, for example when batch creating items or relational ones.
For example, I wanted to quickly identify calls to
fields.create
that were raised by acollections.create
, but the only (unreliable) way to correlate them right now is by timestamp, but when running as a script (making requests), things gets really mixed up.Detailed Design
It would be nice to add to the hook meta information:
context_id
as a unique id (generated for all "actions")batch_id
as a unique id for items being created in batchesflow_execution_id
(in case it was started inside a flow)operation_id
(in case it was started by an operation)request_id
(in case it was started by a HTTP request)This would cause a call to
my_filter
to read the same exact value asmy_action
.This is useful because since there's no unique information flowing to both hook handlers (filter and action), it's almost impossible to correlate those events.
Requirements List
Must Have:
Should Have:
Drawbacks
Nothing to comment here.
Alternatives
Adoption Strategy
It's just a matter of documenting that this information is available inside filter/action hooks. Might not be useful for everyone at first, but opens many doors for extension developers.
Unresolved Questions
I'm basically only covering filter/action events, but if there's any other nested hook calls or relationship between hook executions, it would be nice to also be able to correlate them somehow too.
Beta Was this translation helpful? Give feedback.
All reactions