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
No known key found for this signature in database
GPG key ID: 047556B5D93FFE28
3 changed files with 39 additions and 21 deletions

23
lib/tracer-config.js generated
View file

@ -37,15 +37,24 @@ async function endTracingForCluster(config) {
// If there are no traced languages, we don't need to do anything.
if (!config.languages.some(languages_1.isTracedLanguage))
return;
const endTracingEnvVariables = JSON.parse(fs.readFileSync(path.resolve(config.dbLocation, "temp/tracingEnvironment/end-tracing.json"), "utf8"));
for (const [key, value] of Object.entries(endTracingEnvVariables)) {
if (value !== null) {
process.env[key] = value;
}
else {
delete process.env[key];
const envVariablesFile = path.resolve(config.dbLocation, "temp/tracingEnvironment/end-tracing.json");
if (!fs.existsSync(envVariablesFile)) {
throw new Error(`Environment file for ending tracing not found: ${envVariablesFile}`);
}
try {
const endTracingEnvVariables = 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}`);
}
}
exports.endTracingForCluster = endTracingForCluster;
async function getTracerConfigForCluster(config) {

File diff suppressed because one or more lines are too long

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}`
);
}
}