s3-orchestrator

audit

import "github.com/afreidah/s3-orchestrator/internal/observe/audit"

Package audit provides request ID propagation and structured audit logging for security-relevant operations.

Index

func Log

func Log(ctx context.Context, event string, attrs ...slog.Attr)

Log emits a structured audit log entry at Info level. Automatically includes the request ID from context. If OnEvent is set, it is called with the event name for metrics integration.

func NewID

func NewID() string

NewID generates a hex-encoded 16-byte random ID suitable for request correlation. crypto/rand.Read always returns len(b) and nil error on all supported platforms (see Go docs), so no error handling is needed.

func RequestID

func RequestID(ctx context.Context) string

RequestID extracts the request ID from the context. Returns empty string if no request ID is set.

func SetOnEvent

func SetOnEvent(fn func(event string))

SetOnEvent registers a callback invoked for each audit event. Pass nil to clear a previously registered callback.

func WithRequestID

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

WithRequestID stores a request ID in the context.

Generated by gomarkdoc