Skip to content

Commit afbddca

Browse files
Improve error handling for ending tracing
1 parent c592525 commit afbddca

File tree

3 files changed

+39
-21
lines changed

3 files changed

+39
-21
lines changed

lib/tracer-config.js

Lines changed: 16 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/tracer-config.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/tracer-config.ts

Lines changed: 22 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -26,21 +26,30 @@ export async function endTracingForCluster(
2626
// If there are no traced languages, we don't need to do anything.
2727
if (!config.languages.some(isTracedLanguage)) return;
2828

29-
const endTracingEnvVariables: Map<string, string | null> = JSON.parse(
30-
fs.readFileSync(
31-
path.resolve(
32-
config.dbLocation,
33-
"temp/tracingEnvironment/end-tracing.json"
34-
),
35-
"utf8"
36-
)
29+
const envVariablesFile = path.resolve(
30+
config.dbLocation,
31+
"temp/tracingEnvironment/end-tracing.json"
3732
);
38-
for (const [key, value] of Object.entries(endTracingEnvVariables)) {
39-
if (value !== null) {
40-
process.env[key] = value;
41-
} else {
42-
delete process.env[key];
33+
if (!fs.existsSync(envVariablesFile)) {
34+
throw new Error(
35+
`Environment file for ending tracing not found: ${envVariablesFile}`
36+
);
37+
}
38+
try {
39+
const endTracingEnvVariables: Map<string, string | null> = JSON.parse(
40+
fs.readFileSync(envVariablesFile, "utf8")
41+
);
42+
for (const [key, value] of Object.entries(endTracingEnvVariables)) {
43+
if (value !== null) {
44+
process.env[key] = value;
45+
} else {
46+
delete process.env[key];
47+
}
4348
}
49+
} catch (e) {
50+
throw new Error(
51+
`Failed to parse file containing end tracing environment variables: ${e}`
52+
);
4453
}
4554
}
4655

0 commit comments

Comments
 (0)