Skip to content

Commit

Permalink
log with traceID and spanID
Browse files Browse the repository at this point in the history
Signed-off-by: Morlay <[email protected]>
  • Loading branch information
morlay committed Jul 9, 2021
1 parent 64dd6d5 commit b20bbd6
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 @@ -38,6 +38,7 @@ import (
dockerfile "github.com/moby/buildkit/frontend/dockerfile/builder"
"github.com/moby/buildkit/frontend/gateway"
"github.com/moby/buildkit/frontend/gateway/forwarder"
_ "github.com/moby/buildkit/util/log"
"github.com/moby/buildkit/session"
"github.com/moby/buildkit/solver/bboltcachestorage"
"github.com/moby/buildkit/util/apicaps"
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 b20bbd6

Please sign in to comment.