Select execution observers from context

This commit is contained in:
2026-11-22 18:07:17 +00:00
parent f762c0358e
commit ea7cc170ad
6 changed files with 104 additions and 6 deletions

View File

@@ -195,6 +195,22 @@ func (r *Recorder) deliver(event domain.ExecutionEvent) {
type contextKey struct{}
type observerKey struct{}
// WithObserver adds an observer to the inherited contextual selection.
func WithObserver(ctx context.Context, observer domain.ExecutionObserver) context.Context {
if observer == nil {
return ctx
}
return context.WithValue(ctx, observerKey{}, Compose(ObserverFromContext(ctx), observer))
}
// ObserverFromContext returns the contextual observer selection, if any.
func ObserverFromContext(ctx context.Context) domain.ExecutionObserver {
observer, _ := ctx.Value(observerKey{}).(domain.ExecutionObserver)
return observer
}
// WithoutExecutionState starts a public operation without inheriting another
// invocation's recorder or prepared-claim sink. Other context values and all
// cancellation/deadline behavior remain with the caller's context.