trace: github.com/gravitational/trace Index | Files | Directories

package trace

import "github.com/gravitational/trace"

Package trace implements utility functions for capturing logs

Package trace implements utility functions for capturing debugging information about file and line in error reports and logs.

Index

Package Files

errors.go httplib.go log.go trace.go udphook.go

Constants

const (
    // FileField is a field with code file added to structured traces
    FileField = "file"
    // FunctionField is a field with function name
    FunctionField = "func"
    // LevelField returns logging level as set by logrus
    LevelField = "level"
    // Component is a field that represents component - e.g. service or
    // function
    Component = "trace.component"
    // ComponentFields is a fields component
    ComponentFields = "trace.fields"
    // DefaultComponentPadding is a default padding for component field
    DefaultComponentPadding = 11
    // DefaultLevelPadding is a default padding for level field
    DefaultLevelPadding = 4
)
const (
    // UDPDefaultAddr is a default address to emit logs to
    UDPDefaultAddr = "127.0.0.1:5000"
    // UDPDefaultNet is a default network
    UDPDefaultNet = "udp"
)

func AccessDenied Uses

func AccessDenied(message string, args ...interface{}) error

AccessDenied returns new instance of AccessDeniedError

func AlreadyExists Uses

func AlreadyExists(message string, args ...interface{}) error

AlreadyExists returns a new instance of AlreadyExists error

func BadParameter Uses

func BadParameter(message string, args ...interface{}) error

BadParameter returns a new instance of BadParameterError

func CompareFailed Uses

func CompareFailed(message string, args ...interface{}) error

CompareFailed returns new instance of CompareFailedError

func ConnectionProblem Uses

func ConnectionProblem(err error, message string, args ...interface{}) error

ConnectionProblem returns new instance of ConnectionProblemError

func ConvertSystemError Uses

func ConvertSystemError(err error) error

ConvertSystemError converts system error to appropriate trace error if it is possible, otherwise, returns original error

func DebugReport Uses

func DebugReport(err error) string

DebugReport returns debug report with all known information about the error including stack trace if it was captured

func ErrorToCode Uses

func ErrorToCode(err error) int

ErrorToCode returns an appropriate HTTP status code based on the provided error type

func Errorf Uses

func Errorf(format string, args ...interface{}) (err error)

Errorf is similar to fmt.Errorf except that it captures more information about the origin of error, such as callee, line number and function that simplifies debugging

func Fatalf Uses

func Fatalf(format string, args ...interface{}) error

Fatalf - If debug is false Fatalf calls Errorf. If debug is true Fatalf calls panic

func IsAccessDenied Uses

func IsAccessDenied(e error) bool

IsAccessDenied detects if this error is of AccessDeniedError type

func IsAggregate Uses

func IsAggregate(err error) bool

IsAggregate returns whether this error of Aggregate error type

func IsAlreadyExists Uses

func IsAlreadyExists(e error) bool

IsAlreadyExists returns whether this is error indicating that object already exists

func IsBadParameter Uses

func IsBadParameter(e error) bool

IsBadParameter returns whether this error is of BadParameterType

func IsCompareFailed Uses

func IsCompareFailed(e error) bool

IsCompareFailed detects if this error is of CompareFailed type

func IsConnectionProblem Uses

func IsConnectionProblem(e error) bool

IsConnectionProblem returns whether this error is of ConnectionProblemError

func IsDebug Uses

func IsDebug() bool

IsDebug returns true if debug mode is on, false otherwize

func IsEOF Uses

func IsEOF(e error) bool

IsEOF returns true if the passed error is io.EOF

func IsLimitExceeded Uses

func IsLimitExceeded(e error) bool

IsLimitExceeded detects if this error is of LimitExceededError

func IsNotFound Uses

func IsNotFound(e error) bool

IsNotFound returns whether this error is of NotFoundError type

func IsNotImplemented Uses

func IsNotImplemented(e error) bool

IsNotImplemented returns whether this error is of NotImplementedError type

func IsOAuth2 Uses

func IsOAuth2(e error) bool

IsOAuth2 returns if this is a OAuth2-related error

func IsRetryError Uses

func IsRetryError(e error) bool

IsRetryError returns whether this error is of ConnectionProblemError

func IsTrustError Uses

func IsTrustError(e error) bool

IsTrustError returns if this is a trust error

func LimitExceeded Uses

func LimitExceeded(message string, args ...interface{}) error

LimitExceeded returns whether new instance of LimitExceededError

func NewAggregate Uses

func NewAggregate(errs ...error) error

NewAggregate creates a new aggregate instance from the specified list of errors

func NewAggregateFromChannel Uses

func NewAggregateFromChannel(errCh chan error, ctx context.Context) error

NewAggregateFromChannel creates a new aggregate instance from the provided errors channel.

A context.Context can be passed in so the caller has the ability to cancel the operation. If this is not desired, simply pass context.Background().

func NotFound Uses

func NotFound(message string, args ...interface{}) error

NotFound returns new instance of not found error

func NotImplemented Uses

func NotImplemented(message string, args ...interface{}) error

NotImplemented returns a new instance of NotImplementedError

func ReadError Uses

func ReadError(statusCode int, re []byte) error

ReadError converts http error to internal error type based on HTTP response code and HTTP body contents if status code does not indicate error, it will return nil

func Retry Uses

func Retry(err error, message string, args ...interface{}) error

Retry return new instance of RetryError which indicates a transient error type

func SetDebug Uses

func SetDebug(enabled bool)

SetDebug turns on/off debugging mode, that causes Fatalf to panic

func Unwrap Uses

func Unwrap(err error) error

Unwrap unwraps error to it's original error

func UserMessage Uses

func UserMessage(err error) string

UserMessage returns user-friendly part of the error

func WriteError Uses

func WriteError(w http.ResponseWriter, err error)

WriteError sets up HTTP error response and writes it to writer w

type AccessDeniedError Uses

type AccessDeniedError struct {
    Message string `json:"message"`
}

AccessDeniedError indicates denied access

func (*AccessDeniedError) Error Uses

func (e *AccessDeniedError) Error() string

Error is debug - friendly error message

func (*AccessDeniedError) IsAccessDeniedError Uses

func (e *AccessDeniedError) IsAccessDeniedError() bool

IsAccessDeniedError indicates that this error is of AccessDeniedError type

func (*AccessDeniedError) OrigError Uses

func (e *AccessDeniedError) OrigError() error

OrigError returns original error (in this case this is the error itself)

type Aggregate Uses

type Aggregate interface {
    error
    // Errors obtains the list of errors this aggregate combines
    Errors() []error
}

Aggregate interface combines several errors into one error

type AlreadyExistsError Uses

type AlreadyExistsError struct {
    Message string `json:"message"`
}

AlreadyExistsError indicates that there's a duplicate object that already exists in the storage/system

func (*AlreadyExistsError) Error Uses

func (n *AlreadyExistsError) Error() string

Error returns log friendly description of an error

func (AlreadyExistsError) IsAlreadyExistsError Uses

func (AlreadyExistsError) IsAlreadyExistsError() bool

IsAlreadyExistsError indicates that this error of the AlreadyExistsError type

func (*AlreadyExistsError) OrigError Uses

func (e *AlreadyExistsError) OrigError() error

OrigError returns original error (in this case this is the error itself)

type BadParameterError Uses

type BadParameterError struct {
    Message string `json:"message"`
}

BadParameterError indicates that something is wrong with passed parameter to API method

func (*BadParameterError) Error Uses

func (b *BadParameterError) Error() string

Error returns log friendly description of an error

func (*BadParameterError) IsBadParameterError Uses

func (b *BadParameterError) IsBadParameterError() bool

IsBadParameterError indicates that this error is of BadParameterError type

func (*BadParameterError) OrigError Uses

func (b *BadParameterError) OrigError() error

OrigError returns original error (in this case this is the error itself)

type CompareFailedError Uses

type CompareFailedError struct {
    // Message is user-friendly error message
    Message string `json:"message"`
}

CompareFailedError indicates a failed comparison (e.g. bad password or hash)

func (*CompareFailedError) Error Uses

func (e *CompareFailedError) Error() string

Error is debug - friendly message

func (*CompareFailedError) IsCompareFailedError Uses

func (e *CompareFailedError) IsCompareFailedError() bool

IsCompareFailedError indicates that this is CompareFailedError

func (*CompareFailedError) OrigError Uses

func (e *CompareFailedError) OrigError() error

OrigError returns original error (in this case this is the error itself)

type ConnectionProblemError Uses

type ConnectionProblemError struct {
    Message string `json:"message"`
    Err     error  `json:"-"`
}

ConnectionProblemError indicates a network related problem

func (*ConnectionProblemError) Error Uses

func (c *ConnectionProblemError) Error() string

Error is debug - friendly error message

func (*ConnectionProblemError) IsConnectionProblemError Uses

func (c *ConnectionProblemError) IsConnectionProblemError() bool

