Documentation
¶
Index ¶
- Constants
- func IncomingTraceIDFromContext(ctx context.Context) string
- func TraceIDFromContext(ctx context.Context) string
- func WithIncomingTraceID(ctx context.Context, traceID string) context.Context
- func WithTraceID(ctx context.Context, traceID string) context.Context
- type ConsumeHandler
- type ConsumeMiddleware
- type PublishHandler
- type PublishMiddleware
Constants ¶
const ( // OrderRecover wraps outermost so it captures panics from every other // middleware and from the handler. OrderRecover = -100 // OrderTracing runs early so the trace context it installs is visible // to logging, metrics, and the handler. OrderTracing = -50 // OrderLogging runs after tracing so log lines can carry the trace ID. OrderLogging = -25 // OrderMetrics measures the handler plus the inner middlewares. OrderMetrics = 0 // OrderInbox runs innermost so the dedupe decision sits closest to the // handler's side effects. OrderInbox = 100 )
Built-in middleware ordering. Lower Order wraps further out (runs earlier on the way in, later on the way out); equal Order preserves registration order. Custom middleware can position itself relative to these reference points.
Variables ¶
This section is empty.
Functions ¶
func IncomingTraceIDFromContext ¶ added in v0.28.0
IncomingTraceIDFromContext returns the trace ID supplied by the cross-process producer when strict mode is in effect; in the default (trusting) mode it returns "" because the producer-supplied value is already used as the active TraceIDFromContext.
func TraceIDFromContext ¶ added in v0.28.0
TraceIDFromContext returns the active trace ID stamped onto ctx by the Tracing consume middleware. In the default (trusting) mode this is the value the producer sent; in strict mode it is a freshly generated, non-spoofable ID.
func WithIncomingTraceID ¶ added in v0.28.0
WithIncomingTraceID parks the producer-supplied (untrusted) trace ID on ctx. Strict-mode tracing uses this so audit pipelines can distinguish a forged incoming ID from the framework-generated active ID.
Types ¶
type ConsumeHandler ¶
ConsumeHandler is the inner function a ConsumeMiddleware wraps. The Delivery is exposed so middleware can inspect Attempt counts and Ack/Nack the message directly (e.g. inbox dedupe).
func ChainConsume ¶
func ChainConsume(mws []ConsumeMiddleware, caps transport.Capabilities, base ConsumeHandler) ConsumeHandler
ChainConsume composes consume middlewares filtered by transport capabilities, by ascending Order so the lowest Order becomes the outermost wrapper; equal Order keeps registration order. Nil and non-applicable entries are skipped (see ChainPublish).
type ConsumeMiddleware ¶
type ConsumeMiddleware interface {
// Name identifies the middleware for diagnostics.
Name() string
// Order sets the middleware's chain position. Lower values wrap
// further out; equal values keep registration order. See the Order*
// constants.
Order() int
// Applies reports whether the middleware should attach to a
// transport with the given capabilities. For example, Inbox
// returns false on non-AtLeastOnce transports to avoid pointless
// database writes.
Applies(caps transport.Capabilities) bool
// WrapConsume returns a new handler that wraps next.
WrapConsume(next ConsumeHandler) ConsumeHandler
}
ConsumeMiddleware augments the consume pipeline. Implementations run before the user-registered handler and may transform context, log, dedupe, capture metrics, recover panics, etc.
type PublishHandler ¶
PublishHandler is the inner function a PublishMiddleware wraps.
func ChainPublish ¶
func ChainPublish(mws []PublishMiddleware, base PublishHandler) PublishHandler
ChainPublish composes middlewares by ascending Order so the lowest Order becomes the outermost wrapper; equal Order keeps registration order. Nil entries are skipped so opt-out constructors (returning nil under disabled feature flags) compose safely with fx groups.
type PublishMiddleware ¶
type PublishMiddleware interface {
// Name identifies the middleware for diagnostics.
Name() string
// Order sets the middleware's chain position. Lower values wrap
// further out; equal values keep registration order. See the Order*
// constants.
Order() int
// WrapPublish returns a new handler that wraps next with the
// middleware's behavior.
WrapPublish(next PublishHandler) PublishHandler
}
PublishMiddleware augments the publish pipeline. Implementations can mutate the Envelope (e.g. inject tracing headers) before invoking next, or short-circuit by returning without calling next.