logctx

package
v0.0.21 Latest Latest
Warning

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

Go to latest
Published: Oct 26, 2026 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Package logctx provides shared context utilities for logger sub-packages.

This package exists to avoid import cycles between the parent logger package and its sub-packages (zap, stdlib). Both the parent and sub-packages import this package for context key definitions and PII redaction.

Index

Constants

View Source
const StacktraceKey = "stacktrace"

StacktraceKey is the attribute key under which the captured stack is logged.

Variables

This section is empty.

Functions

func CorrelationID

func CorrelationID(ctx context.Context) string

CorrelationID extracts the correlation ID from context. Returns empty string if no correlation ID is present.

func NewStacktraceHandler

func NewStacktraceHandler(inner slog.Handler, minLevel slog.Level) slog.Handler

NewStacktraceHandler returns a handler that appends a captured stack trace to records logged at or above minLevel. Records below the threshold pass through unchanged.

func RedactPII

func RedactPII(s string) string

RedactPII replaces PII (email, phone, SSN, IPv4, auth tokens) with "[REDACTED]" in a single pass.

func SpanID

func SpanID(ctx context.Context) string

SpanID extracts the OpenTelemetry span ID from context. Returns the hex-encoded span ID string if a valid span context is present, empty string otherwise. This enables drill-down from log entries to specific spans within a trace.

func TraceID

func TraceID(ctx context.Context) string

TraceID extracts the OpenTelemetry trace ID from context. Returns the hex-encoded trace ID string if a valid span context is present, empty string otherwise. This enables log-trace correlation in Grafana (Loki → Tempo linking).

func WithCorrelationID

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

WithCorrelationID returns a context with the given correlation ID.

Types

This section is empty.

Jump to

Keyboard shortcuts

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