Skip to content

Commit

Permalink
Merge pull request #133 from ymtdzzz/feature/event_name_in_logs_list
Browse files Browse the repository at this point in the history
Add event name ( `event.name` ) column in the list of Logs
  • Loading branch information
ymtdzzz authored Aug 18, 2024
2 parents db78cd1 + 06b60c3 commit ceb6e0e
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 5 deletions.
12 changes: 10 additions & 2 deletions tuiexporter/internal/tui/component/log.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,9 @@ func (l LogDataForTable) GetColumnCount() int {
// 1: ServiceName
// 2: Timestamp
// 3: Severity
// 4: RawData
return 5
// 4: EventName
// 5: RawData
return 6
}

// getCellFromLog returns a table cell for the given log and column.
Expand All @@ -59,6 +60,13 @@ func getCellFromLog(log *telemetry.LogData, column int) *tview.TableCell {
case 3:
text = log.Log.SeverityText()
case 4:
// see: https://github.com/open-telemetry/semantic-conventions/blob/a4fc971e0c7ffa4b9572654f075d3cb8560db770/docs/general/events.md#event-definition
if ename, ok := log.Log.Attributes().Get("event.name"); ok {
text = ename.AsString()
} else {
text = "N/A<Event Name>"
}
case 5:
text = log.Log.Body().AsString()
}

Expand Down
19 changes: 16 additions & 3 deletions tuiexporter/internal/tui/component/log_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ func TestLogDataForTable(t *testing.T) {
// └- log: log-1-1-1-2
_, testdata1 := test.GenerateOTLPLogsPayload(t, 1, 2, []int{2, 1}, [][]int{{2, 1}, {1}})
_, testdata2 := test.GenerateOTLPLogsPayload(t, 2, 1, []int{1}, [][]int{{1}})
testdata1.Logs[0].Attributes().PutStr("event.name", "device.app.lifecycle")
logs := &[]*telemetry.LogData{
{
Log: testdata1.Logs[0],
Expand Down Expand Up @@ -87,7 +88,7 @@ func TestLogDataForTable(t *testing.T) {
})

t.Run("GetColumnCount", func(t *testing.T) {
assert.Equal(t, 5, ldftable.GetColumnCount())
assert.Equal(t, 6, ldftable.GetColumnCount())
})

t.Run("GetCell", func(t *testing.T) {
Expand All @@ -106,7 +107,7 @@ func TestLogDataForTable(t *testing.T) {
{
name: "invalid column",
row: 0,
column: 5,
column: 6,
want: "N/A",
},
{
Expand All @@ -115,6 +116,12 @@ func TestLogDataForTable(t *testing.T) {
column: 0,
want: "01000000000000000000000000000000",
},
{
name: "event name trace 1 span-1-1-1",
row: 0,
column: 4,
want: "device.app.lifecycle",
},
{
name: "service name trace 1 span-2-1-1",
row: 6,
Expand All @@ -134,9 +141,15 @@ func TestLogDataForTable(t *testing.T) {
want: "INFO",
},
{
name: "raw data trace 2 span-1-1-1",
name: "event name trace 2 span-1-1-1",
row: 8,
column: 4,
want: "N/A<Event Name>",
},
{
name: "raw data trace 2 span-1-1-1",
row: 8,
column: 5,
want: "log body 0-0-0-0",
},
}
Expand Down

0 comments on commit ceb6e0e

Please sign in to comment.