wool

package
v0.1.139 Latest Latest
Warning

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

Go to latest
Published: Oct 7, 2024 License: MIT Imports: 23 Imported by: 7

README

Observability

Wool

Wrapper Over Open-Telemetry is accurate and has a meaningful acronym. Yarn, fiber, we are in the "context" space.

Goal of this package is to provide a Canvas that satisfies the following requirements:

Requirement:

  • context.Context based
  • opentelemetry support with flexible backend
  • logger support as Events (where opentelemetry is going) with flexible backend

Documentation

Index

Constants

View Source
const CodePathKey = "codepath"
View Source
const LogEvent = "log"
View Source
const ProviderKey = ContextKey("provider")

Variables

View Source
var ContextKeys []ContextKey
View Source
var HTTPMappings = map[string]ContextKey{
	"X-Codefly-User-Auth-Id":    UserAuthIDKey,
	"X-Codefly-User-Email":      UserEmailKey,
	"X-Codefly-User-Name":       UserNameKey,
	"X-Codefly-User-Given-Name": UserGivenNameKey,
}

Functions

func GRPCInstrumentation added in v0.1.123

func GRPCInstrumentation() []grpc.ServerOption
func Header(key ContextKey) string

func HeaderKey added in v0.1.16

func HeaderKey(header string) string

HeaderKey sanitizes the header name to be used in metadata Append wool: Lower case Suppress X-Codefly

func Headers added in v0.1.124

func Headers() []string

func InitTracer added in v0.1.123

func InitTracer() (func(context.Context) error, error)

func IsDebug added in v0.0.60

func IsDebug() bool

func IsNotFound added in v0.1.139

func IsNotFound(err error) bool

func IsUnauthorized added in v0.1.139

func IsUnauthorized(err error) bool

func MetadataFromRequest added in v0.1.123

func MetadataFromRequest(ctx context.Context, req *http.Request) metadata.MD

func NotFound added in v0.1.18

func NotFound(what ContextKey) error

func SetGlobalLogLevel added in v0.0.65

func SetGlobalLogLevel(loglevel Loglevel)

func TypeOf added in v0.0.55

func TypeOf[T any]() string

func WithTelemetry

func WithTelemetry() bool

Types

type CodePath added in v0.0.55

type CodePath struct {
	Method string      `json:"method"`
	Fields []*LogField `json:"fields"`
}

type CodeReference added in v0.0.60

type CodeReference struct {
	Line int    `json:"line"`
	File string `json:"file"`
}

func (*CodeReference) String added in v0.0.71

func (c *CodeReference) String() string

type Console added in v0.0.57

type Console struct {
	// contains filtered or unexported fields
}

func NewMessageConsole added in v0.1.89

func NewMessageConsole() *Console

func (Console) Process added in v0.0.57

func (c Console) Process(msg *Log)

type ContextKey

type ContextKey string
const (
	UserAuthIDKey    ContextKey = "codefly.user.auth.id"
	UserEmailKey     ContextKey = "codefly.user.email"
	UserNameKey      ContextKey = "codefly.user.name"
	UserGivenNameKey ContextKey = "codefly.user.given_name"
)

type GRPC added in v0.1.123

type GRPC struct {
	// contains filtered or unexported fields
}

func (*GRPC) Inject added in v0.1.123

func (grpc *GRPC) Inject() *Wool

func (*GRPC) Metadata added in v0.1.123

func (grpc *GRPC) Metadata() metadata.MD

func (*GRPC) Out added in v0.1.123

func (grpc *GRPC) Out() context.Context

type HTTP added in v0.1.123

type HTTP struct {
	// contains filtered or unexported fields
}

func (*HTTP) Headers added in v0.1.123

func (http *HTTP) Headers() http.Header

type Identifier added in v0.0.55

type Identifier struct {
	Kind   string `json:"kind"`
	Unique string `json:"unique"`
}

func System added in v0.0.67

func System() *Identifier

func (*Identifier) IsSystem added in v0.0.67

func (identifier *Identifier) IsSystem() bool

type Log

type Log struct {
	Level   Loglevel    `json:"level"`
	Header  string      `json:"header"`
	Message string      `json:"message"`
	Fields  []*LogField `json:"fields"`
}

