diff --git a/tool/tsh/common/tsh.go b/tool/tsh/common/tsh.go index 43db25283b23a..e8b3544d633f4 100644 --- a/tool/tsh/common/tsh.go +++ b/tool/tsh/common/tsh.go @@ -1624,6 +1624,18 @@ func Run(ctx context.Context, args []string, opts ...CliOption) error { defer runtimetrace.Stop() } + // print tsh version when --debug flag is set + // to diagnose potential client version mismatch + if cf.Debug && command != ver.FullCommand() { + logger.InfoContext(ctx, "Initializing tsh", + "version", slog.GroupValue( + slog.String("teleport", teleport.Version), + slog.String("teleport_git", teleport.Gitref), + slog.String("go", runtime.Version()), + ), + ) + } + switch command { case ver.FullCommand(): err = onVersion(&cf) diff --git a/tool/tsh/common/tsh_test.go b/tool/tsh/common/tsh_test.go index ba62e1754b775..f5afc09948ef1 100644 --- a/tool/tsh/common/tsh_test.go +++ b/tool/tsh/common/tsh_test.go @@ -7710,3 +7710,23 @@ func Test_humanFriendlyValidUntilDuration(t *testing.T) { }) } } + +func TestDebugVersionOutput(t *testing.T) { + t.Setenv(tshBinMainTestEnv, "1") + testExecutable, err := os.Executable() + require.NoError(t, err) + + output, err := exec.Command(testExecutable, "logout", "--debug").CombinedOutput() + require.NoError(t, err) + + vers := []string{ + teleport.Version, + teleport.Gitref, + runtime.Version(), + } + + require.Contains(t, string(output), "Initializing tsh version") + for _, v := range vers { + require.Contains(t, string(output), v) + } +}