MCPcopy Create free account
hub / github.com/cortexproject/cortex / NewWithLogger

Function NewWithLogger

pkg/util/spanlogger/spanlogger.go:40–55  ·  view source on GitHub ↗

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

(ctx context.Context, l log.Logger, method string, kvps ...any)

Source from the content-addressed store, hash-verified

38// to. The provided context will have the logger attached to it and can be
39// retrieved with FromContext or FromContextWithFallback.
40func NewWithLogger(ctx context.Context, l log.Logger, method string, kvps ...any) (*SpanLogger, context.Context) {
41 span, ctx := opentracing.StartSpanFromContext(ctx, method)
42 if ids, _ := users.TenantIDs(ctx); len(ids) > 0 {
43 span.SetTag(TenantIDTagName, ids)
44 }
45 logger := &SpanLogger{
46 Logger: log.With(util_log.WithContext(ctx, l), "method", method),
47 Span: span,
48 }
49 if len(kvps) > 0 {
50 level.Debug(logger).Log(kvps...)
51 }
52
53 ctx = context.WithValue(ctx, loggerCtxKey, l)
54 return logger, ctx
55}
56
57// FromContext returns a span logger using the current parent span. If there
58// is no parent span, the SpanLogger will only log to the logger

Callers 2

NewFunction · 0.85

Calls 3

TenantIDsFunction · 0.92
SetTagMethod · 0.80
LogMethod · 0.45

Tested by 1