Skip to content

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

feat: evals queue logic (#1615)

Max Deichmanna89afd47c72e
diff --git a/.github/workflows/pipeline.yml b/.github/workflows/pipeline.yml
index 8824c3251c..14e1198b87 100644
--- a/.github/workflows/pipeline.yml
+++ b/.github/workflows/pipeline.yml
@@ -54,7 +54,7 @@ jobs:
file: ./worker/Dockerfile
push: false
- tests:
+ tests-web:
runs-on: ubuntu-latest
strategy:
matrix:
@@ -102,7 +102,56 @@ jobs:
run: (pnpm run start&)
- name: run tests
- run: pnpm run test
+ run: pnpm --filter=web run test
+
+ tests-worker:
+ runs-on: ubuntu-latest
+ strategy:
+ matrix:
+ node-version: [20]
+ env:
+ OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }}
+ steps:
+ - name: Set Swap Space
+ uses: pierotofy/set-swap-space@master
+ with:
+ swap-size-gb: 10
+
+ - uses: actions/checkout@v3
+ - uses: pnpm/action-setup@v3
+ with:
+ version: 8
+ - name: Use Node.js ${{ matrix.node-version }}
+ uses: actions/setup-node@v3
+ with:
+ node-version: ${{ matrix.node-version }}
+ cache: "pnpm"
+ cache-dependency-path: "pnpm-lock.yaml"
+
+ - name: install dependencies
+ run: |
+ pnpm install
+
+ - name: Load default env
+ run: |
+ cp .env.dev.example .env
+ cp .env.dev.example web/.env
+
+ - name: Run + migrate
+ run: |
+ docker compose -f docker-compose.dev.yml up -d
+ sleep 5 # Wait for PostgreSQL to accept connections
+
+ - name: Seed DB
+ run: |
+ pnpm run db:migrate
+ pnpm run db:seed
+
+ - name: Build
+ run: pnpm --filter=worker... run build
+
+ - name: run tests
+ run: pnpm --filter=worker run test
e2e-tests:
runs-on: ubuntu-latest
@@ -148,7 +197,7 @@ jobs:
all-ci-passed:
# This allows us to have a branch protection rule for tests and deploys with matrix
runs-on: ubuntu-latest
- needs: [lint, tests, e2e-tests, test-docker-build]
+ needs: [lint, tests-web, tests-worker, e2e-tests, test-docker-build]
if: always()
steps:
- name: Successful deploy
diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml
index d2a8aabd39..d851c5bec7 100644
--- a/pnpm-lock.yaml
+++ b/pnpm-lock.yaml
@@ -532,6 +532,9 @@ importers:
cors:
specifier: ^2.8.5
version: 2.8.5
+ decimal.js:
+ specifier: ^10.4.3
+ version: 10.4.3
dotenv:
specifier: ^16.4.5
version: 16.4.5
diff --git a/worker/package.json b/worker/package.json
index f4207008e5..d4bbcabefa 100644
--- a/worker/package.json
+++ b/worker/package.json
@@ -9,7 +9,7 @@
"node": ">=20"
},
"scripts": {
- "test": "vitest run",
+ "test": "dotenv -e ../.env -- vitest run --reporter=basic --disable-console-intercept",
"coverage": "vitest run --coverage",
"start": "dotenv -e ../.env -- node dist/src/index.js",
"build": "tsc",
@@ -25,6 +25,7 @@
"backoff": "^2.5.0",
"bullmq": "^5.4.2",
"cors": "^2.8.5",
+ "decimal.js": "^10.4.3",
"dotenv": "^16.4.5",
"express": "^4.19.2",
"express-basic-auth": "^1.2.1",
diff --git a/worker/src/__tests__/eval-service.test.ts b/worker/src/__tests__/eval-service.test.ts
new file mode 100644
index 0000000000..d272c11c7c
--- /dev/null
+++ b/worker/src/__tests__/eval-service.test.ts
@@ -0,0 +1,384 @@
+import { expect, test, describe, vi } from "vitest";
+import { createEvalJobs, evaluate } from "../eval-service";
+import { kyselyPrisma, prisma } from "@langfuse/shared/src/db";
+import { randomUUID } from "crypto";
+import Decimal from "decimal.js";
+import { pruneDatabase } from "./utils";
+import { sql } from "kysely";
+import logger from "../logger";
+
+vi.mock("../redis/consumer", () => ({
+ evalQueue: {
+ add: vi.fn().mockImplementation((jobName, jobData) => {
+ console.log(
+ `Mock evalQueue.add called with jobName: ${jobName} and jobData:`,
+ jobData
+ );
+ // Simulate the job being processed immediately by calling the job's processing function
+ // Note: You would replace `processJobFunction` with the actual function that processes the job
+ // For example, if `createEvalJobs` is the function that should be called, you would use it here
+ // processJobFunction({ data: jobData.payload });
+ }),
+ },
+}));
+
+describe("create eval jobs", () => {
+ test("creates new eval job", async () => {
+ await pruneDatabase();
+ const traceId = randomUUID();
+
+ await kyselyPrisma.$kysely
+ .insertInto("traces")
+ .values({
+ id: traceId,
+ project_id: "7a88fb47-b4e2-43b8-a06c-a5ce950dc53a",
+ })
+ .execute();
+
+ await prisma.jobConfiguration.create({
+ data: {
+ id: randomUUID(),
+ projectId: "7a88fb47-b4e2-43b8-a06c-a5ce950dc53a",
+ filter: JSON.parse("[]"),
+ jobType: "EVAL",
+ delay: 0,
+ sampling: new Decimal("1"),
+ targetObject: "traces",
+ scoreName: "score",
+ variableMapping: JSON.parse("[]"),
+ },
+ });
+
+ const payload = {
+ timestamp: "2022-01-01T00:00:00.000Z",
+ id: "abc",
+ data: {
+ projectId: "7a88fb47-b4e2-43b8-a06c-a5ce950dc53a",
+ traceId: traceId,
+ },
+ };
+
+ await createEvalJobs({ data: payload });
+
+ const jobs = await kyselyPrisma.$kysely
+ .selectFrom("job_executions")
+ .selectAll()
+ .where("project_id", "=", "7a88fb47-b4e2-43b8-a06c-a5ce950dc53a")
+ .execute();
+
+ expect(jobs.length).toBe(1);
+ expect(jobs[0].project_id).toBe("7a88fb47-b4e2-43b8-a06c-a5ce950dc53a");
+ expect(jobs[0].job_input_trace_id).toBe(traceId);
+ expect(jobs[0].status.toString()).toBe("PENDING");
+ }, 10_000);
+
+ test("does not create eval job for existing job execution", async () => {
+ await pruneDatabase();
+ const traceId = randomUUID();
+
+ await kyselyPrisma.$kysely
+ .insertInto("traces")
+ .values({
+ id: traceId,
+ project_id: "7a88fb47-b4e2-43b8-a06c-a5ce950dc53a",
+ })
+ .execute();
+
+ await prisma.jobConfiguration.create({
+ data: {
+ id: randomUUID(),
+ projectId: "7a88fb47-b4e2-43b8-a06c-a5ce950dc53a",
+ filter: JSON.parse("[]"),
+ jobType: "EVAL",
+ delay: 0,
+ sampling: new Decimal("1"),
+ targetObject: "traces",
+ scoreName: "score",
+ variableMapping: JSON.parse("[]"),
+ },
+ });
+
+ const payload = {
+ timestamp: "2022-01-01T00:00:00.000Z",
+ id: "abc",
+ data: {
+ projectId: "7a88fb47-b4e2-43b8-a06c-a5ce950dc53a",
+ traceId: traceId,
+ },
+ };
+
+ await createEvalJobs({ data: payload });
+ await createEvalJobs({ data: payload }); // calling it twice to check it is only generated once
+
+ const jobs = await kyselyPrisma.$kysely
+ .selectFrom("job_executions")
+ .selectAll()
+ .where("project_id", "=", "7a88fb47-b4e2-43b8-a06c-a5ce950dc53a")
+ .execute();
+
+ expect(jobs.length).toBe(1);
+ expect(jobs[0].project_id).toBe("7a88fb47-b4e2-43b8-a06c-a5ce950dc53a");
+ expect(jobs[0].job_input_trace_id).toBe(traceId);
+ expect(jobs[0].status.toString()).toBe("PENDING");
+ }, 10_000);
+
+ test("cancels a job if the second event deselects", async () => {
+ await pruneDatabase();
+ const traceId = randomUUID();
+
+ await kyselyPrisma.$kysely
+ .insertInto("traces")
+ .values({
+ id: traceId,
+ project_id: "7a88fb47-b4e2-43b8-a06c-a5ce950dc53a",
+ user_id: "a",
+ })
+ .execute();
+
+ await prisma.jobConfiguration.create({
+ data: {
+ id: randomUUID(),
+ projectId: "7a88fb47-b4e2-43b8-a06c-a5ce950dc53a",
+ filter: [
+ {
+ type: "string",
+ value: "a",
+ column: "User ID",
+ operator: "contains",
+ },
+ ],
+ jobType: "EVAL",
+ delay: 0,
+ sampling: new Decimal("1"),
+ targetObject: "traces",
+ scoreName: "score",
+ variableMapping: JSON.parse("[]"),
+ },
+ });
+
+ const payload = {
+ timestamp: "2022-01-01T00:00:00.000Z",
+ id: "abc",
+ data: {
+ projectId: "7a88fb47-b4e2-43b8-a06c-a5ce950dc53a",
+ traceId: traceId,
+ },
+ };
+
+ await createEvalJobs({ data: payload });
+
+ // update the trace to deselect the trace
+ await kyselyPrisma.$kysely
+ .updateTable("traces")
+ .set("user_id", "b")
+ .where("id", "=", traceId)
+ .execute();
+
+ await createEvalJobs({
+ data: payload,
+ }); // calling it twice to check it is only generated once
+
+ const jobs = await kyselyPrisma.$kysely
+ .selectFrom("job_executions")
+ .selectAll()
+ .where("project_id", "=", "7a88fb47-b4e2-43b8-a06c-a5ce950dc53a")
+ .execute();
+
+ expect(jobs.length).toBe(1);
+ expect(jobs[0].project_id).toBe("7a88fb47-b4e2-43b8-a06c-a5ce950dc53a");
+ expect(jobs[0].job_input_trace_id).toBe(traceId);
+ expect(jobs[0].status.toString()).toBe("CANCELLED");
+ }, 10_000);
+});
+
+describe("execute evals", () => {
+ test("evals a valid eval event", async () => {
+ await pruneDatabase();
+ const traceId = randomUUID();
+
+ await kyselyPrisma.$kysely
+ .insertInto("traces")
+ .values({
+ id: traceId,
+ project_id: "7a88fb47-b4e2-43b8-a06c-a5ce950dc53a",
+ user_id: "a",
+ input: { input: "This is a great prompt" },
+ output: { output: "This is a great response" },
+ })
+ .execute();
+
+ const templateId = randomUUID();
+ await kyselyPrisma.$kysely
+ .insertInto("eval_templates")
+ .values({
+ id: templateId,
+ project_id: "7a88fb47-b4e2-43b8-a06c-a5ce950dc53a",
+ name: "test-template",
+ version: 1,
+ prompt: "Please evaluate toxicity {{input}} {{output}}",
+ model: "gpt-3.5-turbo",
+ model_params: {},
+ output_schema: {
+ reasoning: "Please explain your reasoning",
+ score: "Please provide a score between 0 and 1",
+ },
+ })
+ .executeTakeFirst();
+
+ const jobConfiguration = await prisma.jobConfiguration.create({
+ data: {
+ id: randomUUID(),
+ projectId: "7a88fb47-b4e2-43b8-a06c-a5ce950dc53a",
+ filter: [
+ {
+ type: "string",
+ value: "a",
+ column: "User ID",
+ operator: "contains",
+ },
+ ],
+ jobType: "EVAL",
+ delay: 0,
+ sampling: new Decimal("1"),
+ targetObject: "traces",
+ scoreName: "score",
+ variableMapping: JSON.parse("[]"),
+ evalTemplateId: templateId,
+ },
+ });
+
+ const jobExecutionId = randomUUID();
+
+ await kyselyPrisma.$kysely
+ .insertInto("job_executions")
+ .values({
+ id: jobExecutionId,
+ project_id: "7a88fb47-b4e2-43b8-a06c-a5ce950dc53a",
+ job_configuration_id: jobConfiguration.id,
+ status: sql`'PENDING'::"JobExecutionStatus"`,
+ start_time: new Date(),
+ job_input_trace_id: traceId,
+ })
+ .execute();
+
+ const payload = {
+ timestamp: "2022-01-01T00:00:00.000Z",
+ id: "abc",
+ data: {
+ projectId: "7a88fb47-b4e2-43b8-a06c-a5ce950dc53a",
+ jobExecutionId: jobExecutionId,
+ },
+ };
+
+ await evaluate({ data: payload });
+
+ const jobs = await kyselyPrisma.$kysely
+ .selectFrom("job_executions")
+ .selectAll()
+ .where("project_id", "=", "7a88fb47-b4e2-43b8-a06c-a5ce950dc53a")
+ .execute();
+
+ expect(jobs.length).toBe(1);
+ expect(jobs[0].project_id).toBe("7a88fb47-b4e2-43b8-a06c-a5ce950dc53a");
+ expect(jobs[0].job_input_trace_id).toBe(traceId);
+ expect(jobs[0].status.toString()).toBe("COMPLETED");
+
+ const scores = await kyselyPrisma.$kysely
+ .selectFrom("scores")
+ .selectAll()
+ .where("trace_id", "=", traceId)
+ .execute();
+
+ expect(scores.length).toBe(1);
+ expect(scores[0].trace_id).toBe(traceId);
+ expect(scores[0].comment).not.toBeNull();
+ }, 10_000);
+
+ test("evals should cancel if job is cancelled", async () => {
+ await pruneDatabase();
+ const traceId = randomUUID();
+
+ await kyselyPrisma.$kysely
+ .insertInto("traces")
+ .values({
+ id: traceId,
+ project_id: "7a88fb47-b4e2-43b8-a06c-a5ce950dc53a",
+ user_id: "a",
+ input: { input: "This is a great prompt" },
+ output: { output: "This is a great response" },
+ })
+ .execute();
+
+ const templateId = randomUUID();
+ await kyselyPrisma.$kysely
+ .insertInto("eval_templates")
+ .values({
+ id: templateId,
+ project_id: "7a88fb47-b4e2-43b8-a06c-a5ce950dc53a",
+ name: "test-template",
+ version: 1,
+ prompt: "Please evaluate toxicity {{input}} {{output}}",
+ model: "gpt-3.5-turbo",
+ model_params: {},
+ output_schema: {
+ reasoning: "Please explain your reasoning",
+ score: "Please provide a score between 0 and 1",
+ },
+ })
+ .executeTakeFirst();
+
+ const jobConfiguration = await prisma.jobConfiguration.create({
+ data: {
+ id: randomUUID(),
+ projectId: "7a88fb47-b4e2-43b8-a06c-a5ce950dc53a",
+ filter: [
+ {
+ type: "string",
+ value: "a",
+ column: "User ID",
+ operator: "contains",
+ },
+ ],
+ jobType: "EVAL",
+ delay: 0,
+ sampling: new Decimal("1"),
+ targetObject: "traces",
+ scoreName: "score",
+ variableMapping: JSON.parse("[]"),
+ evalTemplateId: templateId,
+ },
+ });
+
+ const jobExecutionId = randomUUID();
+ await kyselyPrisma.$kysely
+ .insertInto("job_executions")
+ .values({
+ id: jobExecutionId,
+ project_id: "7a88fb47-b4e2-43b8-a06c-a5ce950dc53a",
+ job_configuration_id: jobConfiguration.id,
+ status: sql`'CANCELLED'::"JobExecutionStatus"`,
+ start_time: new Date(),
+ job_input_trace_id: traceId,
+ })
+ .execute();
+
+ const payload = {
+ timestamp: "2022-01-01T00:00:00.000Z",
+ id: "abc",
+ data: {
+ projectId: "7a88fb47-b4e2-43b8-a06c-a5ce950dc53a",
+ jobExecutionId: jobExecutionId,
+ },
+ };
+
+ await evaluate({ data: payload });
+
+ const jobs = await kyselyPrisma.$kysely
+ .selectFrom("job_executions")
+ .selectAll()
+ .where("project_id", "=", "7a88fb47-b4e2-43b8-a06c-a5ce950dc53a")
+ .execute();
+
+ expect(jobs.length).toBe(0);
+ }, 10_000);
+});
diff --git a/worker/src/__tests__/redis-consumer.test.ts b/worker/src/__tests__/redis-consumer.test.ts
new file mode 100644
index 0000000000..7e4be69adb
--- /dev/null
+++ b/worker/src/__tests__/redis-consumer.test.ts
@@ -0,0 +1,43 @@
+import { expect, test, describe, vi } from "vitest";
+import { evalQueue } from "../api";
+import { QueueJobs, TraceUpsertEvent } from "@langfuse/shared";
+import { randomUUID } from "crypto";
+import { z } from "zod";
+
+describe("handle redis events", () => {
+ test("handle redis job succeeding", async () => {
+ vi.mock("../eval-service", () => ({
+ createEvalJobs: async ({
+ data,
+ }: {
+ data: z.infer<typeof TraceUpsertEvent>;
+ }) => {
+ return true;
+ },
+ }));
+
+ expect(evalQueue).toBeDefined();
+
+ const job = await evalQueue?.add(QueueJobs.TraceUpsert, {
+ payload: {
+ id: randomUUID(),
+ timestamp: new Date().toISOString(),
+ data: {
+ projectId: "project-id",
+ traceId: "trace-id",
+ },
+ },
+ name: QueueJobs.TraceUpsert as const,
+ });
+
+ await vi.waitFor(
+ async () => {
+ const jobState = await evalQueue?.getJobState(job!.id!);
+ expect(jobState).toEqual("completed");
+ },
+ {
+ timeout: 10_000,
+ }
+ );
+ }, 10_000);
+});
diff --git a/worker/src/__tests__/sum.test.ts b/worker/src/__tests__/sum.test.ts
deleted file mode 100644
index d95817efb2..0000000000
--- a/worker/src/__tests__/sum.test.ts
+++ /dev/null
@@ -1,5 +0,0 @@
-import { expect, test } from "vitest";
-
-test("adds 1 + 2 to equal 3", () => {
- expect(3).toBe(3);
-});
diff --git a/worker/src/__tests__/utils.ts b/worker/src/__tests__/utils.ts
new file mode 100644
index 0000000000..e70a01b6e9
--- /dev/null
+++ b/worker/src/__tests__/utils.ts
@@ -0,0 +1,18 @@
+import { prisma } from "@langfuse/shared/src/db";
+import logger from "../logger";
+
+export const pruneDatabase = async () => {
+ logger.info("Pruning database");
+ await prisma.score.deleteMany();
+ await prisma.observation.deleteMany();
+ await prisma.trace.deleteMany();
+ await prisma.datasetItem.deleteMany();
+ await prisma.dataset.deleteMany();
+ await prisma.datasetRuns.deleteMany();
+ await prisma.prompt.deleteMany();
+ await prisma.events.deleteMany();
+ await prisma.model.deleteMany();
+ await prisma.jobExecution.deleteMany();
+ await prisma.jobConfiguration.deleteMany();
+ await prisma.evalTemplate.deleteMany();
+};
diff --git a/worker/src/api/index.ts b/worker/src/api/index.ts
index 4bffe3f204..bad79057b0 100644
--- a/worker/src/api/index.ts
+++ b/worker/src/api/index.ts
@@ -83,6 +83,13 @@ router
},
},
name: QueueJobs.TraceUpsert as const,
+ opts: {
+ attempts: 5,
+ backoff: {
+ type: "exponential",
+ delay: 1000,
+ },
+ },
},
}));
diff --git a/worker/src/eval-service.ts b/worker/src/eval-service.ts
index 6c6a164827..6a8c354d86 100644
--- a/worker/src/eval-service.ts
+++ b/worker/src/eval-service.ts
@@ -12,7 +12,6 @@ import {
tableColumnsToSqlFilterAndPrefix,
tracesTableCols,
variableMappingList,
- observationsTableCols,
evalObjects,
TraceUpsertEvent,
} from "@langfuse/shared";
@@ -22,8 +21,6 @@ import { randomUUID } from "crypto";
import { evalQueue } from "./redis/consumer";
import { sql } from "kysely";
import Handlebars from "handlebars";
-import { JobExecution, EvalTemplate } from "@langfuse/shared";
-import lodash from "lodash";
import logger from "./logger";
// this function is used to determine which eval jobs to create for a given trace
@@ -36,7 +33,7 @@ export const createEvalJobs = async ({
const configs = await kyselyPrisma.$kysely
.selectFrom("job_configurations")
.selectAll()
- .where("job_type", "=", "EVAL")
+ .where(sql.raw("job_type::text"), "=", "EVAL")
.where("project_id", "=", data.data.projectId)
.execute();
@@ -44,8 +41,10 @@ export const createEvalJobs = async ({
logger.info("No evaluation jobs found for project", data.data.projectId);
return;
}
+ logger.info("Creating eval jobs for trace", data.data.traceId);
for (const config of configs) {
+ logger.info("Creating eval job for config", config.id);
const validatedFilter = z.array(singleFilter).parse(config.filter);
const condition = tableColumnsToSqlFilterAndPrefix(
@@ -64,12 +63,33 @@ export const createEvalJobs = async ({
const traces = await prisma.$queryRaw<Array<{ id: string }>>(joinedQuery);
+ const existingJob = await kyselyPrisma.$kysely
+ .selectFrom("job_executions")
+ .select("id")
+ .where("project_id", "=", data.data.projectId)
+ .where("job_configuration_id", "=", config.id)
+ .where("job_input_trace_id", "=", data.data.traceId)
+ .execute();
+
+ // if we have a match, and no execution exists already, we want to create a job execution
if (traces.length > 0) {
logger.info(
`Eval job for config ${config.id} matched trace ids ${JSON.stringify(traces.map((t) => t.id))}`
);
const jobExecutionId = randomUUID();
+
+ if (existingJob.length > 0) {
+ logger.info(
+ `Eval job for config ${config.id} and trace ${data.data.traceId} already exists`
+ );
+ continue;
+ }
+
+ logger.info(
+ `Creating eval job for config ${config.id} and trace ${data.data.traceId}`
+ );
+
await kyselyPrisma.$kysely
.insertInto("job_executions")
.values({
@@ -77,7 +97,7 @@ export const createEvalJobs = async ({
project_id: data.data.projectId,
job_configuration_id: config.id,
job_input_trace_id: data.data.traceId,
- status: "PENDING",
+ status: sql`'PENDING'::"JobExecutionStatus"`,
})
.execute();
@@ -103,6 +123,20 @@ export const createEvalJobs = async ({
delay: config.delay, // milliseconds
}
);
+ } else {
+ // if we do not have a match, and execution exists, we mark the job as cancelled
+ // we do this, because a second trace event might 'deselect' a trace
+ logger.info(`Eval job for config ${config.id} did not match trace`);
+ if (existingJob.length > 0) {
+ logger.info(
+ `Cancelling eval job for config ${config.id} and trace ${data.data.traceId}`
+ );
+ await kyselyPrisma.$kysely
+ .updateTable("job_executions")
+ .set("status", sql`'CANCELLED'::"JobExecutionStatus"`)
+ .where("id", "=", existingJob[0].id)
+ .execute();
+ }
}
}
};
@@ -124,20 +158,36 @@ export const evaluate = async ({
.where("project_id", "=", data.data.projectId)
.executeTakeFirstOrThrow();
- if (!job.job_input_trace_id) {
+ if (!job?.job_input_trace_id) {
throw new Error("Jobs can only be executed on traces for now.");
}
+ if (job.status === "CANCELLED") {
+ logger.info(
+ `Job ${job.id} for project ${data.data.projectId} was cancelled.`
+ );
+
+ await kyselyPrisma.$kysely
+ .deleteFrom("job_executions")
+ .where("id", "=", job.id)
+ .where("project_id", "=", data.data.projectId)
+ .execute();
+
+ return;
+ }
+
const config = await kyselyPrisma.$kysely
.selectFrom("job_configurations")
.selectAll()
.where("id", "=", job.job_configuration_id)
+ .where("project_id", "=", data.data.projectId)
.executeTakeFirstOrThrow();
const template = await kyselyPrisma.$kysely
.selectFrom("eval_templates")
.selectAll()
.where("id", "=", config.eval_template_id)
+ .where("project_id", "=", data.data.projectId)
.executeTakeFirstOrThrow();
logger.info(
@@ -215,7 +265,7 @@ export const evaluate = async ({
await kyselyPrisma.$kysely
.updateTable("job_executions")
- .set("status", "COMPLETED")
+ .set("status", sql`'COMPLETED'::"JobExecutionStatus"`)
.set("end_time", new Date())
.set("job_output_score_id", scoreId)
.where("id", "=", data.data.jobExecutionId)
@@ -226,7 +276,7 @@ export function compileHandlebarString(
handlebarString: string,
context: Record<string, any>
): string {
- console.log("Compiling handlebar string", handlebarString, context);
+ logger.info("Compiling handlebar string", handlebarString, context);
const template = Handlebars.compile(handlebarString, { noEscape: true });
return template(context);
}
diff --git a/worker/src/logger.ts b/worker/src/logger.ts
index e8896b831c..72c1a97d7a 100644
--- a/worker/src/logger.ts
+++ b/worker/src/logger.ts
@@ -2,19 +2,18 @@ import pino from "pino";
import { env } from "./env";
export const getLogger = (env: "development" | "production" | "test") => {
- if (env === "development") {
- return pino({
- transport: {
- target: "pino-pretty",
- options: {
- translateTime: "HH:MM:ss Z",
- ignore: "pid,hostname",
- },
- },
- });
- } else {
+ if (env === "production") {
return pino();
}
+ return pino({
+ transport: {
+ target: "pino-pretty",
+ options: {
+ translateTime: "HH:MM:ss Z",
+ ignore: "pid,hostname",
+ },
+ },
+ });
};
const logger = getLogger(env.NODE_ENV);
diff --git a/worker/src/redis/consumer.ts b/worker/src/redis/consumer.ts
index 1b9fc85c28..65ce0a2bc7 100644
--- a/worker/src/redis/consumer.ts
+++ b/worker/src/redis/consumer.ts
@@ -41,12 +41,12 @@ export const evalJobCreator = redis
QueueName.TraceUpsert,
async (job: Job<TQueueJobTypes[QueueName.TraceUpsert]>) => {
try {
- console.log("Executing Evaluation Job", job.data);
+ logger.info("Executing Evaluation Job", job.data);
await createEvalJobs({ data: job.data.payload });
return true;
} catch (e) {
- console.error(
+ logger.error(
`Failed job Evaluation for traceId ${job.data.payload.data.traceId}`,
e
);
@@ -68,7 +68,7 @@ export const evalJobExecutor = redis
await evaluate({ data: job.data.payload });
return true;
} catch (e) {
- console.error(
+ logger.error(
`Failed Evaluation_Execution job for id ${job.data.payload.data.jobExecutionId}`,
e
);