Documentation
¶
Index ¶
- Constants
- func Caller(defaultStackDepth int) log.Valuer
- type SpanLogger
- func FromContext(ctx context.Context, fallback log.Logger, resolver TenantResolver) *SpanLogger
- func New(ctx context.Context, logger log.Logger, method string, resolver TenantResolver, ...) (*SpanLogger, context.Context)
- func NewOTel(ctx context.Context, logger log.Logger, tracer trace.Tracer, method string, ...) (*SpanLogger, context.Context)
- func (s *SpanLogger) DebugLog(kvps ...interface{})
- func (s *SpanLogger) Error(err error) error
- func (s *SpanLogger) Finish()
- func (s *SpanLogger) Log(kvps ...interface{}) error
- func (s *SpanLogger) LogFields(kvps ...otlog.Field)
- func (s *SpanLogger) LogKV(kvps ...interface{})
- func (s *SpanLogger) SetError()
- func (s *SpanLogger) SetSpanAndLogTag(key string, value interface{})
- func (s *SpanLogger) SetTag(key string, value interface{})
- type TenantResolver
Constants ¶
const (
// TenantIDsTagName is the tenant IDs tag name.
TenantIDsTagName = "tenant_ids"
)
Variables ¶
This section is empty.
Functions ¶
func Caller ¶
Caller is like github.com/go-kit/log's Caller, but ensures that the caller information is that of the caller to SpanLogger (if SpanLogger is being used), not SpanLogger itself.
defaultStackDepth should be the number of stack frames to skip by default, as would be passed to github.com/go-kit/log's Caller method.
Types ¶
type SpanLogger ¶
type SpanLogger struct {
// 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) LogFields ¶
func (s *SpanLogger) LogFields(kvps ...otlog.Field)
LogFields will log the provided fields in the span, this is more performant that LogKV when using opentracing library.
func (*SpanLogger) LogKV ¶
func (s *SpanLogger) LogKV(kvps ...interface{})
LogKV will log the provided key/value pairs in the span, this is less performant than LogFields when using opentracing library.
func (*SpanLogger) SetError ¶
func (s *SpanLogger) SetError()
SetError will set the error flag on the span.
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).
func (*SpanLogger) SetTag ¶
func (s *SpanLogger) SetTag(key string, value interface{})
SetTag will set a tag/attribute on the span.
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.