Improve error handling for ending tracing

This commit is contained in:
Edoardo Pirovano
2022-02-23 16:43:38 +00:00
parent c592525a67
commit afbddca263
3 changed files with 39 additions and 21 deletions

View File

@@ -26,21 +26,30 @@ export async function endTracingForCluster(
// If there are no traced languages, we don't need to do anything.
if (!config.languages.some(isTracedLanguage)) return;
const endTracingEnvVariables: Map<string, string | null> = JSON.parse(
fs.readFileSync(
path.resolve(
config.dbLocation,
"temp/tracingEnvironment/end-tracing.json"
),
"utf8"
)
const envVariablesFile = path.resolve(
config.dbLocation,
"temp/tracingEnvironment/end-tracing.json"
);
for (const [key, value] of Object.entries(endTracingEnvVariables)) {
if (value !== null) {
process.env[key] = value;
} else {
delete process.env[key];
if (!fs.existsSync(envVariablesFile)) {
throw new Error(
`Environment file for ending tracing not found: ${envVariablesFile}`
);
}
try {
const endTracingEnvVariables: Map<string, string | null> = JSON.parse(
fs.readFileSync(envVariablesFile, "utf8")
);
for (const [key, value] of Object.entries(endTracingEnvVariables)) {
if (value !== null) {
process.env[key] = value;
} else {
delete process.env[key];
}
}
} catch (e) {
throw new Error(
`Failed to parse file containing end tracing environment variables: ${e}`
);
}
}