IsConnectionProblemError indicates that this error is of ConnectionProblemError type

func (*ConnectionProblemError) OrigError Uses

func (c *ConnectionProblemError) OrigError() error

OrigError returns original error (in this case this is the error itself)

type Error Uses

type Error interface {
    error
    // OrigError returns original error wrapped in this error
    OrigError() error
    // AddMessage adds formatted user-facing message
    // to the error, depends on the implementation,
    // usually works as fmt.Sprintf(formatArg, rest...)
    // but implementations can choose another way, e.g. treat
    // arguments as structured args
    AddUserMessage(formatArg interface{}, rest ...interface{})

    // UserMessage returns user-friendly error message
    UserMessage() string

    // DebugReport returns develeoper-friendly error report
    DebugReport() string
}

Error is an interface that helps to adapt usage of trace in the code When applications define new error types, they can implement the interface So error handlers can use OrigError() to retrieve error from the wrapper

func OAuth2 Uses

func OAuth2(code, message string, query url.Values) Error

OAuth2 returns new instance of OAuth2Error

func Wrap Uses

func Wrap(err error, args ...interface{}) Error

Wrap takes the original error and wraps it into the Trace struct memorizing the context of the error.

func WrapWithMessage Uses

func WrapWithMessage(err error, message interface{}, args ...interface{}) Error

WrapWithMessage wraps the original error into Error and adds user message if any

type Frame Uses

type Frame struct {
    Time    time.Time              `json:"time"`
    Type    string                 `json:"type"`
    Entry   map[string]interface{} `json:"entry"`
    Message string                 `json:"message"`
    Level   string                 `json:"level"`
}

type JSONFormatter Uses

type JSONFormatter struct {
    log.JSONFormatter
}

JSONFormatter implements logrus.Formatter interface and adds file and line properties to JSON entries

func (*JSONFormatter) Format Uses

func (j *JSONFormatter) Format(e *log.Entry) ([]byte, error)

Format implements logrus.Formatter interface

type LimitExceededError Uses

type LimitExceededError struct {
    Message string `json:"message"`
}

LimitExceededError indicates rate limit or connection limit problem

func (*LimitExceededError) Error Uses

func (c *LimitExceededError) Error() string

Error is debug - friendly error message

func (*LimitExceededError) IsLimitExceededError Uses

func (c *LimitExceededError) IsLimitExceededError() bool

IsLimitExceededError indicates that this error is of ConnectionProblem

func (*LimitExceededError) OrigError Uses

func (c *LimitExceededError) OrigError() error

OrigError returns original error (in this case this is the error itself)

type NotFoundError Uses

type NotFoundError struct {
    Message string `json:"message"`
}

NotFoundError indicates that object has not been found

func (*NotFoundError) Error Uses

func (e *NotFoundError) Error() string

Error returns log friendly description of an error

func (*NotFoundError) IsNotFoundError Uses

func (e *NotFoundError) IsNotFoundError() bool

IsNotFoundError returns true to indicate that is NotFoundError

func (*NotFoundError) OrigError Uses

func (e *NotFoundError) OrigError() error

OrigError returns original error (in this case this is the error itself)

type NotImplementedError Uses

type NotImplementedError struct {
    Message string `json:"message"`
}

NotImplementedError defines an error condition to describe the result of a call to an unimplemented API

func (*NotImplementedError) Error Uses

func (e *NotImplementedError) Error() string

Error returns log friendly description of an error

func (*NotImplementedError) IsNotImplementedError Uses

func (e *NotImplementedError) IsNotImplementedError() bool

IsNotImplementedError indicates that this error is of NotImplementedError type

func (*NotImplementedError) OrigError Uses

func (e *NotImplementedError) OrigError() error

OrigError returns original error

type OAuth2Error Uses

type OAuth2Error struct {
    Code    string     `json:"code"`
    Message string     `json:"message"`
    Query   url.Values `json:"query"`
}

OAuth2Error defined an error used in OpenID Connect Flow (OIDC)

func (*OAuth2Error) Error Uses

func (o *OAuth2Error) Error() string

Error returns log friendly description of an error

func (*OAuth2Error) IsOAuth2Error Uses

func (o *OAuth2Error) IsOAuth2Error() bool

IsOAuth2Error returns whether this error of OAuth2Error type

type RawTrace Uses

type RawTrace struct {
    Err     json.RawMessage `json:"error"`
    Traces  `json:"traces"`
    Message string `json:"message"`
}

type RetryError Uses

type RetryError struct {
    Message string `json:"message"`
    Err     error  `json:"-"`
}

