🪢 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
fix(api-scores): return executionTraceId (#12254)
Hassieb Pakzad25b51393d31c
diff --git a/fern/apis/server/definition/score-v2.yml b/fern/apis/server/definition/score-v2.ymlindex 93cfc675c8..7cd273ac68 100644--- a/fern/apis/server/definition/score-v2.yml+++ b/fern/apis/server/definition/score-v2.yml@@ -74,7 +74,7 @@ service:docs: Only scores linked to traces that include all of these tags will be returned.fields:type: optional<string>- docs: "Comma-separated list of field groups to include in the response. Available field groups: 'score' (core score fields), 'trace' (trace properties: userId, tags, environment). If not specified, both 'score' and 'trace' are returned by default. Example: 'score' to exclude trace data, 'score,trace' to include both. Note: When filtering by trace properties (using userId or traceTags parameters), the 'trace' field group must be included, otherwise a 400 error will be returned."+ docs: "Comma-separated list of field groups to include in the response. Available field groups: 'score' (core score fields), 'trace' (trace properties: userId, tags, environment, sessionId). If not specified, both 'score' and 'trace' are returned by default. Example: 'score' to exclude trace data, 'score,trace' to include both. Note: When filtering by trace properties (using userId or traceTags parameters), the 'trace' field group must be included, otherwise a 400 error will be returned."filter:type: optional<string>docs: >@@ -106,6 +106,9 @@ types:environment:type: optional<string>docs: The environment of the trace referenced by score+ sessionId:+ type: optional<string>+ docs: The session ID associated with the trace referenced by scoreGetScoresResponseDataNumeric:extends: commons.NumericScorediff --git a/packages/shared/src/features/scores/interfaces/api/v2/endpoints.ts b/packages/shared/src/features/scores/interfaces/api/v2/endpoints.tsindex a3eef7693d..1713ee4628 100644--- a/packages/shared/src/features/scores/interfaces/api/v2/endpoints.ts+++ b/packages/shared/src/features/scores/interfaces/api/v2/endpoints.ts@@ -29,6 +29,7 @@ export const GetScoreResponseDataV2 = zuserId: z.string().nullish(),tags: z.array(z.string()).nullish(),environment: z.string().nullish(),+ sessionId: z.string().nullish(),}).nullish(),}),diff --git a/web/public/generated/api/openapi.yml b/web/public/generated/api/openapi.ymlindex 3754603a54..b50a138bd1 100644--- a/web/public/generated/api/openapi.yml+++ b/web/public/generated/api/openapi.yml@@ -2669,11 +2669,10 @@ paths:nullable: true- name: parseIoAsJsonin: query- description: >-- Set to `true` to parse input/output fields as JSON, or `false` to- return raw strings.-- Defaults to `false` if not provided.+ description: |-+ **Deprecated.** Setting this to `true` will return a 400 error.+ Input/output fields are always returned as raw strings.+ Remove this parameter or set it to `false`.required: falseschema:type: boolean@@ -5235,9 +5234,9 @@ paths:description: >-Comma-separated list of field groups to include in the response.Available field groups: 'score' (core score fields), 'trace' (trace- properties: userId, tags, environment). If not specified, both- 'score' and 'trace' are returned by default. Example: 'score' to- exclude trace data, 'score,trace' to include both. Note: When+ properties: userId, tags, environment, sessionId). If not specified,+ both 'score' and 'trace' are returned by default. Example: 'score'+ to exclude trace data, 'score,trace' to include both. Note: Whenfiltering by trace properties (using userId or traceTagsparameters), the 'trace' field group must be included, otherwise a400 error will be returned.@@ -10405,6 +10404,10 @@ components:type: stringnullable: truedescription: The environment of the trace referenced by score+ sessionId:+ type: string+ nullable: true+ description: The session ID associated with the trace referenced by scoreGetScoresResponseDataNumeric:title: GetScoresResponseDataNumerictype: objectdiff --git a/web/src/__tests__/server/scores-api-v2.servertest.ts b/web/src/__tests__/server/scores-api-v2.servertest.tsindex b2ee5514c1..ceec1c174a 100644--- a/web/src/__tests__/server/scores-api-v2.servertest.ts+++ b/web/src/__tests__/server/scores-api-v2.servertest.ts@@ -219,11 +219,13 @@ describe("/api/public/v2/scores API Endpoint", () => {const correctionScoreId_2 = v4();let authentication: string;let newProjectId: string;+ let executionTraceId: string;beforeEach(async () => {const { projectId, auth } = await createOrgProjectAndApiKey();authentication = auth;newProjectId = projectId;+ executionTraceId = v4();const trace = createTrace({id: traceId,@@ -278,6 +280,7 @@ describe("/api/public/v2/scores API Endpoint", () => {observation_id: generationId,config_id: config.id,comment: "comment",+ execution_trace_id: executionTraceId,});const score2 = createTraceScore({@@ -432,6 +435,13 @@ describe("/api/public/v2/scores API Endpoint", () => {).toBeTruthy();}}++ const scoreWithExecutionTraceId = getAllScore.body.data.find(+ (score) => score.id === scoreId_1,+ );+ expect(scoreWithExecutionTraceId?.executionTraceId).toBe(+ executionTraceId,+ );});it("get all scores for config", async () => {@@ -1356,11 +1366,13 @@ describe("/api/public/v2/scores API Endpoint", () => {it("should include both when fields=score,trace", async () => {const { projectId, auth } = await createOrgProjectAndApiKey();const traceId = v4();+ const traceSessionId = v4();const scoreId = v4();const trace = createTrace({id: traceId,project_id: projectId,+ session_id: traceSessionId,user_id: "test-user",tags: ["tag1"],});@@ -1393,6 +1405,7 @@ describe("/api/public/v2/scores API Endpoint", () => {trace: {userId: "test-user",tags: ["tag1"],+ sessionId: traceSessionId,},});});diff --git a/web/src/features/public-api/server/scores.ts b/web/src/features/public-api/server/scores.tsindex 6687c78f22..fd68889688 100644--- a/web/src/features/public-api/server/scores.ts+++ b/web/src/features/public-api/server/scores.ts@@ -91,7 +91,7 @@ export const _handleGenerateScoresForPublicApi = async ({const query = `SELECT- ${needsTraceJoin ? "t.user_id as user_id, t.tags as tags, t.environment as trace_environment," : ""}+ ${needsTraceJoin ? "t.user_id as user_id, t.tags as tags, t.environment as trace_environment, t.session_id as trace_session_id," : ""}s.id as id,s.project_id as project_id,s.timestamp as timestamp,@@ -109,6 +109,7 @@ export const _handleGenerateScoresForPublicApi = async ({s.data_type as data_type,s.config_id as config_id,s.queue_id as queue_id,+ s.execution_trace_id as execution_trace_id,s.trace_id as trace_id,s.observation_id as observation_id,s.session_id as session_id,@@ -173,6 +174,7 @@ export const _handleGenerateScoresForPublicApi = async ({tags?: string[];user_id?: string;trace_environment?: string;+ trace_session_id?: string | null;}>({query: query.replace("__TRACE_TABLE__", "traces"),@@ -192,6 +194,7 @@ export const _handleGenerateScoresForPublicApi = async ({userId: record.user_id,tags: record.tags,environment: record.trace_environment,+ sessionId: record.trace_session_id,}: null,};