Merge pull request #2235 from morlay/log-with-tracing

log should with traceID and spanID
v0.9
Tõnis Tiigi 2021-07-08 22:55:50 -07:00 committed by GitHub
commit b93b5b62d1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 29 additions and 0 deletions

View File

@ -45,6 +45,7 @@ import (
"github.com/moby/buildkit/util/appdefaults"
"github.com/moby/buildkit/util/archutil"
"github.com/moby/buildkit/util/grpcerrors"
_ "github.com/moby/buildkit/util/log"
"github.com/moby/buildkit/util/profiler"
"github.com/moby/buildkit/util/resolver"
"github.com/moby/buildkit/util/stack"

28
util/log/log.go Normal file
View File

@ -0,0 +1,28 @@
package log
import (
"context"
"github.com/containerd/containerd/log"
"github.com/sirupsen/logrus"
"go.opentelemetry.io/otel/trace"
)
func init() {
log.G = GetLogger
}
func GetLogger(ctx context.Context) *logrus.Entry {
l := log.GetLogger(ctx)
spanContext := trace.SpanFromContext(ctx).SpanContext()
if spanContext.IsValid() {
return l.WithFields(logrus.Fields{
"traceID": spanContext.TraceID(),
"spanID": spanContext.SpanID(),
})
}
return l
}