observability

package
v0.80.0 Latest Latest
Warning

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

Go to latest
Published: Feb 1, 2026 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// LogFieldRequestID is the field name for request ID.
	LogFieldRequestID = "request_id"
	// LogFieldUserID is the field name for user ID.
	LogFieldUserID = "user_id"
	// LogFieldAgentType is the field name for agent type.
	LogFieldAgentType = "agent_type"
	// LogFieldDuration is the field name for duration in milliseconds.
	LogFieldDuration = "duration_ms"
	// LogFieldMessageLen is the field name for message length.
	LogFieldMessageLen = "message_length"
	// LogFieldErrorCode is the field name for error code.
	LogFieldErrorCode = "error_code"
	// LogFieldEventType is the field name for event type.
	LogFieldEventType = "event_type"
	// LogFieldIteration is the field name for iteration count.
	LogFieldIteration = "iteration"
)

Variables

This section is empty.

Functions

func WithRequestContext

func WithRequestContext(ctx context.Context, reqCtx *RequestContext) context.Context

WithRequestContext adds the request context to the context.

Types

type RequestContext

type RequestContext struct {
	StartTime time.Time
	Logger    *slog.Logger
	RequestID string
	AgentType string
	UserID    int32
}

RequestContext represents the context for a single request with structured logging.

func FromContext

func FromContext(ctx context.Context) (*RequestContext, bool)

FromContext extracts the request context from the context.

func MustFromContext

func MustFromContext(ctx context.Context) *RequestContext

MustFromContext extracts the request context from the context or panics.

func NewRequestContext

func NewRequestContext(logger *slog.Logger, agentType string, userID int32) *RequestContext

NewRequestContext creates a new request context with a generated request ID.

func NewRequestContextWithID

func NewRequestContextWithID(logger *slog.Logger, requestID, agentType string, userID int32) *RequestContext

NewRequestContextWithID creates a new request context with a specific request ID.

func (*RequestContext) Debug

func (r *RequestContext) Debug(msg string, attrs ...slog.Attr)

Debug logs a debug message.

func (*RequestContext) Duration

func (r *RequestContext) Duration() time.Duration

Duration returns the elapsed time since the request started.

func (*RequestContext) DurationMs

func (r *RequestContext) DurationMs() int64

DurationMs returns the elapsed time in milliseconds.

func (*RequestContext) Error

func (r *RequestContext) Error(msg string, err error, attrs ...slog.Attr)

Error logs an error message with the error.

func (*RequestContext) Info

func (r *RequestContext) Info(msg string, attrs ...slog.Attr)

Info logs an info message.

func (*RequestContext) Warn

func (r *RequestContext) Warn(msg string, attrs ...slog.Attr)

Warn logs a warning message.

func (*RequestContext) WithFields

func (r *RequestContext) WithFields(attrs ...slog.Attr) *slog.Logger

WithFields returns a new logger with additional fields.

Jump to

Keyboard shortcuts

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