-
Notifications
You must be signed in to change notification settings - Fork 35
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
feat: go context in hook calls #163
Conversation
Thank you for the contribution! |
Codecov Report
@@ Coverage Diff @@
## main #163 +/- ##
=======================================
Coverage 71.25% 71.25%
=======================================
Files 8 8
Lines 668 668
=======================================
Hits 476 476
Misses 174 174
Partials 18 18
📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more |
I don't believe that we generally want to encourage interdependence between hooks, so my initial reaction is that this is OK... but I'm wondering what other use-cases we would be preventing here. Particularly interested in @skyerus and @james-milligan 's opinions on this. |
Do other SDKs behave in this manor? An example of a limitation would be that a user couldn't use a Before hook to start a timer and an After hook to end the timer and log the transaction time. It does seem somewhat limiting. |
Other SDKs don't use a go Personally, I think using the I guess the Go equivalent to what I'm saying above would be a hook that has a |
IMHO hooks should be seen as events and be functional and don't rely on any carry-over state. They should rely only on the properties of the |
Yep, I pretty much agree. I think maintaining state between STAGES in the same hook is valid, but that state should not be maintained in the |
@toddbaert a weakmap would be perfect for this use case, but Go doesn't have them :( Creating a new |
I this PR, we are using the context passed in to the evaluation. When you say "Creating a new context.Context" are you meaning something different? |
To state the problem declaratively (to avoid confusion, I got myself confused by the problem statement initially). Given that each of the hook's functions (Before/After/Finally/Error) are applied on the same structure, there is already the ability to pass data between the hook functions. The concern is when it comes to chaining data between independent hooks e.g. no way to pass data from hook1.Before() to hook2.Before(). In which case, the next steps for this PR are to fix the linting and DCO check. @Kunde21 are you happy to do this? If not, I'm happy to takeover. |
Agreed on all counts. |
675a5cb
to
8467ceb
Compare
Include the go context in hook methods, to maintain the request context through the hooks. Go context often includes instrumentation and request-scoped information that is useful for processing events in the hooks. Plumbing the go context through hook methods enables richer processing of hook events. Signed-off-by: Chad Kunde <Kunde21@gmail.com>
8467ceb
to
85ba23d
Compare
@skyerus - Fixed up the commit. Should cover the issues in the workflow checks. |
@Kunde21 thank you! As the PR currently stands, this will be a breaking change. As Hooks are experimental, we could argue that a breaking change is ok without bumping the major version. To make this a non-breaking change we'd be forced to convert places that currently take a What are your thoughts? @toddbaert @beeme1mr @Kavindu-Dodan @james-milligan |
This PR is a breaking change of the unstable Hooks API.
Structures implementing the Hook interface will need to be modified.
This PR
Include the go context in hook methods, to maintain the request context through the hooks and enabling request-scoped actions.
Related Issues
Fixes #159
Notes
There's no good way to pass the context from one hook call to the next in the chain. If the goal is to use hooks like HTTP middleware or gRPC interceptors, then this breaks the pattern.