correlation

package
v2.60.0 Latest Latest
Warning

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

Go to latest
Published: Sep 28, 2026 License: MIT Imports: 4 Imported by: 0

Documentation

Overview

Package correlation provides correlation ID propagation via context.

Index

Constants

View Source
const MaxIDLen = 255

MaxIDLen is the maximum number of characters accepted for an incoming correlation ID. Longer values are treated as absent by Sanitize.

Variables

This section is empty.

Functions

func ExtractFromContext

func ExtractFromContext(ctx context.Context) string

ExtractFromContext returns the correlation ID stored in ctx, or an empty string if none is present.

func InjectToContext

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

InjectToContext returns a copy of ctx with the correlation ID set.

func Sanitize added in v2.58.0

func Sanitize(id string) string

Sanitize returns id trimmed of surrounding whitespace when it is a valid correlation ID, or a freshly generated UUID otherwise. An ID is valid when it is non-empty, at most MaxIDLen characters, and consists only of [a-zA-Z0-9_-]. This prevents log injection and downstream poisoning from caller-supplied values.

Transport packages (httpserver, grpcserver) apply this to the incoming header so every transport enforces the same rule.

Types

This section is empty.

Jump to

Keyboard shortcuts

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