From ec3462599ca26e7a8a20c277bab1c076c1f856dd Mon Sep 17 00:00:00 2001 From: "Y.Matsuda" Date: Sat, 3 Aug 2024 21:27:36 +0900 Subject: [PATCH] Print attributes according to their type --- go.work.sum | 13 ++++++++++ tuiexporter/internal/tui/component/log.go | 6 ++--- .../internal/tui/component/log_test.go | 6 ++--- tuiexporter/internal/tui/component/metric.go | 24 +++++++++---------- .../internal/tui/component/timeline.go | 15 +++--------- tuiexporter/internal/tui/component/trace.go | 17 +++++++------ .../internal/tui/component/trace_test.go | 4 ++-- 7 files changed, 46 insertions(+), 39 deletions(-) diff --git a/go.work.sum b/go.work.sum index 512f067..e64e156 100644 --- a/go.work.sum +++ b/go.work.sum @@ -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= @@ -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= @@ -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= @@ -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= diff --git a/tuiexporter/internal/tui/component/log.go b/tuiexporter/internal/tui/component/log.go index 53074a5..fee96e6 100644 --- a/tuiexporter/internal/tui/component/log.go +++ b/tuiexporter/internal/tui/component/log.go @@ -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 @@ -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) @@ -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) diff --git a/tuiexporter/internal/tui/component/log_test.go b/tuiexporter/internal/tui/component/log_test.go index 09faae5..5bec1d7 100644 --- a/tuiexporter/internal/tui/component/log_test.go +++ b/tuiexporter/internal/tui/component/log_test.go @@ -194,7 +194,7 @@ 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 @@ -202,7 +202,7 @@ func TestGetLogInfoTree(t *testing.T) { │ ├──version: v0.0.1 │ ├──dropped attributes count: 2 │ └──Attributes - │ └──scope index: %!s(int64=0) + │ └──scope index: 0 └──LogRecord ├──trace id: 01000000000000000000000000000000 ├──span id: 0100000000000000 @@ -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()) } diff --git a/tuiexporter/internal/tui/component/metric.go b/tuiexporter/internal/tui/component/metric.go index b306bec..582909c 100644 --- a/tuiexporter/internal/tui/component/metric.go +++ b/tuiexporter/internal/tui/component/metric.go @@ -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 @@ -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) @@ -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") @@ -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) @@ -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) @@ -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) @@ -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) @@ -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) diff --git a/tuiexporter/internal/tui/component/timeline.go b/tuiexporter/internal/tui/component/timeline.go index 11e493e..5dff78b 100644 --- a/tuiexporter/internal/tui/component/timeline.go +++ b/tuiexporter/internal/tui/component/timeline.go @@ -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 @@ -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) @@ -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) diff --git a/tuiexporter/internal/tui/component/trace.go b/tuiexporter/internal/tui/component/trace.go index c8ed7d7..07dda18 100644 --- a/tuiexporter/internal/tui/component/trace.go +++ b/tuiexporter/internal/tui/component/trace.go @@ -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. @@ -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 @@ -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) @@ -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) } } diff --git a/tuiexporter/internal/tui/component/trace_test.go b/tuiexporter/internal/tui/component/trace_test.go index 667897b..5a54db3 100644 --- a/tuiexporter/internal/tui/component/trace_test.go +++ b/tuiexporter/internal/tui/component/trace_test.go @@ -175,7 +175,7 @@ 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 @@ -183,7 +183,7 @@ func TestGetTraceInfoTree(t *testing.T) { │ ├──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