File tree Expand file tree Collapse file tree 2 files changed +20
-7
lines changed Expand file tree Collapse file tree 2 files changed +20
-7
lines changed Original file line number Diff line number Diff line change 12
12
L = logrus .NewEntry (logrus .StandardLogger ())
13
13
)
14
14
15
+ var (
16
+ logWithTraceID = false
17
+ )
18
+
19
+ func EnableLogWithTraceID (b bool ) {
20
+ logWithTraceID = b
21
+ }
22
+
15
23
type (
16
24
loggerKey struct {}
17
25
)
@@ -33,13 +41,13 @@ func GetLogger(ctx context.Context) (l *logrus.Entry) {
33
41
l = L
34
42
}
35
43
36
- spanContext := trace . SpanFromContext ( ctx ). SpanContext ()
37
-
38
- if spanContext . IsValid () {
39
- return l . WithFields (logrus. Fields {
40
- "traceID " : spanContext .TraceID (),
41
- "spanID" : spanContext . SpanID (),
42
- })
44
+ if logWithTraceID {
45
+ if spanContext := trace . SpanFromContext ( ctx ). SpanContext (); spanContext . IsValid () {
46
+ return l . WithFields (logrus. Fields {
47
+ "traceID" : spanContext . TraceID (),
48
+ "spanID " : spanContext .SpanID (),
49
+ })
50
+ }
43
51
}
44
52
45
53
return l
Original file line number Diff line number Diff line change 8
8
"strconv"
9
9
"sync"
10
10
11
+ "github.com/moby/buildkit/util/bklog"
11
12
"github.com/pkg/errors"
12
13
"go.opentelemetry.io/otel/sdk/resource"
13
14
sdktrace "go.opentelemetry.io/otel/sdk/trace"
@@ -82,6 +83,10 @@ func detect() error {
82
83
if exp == nil {
83
84
return nil
84
85
}
86
+
87
+ // enable log with traceID when valid exporter
88
+ bklog .EnableLogWithTraceID (true )
89
+
85
90
res , err := resource .Detect (context .Background (), serviceNameDetector {})
86
91
if err != nil {
87
92
return err
You can’t perform that action at this time.
0 commit comments