observability

package
v0.1.4 Latest Latest
Warning

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

Go to latest
Published: Nov 13, 2021 License: Apache-2.0 Imports: 9 Imported by: 40

README

Observability

Logging

Logging controls

export LOG_ENABLED=true
# DEBUG, INFO, WARN, ERROR
export LOG_LEVEL=INFO
Logging Usage
  • "Exit" - Exits
  • "Fatal" - Panics
  • "Debug"
  • "Info"
  • "Warn"
  • "Error"

observability.Logger(ctx, "Info", "my string"))

Correlation and Causation

Set or generate causation and correlationids to allow tracking of log messages across technical domains (apis & events)

Timing

func (timer *Timer) Start(timing bool, str string) {
func (timer *Timer) EndAndPrint(timing bool) {
func (timer *Timer) EndAndPrintStderr(timing bool) {
timingOn := true // toggle, eg set via environment variable
t1 := observability.Timer{}
t1.Start(timingOn, fmt.Sprintf("loadImageFromFile=%s", path))
// do stuff
t1.EndAndPrintStderr(timingOn)

Write memory consumption to log output

observability.LogMemory("Info")

Metrics

func (ms *Metrics) setKeyValue(key string, m Metric)
func (ms *Metrics) SetDuration(key string, d time.Duration)
func (ms *Metrics) SetInteger(key string, i int)
func (ms *Metrics) SetFloat(key string, f float64)
func (ms *Metrics) Dump()
type a {
    metrics     observability.Metrics
}

a.metrics.Init()

t1 = time.Now()
// Do load
count++
t2 = time.Now()
ela = t2.Sub(t1)
a.metrics.SetInteger("LOAD_COUNT", count)
a.metrics.SetDuration("LOAD_TOTAL_TIME_S", ela)

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ClearCausationId

func ClearCausationId(ctx context.Context) context.Context

ClearCausationId -

func ClearCorrId

func ClearCorrId(ctx context.Context) context.Context

ClearCorrId -

func Debug

func Debug(ctx context.Context, logString string)

func Debugf

func Debugf(ctx context.Context, s string, i ...interface{})

Logger is externalised for first level caller that doesnt care

func Error

func Error(ctx context.Context, logString string)

func Errorf

func Errorf(ctx context.Context, s string, i ...interface{})

func Fatal

func Fatal(ctx context.Context, logString string)

func Fatalf

func Fatalf(ctx context.Context, s string, i ...interface{})

func GenCausationId

func GenCausationId(ctx context.Context) context.Context

GenCausationId -

func GenCorrId

func GenCorrId(ctx context.Context) context.Context

GenCorrId -

func GetAppName added in v0.1.1

func GetAppName(ctx context.Context) string

func GetCausationId

func GetCausationId(ctx context.Context) string

GetCausationId -

func GetContextStringValue added in v0.1.1

func GetContextStringValue(ctx context.Context, key ContextType) (val string)

func GetCorrId

func GetCorrId(ctx context.Context) string

GetCorrId -

func Info

func Info(ctx context.Context, logString string)

func Infof

func Infof(ctx context.Context, s string, i ...interface{})

func IsLogEnabled added in v0.1.1

func IsLogEnabled(ctx context.Context) bool

func LogEnvVars

func LogEnvVars(ctx context.Context)

func LogMemory

func LogMemory(ctx context.Context, loggingType LoggingType)

LogMemory prints memory usage to the trace

func SetAppName

func SetAppName(ctx context.Context, s string) context.Context

func SetCausationId

func SetCausationId(ctx context.Context, s string) context.Context

SetCausationId -

func SetContextStringValue added in v0.1.1

func SetContextStringValue(ctx context.Context, key ContextType, value string) context.Context

func SetCorrId

func SetCorrId(ctx context.Context, s string) context.Context

SetCorrId -

func SetLogEnabled added in v0.1.1

func SetLogEnabled(ctx context.Context, s LoggingEnabled) context.Context

func SetLogLevel added in v0.1.1

func SetLogLevel(ctx context.Context, s LoggingType) context.Context

func Warn

func Warn(ctx context.Context, logString string)

func Warnf

func Warnf(ctx context.Context, s string, i ...interface{})

Types

type Caller

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

Caller is externalised

func (*Caller) Get

func (caller *Caller) Get(n int) string

Get calls internal function get

type ContextType added in v0.1.1

type ContextType string
const (
	CONTEXT_APPNAME        ContextType = "appName"
	CONTEXT_CAUSATION_ID   ContextType = "causationId"
	CONTEXT_CORRELATION_ID ContextType = "correlationId"
	CONTEXT_LOG_ENABLED    ContextType = "LOG_ENABLED"
	CONTEXT_LOG_LEVEL      ContextType = "LOG_LEVEL"
)

type LoggingEnabled added in v0.1.2

type LoggingEnabled string
const (
	LOGGING_ON  LoggingEnabled = "TRUE"
	LOGGING_OFF LoggingEnabled = "FALSE"
)

type LoggingType added in v0.1.1

type LoggingType string
const (
	LOGGING_DEBUG LoggingType = "DEBUG"
	LOGGING_INFO  LoggingType = "INFO"
	LOGGING_WARN  LoggingType = "WARN"
	LOGGING_ERROR LoggingType = "ERROR"
	LOGGING_FATAL LoggingType = "FATAL"
	LOGGING_PANIC LoggingType = "PANIC"
	LOGGING_EXIT  LoggingType = "EXIT"
)

func GetLogLevel added in v0.1.1

func GetLogLevel(ctx context.Context) LoggingType

type Metric

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

Metric type to contain observations

type MetricTypeID

type MetricTypeID uint8

MetricTypeID gives the type of the metric

type Metrics

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

Metrics type to contain observations

func (*Metrics) Dump

func (ms *Metrics) Dump(ctx context.Context)

Dump values

func (*Metrics) Init

func (ms *Metrics) Init()

Init the map

func (*Metrics) SetDuration

func (ms *Metrics) SetDuration(key string, d time.Duration)

SetDuration blah

func (*Metrics) SetFloat

func (ms *Metrics) SetFloat(key string, f float64)

SetFloat blah

func (*Metrics) SetInteger

func (ms *Metrics) SetInteger(key string, i int)

SetInteger blah

type Timer

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

Timer holds start and end times

func (*Timer) EndAndPrint

func (timer *Timer) EndAndPrint(ctx context.Context, timing bool)

EndAndPrint ends the timer and prints the number of seconds

func (*Timer) EndAndPrintStderr

func (timer *Timer) EndAndPrintStderr(ctx context.Context, timing bool)

EndAndPrintStderr ends the timer and prints the number of seconds

func (*Timer) Start

func (timer *Timer) Start(timing bool, str string)

Start starts the timer

Jump to

Keyboard shortcuts

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