in pkg/xcontext/context.go [249:309]
func NewContext(
stdCtx context.Context,
traceID TraceID,
loggerInstance Logger,
metrics Metrics,
tracer Tracer,
tags Fields,
fields Fields,
) Context {
if traceID == "" {
traceID = NewTraceID()
}
if loggerInstance == nil {
loggerInstance = logger.Dummy()
}
ctx := &ctxValue{
traceIDValue: traceID,
debugTools: &debugTools{
loggerInstance: loggerInstance,
metricsInstance: metrics,
tracerInstance: tracer,
},
}
if stdCtx != nil && stdCtx != context.Background() {
ctx = ctx.cloneWithStdContext(stdCtx).(*ctxValue)
}
if tags == nil {
tags = Fields{}
if buildinfo.BuildMode != "" {
tags["buildMode"] = buildinfo.BuildMode
}
if buildinfo.BuildDate != "" {
tags["buildDate"] = buildinfo.BuildDate
}
if buildinfo.Revision != "" {
tags["revision"] = buildinfo.Revision
}
if DefaultLogHostname && hostname != "" {
tags["hostname"] = hostname
}
if DefaultLogUsername && curUser != nil {
tags["username"] = curUser.Name
}
}
if len(tags) > 0 {
ctx.debugTools.pendingTags.AddMultiple(tags)
}
if fields == nil {
fields = Fields{}
}
if DefaultLogTraceID {
fields["traceID"] = traceID
}
ctx.debugTools.pendingFields.AddMultiple(fields)
return ctx
}