From 48c71c269b035cd5e89b8d5bd5bdec4ee87b1fdd Mon Sep 17 00:00:00 2001 From: David Schmitt Date: Fri, 21 Jun 2024 12:43:30 +0200 Subject: [PATCH] Record if the CLI was aborted and how far it got --- cmd/root.go | 3 +++ cmd/tea_terraform.go | 11 ++++++++++- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/cmd/root.go b/cmd/root.go index fd88f519..b58496d2 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -198,6 +198,9 @@ func Execute() { select { case <-sigs: log.Info("Received signal, shutting down") + if cmdSpan != nil { + cmdSpan.SetAttributes(attribute.Bool("ovm.cli.aborted", true)) + } cancel() case <-ctx.Done(): } diff --git a/cmd/tea_terraform.go b/cmd/tea_terraform.go index ec969b84..38c4d03f 100644 --- a/cmd/tea_terraform.go +++ b/cmd/tea_terraform.go @@ -102,7 +102,13 @@ func (m *cmdModel) Init() tea.Cmd { } func (m *cmdModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) { - log.Debugf("cmdModel: Update %T received %#v", msg, msg) + lastMsgType := fmt.Sprintf("%T", msg) + if lastMsgType != "spinner.TickMsg" { + log.Debugf("cmdModel: Update %v received %#v", lastMsgType, msg) + if cmdSpan != nil && !slices.Contains([]string{"tea.KeyMsg", "tea.Quit"}, lastMsgType) { + cmdSpan.SetAttributes(attribute.String("ovm.cli.lastMsgType", lastMsgType)) + } + } cmds := []tea.Cmd{} @@ -113,6 +119,9 @@ func (m *cmdModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) { case tea.KeyMsg: if msg.String() == "ctrl+c" { + if cmdSpan != nil { + cmdSpan.SetAttributes(attribute.Bool("ovm.cli.aborted", true)) + } return m, tea.Quit } case freezeViewMsg: