interceptors

package
v1.53.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 9, 2026 License: AGPL-3.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewErrorRecorderInterceptor

func NewErrorRecorderInterceptor(registry ErrorRecorder) connect.UnaryInterceptorFunc

NewErrorRecorderInterceptor returns a ConnectRPC unary interceptor that records errors as OTel span events with the error message, first 5 stack frames, and RPC procedure name. It is safe to use when OTel is not configured (span.IsRecording() returns false and the span recording block is a no-op).

When registry is non-nil, every error is also persisted to SQLite via registry.Record for the /ListErrors and /AcknowledgeError RPCs.

func NewFeatureFlagInterceptor

func NewFeatureFlagInterceptor(flagName string, isEnabled func() bool) connect.UnaryInterceptorFunc

NewFeatureFlagInterceptor returns a ConnectRPC unary interceptor that returns connect.CodeNotFound when isEnabled reports false. Use this to gate an entire service handler behind a runtime feature flag so that unauthenticated API calls are rejected even if the caller bypasses the frontend redirect.

isEnabled is called on every request so flag changes are reflected immediately without a server restart. The recommended implementation is:

func() bool { return config.LoadConfig().GetFeatureFlag("backlog") }

func NewScopedFeatureFlagInterceptor added in v1.42.0

func NewScopedFeatureFlagInterceptor(flagName string, isEnabled func() bool, gatedMethods ...string) connect.UnaryInterceptorFunc

NewScopedFeatureFlagInterceptor returns a ConnectRPC unary interceptor that gates only the given RPC method names behind a runtime feature flag, letting every other method on the same service handler through unconditionally. Use this when a service mixes read-only RPCs (which should always be reachable) with mutating RPCs that are still gated behind a rollout flag -- registering NewFeatureFlagInterceptor on the whole handler would incorrectly gate the read-only methods too.

gatedMethods holds bare RPC method names (e.g. "CommitImportExternalSession"), not full procedure paths -- this matches against the last path segment of connect.Spec().Procedure ("/pkg.Service/MethodName").

Returns connect.CodeUnimplemented (rather than CodeNotFound, see NewFeatureFlagInterceptor) since a gated mutating RPC on an otherwise-live service reads more accurately as "not yet available" than "not found".

Types

type ErrorRecorder

type ErrorRecorder interface {
	Record(ctx context.Context, err error, procedure string)
}

ErrorRecorder is the minimal interface the interceptor needs to persist errors. Implemented by *services.ErrorRegistry; using an interface avoids a circular import.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL