Skip to content

Hooks Interface (#663)#669

Open
nikrooz wants to merge 41 commits intomainfrom
NN_hooks
Open

Hooks Interface (#663)#669
nikrooz wants to merge 41 commits intomainfrom
NN_hooks

Conversation

@nikrooz
Copy link
Copy Markdown
Contributor

@nikrooz nikrooz commented Apr 7, 2026

  • Add hooks at endpoint, service, and handler levels.
  • Split hooks into interceptor and listener: interceptors participate in execution, listeners are observational only.
  • handler interceptors run on every attempt; run interceptors run only when the ctx.run() closure actually executes, not when the result is replayed from the journal.
  • attemptEnd is the normalized attempt outcome: success, retryableError, terminalError, or abandoned.
  • Interceptors use normal try/catch/finally flow. next() may reject with AttemptAbandonedError when an attempt is suspended or otherwise ended by the SDK; this is attempt-boundary control flow, not a user failure.
  • Hooks do not modify handler inputs or return values; the API is focused on observability, context propagation, and execution boundaries.
  • Add e2e coverage for retries, replay, suspension, cancellation, failures, and composition ordering.
  • Add an OTel example for tracing and context propagation (only for testing in SDK). you can see the picture below
Screenshot 2026-04-07 at 11 24 48

@github-actions
Copy link
Copy Markdown

github-actions bot commented Apr 7, 2026

Test Results

  8 files  ±0    8 suites  ±0   2m 23s ⏱️ -22s
 53 tests ±0   53 ✅ ±0  0 💤 ±0  0 ❌ ±0 
233 runs  ±0  233 ✅ ±0  0 💤 ±0  0 ❌ ±0 

Results for commit 35ffa74. ± Comparison against base commit 32151c5.

♻️ This comment has been updated with latest results.

@nikrooz nikrooz requested a review from slinkydeveloper April 7, 2026 10:52
Copy link
Copy Markdown
Collaborator

@slinkydeveloper slinkydeveloper left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • trim down things we dont need for otel, such as:
    • listener
    • attempt abandoned error
  • remove endpoint hooks setters
  • make sure to specify exact behavior of listeners
  • move otel integration into core sdk

Comment on lines +70 to +73
public setHooksProviders(hooks: HooksProvider[]): RestateEndpoint {
this.builder.setHooksProviders(hooks);
return this;
}
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do we need this? given it's in service options, one should be able to set it from default service options

Comment on lines +23 to +26
serviceName: string;
handlerName: string;
key?: string;
invocationId: string;
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove that

nikrooz added 27 commits April 7, 2026 15:25
Signed-off-by: Nik Nasr <nik@restate.dev>
Signed-off-by: Nik Nasr <nik@restate.dev>
Signed-off-by: Nik Nasr <nik@restate.dev>
Signed-off-by: Nik Nasr <nik@restate.dev>
Signed-off-by: Nik Nasr <nik@restate.dev>
Signed-off-by: Nik Nasr <nik@restate.dev>
Signed-off-by: Nik Nasr <nik@restate.dev>
Signed-off-by: Nik Nasr <nik@restate.dev>
Signed-off-by: Nik Nasr <nik@restate.dev>
Signed-off-by: Nik Nasr <nik@restate.dev>
Signed-off-by: Nik Nasr <nik@restate.dev>
Signed-off-by: Nik Nasr <nik@restate.dev>
Signed-off-by: Nik Nasr <nik@restate.dev>
Signed-off-by: Nik Nasr <nik@restate.dev>
Signed-off-by: Nik Nasr <nik@restate.dev>
Signed-off-by: Nik Nasr <nik@restate.dev>
Signed-off-by: Nik Nasr <nik@restate.dev>
Signed-off-by: Nik Nasr <nik@restate.dev>
Signed-off-by: Nik Nasr <nik@restate.dev>
Signed-off-by: Nik Nasr <nik@restate.dev>
Signed-off-by: Nik Nasr <nik@restate.dev>
Signed-off-by: Nik Nasr <nik@restate.dev>
Signed-off-by: Nik Nasr <nik@restate.dev>
Signed-off-by: Nik Nasr <nik@restate.dev>
Signed-off-by: Nik Nasr <nik@restate.dev>
Signed-off-by: Nik Nasr <nik@restate.dev>
Signed-off-by: Nik Nasr <nik@restate.dev>
nikrooz added 9 commits April 7, 2026 15:27
Signed-off-by: Nik Nasr <nik@restate.dev>
Signed-off-by: Nik Nasr <nik@restate.dev>
Signed-off-by: Nik Nasr <nik@restate.dev>
Signed-off-by: Nik Nasr <nik@restate.dev>
Signed-off-by: Nik Nasr <nik@restate.dev>
Signed-off-by: Nik Nasr <nik@restate.dev>
Signed-off-by: Nik Nasr <nik@restate.dev>
Signed-off-by: Nik Nasr <nik@restate.dev>
Signed-off-by: Nik Nasr <nik@restate.dev>
nikrooz added 4 commits April 7, 2026 17:52
Signed-off-by: Nik Nasr <nik@restate.dev>
Signed-off-by: Nik Nasr <nik@restate.dev>
Signed-off-by: Nik Nasr <nik@restate.dev>
Signed-off-by: Nik Nasr <nik@restate.dev>
@nikrooz
Copy link
Copy Markdown
Contributor Author

nikrooz commented Apr 7, 2026

@slinkydeveloper I think your comments are addressed if you want to have another look
I'll the Otel tracing integration in another PR.

Signed-off-by: Nik Nasr <nik@restate.dev>
@slinkydeveloper
Copy link
Copy Markdown
Collaborator

@nikrooz for the tests, we wanna merge like this and you rebase on my pr later? or we merge my pr with the custom tests and you rebuild the tests on top?

@nikrooz
Copy link
Copy Markdown
Contributor Author

nikrooz commented Apr 8, 2026

@slinkydeveloper I am open either way, but I think it would be faster to get it merge and get the feature out and then refactor the test.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants