Skip to content

Commit

Permalink
Merge pull request #2235 from morlay/log-with-tracing
Browse files Browse the repository at this point in the history
log should with traceID and spanID
  • Loading branch information
tonistiigi authored Jul 9, 2021
2 parents 64dd6d5 + 1ed2d45 commit b93b5b6
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
1 change: 1 addition & 0 deletions cmd/buildkitd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
28 changes: 28 additions & 0 deletions util/log/log.go
Original file line number Diff line number Diff line change
@@ -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
}

0 comments on commit b93b5b6

Please sign in to comment.