Skip to content

Commit c994279

Browse files
committed
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 <[email protected]> TryBot-Result: Gobot Gobot <[email protected]> Reviewed-by: Robert Findley <[email protected]>
1 parent 1386b93 commit c994279

File tree

3 files changed

+39
-5
lines changed

3 files changed

+39
-5
lines changed

internal/lsp/debug/trace.go

+1-2
Original file line numberDiff line numberDiff line change
@@ -172,8 +172,7 @@ func fillOffsets(td *traceData, start time.Time) {
172172
func renderTags(tags event.TagIterator) string {
173173
buf := &bytes.Buffer{}
174174
for ; tags.Valid(); tags.Advance() {
175-
tag := tags.Tag()
176-
fmt.Fprintf(buf, "%s=%q ", tag.Key.Name(), tag.Value)
175+
fmt.Fprintf(buf, "%v ", tags.Tag())
177176
}
178177
return buf.String()
179178
}

internal/telemetry/event/event.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ func (ev Event) Format(f fmt.State, r rune) {
5151
}
5252
for it := ev.Tags(); it.Valid(); it.Advance() {
5353
tag := it.Tag()
54-
fmt.Fprintf(f, "\n\t%s = %v", tag.Key.Name(), tag.Value)
54+
fmt.Fprintf(f, "\n\t%v", tag)
5555
}
5656
}
5757

internal/telemetry/event/tag.go

+37-2
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ type tagMapChain struct {
6767
maps []TagMap
6868
}
6969

70-
// Key returns the key for this Tag.
70+
// Valid returns true if the Tag is a valid one (it has a key).
7171
func (t Tag) Valid() bool { return t.Key != nil }
7272

7373
// Format is used for debug printing of tags.
@@ -76,7 +76,42 @@ func (t Tag) Format(f fmt.State, r rune) {
7676
fmt.Fprintf(f, `nil`)
7777
return
7878
}
79-
fmt.Fprintf(f, `%v="%v"`, t.Key.Name(), t.Value)
79+
switch key := t.Key.(type) {
80+
case *IntKey:
81+
fmt.Fprintf(f, "%s=%d", key.Name(), key.From(t))
82+
case *Int8Key:
83+
fmt.Fprintf(f, "%s=%d", key.Name(), key.From(t))
84+
case *Int16Key:
85+
fmt.Fprintf(f, "%s=%d", key.Name(), key.From(t))
86+
case *Int32Key:
87+
fmt.Fprintf(f, "%s=%d", key.Name(), key.From(t))
88+
case *Int64Key:
89+
fmt.Fprintf(f, "%s=%d", key.Name(), key.From(t))
90+
case *UIntKey:
91+
fmt.Fprintf(f, "%s=%d", key.Name(), key.From(t))
92+
case *UInt8Key:
93+
fmt.Fprintf(f, "%s=%d", key.Name(), key.From(t))
94+
case *UInt16Key:
95+
fmt.Fprintf(f, "%s=%d", key.Name(), key.From(t))
96+
case *UInt32Key:
97+
fmt.Fprintf(f, "%s=%d", key.Name(), key.From(t))
98+
case *UInt64Key:
99+
fmt.Fprintf(f, "%s=%d", key.Name(), key.From(t))
100+
case *Float32Key:
101+
fmt.Fprintf(f, "%s=%g", key.Name(), key.From(t))
102+
case *Float64Key:
103+
fmt.Fprintf(f, "%s=%g", key.Name(), key.From(t))
104+
case *BooleanKey:
105+
fmt.Fprintf(f, "%s=%t", key.Name(), key.From(t))
106+
case *StringKey:
107+
fmt.Fprintf(f, "%s=%q", key.Name(), key.From(t))
108+
case *ErrorKey:
109+
fmt.Fprintf(f, "%s=%q", key.Name(), key.From(t))
110+
case *ValueKey:
111+
fmt.Fprintf(f, "%s=%q", key.Name(), key.From(t))
112+
default:
113+
fmt.Fprintf(f, `%s="invalid type %T"`, key.Name(), key)
114+
}
80115
}
81116

82117
func (i *TagIterator) Valid() bool {

0 commit comments

Comments
 (0)