Skip to content

🪢 Open source agent evals & observability: Trace, evaluate, and improve LLM applications with one open platform.

fix: avoid potentialy expensive JSON.stringify when debug logging is disabled (#11661)

Valery Meleshkin60b5706c182c
diff --git a/worker/src/features/evaluation/evalService.ts b/worker/src/features/evaluation/evalService.ts
index b7c5e411ba..87ccc44ed8 100644
--- a/worker/src/features/evaluation/evalService.ts
+++ b/worker/src/features/evaluation/evalService.ts
@@ -719,9 +719,11 @@ export const evaluate = async ({
variableMapping: parsedVariableMapping,
});
- logger.debug(
- `Evaluating job ${event.jobExecutionId} extracted variables ${JSON.stringify(mappingResult)} `,
- );
+ if (logger.isLevelEnabled("debug")) {
+ logger.debug(
+ `Evaluating job ${event.jobExecutionId} extracted variables ${JSON.stringify(mappingResult)} `,
+ );
+ }
// Get environment from trace or observation variables
const environment = mappingResult.find((r) => r.environment)?.environment;
@@ -830,9 +832,11 @@ export const evaluate = async ({
);
}
- logger.debug(
- `Evaluating job ${event.jobExecutionId} Parsed LLM output ${JSON.stringify(parsedLLMOutput)}`,
- );
+ if (logger.isLevelEnabled("debug")) {
+ logger.debug(
+ `Evaluating job ${event.jobExecutionId} Parsed LLM output ${JSON.stringify(parsedLLMOutput)}`,
+ );
+ }
const baseScore = {
id: scoreId,
@@ -1126,9 +1130,11 @@ export const parseDatabaseRowToString = (
let jsonSelectedColumn;
if (mapping.jsonSelector) {
- logger.debug(
- `Parsing JSON for json selector ${mapping.jsonSelector} from ${JSON.stringify(selectedColumn)}`,
- );
+ if (logger.isLevelEnabled("debug")) {
+ logger.debug(
+ `Parsing JSON for json selector ${mapping.jsonSelector} from ${JSON.stringify(selectedColumn)}`,
+ );
+ }
try {
jsonSelectedColumn = JSONPath({