RetryError indicates a transient error type

func (*RetryError) Error Uses

func (c *RetryError) Error() string

Error is debug-friendly error message

func (*RetryError) IsRetryError Uses

func (c *RetryError) IsRetryError() bool

IsRetryError indicates that this error is of RetryError type

func (*RetryError) OrigError Uses

func (c *RetryError) OrigError() error

OrigError returns original error (in this case this is the error itself)

type TextFormatter Uses

type TextFormatter struct {
    // DisableTimestamp disables timestamp output (useful when outputting to
    // systemd logs)
    DisableTimestamp bool
    // ComponentPadding is a padding to pick when displaying
    // and formatting component field, defaults to DefaultComponentPadding
    ComponentPadding int
}

TextFormatter is logrus-compatible formatter and adds file and line details to every logged entry.

func (*TextFormatter) Format Uses

func (tf *TextFormatter) Format(e *log.Entry) (data []byte, err error)

Format implements logrus.Formatter interface and adds file and line

type Trace Uses

type Trace struct {
    // Path is a full file path
    Path string `json:"path"`
    // Func is a function name
    Func string `json:"func"`
    // Line is a code line number
    Line int `json:"line"`
}

Trace stores structured trace entry, including file line and path

func (*Trace) String Uses

func (t *Trace) String() string

String returns debug-friendly representation of this trace

type TraceErr Uses

type TraceErr struct {
    Err     error `json:"error"`
    Traces  `json:"traces"`
    Message string `json:"message,omitemtpy"`
}

TraceErr contains error message and some additional information about the error origin

func (*TraceErr) AddUserMessage Uses

func (e *TraceErr) AddUserMessage(formatArg interface{}, rest ...interface{})

AddUserMessage adds user-friendly message describing the error nature

func (*TraceErr) DebugReport Uses

func (e *TraceErr) DebugReport() string

DebugReport returns develeoper-friendly error report

func (*TraceErr) Error Uses

func (e *TraceErr) Error() string

Error returns user-friendly error message when not in debug mode

func (*TraceErr) GoString Uses

func (e *TraceErr) GoString() string

GoString formats this trace object for use with with the "%#v" format string

func (*TraceErr) OrigError Uses

func (e *TraceErr) OrigError() error

OrigError returns original wrapped error

func (*TraceErr) UserMessage Uses

func (e *TraceErr) UserMessage() string

UserMessage returns user-friendly error message

type Traces Uses

type Traces []Trace

Traces is a list of trace entries

func (Traces) Func Uses

func (s Traces) Func() string

Func returns first function in trace list

func (Traces) FuncName Uses

func (s Traces) FuncName() string

Func returns just function name

func (Traces) Loc Uses

func (s Traces) Loc() string

Loc points to file/line location in the code

func (Traces) SetTraces Uses

func (s Traces) SetTraces(traces ...Trace)

SetTraces adds new traces to the list

func (Traces) String Uses

func (s Traces) String() string

String returns debug-friendly representaton of trace stack

type TrustError Uses

type TrustError struct {
    // Err is original error
    Err     error  `json:"-"`
    Message string `json:"message"`
}

TrustError indicates trust-related validation error (e.g. untrusted cert)

func (*TrustError) Error Uses

func (t *TrustError) Error() string

Error returns log-friendly error description

func (*TrustError) IsTrustError Uses

func (*TrustError) IsTrustError() bool

IsTrustError indicates that this error is of TrustError type

func (*TrustError) OrigError Uses

func (t *TrustError) OrigError() error

OrigError returns original error (in this case this is the error itself)

type UDPHook Uses

type UDPHook struct {
    Clock clockwork.Clock
    // contains filtered or unexported fields
}

func NewUDPHook Uses

func NewUDPHook(opts ...UDPOptionSetter) (*UDPHook, error)

NewUDPHook returns logrus-compatible hook that sends data to UDP socket

func (*UDPHook) Fire Uses

func (elk *UDPHook) Fire(e *log.Entry) error

Fire fires the event to the ELK beat

func (*UDPHook) Levels Uses

func (elk *UDPHook) Levels() []log.Level

Levels returns logging levels supported by logrus

type UDPOptionSetter Uses

type UDPOptionSetter func(f *UDPHook)

UDPOptionSetter represents functional arguments passed to ELKHook

Directories

PathSynopsis
trailPackage trail integrates trace errors with GRPC

Package trace imports 21 packages (graph) and is imported by 147 packages. Updated 2018-08-14. Refresh now. Tools for package owners.