func LogError added in v0.0.67

func LogError(err error, msg string, fields ...*LogField) *Log

func LogTrace added in v0.0.67

func LogTrace(msg string, fields ...*LogField) *Log

func (*Log) AtLevel

func (l *Log) AtLevel(debug Loglevel) *Log

func (*Log) Event

func (l *Log) Event() trace.SpanStartEventOption

func (*Log) String added in v0.0.65

func (l *Log) String() string

String display a log message into this format (level) (this) message [key=value, key=value]

type LogField

type LogField struct {
	Key   string   `json:"key"`
	Level Loglevel `json:"level"`
	Value any      `json:"value"`
}

LogField is a key value pair with a log level A Field is shown only if the log level is equal or higher than the log level of the log

func DirField added in v0.0.55

func DirField(dir string) *LogField

func ErrField added in v0.0.55

func ErrField(err error) *LogField

func Field

func Field(key string, value any) *LogField

Field with default level

func FileField added in v0.0.55

func FileField(file string) *LogField

func FocusField added in v0.0.69

func FocusField() *LogField

func GenericField added in v0.0.55

func GenericField[T any]() *LogField

func InField added in v0.0.81

func InField(s string) *LogField

func ModuleField added in v0.1.89

func ModuleField(name string) *LogField

func NameField added in v0.0.55

func NameField(name string) *LogField

func NullableField added in v0.0.81

func NullableField[T any](key string, value T) *LogField

func Path added in v0.1.114

func Path(dir string) *LogField

func PointerField added in v0.0.57

func PointerField[T any](override *T) *LogField

func RequestField added in v0.0.55

func RequestField(req any) *LogField

func ResponseField added in v0.0.67

func ResponseField(req any) *LogField

func ServiceField added in v0.1.18

func ServiceField(name string) *LogField

func SliceCountField added in v0.0.57

func SliceCountField[T any](slice []T) *LogField

func StatusFailed added in v0.0.55

func StatusFailed() *LogField

func StatusOK added in v0.0.55

func StatusOK() *LogField

func ThisField added in v0.0.55

func ThisField(this Unique) *LogField

func WorkspaceField added in v0.1.89

func WorkspaceField(name string) *LogField

func Writer added in v0.0.67

func Writer() *LogField

func (*LogField) Debug added in v0.0.67

func (f *LogField) Debug() *LogField

func (*LogField) Error added in v0.0.67

func (f *LogField) Error() *LogField

func (*LogField) String added in v0.0.57

func (f *LogField) String() string

func (*LogField) Trace added in v0.0.67

func (f *LogField) Trace() *LogField

type LogFunc added in v0.1.69

type LogFunc func(string, ...*LogField)

type LogProcessor added in v0.0.55

type LogProcessor interface {
	Process(msg *Log)
}

type LogProcessorWithSource added in v0.0.55

type LogProcessorWithSource interface {
	ProcessWithSource(source *Identifier, msg *Log)
}

type Loglevel

type Loglevel int
const (
	DEFAULT Loglevel = iota
	TRACE
	DEBUG
	FOCUS
	INFO
	WARN
	ERROR
	FATAL
	FORWARD
)

func GlobalLogLevel added in v0.0.65

func GlobalLogLevel() Loglevel

type NotFoundError added in v0.1.18

type NotFoundError struct {
	// contains filtered or unexported fields
}

func (*NotFoundError) Error added in v0.1.18

func (err *NotFoundError) Error() string

type Provider added in v0.0.55

type Provider struct {
	// contains filtered or unexported fields
}

Provider keeping track

func New

func New(ctx context.Context, r *Resource) *Provider

func (*Provider) Done added in v0.0.55

func (provider *Provider) Done()

func (*Provider) Get added in v0.0.55

func (provider *Provider) Get(ctx context.Context) *Wool

func (*Provider) Inject added in v0.0.71

func (provider *Provider) Inject(ctx context.Context) context.Context

func (*Provider) WithConsole added in v0.0.69

func (provider *Provider) WithConsole(lvl Loglevel) *Provider

func (*Provider) WithLogger added in v0.0.55

func (provider *Provider) WithLogger(l LogProcessor) *Provider

