Documentation ¶
Overview ¶
Package observability for logging, tracing and exporting metrics.
Index ¶
- Constants
- func InitDefaults(appID, version, tracerEndpoint, sentryDSN string, ...)
- func SetLogger(logger Logger, fields map[string]interface{})
- func SetMetricsExporter(exporter MetricsExporter)
- func SetTracer(tracer Tracer)
- type Level
- type Logger
- type LoggerConfiguration
- type MetricsConfiguration
- type MetricsExporter
- type Operation
- type SentryEventIdentityModifier
- type SentryHook
- type Span
- type Tracer
- type TracingConfiguration
Constants ¶
const ( // DefaultMetricsCollectionInterval is 15 seconds. DefaultMetricsCollectionInterval = 15 // DefaultLogLevel is ErrorLevel. DefaultLogLevel = ErrorLevel // DefaultSamplingRate is 5%. DefaultSamplingRate = 0.05 )
Variables ¶
This section is empty.
Functions ¶
func InitDefaults ¶
InitDefaults initializes Logger, MetricsExporter and Tracer with default values.
func SetMetricsExporter ¶
func SetMetricsExporter(exporter MetricsExporter)
SetMetricsExporter sets global metrics exporter.
Types ¶
type Level ¶
type Level uint32
Level log level type.
const ( // PanicLevel level, highest level of severity. Logs and then calls panic with the // message passed to Debug, Info, ... PanicLevel Level = iota // FatalLevel level. Logs and then calls `logger.Exit(1)`. It will exit even if the // logging level is set to Panic. FatalLevel // ErrorLevel level. Logs. Used for errors that should definitely be noted. // Commonly used for hooks to send errors to an error tracking service. ErrorLevel // WarnLevel level. Non-critical entries that deserve eyes. WarnLevel // InfoLevel level. General operational entries about what's going on inside the // application. InfoLevel // DebugLevel level. Usually only enabled when debugging. Very verbose logging. DebugLevel // TraceLevel level. Designates finer-grained informational events than the Debug. TraceLevel )
These are the different logging levels. You can set the logging level to log on your instance of logger.
type Logger ¶
type Logger interface { Debug(args ...interface{}) Debugf(format string, args ...interface{}) Info(args ...interface{}) Infof(format string, args ...interface{}) Error(args ...interface{}) Errorf(format string, args ...interface{}) Warning(args ...interface{}) Warningf(format string, args ...interface{}) Panic(args ...interface{}) Panicf(format string, args ...interface{}) Fatal(args ...interface{}) Fatalf(format string, args ...interface{}) WithFields(map[string]interface{}) Logger WithField(key string, value interface{}) Logger SetLevel(level Level) }
Logger ya know, for logging.
func DefaultLogger ¶
func DefaultLogger() Logger
DefaultLogger creates instance of logger if no config provided.
type LoggerConfiguration ¶
LoggerConfiguration sets log formatter and severity.
type MetricsConfiguration ¶
type MetricsConfiguration struct {
CollectionInterval int
}
MetricsConfiguration sets metrics collection interval.
type MetricsExporter ¶
type MetricsExporter interface { HTTPHandler(w http.ResponseWriter, r *http.Request) AddOperationCall(operationID string, duration time.Duration, result interface{}, fields map[string]interface{}) Start() Stop() }
MetricsExporter interface.
func GetMetricsExporter ¶
func GetMetricsExporter() MetricsExporter
GetMetricsExporter returns global MetricsExporter or nil, if it wasn't initialized.
func NewMetricsExporter ¶
func NewMetricsExporter(config MetricsConfiguration, fields map[string]interface{}) MetricsExporter
NewMetricsExporter initializes new prometheus exporter.
type Operation ¶
type Operation interface {
End(result interface{})
}
Operation contains all info to log, trace and gather metrics about concrete operation.
type SentryEventIdentityModifier ¶
type SentryEventIdentityModifier struct{}
SentryEventIdentityModifier is a sentry event modifier that simply passes through the event.
func (*SentryEventIdentityModifier) ApplyToEvent ¶
func (m *SentryEventIdentityModifier) ApplyToEvent(event *sentry.Event, hint *sentry.EventHint) *sentry.Event
ApplyToEvent simply returns the event (ignoring the hint).
type SentryHook ¶
type SentryHook struct {
// contains filtered or unexported fields
}
SentryHook implements logrus.Hook to send errors to sentry.
func NewSentryHook ¶
func NewSentryHook(dsn, release string) (*SentryHook, error)
NewSentryHook creates a sentry hook for logrus given a sentry dsn.
func (*SentryHook) Fire ¶
func (h *SentryHook) Fire(e *log.Entry) error
Fire is an event handler for logrus. This is a part of logrus.Hook.
func (*SentryHook) Levels ¶
func (h *SentryHook) Levels() []log.Level
Levels returns the levels this hook is enabled for. This is a part of logrus.Hook.
type Tracer ¶
type Tracer interface { // Starts a span. Start(ctx context.Context, operationID string, fields map[string]interface{}) (context.Context, Span) }
Tracer interface for wrapping Jaeger tracer.
func NewTracer ¶
func NewTracer(config TracingConfiguration, appID string) Tracer
NewTracer traces exporter with provided values.
type TracingConfiguration ¶
TracingConfiguration sets tracer service endpoint and sampling rate.