Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RSDK-9326 - log important viam env variables #4602

Merged
21 changes: 21 additions & 0 deletions web/server/entrypoint.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,25 @@ type robotServer struct {
registry *logging.Registry
}

func logViamEnvVariables(logger logging.Logger) {
var viamEnvVariables []interface{}
Copy link
Member

@dgottlieb dgottlieb Dec 4, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's also grab the home directory via PlatformHomeDir here.

(and looking at that function -- it should be using Go's stdlib os.UserHomeDir() because maybe windows one day -- not a required change for this PR)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

added

if value, exists := os.LookupEnv("VIAM_MODULE_ROOT"); exists {
viamEnvVariables = append(viamEnvVariables, "VIAM_MODULE_ROOT", value)
}
if value, exists := os.LookupEnv("VIAM_RESOURCE_CONFIGURATION_TIMEOUT"); exists {
viamEnvVariables = append(viamEnvVariables, "VIAM_RESOURCE_CONFIGURATION_TIMEOUT", value)
}
if value, exists := os.LookupEnv("VIAM_MODULE_STARTUP_TIMEOUT"); exists {
viamEnvVariables = append(viamEnvVariables, "VIAM_MODULE_STARTUP_TIMEOUT", value)
}
if rutils.PlatformHomeDir() != "" {
viamEnvVariables = append(viamEnvVariables, "HOME", rutils.PlatformHomeDir())
}
if len(viamEnvVariables) != 0 {
logger.Infow("Starting viam-server with following environment variables", viamEnvVariables...)
}
}

func logVersion(logger logging.Logger) {
var versionFields []interface{}
if config.Version != "" {
Expand Down Expand Up @@ -164,6 +183,8 @@ func RunServer(ctx context.Context, args []string, _ logging.Logger) (err error)
logVersion(logger)
versionLogged = true

logViamEnvVariables(logger)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we put this in the logVersion method or slightly refactor the flow so that logViamEnvVariables is also tracked by the defer statement above? maybe change versionLogged to startupInfoLogged or something


server := robotServer{
logger: logger,
args: argsParsed,
Expand Down
Loading