Skip to content

Commit

Permalink
Print attributes according to their type
Browse files Browse the repository at this point in the history
  • Loading branch information
ymtdzzz committed Aug 3, 2024
1 parent 40ce62b commit ec34625
Show file tree
Hide file tree
Showing 7 changed files with 46 additions and 39 deletions.
13 changes: 13 additions & 0 deletions go.work.sum
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,10 @@ github.com/alecthomas/units v0.0.0-20211218093645-b94a6e3cc137/go.mod h1:OMCwj8V
github.com/antihax/optional v1.0.0/go.mod h1:uupD/76wgC+ih3iEmQUL+0Ugr19nfwCT1kdvxnR2qWY=
github.com/campoy/embedmd v1.0.0/go.mod h1:oxyr9RCiSXg0M3VJ3ks0UGfp98BpSSGr0kpiX3MzVl8=
github.com/census-instrumentation/opencensus-proto v0.4.1/go.mod h1:4T9NM4+4Vw91VeyqjLS6ao50K5bOcLKN6Q42XnYaRYw=
github.com/chromedp/cdproto v0.0.0-20230802225258-3cf4e6d46a89/go.mod h1:GKljq0VrfU4D5yc+2qA6OVr8pmO/MBbPEWqWQ/oqGEs=
github.com/chromedp/chromedp v0.9.2/go.mod h1:LkSXJKONWTCHAfQasKFUZI+mxqS4tZqhmtGzzhLsnLs=
github.com/chromedp/sysutil v1.0.0/go.mod h1:kgWmDdq8fTzXYcKIBqIYvRRTnYb9aNS9moAV0xufSww=
github.com/chzyer/readline v1.5.1/go.mod h1:Eh+b79XXUwfKfcPLepksvw2tcLE/Ct21YObkaSkeBlk=
github.com/cncf/xds/go v0.0.0-20240318125728-8a4994d93e50/go.mod h1:5e1+Vvlzido69INQaVO6d87Qn543Xr6nooe9Kz7oBFM=
github.com/cncf/xds/go v0.0.0-20240423153145-555b57ec207b/go.mod h1:W+zGtBO5Y1IgJhy4+A9GOqVhqLpfZi+vwmdNXUehLA8=
github.com/envoyproxy/go-control-plane v0.12.0/go.mod h1:ZBTaoJ23lqITozF0M6G4/IragXCQKCnYbmlmtHvwRG0=
Expand All @@ -134,7 +138,11 @@ github.com/go-gl/glfw/v3.3/glfw v0.0.0-20231223183121-56fa3ac82ce7/go.mod h1:tQ2
github.com/go-kit/log v0.2.1/go.mod h1:NwTd00d/i8cPZ3xOwwiv2PO5MOcx78fFErGNcVmBjv0=
github.com/go-latex/latex v0.0.0-20231108140139-5c1ce85aa4ea/go.mod h1:Y7Vld91/HRbTBm7JwoI7HejdDB0u+e9AUBO9MB7yuZk=
github.com/go-logfmt/logfmt v0.5.1/go.mod h1:WYhtIu8zTZfxdn5+rREduYbwxfcBr/Vr6KEVveWlfTs=
github.com/go-logr/logr v1.4.1/go.mod h1:9T104GzyrTigFIr8wt5mBrctHMim0Nb2HLGrmQ40KvY=
github.com/go-pdf/fpdf v0.9.0/go.mod h1:oO8N111TkmKb9D7VvWGLvLJlaZUQVPM+6V42pp3iV4Y=
github.com/gobwas/httphead v0.1.0/go.mod h1:O/RXo79gxV8G+RqlR/otEwx4Q36zl9rqC5u12GKvMCM=
github.com/gobwas/pool v0.2.1/go.mod h1:q8bcK0KcYlCgd9e7WYLm9LpyS+YeLd8JVDW6WezmKEw=
github.com/gobwas/ws v1.2.1/go.mod h1:hRKAFb8wOxFROYNsT1bqfWnhX+b5MFeJM9r2ZSwg/KY=
github.com/goccmack/gocc v0.0.0-20230228185258-2292f9e40198/go.mod h1:DTh/Y2+NbnOVVoypCCQrovMPDKUGp4yZpSbWg5D0XIM=
github.com/golang/freetype v0.0.0-20170609003504-e2365dfdc4a0/go.mod h1:E/TSTwGwJL78qG/PmXZO1EjYhfJinVAhrmmHX6Z8B9k=
github.com/golang/glog v1.2.0/go.mod h1:6AhwSGph0fcJtXVM/PEHPqZlFeoLxhs7/t5UDAwmO+w=
Expand All @@ -143,9 +151,12 @@ github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaS
github.com/golang/protobuf v1.5.4/go.mod h1:lnTiLA8Wa4RWRcIUkrtSVa5nRhsEGBg48fD6rSs7xps=
github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/google/go-cmp v0.5.9/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
github.com/ianlancetaylor/demangle v0.0.0-20240312041847-bd984b5ce465/go.mod h1:gx7rwoVhcfuVKG5uya9Hs3Sxj7EIvldVofAWIUtGouw=
github.com/jezek/xgb v1.1.1/go.mod h1:nrhwO0FX/enq75I7Y7G8iN1ubpSGZEiA3v9e9GyRFlk=
github.com/josharian/intern v1.0.0/go.mod h1:5DoeVV0s6jJacbCEi61lwdGj/aVlrQvzHFFd8Hwg//Y=
github.com/jpillora/backoff v1.0.0/go.mod h1:J/6gKK9jxlEcS3zixgDgUAsiuZ7yrSoa/FX5e0EB2j4=
github.com/julienschmidt/httprouter v1.3.0/go.mod h1:JR6WtHb+2LUe8TCKY3cZOxFyyO8IZAc4RVcycCCAKdM=
github.com/mailru/easyjson v0.7.7/go.mod h1:xzfreul335JAWq5oZzymOObrkdz5UnU4kGfJJLY9Nlc=
github.com/mwitkow/go-conntrack v0.0.0-20190716064945-2f068394615f/go.mod h1:qRWi+5nqEBWmkhHvq77mSJWrCKwh8bxhgT7d/eI7P4U=
github.com/pierrec/lz4/v4 v4.1.21/go.mod h1:gZWDp/Ze/IJXGXf23ltt2EXimqmTUXEy0GFuRQyBid4=
github.com/rogpeppe/fastuuid v1.2.0/go.mod h1:jVj6XXZzXRy/MSR5jhDC/2q6DgLz+nrA6LYCDYWNEvQ=
Expand All @@ -164,6 +175,8 @@ golang.org/x/sync v0.7.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
golang.org/x/sys v0.15.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/sys v0.20.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/telemetry v0.0.0-20240228155512-f48c80bd79b2/go.mod h1:TeRTkGYfJXctD9OcfyVLyj2J3IxLnKwHJR8f4D8a3YE=
golang.org/x/term v0.20.0/go.mod h1:8UkIAJTvZgivsXaD6/pH6U9ecQzZ45awqEOzuCvwpFY=
golang.org/x/text v0.15.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU=
golang.org/x/tools v0.13.0/go.mod h1:HvlwmtVNQAhOuCjW7xxvovg8wbNq7LwfXh/k7wXUl58=
golang.org/x/tools v0.16.0/go.mod h1:kYVVN6I1mBNoB1OX+noeBjbRk4IUEPa7JJ+TJMEooJ0=
golang.org/x/tools v0.21.0/go.mod h1:aiJjzUbINMkxbQROHiO6hDPo2LHcIPhhQsa9DLh0yGk=
Expand Down
6 changes: 3 additions & 3 deletions tuiexporter/internal/tui/component/log.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ func getLogInfoTree(l *telemetry.LogData, tcache *telemetry.TraceCache, drawTime
resource.AddChild(rschema)

attrs := tview.NewTreeNode("Attributes")
appendAttrsSorted(attrs, r.Attributes().AsRaw())
appendAttrsSorted(attrs, r.Attributes())
resource.AddChild(attrs)

// scope info
Expand All @@ -101,7 +101,7 @@ func getLogInfoTree(l *telemetry.LogData, tcache *telemetry.TraceCache, drawTime
scope.AddChild(tview.NewTreeNode(fmt.Sprintf("dropped attributes count: %d", s.DroppedAttributesCount())))

sattrs := tview.NewTreeNode("Attributes")
appendAttrsSorted(sattrs, s.Attributes().AsRaw())
appendAttrsSorted(sattrs, s.Attributes())
scope.AddChild(sattrs)

scopes.AddChild(scope)
Expand Down Expand Up @@ -146,7 +146,7 @@ func getLogInfoTree(l *telemetry.LogData, tcache *telemetry.TraceCache, drawTime
record.AddChild(ldropped)

lattrs := tview.NewTreeNode("Attributes")
appendAttrsSorted(lattrs, l.Log.Attributes().AsRaw())
appendAttrsSorted(lattrs, l.Log.Attributes())
record.AddChild(lattrs)

resource.AddChild(record)
Expand Down
6 changes: 3 additions & 3 deletions tuiexporter/internal/tui/component/log_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -194,15 +194,15 @@ func TestGetLogInfoTree(t *testing.T) {
├──schema url:
├──Attributes
│ ├──resource attribute: resource attribute value
│ ├──resource index: %!s(int64=0)
│ ├──resource index: 0
│ └──service.name: test-service-1
├──Scopes
│ └──test-scope-1-1
│ ├──schema url:
│ ├──version: v0.0.1
│ ├──dropped attributes count: 2
│ └──Attributes
│ └──scope index: %!s(int64=0)
│ └──scope index: 0
└──LogRecord
├──trace id: 01000000000000000000000000000000
├──span id: 0100000000000000
Expand All @@ -213,7 +213,7 @@ func TestGetLogInfoTree(t *testing.T) {
├──flags: 0
├──dropped attributes count: 3
└──Attributes
└──span index: %!s(int64=0)
└──span index: 0
`
assert.Equal(t, want, got.String())
}
24 changes: 12 additions & 12 deletions tuiexporter/internal/tui/component/metric.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ func getMetricInfoTree(m *telemetry.MetricData) *tview.TreeView {
resource.AddChild(rschema)

attrs := tview.NewTreeNode("Attributes")
appendAttrsSorted(attrs, r.Attributes().AsRaw())
appendAttrsSorted(attrs, r.Attributes())
resource.AddChild(attrs)

// scope info
Expand All @@ -124,7 +124,7 @@ func getMetricInfoTree(m *telemetry.MetricData) *tview.TreeView {
scope.AddChild(tview.NewTreeNode(fmt.Sprintf("dropped attributes count: %d", s.DroppedAttributesCount())))

sattrs := tview.NewTreeNode("Attributes")
appendAttrsSorted(sattrs, s.Attributes().AsRaw())
appendAttrsSorted(sattrs, s.Attributes())
scope.AddChild(sattrs)

scopes.AddChild(scope)
Expand All @@ -136,7 +136,7 @@ func getMetricInfoTree(m *telemetry.MetricData) *tview.TreeView {
/// metadata
meta := tview.NewTreeNode("Metadata")
metr.AddChild(meta)
appendAttrsSorted(meta, m.Metric.Metadata().AsRaw())
appendAttrsSorted(meta, m.Metric.Metadata())

/// datapoints
dps := tview.NewTreeNode("Datapoints")
Expand Down Expand Up @@ -177,11 +177,11 @@ func getMetricInfoTree(m *telemetry.MetricData) *tview.TreeView {
// filtered attributes
fattrs := tview.NewTreeNode("Filtered Attributes")
ex.AddChild(fattrs)
appendAttrsSorted(fattrs, e.FilteredAttributes().AsRaw())
appendAttrsSorted(fattrs, e.FilteredAttributes())
}
// attributes
attrs := tview.NewTreeNode("Attributes")
appendAttrsSorted(attrs, d.Attributes().AsRaw())
appendAttrsSorted(attrs, d.Attributes())
dp.AddChild(attrs)

dps.AddChild(dp)
Expand Down Expand Up @@ -221,11 +221,11 @@ func getMetricInfoTree(m *telemetry.MetricData) *tview.TreeView {
// filtered attributes
fattrs := tview.NewTreeNode("Filtered Attributes")
ex.AddChild(fattrs)
appendAttrsSorted(fattrs, e.FilteredAttributes().AsRaw())
appendAttrsSorted(fattrs, e.FilteredAttributes())
}
// attributes
attrs := tview.NewTreeNode("Attributes")
appendAttrsSorted(attrs, d.Attributes().AsRaw())
appendAttrsSorted(attrs, d.Attributes())
dp.AddChild(attrs)

dps.AddChild(dp)
Expand Down Expand Up @@ -265,11 +265,11 @@ func getMetricInfoTree(m *telemetry.MetricData) *tview.TreeView {
// filtered attributes
fattrs := tview.NewTreeNode("Filtered Attributes")
ex.AddChild(fattrs)
appendAttrsSorted(fattrs, e.FilteredAttributes().AsRaw())
appendAttrsSorted(fattrs, e.FilteredAttributes())
}
// attributes
attrs := tview.NewTreeNode("Attributes")
appendAttrsSorted(attrs, d.Attributes().AsRaw())
appendAttrsSorted(attrs, d.Attributes())
dp.AddChild(attrs)

dps.AddChild(dp)
Expand Down Expand Up @@ -316,11 +316,11 @@ func getMetricInfoTree(m *telemetry.MetricData) *tview.TreeView {
// filtered attributes
fattrs := tview.NewTreeNode("Filtered Attributes")
ex.AddChild(fattrs)
appendAttrsSorted(fattrs, e.FilteredAttributes().AsRaw())
appendAttrsSorted(fattrs, e.FilteredAttributes())
}
// attributes
attrs := tview.NewTreeNode("Attributes")
appendAttrsSorted(attrs, d.Attributes().AsRaw())
appendAttrsSorted(attrs, d.Attributes())
dp.AddChild(attrs)

dps.AddChild(dp)
Expand Down Expand Up @@ -350,7 +350,7 @@ func getMetricInfoTree(m *telemetry.MetricData) *tview.TreeView {
dp.AddChild(flg)
// attributes
attrs := tview.NewTreeNode("Attributes")
appendAttrsSorted(attrs, d.Attributes().AsRaw())
appendAttrsSorted(attrs, d.Attributes())
dp.AddChild(attrs)

dps.AddChild(dp)
Expand Down
15 changes: 3 additions & 12 deletions tuiexporter/internal/tui/component/timeline.go
Original file line number Diff line number Diff line change
Expand Up @@ -431,10 +431,7 @@ func getSpanInfoTree(span *telemetry.SpanData, title string) *tview.TreeView {
root.AddChild(droppedNode)

attrs := tview.NewTreeNode("Attributes")
for k, v := range span.Span.Attributes().AsRaw() {
attr := tview.NewTreeNode(fmt.Sprintf("%s: %s", k, v))
attrs.AddChild(attr)
}
appendAttrsSorted(attrs, span.Span.Attributes())
root.AddChild(attrs)

// events
Expand All @@ -453,10 +450,7 @@ func getSpanInfoTree(span *telemetry.SpanData, title string) *tview.TreeView {
eventNode.AddChild(droppedNode)

attrs := tview.NewTreeNode("Attributes")
for k, v := range event.Attributes().AsRaw() {
attr := tview.NewTreeNode(fmt.Sprintf("%s: %s", k, v))
attrs.AddChild(attr)
}
appendAttrsSorted(attrs, event.Attributes())
eventNode.AddChild(attrs)

events.AddChild(eventNode)
Expand Down Expand Up @@ -490,10 +484,7 @@ func getSpanInfoTree(span *telemetry.SpanData, title string) *tview.TreeView {
linkNode.AddChild(linkDroppedNode)

attrs := tview.NewTreeNode("Attributes")
for k, v := range link.Attributes().AsRaw() {
attr := tview.NewTreeNode(fmt.Sprintf("%s: %s", k, v))
attrs.AddChild(attr)
}
appendAttrsSorted(attrs, link.Attributes())
linkNode.AddChild(attrs)

links.AddChild(linkNode)
Expand Down
17 changes: 10 additions & 7 deletions tuiexporter/internal/tui/component/trace.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (

"github.com/rivo/tview"
"github.com/ymtdzzz/otel-tui/tuiexporter/internal/telemetry"
"go.opentelemetry.io/collector/pdata/pcommon"
)

// SpanDataForTable is a wrapper for spans to be displayed in a table.
Expand Down Expand Up @@ -88,7 +89,7 @@ func getTraceInfoTree(spans []*telemetry.SpanData) *tview.TreeView {
resource.AddChild(rschema)

attrs := tview.NewTreeNode("Attributes")
appendAttrsSorted(attrs, r.Attributes().AsRaw())
appendAttrsSorted(attrs, r.Attributes())
resource.AddChild(attrs)

// scope info
Expand All @@ -103,7 +104,7 @@ func getTraceInfoTree(spans []*telemetry.SpanData) *tview.TreeView {
scope.AddChild(tview.NewTreeNode(fmt.Sprintf("dropped attributes count: %d", ss.Scope().DroppedAttributesCount())))

attrs := tview.NewTreeNode("Attributes")
appendAttrsSorted(attrs, ss.Scope().Attributes().AsRaw())
appendAttrsSorted(attrs, ss.Scope().Attributes())
scope.AddChild(attrs)

scopes.AddChild(scope)
Expand All @@ -119,15 +120,17 @@ func getTraceInfoTree(spans []*telemetry.SpanData) *tview.TreeView {
return tree
}

func appendAttrsSorted(parent *tview.TreeNode, attrs map[string]any) {
keys := make([]string, 0, len(attrs))
for k := range attrs {
func appendAttrsSorted(parent *tview.TreeNode, attrs pcommon.Map) {
keys := make([]string, 0, attrs.Len())
attrs.Range(func(k string, _ pcommon.Value) bool {
keys = append(keys, k)
}
return true
})
sort.Strings(keys)

for _, k := range keys {
attr := tview.NewTreeNode(fmt.Sprintf("%s: %s", k, attrs[k]))
v, _ := attrs.Get(k)
attr := tview.NewTreeNode(fmt.Sprintf("%s: %s", k, v.AsString()))
parent.AddChild(attr)
}
}
4 changes: 2 additions & 2 deletions tuiexporter/internal/tui/component/trace_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -175,15 +175,15 @@ func TestGetTraceInfoTree(t *testing.T) {
├──schema url:
├──Attributes
│ ├──resource attribute: resource attribute value
│ ├──resource index: %!s(int64=0)
│ ├──resource index: 0
│ └──service.name: test-service-1
└──Scopes
├──test-scope-1-1
│ ├──schema url:
│ ├──version: v0.0.1
│ ├──dropped attributes count: 2
│ └──Attributes
│ └──scope index: %!s(int64=0)
│ └──scope index: 0
└──test-scope-1-2
├──schema url:
└──version: v0.0.1
Expand Down

0 comments on commit ec34625

Please sign in to comment.