Skip to content

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

feat: introducing LANGFUSE_DISABLE_LEGACY_TRACING_IO_SEARCH flag to allow disabling FTS on v3 tables (#13912)

Valery Meleshkinc77fcd9dad03
diff --git a/.env.dev.example b/.env.dev.example
index b2d12ef0db..5f8ba8fe2d 100644
--- a/.env.dev.example
+++ b/.env.dev.example
@@ -182,6 +182,9 @@ LANGFUSE_AWS_BEDROCK_REGION="eu-west-1"
LANGFUSE_AWS_BEDROCK_MODEL="eu.anthropic.claude-3-haiku-20240307-v1:0"
LANGFUSE_IN_APP_AGENT_AWS_PROFILE="playground"
+# Legacy tracing UI controls
+LANGFUSE_DISABLE_LEGACY_TRACING_IO_SEARCH=false
+
# Events table migration
LANGFUSE_ENABLE_EVENTS_TABLE_OBSERVATIONS=true
LANGFUSE_ENABLE_EVENTS_TABLE_UI=true
diff --git a/.env.prod.example b/.env.prod.example
index 50e7518894..58404278d1 100644
--- a/.env.prod.example
+++ b/.env.prod.example
@@ -248,6 +248,10 @@ LANGFUSE_ENABLE_BLOB_STORAGE_FILE_LOG=true
# Valid values: core, io, scores, observations, metrics
# LANGFUSE_API_TRACEBYID_DEFAULT_FIELDS=
+# Legacy tracing UI controls
+# Disable input/output full-text search in legacy V3 tracing tables (metadata search remains available)
+# LANGFUSE_DISABLE_LEGACY_TRACING_IO_SEARCH=false
+
### START Enterprise Edition Configuration
# Allowlisted users that can create new organizations, by default all users can create organizations
diff --git a/web/src/__tests__/server/traces-trpc.servertest.ts b/web/src/__tests__/server/traces-trpc.servertest.ts
index 1ce0dfa61a..106db65f4c 100644
--- a/web/src/__tests__/server/traces-trpc.servertest.ts
+++ b/web/src/__tests__/server/traces-trpc.servertest.ts
@@ -21,6 +21,11 @@ import { composeAggregateScoreKey } from "@/src/features/scores/lib/aggregateSco
describe("traces trpc", () => {
const projectId = "7a88fb47-b4e2-43b8-a06c-a5ce950dc53a";
+ const mutableEnv = env as unknown as {
+ LANGFUSE_DISABLE_LEGACY_TRACING_IO_SEARCH: "true" | "false";
+ };
+ const originalLegacyIoSearchDisabled =
+ mutableEnv.LANGFUSE_DISABLE_LEGACY_TRACING_IO_SEARCH;
const session: Session = {
expires: "1",
@@ -58,7 +63,31 @@ describe("traces trpc", () => {
const ctx = createInnerTRPCContext({ session });
const caller = appRouter.createCaller({ ...ctx, prisma });
+ afterEach(() => {
+ mutableEnv.LANGFUSE_DISABLE_LEGACY_TRACING_IO_SEARCH =
+ originalLegacyIoSearchDisabled;
+ });
+
describe("traces.all", () => {
+ it("rejects legacy full-text search when legacy IO search is disabled", async () => {
+ mutableEnv.LANGFUSE_DISABLE_LEGACY_TRACING_IO_SEARCH = "true";
+
+ await expect(
+ caller.traces.all({
+ projectId,
+ filter: [],
+ searchQuery: "expensive search",
+ searchType: ["id", "content"],
+ page: 0,
+ limit: 50,
+ orderBy: {
+ column: "timestamp",
+ order: "DESC",
+ },
+ }),
+ ).rejects.toThrow("Input/output search is disabled");
+ });
+
it("list traces for default view", async () => {
const trace = createTrace({
project_id: projectId,
diff --git a/web/src/components/table/data-table-toolbar.tsx b/web/src/components/table/data-table-toolbar.tsx
index 2ec231a853..e0b85e8ce1 100644
--- a/web/src/components/table/data-table-toolbar.tsx
+++ b/web/src/components/table/data-table-toolbar.tsx
@@ -1,5 +1,10 @@
import { Button } from "@/src/components/ui/button";
-import React, { type Dispatch, type SetStateAction, useState } from "react";
+import React, {
+ type Dispatch,
+ type SetStateAction,
+ useEffect,
+ useState,
+} from "react";
import { Input } from "@/src/components/ui/input";
import { DataTableColumnVisibilityFilter } from "@/src/components/table/data-table-column-visibility-filter";
import { PopoverFilterBuilder } from "@/src/features/filters/components/filter-builder";
@@ -210,6 +215,9 @@ export function DataTableToolbar<TData, TValue>({
const [searchString, setSearchString] = useState(
searchConfig?.currentQuery ?? "",
);
+ useEffect(() => {
+ setSearchString(searchConfig?.currentQuery ?? "");
+ }, [searchConfig?.currentQuery]);
const capture = usePostHogClientCapture();
const { open: controlsPanelOpen, setOpen: setControlsPanelOpen } =
diff --git a/web/src/components/table/use-cases/observations.tsx b/web/src/components/table/use-cases/observations.tsx
index 40545dbcfc..b6a60efc33 100644
--- a/web/src/components/table/use-cases/observations.tsx
+++ b/web/src/components/table/use-cases/observations.tsx
@@ -92,6 +92,10 @@ import {
type RefreshInterval,
REFRESH_INTERVALS,
} from "@/src/components/table/data-table-refresh-button";
+import {
+ hasLegacyIoSearchType,
+ isLegacyIoSearchDisabledError,
+} from "@/src/features/traces/lib/legacyIoSearch";
export type ObservationsTableRow = {
// Shown by default
@@ -219,6 +223,17 @@ export default function ObservationsTable({
}, [utils]);
const { searchQuery, searchType, setSearchQuery, setSearchType } =
useFullTextSearch();
+ const legacyTracingSearchConfig = api.public.tracingSearchConfig.useQuery(
+ { projectId },
+ {
+ enabled: !hideControls,
+ refetchOnMount: false,
+ refetchOnWindowFocus: false,
+ refetchOnReconnect: false,
+ },
+ );
+ const legacyTracingIoSearchEnabled =
+ legacyTracingSearchConfig.data?.legacyTracingIoSearchEnabled ?? true;
const { selectAll, setSelectAll } = useSelectAll(projectId, "observations");
const [showAddToDatasetDialog, setShowAddToDatasetDialog] = useState(false);
@@ -534,6 +549,23 @@ export default function ObservationsTable({
const totalCountQuery = api.generations.countAll.useQuery(getCountPayload, {
refetchOnWindowFocus: true,
});
+ const shouldClearLegacyIoSearch =
+ isLegacyIoSearchDisabledError(totalCountQuery.error) ||
+ isLegacyIoSearchDisabledError(generations.error);
+
+ useEffect(() => {
+ if (!shouldClearLegacyIoSearch) return;
+ if (!searchQuery && !hasLegacyIoSearchType(searchType)) return;
+
+ setSearchQuery(null);
+ setSearchType(["id"]);
+ }, [
+ searchQuery,
+ searchType,
+ setSearchQuery,
+ setSearchType,
+ shouldClearLegacyIoSearch,
+ ]);
const totalCount = totalCountQuery.data?.totalCount ?? null;
@@ -1390,9 +1422,13 @@ export default function ObservationsTable({
metadataSearchFields: ["ID", "Name", "Trace Name", "Model"],
updateQuery: setSearchQuery,
currentQuery: searchQuery ?? undefined,
- searchType,
- setSearchType,
- tableAllowsFullTextSearch: true,
+ tableAllowsFullTextSearch: legacyTracingIoSearchEnabled,
+ ...(legacyTracingIoSearchEnabled
+ ? {
+ searchType,
+ setSearchType,
+ }
+ : {}),
}}
viewConfig={{
tableName: TableViewPresetTableName.Observations,
diff --git a/web/src/components/table/use-cases/traces.tsx b/web/src/components/table/use-cases/traces.tsx
index 9e66032c89..4e0d689192 100644
--- a/web/src/components/table/use-cases/traces.tsx
+++ b/web/src/components/table/use-cases/traces.tsx
@@ -102,6 +102,10 @@ import { usePeekTableState } from "@/src/components/table/peek/contexts/PeekTabl
import { useScoreColumns } from "@/src/features/scores/hooks/useScoreColumns";
import { scoreFilters } from "@/src/features/scores/lib/scoreColumns";
import TagList from "@/src/features/tag/components/TagList";
+import {
+ hasLegacyIoSearchType,
+ isLegacyIoSearchDisabledError,
+} from "@/src/features/traces/lib/legacyIoSearch";
export type TracesTableRow = {
// Shown by default
@@ -397,6 +401,17 @@ export default function TracesTable({
const { searchQuery, searchType, setSearchQuery, setSearchType } =
useFullTextSearch();
+ const legacyTracingSearchConfig = api.public.tracingSearchConfig.useQuery(
+ { projectId },
+ {
+ enabled: !hideControls,
+ refetchOnMount: false,
+ refetchOnWindowFocus: false,
+ refetchOnReconnect: false,
+ },
+ );
+ const legacyTracingIoSearchEnabled =
+ legacyTracingSearchConfig.data?.legacyTracingIoSearchEnabled ?? true;
const tracesAllCountFilter = {
projectId,
@@ -424,6 +439,23 @@ export default function TracesTable({
refetchOnMount: false,
refetchOnWindowFocus: true,
});
+ const shouldClearLegacyIoSearch =
+ isLegacyIoSearchDisabledError(totalCountQuery.error) ||
+ isLegacyIoSearchDisabledError(traces.error);
+
+ useEffect(() => {
+ if (!shouldClearLegacyIoSearch) return;
+ if (!searchQuery && !hasLegacyIoSearchType(searchType)) return;
+
+ setSearchQuery(null);
+ setSearchType(["id"]);
+ }, [
+ searchQuery,
+ searchType,
+ setSearchQuery,
+ setSearchType,
+ shouldClearLegacyIoSearch,
+ ]);
const traceMetrics = api.traces.metrics.useQuery(
{
@@ -1409,9 +1441,13 @@ export default function TracesTable({
metadataSearchFields: ["ID", "Trace Name", "User ID"],
updateQuery: setSearchQuery,
currentQuery: searchQuery ?? undefined,
- tableAllowsFullTextSearch: true,
- setSearchType,
- searchType,
+ tableAllowsFullTextSearch: legacyTracingIoSearchEnabled,
+ ...(legacyTracingIoSearchEnabled
+ ? {
+ setSearchType,
+ searchType,
+ }
+ : {}),
}}
columnsWithCustomSelect={["traceName", "traceTags"]}
actionButtons={[
diff --git a/web/src/env.mjs b/web/src/env.mjs
index 8f9123fa17..3127cef1fe 100644
--- a/web/src/env.mjs
+++ b/web/src/env.mjs
@@ -420,6 +420,11 @@ export const env = createEnv({
LANGFUSE_API_TRACES_DEFAULT_FIELDS: z.string().optional(),
LANGFUSE_API_TRACEBYID_DEFAULT_FIELDS: z.string().optional(),
+ // Legacy tracing search controls
+ LANGFUSE_DISABLE_LEGACY_TRACING_IO_SEARCH: z
+ .enum(["true", "false"])
+ .default("false"),
+
// Events table migration
LANGFUSE_ENABLE_EVENTS_TABLE_OBSERVATIONS: z
.enum(["true", "false"])
@@ -846,6 +851,9 @@ export const env = createEnv({
process.env.LANGFUSE_API_TRACES_DEFAULT_FIELDS,
LANGFUSE_API_TRACEBYID_DEFAULT_FIELDS:
process.env.LANGFUSE_API_TRACEBYID_DEFAULT_FIELDS,
+ // Legacy tracing search controls
+ LANGFUSE_DISABLE_LEGACY_TRACING_IO_SEARCH:
+ process.env.LANGFUSE_DISABLE_LEGACY_TRACING_IO_SEARCH,
// Events table migration
LANGFUSE_ENABLE_EVENTS_TABLE_OBSERVATIONS:
process.env.LANGFUSE_ENABLE_EVENTS_TABLE_OBSERVATIONS,
diff --git a/web/src/features/batch-actions/server/addToDatasetRouter.ts b/web/src/features/batch-actions/server/addToDatasetRouter.ts
index 8c9f04b1e9..fce9f44b18 100644
--- a/web/src/features/batch-actions/server/addToDatasetRouter.ts
+++ b/web/src/features/batch-actions/server/addToDatasetRouter.ts
@@ -20,6 +20,7 @@ import {
} from "@langfuse/shared";
import { env } from "@/src/env.mjs";
import { CreateObservationAddToDatasetActionSchema } from "../validation";
+import { assertLegacyTracingIoSearchEnabled } from "@/src/features/traces/server/legacyIoSearch";
const MAX_BATCH_ADD_TO_DATASET_ITEMS = 1000;
@@ -42,6 +43,12 @@ export const addToDatasetRouter = createTRPCRouter({
? BatchTableNames.Events
: BatchTableNames.Observations;
+ assertLegacyTracingIoSearchEnabled({
+ searchQuery: query.searchQuery,
+ searchType: query.searchType,
+ tableName,
+ });
+
// Check observation count doesn't exceed maximum
const queryOpts = {
projectId,
diff --git a/web/src/features/batch-exports/server/batchExport.ts b/web/src/features/batch-exports/server/batchExport.ts
index a3dec45c08..73aeff6fe5 100644
--- a/web/src/features/batch-exports/server/batchExport.ts
+++ b/web/src/features/batch-exports/server/batchExport.ts
@@ -16,6 +16,7 @@ import {
} from "@langfuse/shared/src/server";
import { TRPCError } from "@trpc/server";
import { z } from "zod";
+import { assertLegacyTracingIoSearchEnabled } from "@/src/features/traces/server/legacyIoSearch";
export const batchExportRouter = createTRPCRouter({
create: protectedProjectProcedure
@@ -30,6 +31,12 @@ export const batchExportRouter = createTRPCRouter({
});
const { projectId, query, format, name } = input;
+ assertLegacyTracingIoSearchEnabled({
+ searchQuery: query.searchQuery,
+ searchType: query.searchType,
+ tableName: query.tableName,
+ });
+
logger.info("[BATCH EXPORT] Creating export job", { job: input });
const userId = ctx.session.user.id;
diff --git a/web/src/features/table/server/createBatchActionJob.ts b/web/src/features/table/server/createBatchActionJob.ts
index fd132725dd..2a0eecaafb 100644
--- a/web/src/features/table/server/createBatchActionJob.ts
+++ b/web/src/features/table/server/createBatchActionJob.ts
@@ -13,6 +13,7 @@ import {
QueueJobs,
} from "@langfuse/shared/src/server";
import { TRPCError } from "@trpc/server";
+import { assertLegacyTracingIoSearchEnabled } from "@/src/features/traces/server/legacyIoSearch";
type CreateBatchActionJob = {
projectId: string;
@@ -49,6 +50,12 @@ export const createBatchActionJob = async ({
query,
targetId,
}: CreateBatchActionJob) => {
+ assertLegacyTracingIoSearchEnabled({
+ searchQuery: query.searchQuery,
+ searchType: query.searchType,
+ tableName,
+ });
+
const batchActionId = generateBatchActionId(projectId, actionId, tableName);
const batchActionQueue = BatchActionQueue.getInstance();
diff --git a/web/src/features/traces/lib/legacyIoSearch.ts b/web/src/features/traces/lib/legacyIoSearch.ts
new file mode 100644
index 0000000000..62357f8f6d
--- /dev/null
+++ b/web/src/features/traces/lib/legacyIoSearch.ts
@@ -0,0 +1,20 @@
+import type { TracingSearchType } from "@langfuse/shared";
+
+export const LEGACY_IO_SEARCH_DISABLED_ERROR_MESSAGE =
+ "Input/output search is disabled for legacy tracing tables on this instance. Use ID, name, or user ID search instead.";
+
+export const LEGACY_IO_SEARCH_TYPES = new Set<TracingSearchType>([
+ "content",
+ "input",
+ "output",
+]);
+
+export const hasLegacyIoSearchType = (
+ searchType?: TracingSearchType[] | null,
+) => Boolean(searchType?.some((type) => LEGACY_IO_SEARCH_TYPES.has(type)));
+
+export const isLegacyIoSearchDisabledError = (
+ error?: { data?: { code?: string } | null; message?: string } | null,
+) =>
+ error?.data?.code === "BAD_REQUEST" &&
+ error.message === LEGACY_IO_SEARCH_DISABLED_ERROR_MESSAGE;
diff --git a/web/src/features/traces/server/legacyIoSearch.ts b/web/src/features/traces/server/legacyIoSearch.ts
new file mode 100644
index 0000000000..b9207a6233
--- /dev/null
+++ b/web/src/features/traces/server/legacyIoSearch.ts
@@ -0,0 +1,45 @@
+import { env } from "@/src/env.mjs";
+import {
+ LEGACY_IO_SEARCH_DISABLED_ERROR_MESSAGE,
+ LEGACY_IO_SEARCH_TYPES,
+} from "@/src/features/traces/lib/legacyIoSearch";
+import { BatchTableNames, type TracingSearchType } from "@langfuse/shared";
+import { TRPCError } from "@trpc/server";
+
+const LEGACY_TRACING_TABLE_NAMES = new Set<BatchTableNames>([
+ BatchTableNames.Traces,
+ BatchTableNames.Observations,
+]);
+
+export const isLegacyTracingIoSearchDisabled = () =>
+ env.LANGFUSE_DISABLE_LEGACY_TRACING_IO_SEARCH === "true";
+
+export const hasLegacyTracingIoSearch = (
+ searchType?: TracingSearchType[] | null,
+) => Boolean(searchType?.some((type) => LEGACY_IO_SEARCH_TYPES.has(type)));
+
+export const hasSearchQuery = (searchQuery?: string | null) =>
+ Boolean(searchQuery);
+
+export const isLegacyTracingTableName = (tableName: BatchTableNames) =>
+ LEGACY_TRACING_TABLE_NAMES.has(tableName);
+
+export const assertLegacyTracingIoSearchEnabled = ({
+ searchQuery,
+ searchType,
+ tableName,
+}: {
+ searchQuery?: string | null;
+ searchType?: TracingSearchType[] | null;
+ tableName: BatchTableNames;
+}) => {
+ if (!isLegacyTracingIoSearchDisabled()) return;
+ if (!hasSearchQuery(searchQuery)) return;
+ if (!hasLegacyTracingIoSearch(searchType)) return;
+ if (!isLegacyTracingTableName(tableName)) return;
+
+ throw new TRPCError({
+ code: "BAD_REQUEST",
+ message: LEGACY_IO_SEARCH_DISABLED_ERROR_MESSAGE,
+ });
+};
diff --git a/web/src/server/api/routers/generations/getAllQueries.ts b/web/src/server/api/routers/generations/getAllQueries.ts
index 3826a558c1..bfcdc43bf9 100644
--- a/web/src/server/api/routers/generations/getAllQueries.ts
+++ b/web/src/server/api/routers/generations/getAllQueries.ts
@@ -1,10 +1,11 @@
import { type z } from "zod";
import { protectedProjectProcedure } from "@/src/server/api/trpc";
-import { paginationZod } from "@langfuse/shared";
+import { BatchTableNames, paginationZod } from "@langfuse/shared";
import { GenerationTableOptions } from "./utils/GenerationTableOptions";
import { getAllGenerations } from "@/src/server/api/routers/generations/db/getAllGenerationsSqlQuery";
import { getObservationsTableCount } from "@langfuse/shared/src/server";
import { applyCommentFilters } from "@langfuse/shared/src/server";
+import { assertLegacyTracingIoSearchEnabled } from "@/src/features/traces/server/legacyIoSearch";
const GetAllGenerationsInput = GenerationTableOptions.extend({
...paginationZod,
@@ -16,6 +17,12 @@ export const getAllQueries = {
all: protectedProjectProcedure
.input(GetAllGenerationsInput)
.query(async ({ input, ctx }) => {
+ assertLegacyTracingIoSearchEnabled({
+ searchQuery: input.searchQuery,
+ searchType: input.searchType,
+ tableName: BatchTableNames.Observations,
+ });
+
const { filterState, hasNoMatches } = await applyCommentFilters({
filterState: input.filter ?? [],
prisma: ctx.prisma,
@@ -39,6 +46,12 @@ export const getAllQueries = {
countAll: protectedProjectProcedure
.input(GenerationTableOptions)
.query(async ({ input, ctx }) => {
+ assertLegacyTracingIoSearchEnabled({
+ searchQuery: input.searchQuery,
+ searchType: input.searchType,
+ tableName: BatchTableNames.Observations,
+ });
+
const { filterState, hasNoMatches } = await applyCommentFilters({
filterState: input.filter ?? [],
prisma: ctx.prisma,
diff --git a/web/src/server/api/routers/public.ts b/web/src/server/api/routers/public.ts
index 4bda36667c..f793c09e3c 100644
--- a/web/src/server/api/routers/public.ts
+++ b/web/src/server/api/routers/public.ts
@@ -1,6 +1,10 @@
import { VERSION } from "@/src/constants/VERSION";
import { env } from "@/src/env.mjs";
-import { createTRPCRouter, publicProcedure } from "@/src/server/api/trpc";
+import {
+ createTRPCRouter,
+ protectedProjectProcedure,
+ publicProcedure,
+} from "@/src/server/api/trpc";
import { logger, compareVersions } from "@langfuse/shared/src/server";
import { z } from "zod";
@@ -14,6 +18,12 @@ const ReleaseApiRes = z.array(
);
export const publicRouter = createTRPCRouter({
+ tracingSearchConfig: protectedProjectProcedure
+ .input(z.object({ projectId: z.string() }))
+ .query(() => ({
+ legacyTracingIoSearchEnabled:
+ env.LANGFUSE_DISABLE_LEGACY_TRACING_IO_SEARCH !== "true",
+ })),
checkUpdate: publicProcedure.query(async () => {
// Skip update check on Langfuse Cloud
if (env.NEXT_PUBLIC_LANGFUSE_CLOUD_REGION) return null;
diff --git a/web/src/server/api/routers/traces.ts b/web/src/server/api/routers/traces.ts
index 8f9eb1dcfc..2f9d49907f 100644
--- a/web/src/server/api/routers/traces.ts
+++ b/web/src/server/api/routers/traces.ts
@@ -10,6 +10,7 @@ import {
} from "@/src/server/api/trpc";
import {
BatchActionQuerySchema,
+ BatchTableNames,
BatchExportTableName,
BatchActionType,
ActionId,
@@ -54,6 +55,7 @@ import {
import { TRPCError } from "@trpc/server";
import { createBatchActionJob } from "@/src/features/table/server/createBatchActionJob";
import { throwIfNoEntitlement } from "@/src/features/entitlements/server/hasEntitlement";
+import { assertLegacyTracingIoSearchEnabled } from "@/src/features/traces/server/legacyIoSearch";
import {
type AgentGraphDataResponse,
AgentGraphDataSchema,
@@ -127,6 +129,12 @@ export const traceRouter = createTRPCRouter({
all: protectedProjectProcedure
.input(TraceFilterOptions)
.query(async ({ input, ctx }) => {
+ assertLegacyTracingIoSearchEnabled({
+ searchQuery: input.searchQuery,
+ searchType: input.searchType,
+ tableName: BatchTableNames.Traces,
+ });
+
const { filterState, hasNoMatches } = await applyCommentFilters({
filterState: input.filter ?? [],
prisma: ctx.prisma,
@@ -155,6 +163,12 @@ export const traceRouter = createTRPCRouter({
countAll: protectedProjectProcedure
.input(TraceCountOptions)
.query(async ({ input, ctx }) => {
+ assertLegacyTracingIoSearchEnabled({
+ searchQuery: input.searchQuery,
+ searchType: input.searchType,
+ tableName: BatchTableNames.Traces,
+ });
+
const { filterState, hasNoMatches } = await applyCommentFilters({
filterState: input.filter ?? [],
prisma: ctx.prisma,