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