diff --git a/cmd/buildkitd/main.go b/cmd/buildkitd/main.go index 00244429..94efa9fe 100644 --- a/cmd/buildkitd/main.go +++ b/cmd/buildkitd/main.go @@ -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" diff --git a/util/log/log.go b/util/log/log.go new file mode 100644 index 00000000..6e3536a3 --- /dev/null +++ b/util/log/log.go @@ -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 +}