mirror of
https://github.com/golang/go
synced 2024-11-05 15:56:12 -07:00
internal/telemetry: render trace tags using typed keys
Type switch on the key and use it to get the value and decide how to render it. Use the same render for all debug tag printing. Change-Id: Ia305fded7dcf05b57c5805f48bb5c22fa7def71f Reviewed-on: https://go-review.googlesource.com/c/tools/+/225380 Run-TryBot: Ian Cottrell <iancottrell@google.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Robert Findley <rfindley@google.com>
This commit is contained in:
parent
1386b938c6
commit
c9942794f0
@ -172,8 +172,7 @@ func fillOffsets(td *traceData, start time.Time) {
|
|||||||
func renderTags(tags event.TagIterator) string {
|
func renderTags(tags event.TagIterator) string {
|
||||||
buf := &bytes.Buffer{}
|
buf := &bytes.Buffer{}
|
||||||
for ; tags.Valid(); tags.Advance() {
|
for ; tags.Valid(); tags.Advance() {
|
||||||
tag := tags.Tag()
|
fmt.Fprintf(buf, "%v ", tags.Tag())
|
||||||
fmt.Fprintf(buf, "%s=%q ", tag.Key.Name(), tag.Value)
|
|
||||||
}
|
}
|
||||||
return buf.String()
|
return buf.String()
|
||||||
}
|
}
|
||||||
|
@ -51,7 +51,7 @@ func (ev Event) Format(f fmt.State, r rune) {
|
|||||||
}
|
}
|
||||||
for it := ev.Tags(); it.Valid(); it.Advance() {
|
for it := ev.Tags(); it.Valid(); it.Advance() {
|
||||||
tag := it.Tag()
|
tag := it.Tag()
|
||||||
fmt.Fprintf(f, "\n\t%s = %v", tag.Key.Name(), tag.Value)
|
fmt.Fprintf(f, "\n\t%v", tag)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -67,7 +67,7 @@ type tagMapChain struct {
|
|||||||
maps []TagMap
|
maps []TagMap
|
||||||
}
|
}
|
||||||
|
|
||||||
// Key returns the key for this Tag.
|
// Valid returns true if the Tag is a valid one (it has a key).
|
||||||
func (t Tag) Valid() bool { return t.Key != nil }
|
func (t Tag) Valid() bool { return t.Key != nil }
|
||||||
|
|
||||||
// Format is used for debug printing of tags.
|
// Format is used for debug printing of tags.
|
||||||
@ -76,7 +76,42 @@ func (t Tag) Format(f fmt.State, r rune) {
|
|||||||
fmt.Fprintf(f, `nil`)
|
fmt.Fprintf(f, `nil`)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
fmt.Fprintf(f, `%v="%v"`, t.Key.Name(), t.Value)
|
switch key := t.Key.(type) {
|
||||||
|
case *IntKey:
|
||||||
|
fmt.Fprintf(f, "%s=%d", key.Name(), key.From(t))
|
||||||
|
case *Int8Key:
|
||||||
|
fmt.Fprintf(f, "%s=%d", key.Name(), key.From(t))
|
||||||
|
case *Int16Key:
|
||||||
|
fmt.Fprintf(f, "%s=%d", key.Name(), key.From(t))
|
||||||
|
case *Int32Key:
|
||||||
|
fmt.Fprintf(f, "%s=%d", key.Name(), key.From(t))
|
||||||
|
case *Int64Key:
|
||||||
|
fmt.Fprintf(f, "%s=%d", key.Name(), key.From(t))
|
||||||
|
case *UIntKey:
|
||||||
|
fmt.Fprintf(f, "%s=%d", key.Name(), key.From(t))
|
||||||
|
case *UInt8Key:
|
||||||
|
fmt.Fprintf(f, "%s=%d", key.Name(), key.From(t))
|
||||||
|
case *UInt16Key:
|
||||||
|
fmt.Fprintf(f, "%s=%d", key.Name(), key.From(t))
|
||||||
|
case *UInt32Key:
|
||||||
|
fmt.Fprintf(f, "%s=%d", key.Name(), key.From(t))
|
||||||
|
case *UInt64Key:
|
||||||
|
fmt.Fprintf(f, "%s=%d", key.Name(), key.From(t))
|
||||||
|
case *Float32Key:
|
||||||
|
fmt.Fprintf(f, "%s=%g", key.Name(), key.From(t))
|
||||||
|
case *Float64Key:
|
||||||
|
fmt.Fprintf(f, "%s=%g", key.Name(), key.From(t))
|
||||||
|
case *BooleanKey:
|
||||||
|
fmt.Fprintf(f, "%s=%t", key.Name(), key.From(t))
|
||||||
|
case *StringKey:
|
||||||
|
fmt.Fprintf(f, "%s=%q", key.Name(), key.From(t))
|
||||||
|
case *ErrorKey:
|
||||||
|
fmt.Fprintf(f, "%s=%q", key.Name(), key.From(t))
|
||||||
|
case *ValueKey:
|
||||||
|
fmt.Fprintf(f, "%s=%q", key.Name(), key.From(t))
|
||||||
|
default:
|
||||||
|
fmt.Fprintf(f, `%s="invalid type %T"`, key.Name(), key)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (i *TagIterator) Valid() bool {
|
func (i *TagIterator) Valid() bool {
|
||||||
|
Loading…
Reference in New Issue
Block a user