Skip to content

Commit c246120

Browse files
committed
add custom traces instead of logging
1 parent 914d323 commit c246120

File tree

1 file changed

+16
-19
lines changed

1 file changed

+16
-19
lines changed

packages/build/src/extensions/python.ts

Lines changed: 16 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -124,28 +124,25 @@ export const run = async (
124124
): Promise<Result> => {
125125
const pythonBin = process.env.PYTHON_BIN_PATH || "python";
126126

127-
const result = await x(pythonBin, scriptArgs, {
128-
...options,
129-
throwOnError: false, // Ensure errors are handled manually
130-
});
131-
132-
try {
133-
assert(
134-
result.exitCode === 0,
135-
`Python command exited with non-zero code ${result.exitCode}\nStdout: ${result.stdout}\nStderr: ${result.stderr}`
136-
);
137-
} catch (error) {
138-
logger.error("Python command execution failed", {
139-
error: error instanceof Error ? error.message : error,
127+
return await logger.trace("Python call", async (span) => {
128+
span.addEvent("Properties", {
140129
command: `${pythonBin} ${scriptArgs.join(" ")}`,
141-
stdout: result.stdout,
142-
stderr: result.stderr,
143-
exitCode: result.exitCode,
144130
});
145-
throw error;
146-
}
147131

148-
return result;
132+
const result = await x(pythonBin, scriptArgs, {
133+
...options,
134+
throwOnError: false, // Ensure errors are handled manually
135+
});
136+
137+
span.addEvent("Output", { ...result });
138+
139+
if (result.exitCode !== 0) {
140+
logger.error(result.stderr, { ...result });
141+
throw new Error(`Python command exited with non-zero code ${result.exitCode}`);
142+
}
143+
144+
return result;
145+
});
149146
};
150147

151148
export const runScript = (

0 commit comments

Comments
 (0)