fctx

package
v0.16.1 Latest Latest
Warning

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

Go to latest
Published: Jul 9, 2026 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Fields added in v0.16.0

func Fields(ctx context.Context) []zap.Field

Fields returns the correlation fields for ctx, shared by middleware, the recover handler, and worker seeds. They are discrete, indexable log fields (not the traceparent wire header) so the backend can query by trace_id.

func From

func From(ec echo.Context) context.Context

From returns the request-scoped context.Context from an echo.Context.

Call this once at the handler boundary; downstream code should accept context.Context, not echo.Context.

func Logger

func Logger(ctx context.Context) *zap.Logger

Logger returns the request-scoped *zap.Logger from ctx. Returns a no-op logger if none was registered.

func Middleware

func Middleware(logger *zap.Logger, tracer trace.Tracer) echo.MiddlewareFunc

Middleware injects logger, tracer, and request ID into the request's context.Context, making them available via Logger, Tracer, and RequestID.

tracer may be nil (tracing disabled). Tracer returns a no-op fallback.

func MustLogger

func MustLogger(ctx context.Context) *zap.Logger

MustLogger returns the request-scoped *zap.Logger from ctx. Panics if no logger is present. Use in code that must fail fast when context is misconfigured.

func NewRequestID added in v0.16.0

func NewRequestID() string

NewRequestID returns a fresh UUIDv4 request id

func RequestID

func RequestID(ctx context.Context) string

RequestID returns the request ID from ctx. Returns "" if no request ID is present.

func Tracer

func Tracer(ctx context.Context) trace.Tracer

Tracer returns the OTel tracer from ctx. Returns a no-op tracer if none was registered, no spans are produced.

func TracerFrom added in v0.16.0

func TracerFrom(ctx context.Context) (trace.Tracer, bool)

TracerFrom returns the tracer stored in ctx and whether one was set, for callers that want their own fallback instead of Tracer's no-op.

func WithLogger

func WithLogger(ctx context.Context, l *zap.Logger) context.Context

WithLogger stores the logger in ctx.

func WithNewRequestID added in v0.16.0

func WithNewRequestID(ctx context.Context) context.Context

WithNewRequestID stores a fresh request id in ctx. Use it to seed correlation for work that has no inbound request (background jobs, cron).

func WithRequestID

func WithRequestID(ctx context.Context, id string) context.Context

WithRequestID stores the request ID in ctx.

func WithTracer

func WithTracer(ctx context.Context, t trace.Tracer) context.Context

WithTracer stores the tracer in ctx.

Types

This section is empty.

Jump to

Keyboard shortcuts

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