spanlogger

package
v0.0.0-...-de40865 Latest Latest
Warning

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

Go to latest
Published: Apr 11, 2024 License: Apache-2.0 Imports: 8 Imported by: 11

Documentation

Index

Constants

View Source
const (
	// TenantIDsTagName is the tenant IDs tag name.
	TenantIDsTagName = "tenant_ids"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type SpanLogger

type SpanLogger struct {
	opentracing.Span
	// contains filtered or unexported fields
}

SpanLogger unifies tracing and logging, to reduce repetition.

func FromContext

func FromContext(ctx context.Context, fallback log.Logger, resolver TenantResolver) *SpanLogger

FromContext returns a span logger using the current parent span. If there is no parent span, the SpanLogger will only log to the logger within the context. If the context doesn't have a logger, the fallback logger is used.

func New

func New(ctx context.Context, logger log.Logger, method string, resolver TenantResolver, kvps ...interface{}) (*SpanLogger, context.Context)

New makes a new SpanLogger with a log.Logger to send logs to. The provided context will have the logger attached to it and can be retrieved with FromContext.

func (*SpanLogger) DebugLog

func (s *SpanLogger) DebugLog(kvps ...interface{})

DebugLog is more efficient than level.Debug().Log(). Also it swallows the error return because nobody checks for errors on debug logs.

func (*SpanLogger) Error

func (s *SpanLogger) Error(err error) error

Error sets error flag and logs the error on the span, if non-nil. Returns the err passed in.

func (*SpanLogger) Log

func (s *SpanLogger) Log(kvps ...interface{}) error

Log implements gokit's Logger interface; sends logs to underlying logger and also puts the on the spans.

func (*SpanLogger) SetSpanAndLogTag

func (s *SpanLogger) SetSpanAndLogTag(key string, value interface{})

SetSpanAndLogTag sets a tag on the span used by this SpanLogger, and appends a key/value pair to the logger used for future log lines emitted by this SpanLogger.

It is not safe to call this method from multiple goroutines simultaneously. It is safe to call this method at the same time as calling other SpanLogger methods, however, this may produce inconsistent results (eg. some log lines may be emitted with the provided key/value pair, and others may not).

type TenantResolver

type TenantResolver interface {
	// TenantID tries to extract a tenant ID from a context.
	TenantID(context.Context) (string, error)
	// TenantIDs tries to extract tenant IDs from a context.
	TenantIDs(context.Context) ([]string, error)
}

TenantResolver provides methods for extracting tenant IDs from a context.

Jump to

Keyboard shortcuts

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