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

core/server: Add environment variable to write stacktrace to file #17929

Merged
merged 6 commits into from
Nov 15, 2022

Conversation

jasonodonnell
Copy link
Contributor

@jasonodonnell jasonodonnell commented Nov 14, 2022

When Vault receives a SIGUSR2 signal it will write a stacktrace of the running goroutines to Vault's log file. These can be hard to parse due to log prefixes and in some cases, the logger is unable to log the entire stacktrace. This adds an environment variable will force Vault to also write the stacktrace to a temporary file on the server.

The environment variables are as follows:
VAULT_STACKTRACE_WRITE_TO_FILE=true: this forces the stacktrace to a file.
VAULT_STACKTRACE_FILE_PATH=/some/path: if left unset, Vault will create a temp directory and file for your OS. This let's the user override the path.

Vault will write the locations to the server logs:

2022-11-14T17:11:41.624-0500 [INFO]  Writing stacktrace to file
2022-11-14T17:11:41.625-0500 [INFO]  Wrote stacktrace to: /var/folders/xh/8_phfcd132gfsx4gwbfcnwkm0000gq/T/vault-stacktrace1446709789/stacktrace3626735589

@jasonodonnell jasonodonnell requested a review from a team November 14, 2022 19:23
Copy link
Contributor

@hghaf099 hghaf099 left a comment

Choose a reason for hiding this comment

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

Just a nit, otherwise looks good!

if os.Getenv("VAULT_WRITE_STACKTRACE_TO_FILE") != "" {
c.logger.Info("Writing stacktrace to file..")

tmpFile, err := ioutil.TempFile("", fmt.Sprintf("%s-", filepath.Base(os.Args[0])))
Copy link
Contributor

Choose a reason for hiding this comment

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

Seems like ioutil.TemFile has been deprecated. Shall we use os.CreateTemp instead?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good catch, fixed!

command/server.go Outdated Show resolved Hide resolved
command/server.go Outdated Show resolved Hide resolved
command/server.go Show resolved Hide resolved
command/server.go Show resolved Hide resolved
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants