fix: better logging for gh token refresh

This commit is contained in:
bracesproul 2025-07-24 12:40:57 -07:00
parent d9feebb89d
commit 005190e7bd

View file

@ -12,6 +12,7 @@ const logger = createLogger(LogLevel.INFO, "GitHub-API");
async function getInstallationTokenAndUpdateConfig() { async function getInstallationTokenAndUpdateConfig() {
try { try {
logger.info("Fetching a new GitHub installation token.");
const config = getConfig(); const config = getConfig();
const encryptionSecret = process.env.SECRETS_ENCRYPTION_KEY; const encryptionSecret = process.env.SECRETS_ENCRYPTION_KEY;
if (!encryptionSecret) { if (!encryptionSecret) {
@ -30,6 +31,7 @@ async function getInstallationTokenAndUpdateConfig() {
const token = await getInstallationToken(installationId, appId, privateKey); const token = await getInstallationToken(installationId, appId, privateKey);
const encryptedToken = encryptSecret(token, encryptionSecret); const encryptedToken = encryptSecret(token, encryptionSecret);
updateConfig(GITHUB_INSTALLATION_ID, encryptedToken); updateConfig(GITHUB_INSTALLATION_ID, encryptedToken);
logger.info("Successfully fetched a new GitHub installation token.");
return token; return token;
} catch (e) { } catch (e) {
logger.error("Failed to get installation token and update config", { logger.error("Failed to get installation token and update config", {
@ -77,6 +79,7 @@ async function withGitHubRetry<T>(
} }
logger.error(errorMessage, { logger.error(errorMessage, {
numRetries,
...additionalLogFields, ...additionalLogFields,
...(errorFields ?? { error }), ...(errorFields ?? { error }),
}); });