🪢 Open source agent evals & observability: Trace, evaluate, and improve LLM applications with one open platform.
TypeScript analyticsautogenevaluationlangchainlarge-language-modelsllama-indexllmllm-evaluationllm-observabilityllmopsmonitoringobservabilityopen-sourceopenaiplaygroundprompt-engineeringprompt-managementself-hostedycombinator
feat(blob-export): add opt-in score metadata and provenance field groups (#19138)
Niklas Semmler46d50a3fec37
diff --git a/fern/apis/server/definition/blob-storage-integrations.yml b/fern/apis/server/definition/blob-storage-integrations.ymlindex e384b3a0a2..15c1769443 100644--- a/fern/apis/server/definition/blob-storage-integrations.yml+++ b/fern/apis/server/definition/blob-storage-integrations.yml@@ -88,7 +88,10 @@ types:- LEGACY_TRACES_AND_ENRICHED_OBSERVATIONSBlobStorageExportFieldGroup:- docs: Field group selecting which observation columns are included in the export. Applies to all export sources; groups without a counterpart in the legacy data model (e.g. `trace_context`) are omitted from the legacy observations export.+ docs: |+ Field group selecting which columns are included in the export. Applies to all export sources.+ - Observation groups (`core` through `trace_context`) select observation columns; groups without a counterpart in the legacy data model (e.g. `trace_context`) are omitted from the legacy observations export.+ - Score groups (`score_` prefix) add optional columns to the scores export. The core score columns (`id`, `timestamp`, `trace_id`, `name`, `value`, …) are always exported and are not a selectable group; score groups add columns on top of them. `score_metadata` adds the score `metadata` column. `score_provenance` adds the references to where a score came from: `author_user_id`, `config_id`, `queue_id`, `evaluator_id`, `evaluation_rule_id`, `execution_trace_id`. Score groups are never selected by default.enum:- core- basic@@ -101,6 +104,8 @@ types:- metrics- tools- trace_context+ - score_metadata+ - score_provenanceCreateBlobStorageIntegrationRequest:properties:@@ -156,7 +161,7 @@ types:exportFieldGroups:type: optional<list<BlobStorageExportFieldGroup>>docs: |- Field groups to include in each exported observation row. Applies to all export sources; must include `core` if provided. When omitted on create, the column default (all groups) applies. When omitted on update, the existing value is preserved.+ Field groups to include in each exported observation and score row. Applies to all export sources; must include the observation `core` group if provided. Core score columns are always exported; score groups add columns on top. When omitted on create, all observation groups are selected and no score groups. When omitted on update, the existing value is preserved.`exportFieldGroups` requires `exportSource` to be provided in the same request.@@ -181,7 +186,7 @@ types:exportFieldGroups:type: nullable<list<BlobStorageExportFieldGroup>>docs: |- Field groups included in each exported observation row. An empty list is treated as all groups during export.+ Field groups included in each exported observation and score row. An empty list is treated as all observation groups and no score groups during export. Core score columns are always exported.nextSyncAt: nullable<datetime>lastSyncAt: nullable<datetime>lastError: nullable<string>diff --git a/packages/shared/src/domain/export-field-groups.ts b/packages/shared/src/domain/export-field-groups.tsnew file mode 100644index 0000000000..02f500dc44--- /dev/null+++ b/packages/shared/src/domain/export-field-groups.ts@@ -0,0 +1,87 @@+import {+ OBSERVATION_FIELD_GROUPS_FULL,+ type ObservationFieldGroupFull,+} from "./observation-field-groups";++/**+ * Field groups of the scores blob export. Named with a `score_` prefix so they+ * never collide with an observation group of the same column (e.g. the+ * observation `metadata` group).+ *+ * Score groups are opt-in: they are not part of any default selection, so+ * existing exports keep their columns and size until a group is selected.+ */+export const SCORE_EXPORT_FIELD_GROUPS = [+ "score_metadata",+ "score_provenance",+] as const;++/**+ * Columns of every scores export row, in output order. Always exported, so+ * they are not a stored field group; settings show them as a locked "Core"+ * group. Optional group columns are appended after these.+ */+export const SCORE_EXPORT_CORE_FIELDS = [+ "id",+ "timestamp",+ "project_id",+ "environment",+ "trace_id",+ "observation_id",+ "session_id",+ "dataset_run_id",+ "name",+ "value",+ "source",+ "comment",+ "data_type",+ "string_value",+ "created_at",+ "updated_at",+] as const;++export type ScoreExportFieldGroup = (typeof SCORE_EXPORT_FIELD_GROUPS)[number];++/**+ * Columns each score group adds, appended after the core columns in+ * `SCORE_EXPORT_FIELD_GROUPS` order. Provenance holds the references to where+ * a score came from: author, score config, annotation queue, evaluator.+ */+export const SCORE_EXPORT_GROUP_FIELDS = {+ score_metadata: ["metadata"],+ score_provenance: [+ "author_user_id",+ "config_id",+ "queue_id",+ "evaluator_id",+ "evaluation_rule_id",+ "execution_trace_id",+ ],+} as const satisfies Record<ScoreExportFieldGroup, readonly string[]>;++/**+ * Every value that can be stored in an integration's `exportFieldGroups`.+ * Each group belongs to exactly one exported table; split a selection with+ * `getObservationFieldGroups` / `getScoreFieldGroups` before handing it to a+ * table's query.+ */+export const EXPORT_FIELD_GROUPS = [+ ...OBSERVATION_FIELD_GROUPS_FULL,+ ...SCORE_EXPORT_FIELD_GROUPS,+] as const;++export type ExportFieldGroup = (typeof EXPORT_FIELD_GROUPS)[number];++export const getObservationFieldGroups = (+ groups: readonly string[],+): ObservationFieldGroupFull[] =>+ groups.filter((group): group is ObservationFieldGroupFull =>+ (OBSERVATION_FIELD_GROUPS_FULL as readonly string[]).includes(group),+ );++export const getScoreFieldGroups = (+ groups: readonly string[],+): ScoreExportFieldGroup[] =>+ groups.filter((group): group is ScoreExportFieldGroup =>+ (SCORE_EXPORT_FIELD_GROUPS as readonly string[]).includes(group),+ );diff --git a/packages/shared/src/domain/index.ts b/packages/shared/src/domain/index.tsindex 245e31aada..dc5f9be33d 100644--- a/packages/shared/src/domain/index.ts+++ b/packages/shared/src/domain/index.ts@@ -1,4 +1,5 @@export * from "./observation-field-groups";+export * from "./export-field-groups";export * from "./observations";export * from "./traces";export * from "./scores";diff --git a/packages/shared/src/features/analytics-integrations/index.ts b/packages/shared/src/features/analytics-integrations/index.tsindex dd174d6d8a..cd27ff1b0f 100644--- a/packages/shared/src/features/analytics-integrations/index.ts+++ b/packages/shared/src/features/analytics-integrations/index.ts@@ -7,6 +7,12 @@ import {OBSERVATION_FIELD_GROUPS_FULL,type ObservationFieldGroupFull,} from "../../domain/observation-field-groups";+import {+ SCORE_EXPORT_CORE_FIELDS,+ SCORE_EXPORT_FIELD_GROUPS,+ SCORE_EXPORT_GROUP_FIELDS,+ type ScoreExportFieldGroup,+} from "../../domain/export-field-groups";export * from "./export-source-policy";export * from "./blob-export-tuning";@@ -149,3 +155,23 @@ export const EXPORT_FIELD_GROUP_OPTIONS = OBSERVATION_FIELD_GROUPS_FULL.map(includedInLegacyExport: legacyFieldsForGroup(value).length > 0,}),);++/** Score group labels; groups apply to the scores export of every source and file type. */+const SCORE_EXPORT_FIELD_GROUP_LABELS = {+ score_metadata: { label: "Metadata" },+ score_provenance: { label: "Provenance" },+} satisfies Record<ScoreExportFieldGroup, { label: string }>;++/** Locked score core group for settings; display-only, as score core columns are always exported. */+export const SCORE_EXPORT_CORE_FIELD_GROUP_OPTION = {+ label: "Core",+ description: SCORE_EXPORT_CORE_FIELDS.join(", "),+};++export const SCORE_EXPORT_FIELD_GROUP_OPTIONS = SCORE_EXPORT_FIELD_GROUPS.map(+ (value) => ({+ value,+ ...SCORE_EXPORT_FIELD_GROUP_LABELS[value],+ description: SCORE_EXPORT_GROUP_FIELDS[value].join(", "),+ }),+);diff --git a/packages/shared/src/server/repositories/scores.ts b/packages/shared/src/server/repositories/scores.tsindex c0a30c12f9..80f5b80acb 100644--- a/packages/shared/src/server/repositories/scores.ts+++ b/packages/shared/src/server/repositories/scores.ts@@ -11,6 +11,12 @@ import {ListableScoreDataType,ScoreDataTypeEnum,} from "../../domain/scores";+import {+ SCORE_EXPORT_CORE_FIELDS,+ SCORE_EXPORT_FIELD_GROUPS,+ SCORE_EXPORT_GROUP_FIELDS,+ type ScoreExportFieldGroup,+} from "../../domain/export-field-groups";import { InvalidRequestError, InternalServerError } from "../../errors";import {eventsTableIsRootObservationSql,@@ -2533,30 +2539,23 @@ export const getDistinctScoreNames = async (};// Shared query for both the standard (parsed) and Parquet (`exec` binary)-// score export paths.+// score export paths. Opt-in field group columns are appended after the base+// columns so the base column order stays stable.const buildScoresForBlobStorageExportQuery = (projectId: string,minTimestamp: Date,maxTimestamp: Date,+ fieldGroups: ScoreExportFieldGroup[],) => {+ const columns: string[] = [+ ...SCORE_EXPORT_CORE_FIELDS,+ ...SCORE_EXPORT_FIELD_GROUPS.filter((group) =>+ fieldGroups.includes(group),+ ).flatMap((group) => SCORE_EXPORT_GROUP_FIELDS[group]),+ ];const query = `SELECT- id,- timestamp,- project_id,- environment,- trace_id,- observation_id,- session_id,- dataset_run_id,- name,- value,- source,- comment,- data_type,- string_value,- created_at,- updated_at+ ${columns.join(",\n ")}FROM scores FINALWHERE project_id = {projectId: String}AND timestamp >= {minTimestamp: DateTime64(3)}@@ -2585,9 +2584,15 @@ export const getScoresForBlobStorageExport = function (projectId: string,minTimestamp: Date,maxTimestamp: Date,+ fieldGroups: ScoreExportFieldGroup[] = [],) {return queryClickhouseStream<Record<string, unknown>>(- buildScoresForBlobStorageExportQuery(projectId, minTimestamp, maxTimestamp),+ buildScoresForBlobStorageExportQuery(+ projectId,+ minTimestamp,+ maxTimestamp,+ fieldGroups,+ ),);};@@ -2597,12 +2602,14 @@ export const getScoresForBlobStorageExportParquet = function (projectId: string,minTimestamp: Date,maxTimestamp: Date,+ fieldGroups: ScoreExportFieldGroup[] = [],) {return queryClickhouseExecRaw({...buildScoresForBlobStorageExportQuery(projectId,minTimestamp,maxTimestamp,+ fieldGroups,),format: "Parquet",clickhouseSettings: BLOB_EXPORT_PARQUET_CLICKHOUSE_SETTINGS,diff --git a/web/public/generated/api/openapi.yml b/web/public/generated/api/openapi.ymlindex c4ec07c144..c6684d1f15 100644--- a/web/public/generated/api/openapi.yml+++ b/web/public/generated/api/openapi.yml@@ -7770,11 +7770,24 @@ components:- metrics- tools- trace_context+ - score_metadata+ - score_provenancedescription: >-- Field group selecting which observation columns are included in the- export. Applies to all export sources; groups without a counterpart in- the legacy data model (e.g. `trace_context`) are omitted from the legacy- observations export.+ Field group selecting which columns are included in the export. Applies+ to all export sources.++ - Observation groups (`core` through `trace_context`) select observation+ columns; groups without a counterpart in the legacy data model (e.g.+ `trace_context`) are omitted from the legacy observations export.++ - Score groups (`score_` prefix) add optional columns to the scores+ export. The core score columns (`id`, `timestamp`, `trace_id`, `name`,+ `value`, …) are always exported and are not a selectable group; score+ groups add columns on top of them. `score_metadata` adds the score+ `metadata` column. `score_provenance` adds the references to where a+ score came from: `author_user_id`, `config_id`, `queue_id`,+ `evaluator_id`, `evaluation_rule_id`, `execution_trace_id`. Score groups+ are never selected by default.CreateBlobStorageIntegrationRequest:title: CreateBlobStorageIntegrationRequesttype: object@@ -7893,10 +7906,12 @@ components:$ref: '#/components/schemas/BlobStorageExportFieldGroup'nullable: truedescription: >-- Field groups to include in each exported observation row. Applies to- all export sources; must include `core` if provided. When omitted on- create, the column default (all groups) applies. When omitted on- update, the existing value is preserved.+ Field groups to include in each exported observation and score row.+ Applies to all export sources; must include the observation `core`+ group if provided. Core score columns are always exported; score+ groups add columns on top. When omitted on create, all observation+ groups are selected and no score groups. When omitted on update, the+ existing value is preserved.`exportFieldGroups` requires `exportSource` to be provided in the@@ -7957,8 +7972,9 @@ components:$ref: '#/components/schemas/BlobStorageExportFieldGroup'nullable: truedescription: >-- Field groups included in each exported observation row. An empty- list is treated as all groups during export.+ Field groups included in each exported observation and score row. An+ empty list is treated as all observation groups and no score groups+ during export. Core score columns are always exported.nextSyncAt:type: stringformat: date-timediff --git a/web/src/__tests__/blob-storage-form-field-groups.clienttest.ts b/web/src/__tests__/blob-storage-form-field-groups.clienttest.tsindex 7047fc6fb5..53623027de 100644--- a/web/src/__tests__/blob-storage-form-field-groups.clienttest.ts+++ b/web/src/__tests__/blob-storage-form-field-groups.clienttest.ts@@ -44,6 +44,7 @@ describe("blob storage form — exportFieldGroups validation", () => {],[AnalyticsIntegrationExportSource.TRACES_OBSERVATIONS, []],[AnalyticsIntegrationExportSource.TRACES_OBSERVATIONS, ["basic", "io"]],+ [AnalyticsIntegrationExportSource.EVENTS, ["score_metadata"]],] as const)("blocks submission when exportSource is %s and core is absent (groups: %s)",async (source, exportFieldGroups) => {@@ -86,6 +87,25 @@ describe("blob storage form — exportFieldGroups validation", () => {expect(onSubmit).toHaveBeenCalledOnce();});++ it("allows submission with score groups next to observation groups", async () => {+ const { result } = renderHook(() =>+ useForm({+ resolver: zodResolver(blobStorageIntegrationFormSchema),+ defaultValues: {+ ...VALID_BASE,+ exportFieldGroups: ["core", "score_metadata"],+ },+ }),+ );++ const onSubmit = vi.fn();+ await act(async () => {+ await result.current.handleSubmit(onSubmit)();+ });++ expect(onSubmit).toHaveBeenCalledOnce();+ });});describe("EXPORT_FIELD_GROUP_OPTIONS — parquet description", () => {diff --git a/web/src/features/blobstorage-integration/components/ExportFieldGroupsField.tsx b/web/src/features/blobstorage-integration/components/ExportFieldGroupsField.tsxindex 2c2a2f4692..6f02905c1d 100644--- a/web/src/features/blobstorage-integration/components/ExportFieldGroupsField.tsx+++ b/web/src/features/blobstorage-integration/components/ExportFieldGroupsField.tsx@@ -1,6 +1,5 @@/* eslint-disable no-nested-ternary */import { useFormState, useWatch } from "react-hook-form";-import { Checkbox } from "@/src/components/design-system/Checkbox/Checkbox";import {FormDescription,FormField,@@ -12,9 +11,11 @@ import {AnalyticsIntegrationExportSource,BlobStorageIntegrationFileType,EXPORT_FIELD_GROUP_OPTIONS,- type ObservationFieldGroupFull,+ SCORE_EXPORT_CORE_FIELD_GROUP_OPTION,+ SCORE_EXPORT_FIELD_GROUP_OPTIONS,} from "@langfuse/shared";import { type BlobStorageFormControl } from "@/src/features/blobstorage-integration/components/formValues";+import { FieldGroupCheckbox } from "@/src/features/blobstorage-integration/components/FieldGroupCheckbox";// Field-group checkboxes; descriptions and available groups depend on the// selected export source and file type.@@ -43,6 +44,17 @@ export const ExportFieldGroupsField = ({watchedExportSource ===AnalyticsIntegrationExportSource.TRACES_OBSERVATIONS_EVENTS;+ const describeObservationGroup = (+ option: (typeof EXPORT_FIELD_GROUP_OPTIONS)[number],+ ) => {+ if (isParquetExport) {+ return isLegacyOnlyExport+ ? option.legacyParquetDescription+ : option.parquetDescription;+ }+ return isLegacyOnlyExport ? option.legacyDescription : option.description;+ };+return (<FormFieldcontrol={control}@@ -51,77 +63,62 @@ export const ExportFieldGroupsField = ({<FormItem><FormLabel>Export Field Groups</FormLabel><FormDescription>- Choose which field groups to include in the observation exports.- Deselect large groups (e.g. Input / Output) to reduce export size,- or privacy-sensitive groups (e.g. Metadata) to avoid storing user- data.+ Choose which field groups to include in the observation and score+ exports. Deselect large groups (e.g. Input / Output) to reduce+ export size, or privacy-sensitive groups (e.g. Metadata) to avoid+ storing user data.{includesLegacyExport? isLegacyOnlyExport- ? " Traces and scores are always exported in full. Field groups that only exist on the enriched observations (e.g. Trace Context) are not available for this export source."- : " Traces and scores are always exported in full. Fields that only exist on the enriched observations (e.g. Trace Context) are omitted from the legacy observations export."- : " Scores are always exported in full."}+ ? " Traces are always exported in full. Field groups that only exist on the enriched observations (e.g. Trace Context) are not available for this export source."+ : " Traces are always exported in full. Fields that only exist on the enriched observations (e.g. Trace Context) are omitted from the legacy observations export."+ : ""}</FormDescription>+ <div className="text-sm font-bold">Observations</div><div className="mt-2 space-y-2">{EXPORT_FIELD_GROUP_OPTIONS.filter(// Hide no-op groups (no legacy columns) for legacy-only// exports; a saved selection is kept and applies again if// the source is migrated to enriched observations.(option) => !isLegacyOnlyExport || option.includedInLegacyExport,- ).map((option) => {- const isCore = option.value === "core";- return (- <div key={option.value} className="flex items-start gap-2">- <Checkbox- id={`field-group-${option.value}`}- checked={- isCore ? true : (field.value ?? []).includes(option.value)- }- disabled={isCore}- onCheckedChange={- isCore- ? undefined- : (checked) => {- const current = field.value ?? [];- const next =- checked === true- ? current.includes(option.value)- ? current- : [...current, option.value]- : current.filter(- (v: ObservationFieldGroupFull) =>- v !== option.value,- );- field.onChange(next);- }- }- />- <label- htmlFor={`field-group-${option.value}`}- className={- isCore ? "space-y-0.5" : "cursor-pointer space-y-0.5"- }- >- <div className="text-sm leading-none font-bold">- {option.label}- {isCore && (- <span className="text-muted-foreground ml-1 font-normal">- (required)- </span>- )}- </div>- <div className="text-muted-foreground text-xs">- {isParquetExport- ? isLegacyOnlyExport- ? option.legacyParquetDescription- : option.parquetDescription- : isLegacyOnlyExport- ? option.legacyDescription- : option.description}- </div>- </label>- </div>- );- })}+ ).map((option) =>+ option.value === "core" ? (+ <FieldGroupCheckbox+ key={option.value}+ id="field-group-core"+ required+ label={option.label}+ description={describeObservationGroup(option)}+ />+ ) : (+ <FieldGroupCheckbox+ key={option.value}+ value={option.value}+ label={option.label}+ description={describeObservationGroup(option)}+ selected={field.value ?? []}+ onChange={field.onChange}+ />+ ),+ )}+ </div>+ <div className="text-sm font-bold">Scores</div>+ <div className="mt-2 space-y-2">+ <FieldGroupCheckbox+ id="field-group-score-core"+ required+ label={SCORE_EXPORT_CORE_FIELD_GROUP_OPTION.label}+ description={SCORE_EXPORT_CORE_FIELD_GROUP_OPTION.description}+ />+ {SCORE_EXPORT_FIELD_GROUP_OPTIONS.map((option) => (+ <FieldGroupCheckbox+ key={option.value}+ value={option.value}+ label={option.label}+ description={option.description}+ selected={field.value ?? []}+ onChange={field.onChange}+ />+ ))}</div><FormMessage>{errors.exportFieldGroups?.message}</FormMessage></FormItem>diff --git a/web/src/features/blobstorage-integration/components/FieldGroupCheckbox.tsx b/web/src/features/blobstorage-integration/components/FieldGroupCheckbox.tsxnew file mode 100644index 0000000000..bb43b971fe--- /dev/null+++ b/web/src/features/blobstorage-integration/components/FieldGroupCheckbox.tsx@@ -0,0 +1,62 @@+import { Checkbox } from "@/src/components/design-system/Checkbox/Checkbox";+import { type ExportFieldGroup } from "@langfuse/shared";++type FieldGroupCheckboxProps = {+ label: string;+ description: string;+} & (+ | {+ // Always exported: rendered checked and locked.+ required: true;+ id: string;+ }+ | {+ required?: false;+ value: ExportFieldGroup;+ selected: ExportFieldGroup[];+ onChange: (next: ExportFieldGroup[]) => void;+ }+);++/** Toggles one export field group; required groups render checked and locked. */+export const FieldGroupCheckbox = (props: FieldGroupCheckboxProps) => {+ const id = props.required ? props.id : `field-group-${props.value}`;++ const handleCheckedChange = (checked: boolean | "indeterminate") => {+ if (props.required) return;+ const { value, selected, onChange } = props;+ if (checked !== true) {+ onChange(selected.filter((group) => group !== value));+ return;+ }+ if (selected.includes(value)) return;+ onChange([...selected, value]);+ };++ return (+ <div className="flex items-start gap-2">+ <Checkbox+ id={id}+ checked={props.required || props.selected.includes(props.value)}+ disabled={props.required}+ onCheckedChange={props.required ? undefined : handleCheckedChange}+ />+ <label+ htmlFor={id}+ className={+ props.required ? "space-y-0.5" : "cursor-pointer space-y-0.5"+ }+ >+ <div className="text-sm leading-none font-bold">+ {props.label}+ {props.required && (+ <span className="text-muted-foreground ml-1 font-normal">+ (required)+ </span>+ )}+ </div>+ <div className="text-muted-foreground text-xs">{props.description}</div>+ </label>+ </div>+ );+};diff --git a/web/src/features/blobstorage-integration/components/formValues.ts b/web/src/features/blobstorage-integration/components/formValues.tsindex 7216195df8..2b47ddff3b 100644--- a/web/src/features/blobstorage-integration/components/formValues.ts+++ b/web/src/features/blobstorage-integration/components/formValues.ts@@ -6,7 +6,7 @@ import {BlobStorageExportMode,OBSERVATION_FIELD_GROUPS_FULL,type BlobStorageIntegration,- type ObservationFieldGroupFull,+ type ExportFieldGroup,type ExportSourceContext,GCS_USE_DEFAULT_CREDENTIALS,} from "@langfuse/shared";@@ -63,7 +63,7 @@ export function buildBlobStorageFormValues(// Empty array in the DB means "export everything" (the worker falls back// to all groups), so surface it as the full selection in the form.exportFieldGroups: state?.exportFieldGroups?.length- ? (state.exportFieldGroups as ObservationFieldGroupFull[])+ ? (state.exportFieldGroups as ExportFieldGroup[]): [...OBSERVATION_FIELD_GROUPS_FULL],compressed: state?.compressed ?? true,};diff --git a/web/src/features/blobstorage-integration/service.ts b/web/src/features/blobstorage-integration/service.tsindex d7e1012a2f..c030f14037 100644--- a/web/src/features/blobstorage-integration/service.ts+++ b/web/src/features/blobstorage-integration/service.ts@@ -5,7 +5,7 @@ import {InvalidRequestError,type AnalyticsIntegrationExportSource,BlobStorageIntegrationFileType,- type ObservationFieldGroupFull,+ type ExportFieldGroup,BLOB_STORAGE_REGION_INVALID_MESSAGE,normalizeBlobStorageRegion,GCPServiceAccountKeySchema,@@ -36,7 +36,7 @@ type UpsertBlobStorageIntegrationInput = {exportMode: BlobStorageExportMode;exportStartDate: Date | null;exportSource?: AnalyticsIntegrationExportSource;- exportFieldGroups?: ObservationFieldGroupFull[];+ exportFieldGroups?: ExportFieldGroup[];compressed?: boolean;};diff --git a/web/src/features/blobstorage-integration/types.ts b/web/src/features/blobstorage-integration/types.tsindex fa1effa141..8532e8cbb8 100644--- a/web/src/features/blobstorage-integration/types.ts+++ b/web/src/features/blobstorage-integration/types.ts@@ -5,6 +5,7 @@ import {BlobStorageExportMode,AnalyticsIntegrationExportSource,OBSERVATION_FIELD_GROUPS_FULL,+ EXPORT_FIELD_GROUPS,BLOB_STORAGE_REGION_INVALID_MESSAGE,BLOB_STORAGE_REGION_REGEX,} from "@langfuse/shared";@@ -56,7 +57,7 @@ export const blobStorageIntegrationFormSchemaBase = z.object({.enum(AnalyticsIntegrationExportSource).default(AnalyticsIntegrationExportSource.TRACES_OBSERVATIONS),exportFieldGroups: z- .array(z.enum(OBSERVATION_FIELD_GROUPS_FULL))+ .array(z.enum(EXPORT_FIELD_GROUPS)).default([...OBSERVATION_FIELD_GROUPS_FULL]),compressed: z.boolean().default(true),});diff --git a/web/src/features/public-api/types/blob-storage-integrations.ts b/web/src/features/public-api/types/blob-storage-integrations.tsindex 48c234165f..2a36a8409f 100644--- a/web/src/features/public-api/types/blob-storage-integrations.ts+++ b/web/src/features/public-api/types/blob-storage-integrations.ts@@ -1,7 +1,7 @@import { z } from "zod";import {AnalyticsIntegrationExportSource,- OBSERVATION_FIELD_GROUPS_FULL,+ EXPORT_FIELD_GROUPS,BLOB_STORAGE_REGION_INVALID_MESSAGE,BLOB_STORAGE_REGION_REGEX,} from "@langfuse/shared";@@ -89,7 +89,7 @@ export const toPublicExportSource = (): z.infer<typeof BlobStorageExportSource> =>INTERNAL_TO_PUBLIC_EXPORT_SOURCE[internalValue];-const BlobStorageExportFieldGroup = z.enum(OBSERVATION_FIELD_GROUPS_FULL);+const BlobStorageExportFieldGroup = z.enum(EXPORT_FIELD_GROUPS);/*** Request/Response Typesdiff --git a/web/src/pages/api/public/integrations/blob-storage/index.ts b/web/src/pages/api/public/integrations/blob-storage/index.tsindex 39c5b7986a..640fba8f4a 100644--- a/web/src/pages/api/public/integrations/blob-storage/index.ts+++ b/web/src/pages/api/public/integrations/blob-storage/index.ts@@ -7,10 +7,7 @@ import {toPublicExportSource,type BlobStorageIntegrationResponseType,} from "@/src/features/public-api/types/blob-storage-integrations";-import {- type ObservationFieldGroupFull,- LangfuseNotFoundError,-} from "@langfuse/shared";+import { type ExportFieldGroup, LangfuseNotFoundError } from "@langfuse/shared";import { upsertBlobStorageIntegration } from "@/src/features/blobstorage-integration/service";import { resolveExportSource } from "@/src/features/analytics-integrations/server";import { auditLog } from "@/src/features/audit-logs/server";@@ -59,8 +56,7 @@ async function handleGetBlobStorageIntegrations(exportStartDate: integration.exportStartDate,compressed: integration.compressed,exportSource: toPublicExportSource(integration.exportSource),- exportFieldGroups:- integration.exportFieldGroups as ObservationFieldGroupFull[],+ exportFieldGroups: integration.exportFieldGroups as ExportFieldGroup[],nextSyncAt: integration.nextSyncAt,lastSyncAt: integration.lastSyncAt,lastError: integration.lastError,@@ -171,8 +167,7 @@ async function handleUpsertBlobStorageIntegration(exportStartDate: integration.exportStartDate,compressed: integration.compressed,exportSource: toPublicExportSource(integration.exportSource),- exportFieldGroups:- integration.exportFieldGroups as ObservationFieldGroupFull[],+ exportFieldGroups: integration.exportFieldGroups as ExportFieldGroup[],nextSyncAt: integration.nextSyncAt,lastSyncAt: integration.lastSyncAt,lastError: integration.lastError,diff --git a/worker/src/__tests__/blobStorageIntegrationProcessing.test.ts b/worker/src/__tests__/blobStorageIntegrationProcessing.test.tsindex 787351f716..b7ea55d8e4 100644--- a/worker/src/__tests__/blobStorageIntegrationProcessing.test.ts+++ b/worker/src/__tests__/blobStorageIntegrationProcessing.test.ts@@ -1065,6 +1065,8 @@ describe("BlobStorageIntegrationProcessingJob", () => {expect(content).toContain(scoreId);expect(content).toContain("Test Score");expect(content).toContain("0.95");+ // Score metadata is opt-in; the column-default field groups omit it+ expect(content.split("\n")[0]).not.toContain("metadata");// Verify session_id is exported for session-scoped scoresexpect(content).toContain(sessionScoreId);expect(content).toContain(sessionId);@@ -1203,6 +1205,114 @@ describe("BlobStorageIntegrationProcessingJob", () => {}});+ it.each([+ // observation metadata must not switch on score metadata+ [["core", "metadata"], false, true, false],+ [["core", "score_metadata"], true, false, false],+ [["core", "metadata", "score_metadata"], true, true, false],+ [["core", "score_provenance"], false, false, true],+ ])(+ "should apply field groups %j per table (score metadata: %s, observation metadata: %s, score provenance: %s)",+ async (+ exportFieldGroups,+ expectScoreMetadata,+ expectEventMetadata,+ expectScoreProvenance,+ ) => {+ const { projectId } = await createOrgProjectAndApiKey();+ s3Prefix = projectId;+ const now = new Date();+ const twoHoursAgo = new Date(now.getTime() - 2 * 60 * 60 * 1000);+ const dataTime = now.getTime() - 90 * 60 * 1000;++ await prisma.blobStorageIntegration.create({+ data: {+ projectId,+ type: BlobStorageIntegrationType.S3,+ bucketName,+ prefix: s3Prefix,+ accessKeyId: minioAccessKeyId,+ secretAccessKey: encrypt(minioAccessKeySecret),+ region: region ? region : "auto",+ endpoint: minioEndpoint,+ forcePathStyle:+ env.LANGFUSE_S3_EVENT_UPLOAD_FORCE_PATH_STYLE === "true",+ enabled: true,+ exportFrequency: "hourly",+ exportSource: "EVENTS",+ exportFieldGroups,+ nextSyncAt: twoHoursAgo,+ lastSyncAt: twoHoursAgo,+ compressed: false,+ fileType: BlobStorageIntegrationFileType.JSONL,+ },+ });++ const traceId = randomUUID();+ await Promise.all([+ createEventsCh([+ createEvent({+ project_id: projectId,+ trace_id: traceId,+ start_time: dataTime * 1000,+ end_time: (dataTime + 5000) * 1000,+ metadata: { source: "observation" },+ metadata_names: ["source"],+ metadata_values: ["observation"],+ }),+ ]),+ createScoresCh([+ createTraceScore({+ trace_id: traceId,+ project_id: projectId,+ timestamp: dataTime,+ metadata: { source: "score" },+ author_user_id: "author-1",+ config_id: "config-1",+ queue_id: "queue-1",+ }),+ ]),+ ]);++ await handleBlobStorageIntegrationProjectJob({+ data: { payload: { projectId } },+ } as Job);++ const files = await s3StorageService.listFiles(s3Prefix);+ const readFirstRow = async (table: string) => {+ const file = files.find((f) => f.file.includes(`/${table}/`));+ expect(file).toBeDefined();+ const content = await s3StorageService.download(file!.file);+ return JSON.parse(content.trim().split("\n")[0]);+ };++ const scoreRow = await readFirstRow("scores");+ expect(scoreRow).toHaveProperty("value");+ if (expectScoreMetadata) {+ expect(scoreRow.metadata).toEqual({ source: "score" });+ } else {+ expect(scoreRow).not.toHaveProperty("metadata");+ }+ if (expectScoreProvenance) {+ expect(scoreRow).toMatchObject({+ author_user_id: "author-1",+ config_id: "config-1",+ queue_id: "queue-1",+ });+ expect(scoreRow).toHaveProperty("execution_trace_id");+ } else {+ expect(scoreRow).not.toHaveProperty("author_user_id");+ }++ const eventRow = await readFirstRow("observations_v2");+ if (expectEventMetadata) {+ expect(eventRow.metadata).toEqual({ source: "observation" });+ } else {+ expect(eventRow).not.toHaveProperty("metadata");+ }+ },+ );+it("should respect export frequency when setting nextSyncAt", async () => {const { projectId } = await createOrgProjectAndApiKey();diff --git a/worker/src/features/blobstorage/handleBlobStorageIntegrationProjectJob.ts b/worker/src/features/blobstorage/handleBlobStorageIntegrationProjectJob.tsindex 63502e3c2b..ae2f3163e1 100644--- a/worker/src/features/blobstorage/handleBlobStorageIntegrationProjectJob.ts+++ b/worker/src/features/blobstorage/handleBlobStorageIntegrationProjectJob.ts@@ -62,6 +62,9 @@ import {BlobStorageExportMode,OBSERVATION_FIELD_GROUPS_FULL,type ObservationFieldGroupFull,+ type ExportFieldGroup,+ getObservationFieldGroups,+ getScoreFieldGroups,isLegacyExportSource,isLegacyExporter,resolveBlobExportTuning,@@ -413,7 +416,7 @@ const processBlobStorageExport = async (config: {// when `compressed` is true.gzipLevel: number | undefined;convertV4LatencyToSeconds: boolean;- exportFieldGroups?: ObservationFieldGroupFull[];+ exportFieldGroups?: ExportFieldGroup[];rawPassthrough: boolean;// undefined concurrency/attempts => backend keeps its native default.partSizeBytes: number;@@ -552,10 +555,15 @@ const processBlobStorageExport = async (config: {return blobStorageProps.contentType;})();- const exportFieldGroups =+ // Each table's query only receives its own groups. Score groups are+ // opt-in, so the empty-selection fallback covers observation groups only.+ const selectedFieldGroups: ExportFieldGroup[] =config.exportFieldGroups && config.exportFieldGroups.length > 0? config.exportFieldGroups: [...OBSERVATION_FIELD_GROUPS_FULL];+ const observationFieldGroups =+ getObservationFieldGroups(selectedFieldGroups);+ const scoreFieldGroups = getScoreFieldGroups(selectedFieldGroups);// blob.path already encodes parquet (no per-table fallback), so no// separate blob.config.parquet attribute is needed.@@ -623,6 +631,7 @@ const processBlobStorageExport = async (config: {config.projectId,config.minTimestamp,config.maxTimestamp,+ scoreFieldGroups,)).stream;break;@@ -632,7 +641,7 @@ const processBlobStorageExport = async (config: {config.projectId,config.minTimestamp,config.maxTimestamp,- exportFieldGroups,+ observationFieldGroups,)).stream;break;@@ -642,7 +651,7 @@ const processBlobStorageExport = async (config: {config.projectId,config.minTimestamp,config.maxTimestamp,- exportFieldGroups,+ observationFieldGroups,config.convertV4LatencyToSeconds,)).stream;@@ -669,13 +678,13 @@ const processBlobStorageExport = async (config: {config.projectId,config.minTimestamp,config.maxTimestamp,- exportFieldGroups,+ observationFieldGroups,): getEventsForBlobStorageExportRaw(config.projectId,config.minTimestamp,config.maxTimestamp,- exportFieldGroups,+ observationFieldGroups,config.convertV4LatencyToSeconds,);@@ -717,14 +726,14 @@ const processBlobStorageExport = async (config: {config.projectId,config.minTimestamp,config.maxTimestamp,- exportFieldGroups,+ observationFieldGroups,),chStats,),config.projectId,"model_id",false, // v3 query already returns latency in seconds- exportFieldGroups,+ observationFieldGroups,config.skipEnrichment,);break;@@ -733,6 +742,7 @@ const processBlobStorageExport = async (config: {config.projectId,config.minTimestamp,config.maxTimestamp,+ scoreFieldGroups,);break;case "observations_v2": // observations_v2 is the events table@@ -743,14 +753,14 @@ const processBlobStorageExport = async (config: {config.projectId,config.minTimestamp,config.maxTimestamp,- exportFieldGroups,+ observationFieldGroups,),chStats,),config.projectId,"model_id",config.convertV4LatencyToSeconds,- exportFieldGroups,+ observationFieldGroups,config.skipEnrichment,);break;@@ -1311,7 +1321,7 @@ export const handleBlobStorageIntegrationProjectJob = async (gzipLevel: exportTuning.gzipLevel,convertV4LatencyToSeconds,exportFieldGroups:- blobStorageIntegration.exportFieldGroups as ObservationFieldGroupFull[],+ blobStorageIntegration.exportFieldGroups as ExportFieldGroup[],rawPassthrough: exportTuning.rawPassthrough,partSizeBytes: exportTuning.partSizeBytes,maxConcurrentParts: exportTuning.maxConcurrentParts,