github.com/cockroachdb/cockroach@v20.2.0-alpha.1+incompatible/pkg/util/tracing/recorded_span.go (about) 1 // Copyright 2019 The Cockroach Authors. 2 // 3 // Use of this software is governed by the Business Source License 4 // included in the file licenses/BSL.txt. 5 // 6 // As of the Change Date specified in that file, in accordance with 7 // the Business Source License, use of this software will be governed 8 // by the Apache License, Version 2.0, included in the file 9 // licenses/APL.txt. 10 11 package tracing 12 13 import ( 14 "fmt" 15 "strings" 16 "time" 17 ) 18 19 // LogMessageField is the field name used for the opentracing.Span.LogFields() 20 // for a log message. 21 const LogMessageField = "event" 22 23 func (s *RecordedSpan) String() string { 24 sb := strings.Builder{} 25 sb.WriteString(fmt.Sprintf("=== %s (id: %d parent: %d)\n", s.Operation, s.SpanID, s.ParentSpanID)) 26 for _, ev := range s.Logs { 27 sb.WriteString(fmt.Sprintf("%s %s\n", ev.Time.UTC().Format(time.RFC3339Nano), ev.Msg())) 28 } 29 return sb.String() 30 } 31 32 // Msg extracts the message of the LogRecord, which is either in an "event" or 33 // "error" field. 34 func (l LogRecord) Msg() string { 35 for _, f := range l.Fields { 36 key := f.Key 37 if key == LogMessageField { 38 return f.Value 39 } 40 if key == "error" { 41 return fmt.Sprint("error:", f.Value) 42 } 43 } 44 return "" 45 }