type Resource added in v0.0.55

type Resource struct {
	Resource *resource.Resource
	*Identifier
}

type Unique added in v0.0.55

type Unique interface {
	Unique() string
}

type Wool

type Wool struct {
	// contains filtered or unexported fields
}

func Get

func Get(ctx context.Context) *Wool

func (*Wool) Catch added in v0.0.55

func (w *Wool) Catch()

Catch recovers from a panic and logs the error

func (*Wool) Close added in v0.0.55

func (w *Wool) Close() error

func (*Wool) Context

func (w *Wool) Context() context.Context

func (*Wool) Debug added in v0.0.55

func (w *Wool) Debug(msg string, fields ...*LogField)

func (*Wool) DisableCatch added in v0.1.89

func (w *Wool) DisableCatch()

func (*Wool) Error added in v0.0.55

func (w *Wool) Error(msg string, fields ...*LogField)

func (*Wool) Fatal added in v0.0.55

func (w *Wool) Fatal(msg string, fields ...*LogField)

func (*Wool) Focus added in v0.0.69

func (w *Wool) Focus(msg string, fields ...*LogField)

func (*Wool) Forward added in v0.0.71

func (w *Wool) Forward(p []byte) (n int, err error)

func (*Wool) Forwardf added in v0.1.89

func (w *Wool) Forwardf(msg string, args ...any)

func (*Wool) GRPC added in v0.1.123

func (w *Wool) GRPC() *GRPC

func (*Wool) HTTP added in v0.1.123

func (w *Wool) HTTP() *HTTP

func (*Wool) In added in v0.0.55

func (w *Wool) In(method string, fields ...*LogField) *Wool

func (*Wool) Info added in v0.0.55

func (w *Wool) Info(msg string, fields ...*LogField)

func (*Wool) Inject added in v0.0.67

func (w *Wool) Inject(ctx context.Context) context.Context

func (*Wool) LogLevel added in v0.1.20

func (w *Wool) LogLevel() Loglevel

func (*Wool) Name added in v0.0.55

func (w *Wool) Name() string

func (*Wool) NewError added in v0.0.55

func (w *Wool) NewError(format string, args ...any) error

func (*Wool) Source added in v0.0.67

func (w *Wool) Source() *Identifier

func (*Wool) StackTrace added in v0.0.55

func (w *Wool) StackTrace() []CodePath

func (*Wool) Trace added in v0.0.55

func (w *Wool) Trace(msg string, fields ...*LogField)

func (*Wool) UserAuthID added in v0.1.35

func (w *Wool) UserAuthID() (string, bool)

UserAuthID returns the ID from the Auth process from the context

func (*Wool) UserEmail added in v0.1.18

func (w *Wool) UserEmail() (string, bool)

UserEmail returns the UserEmail from the context

func (*Wool) UserGivenName added in v0.1.35

func (w *Wool) UserGivenName() (string, bool)

UserGivenName returns the UserGivenName from the context

func (*Wool) UserName added in v0.1.35

func (w *Wool) UserName() (string, bool)

UserName returns the UserName from the context

func (*Wool) Warn added in v0.0.55

func (w *Wool) Warn(msg string, fields ...*LogField)

func (*Wool) With added in v0.0.60

func (w *Wool) With(fields ...*LogField) *Wool

func (*Wool) WithLogger added in v0.0.55

func (w *Wool) WithLogger(l LogProcessor) *Wool

func (*Wool) WithLoglevel added in v0.0.87

func (w *Wool) WithLoglevel(level Loglevel)

func (*Wool) WithUserAuthID added in v0.1.123

func (w *Wool) WithUserAuthID(authID string)

func (*Wool) WithUserEmail added in v0.1.123

func (w *Wool) WithUserEmail(s string)

func (*Wool) Wrap added in v0.0.55

func (w *Wool) Wrap(err error) error

func (*Wool) Wrapf added in v0.0.55

func (w *Wool) Wrapf(err error, msg string, args ...any) error

func (*Wool) Write added in v0.0.67

func (w *Wool) Write(p []byte) (n int, err error)

Writer implements the io.WriteCloser interface

Directories

Path Synopsis
adapters
log

Jump to

Keyboard shortcuts

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