Improve error handling for ending tracing
This commit is contained in:
parent
c592525a67
commit
afbddca263
3 changed files with 39 additions and 21 deletions
23
lib/tracer-config.js
generated
23
lib/tracer-config.js
generated
|
|
@ -37,15 +37,24 @@ async function endTracingForCluster(config) {
|
||||||
// If there are no traced languages, we don't need to do anything.
|
// If there are no traced languages, we don't need to do anything.
|
||||||
if (!config.languages.some(languages_1.isTracedLanguage))
|
if (!config.languages.some(languages_1.isTracedLanguage))
|
||||||
return;
|
return;
|
||||||
const endTracingEnvVariables = 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 (!fs.existsSync(envVariablesFile)) {
|
||||||
if (value !== null) {
|
throw new Error(`Environment file for ending tracing not found: ${envVariablesFile}`);
|
||||||
process.env[key] = value;
|
}
|
||||||
}
|
try {
|
||||||
else {
|
const endTracingEnvVariables = JSON.parse(fs.readFileSync(envVariablesFile, "utf8"));
|
||||||
delete process.env[key];
|
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;
|
exports.endTracingForCluster = endTracingForCluster;
|
||||||
async function getTracerConfigForCluster(config) {
|
async function getTracerConfigForCluster(config) {
|
||||||
|
|
|
||||||
File diff suppressed because one or more lines are too long
|
|
@ -26,21 +26,30 @@ export async function endTracingForCluster(
|
||||||
// If there are no traced languages, we don't need to do anything.
|
// If there are no traced languages, we don't need to do anything.
|
||||||
if (!config.languages.some(isTracedLanguage)) return;
|
if (!config.languages.some(isTracedLanguage)) return;
|
||||||
|
|
||||||
const endTracingEnvVariables: Map<string, string | null> = JSON.parse(
|
const envVariablesFile = path.resolve(
|
||||||
fs.readFileSync(
|
config.dbLocation,
|
||||||
path.resolve(
|
"temp/tracingEnvironment/end-tracing.json"
|
||||||
config.dbLocation,
|
|
||||||
"temp/tracingEnvironment/end-tracing.json"
|
|
||||||
),
|
|
||||||
"utf8"
|
|
||||||
)
|
|
||||||
);
|
);
|
||||||
for (const [key, value] of Object.entries(endTracingEnvVariables)) {
|
if (!fs.existsSync(envVariablesFile)) {
|
||||||
if (value !== null) {
|
throw new Error(
|
||||||
process.env[key] = value;
|
`Environment file for ending tracing not found: ${envVariablesFile}`
|
||||||
} else {
|
);
|
||||||
delete process.env[key];
|
}
|
||||||
|
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}`
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue