Skip to content

Commit

Permalink
Improve error handling for ending tracing
Browse files Browse the repository at this point in the history
  • Loading branch information
edoardopirovano committed Feb 23, 2022
1 parent c592525 commit afbddca
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 21 deletions.
23 changes: 16 additions & 7 deletions lib/tracer-config.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion lib/tracer-config.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

35 changes: 22 additions & 13 deletions src/tracer-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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}`
);
}
}

Expand Down

0 comments on commit afbddca

Please sign in to comment.