propagate

package
v0.9.0 Latest Latest
Warning

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

Go to latest
Published: Jan 28, 2026 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ExtractAttrs

func ExtractAttrs(ctx context.Context, _ time.Time, _ slog.Level, _ string) []slog.Attr

ExtractAttrs is a slogctx Extractor that must be used with a slogctx.Handler (via slogctx.HandlerOptions) as Prependers or Appenders. It will cause the Handler to add the Attributes added by slogctx.Add() to all log lines using that same context.

func Init

func Init(parent context.Context) context.Context

Init initializes a context that allows propagating attributes from child context back to parents. Essentially, it lets you collect slog attributes that are discovered later in the stack (such as authentication and user ID's, derived values, attributes only discovered halfway-through the final request handler after several db queries, etc), and be able to have them be included in the log lines of other middlewares (such as a middleware that logs all requests that come in). For a ready-to-use http middleware that implements this feature, see package github.com/veqryn/slog-context/http

func With

func With(ctx context.Context, args ...any) context.Context

With adds the provided attributes to the context and propagates them to parent contextes. If propagation wasn't initialized on the context via a Init(), it will initialize at this point, followed by adding the attributes to it.

Types

This section is empty.

Jump to

Keyboard shortcuts

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