Skip to content

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

fix(agent): Add user email to trace metadata (#14462)

Ben Bachem390e76e3a20c
diff --git a/web/src/__tests__/server/in-app-agent-stream.servertest.ts b/web/src/__tests__/server/in-app-agent-stream.servertest.ts
index b4234e6118..74ef064fa8 100644
--- a/web/src/__tests__/server/in-app-agent-stream.servertest.ts
+++ b/web/src/__tests__/server/in-app-agent-stream.servertest.ts
@@ -431,7 +431,7 @@ describe("createAgUiStream", () => {
langfuseTracing: {
environment: "langfuse-in-app-agent",
metadata: { langfuse_project_id: "project-1" },
- userId: "user-1",
+ user: { id: "user-1" },
traceId: "0123456789abcdef0123456789abcdef",
targetProjectId: "project-1",
},
diff --git a/web/src/__tests__/server/unit/in-app-agent-instrumentation.servertest.ts b/web/src/__tests__/server/unit/in-app-agent-instrumentation.servertest.ts
index 4684e966b5..39ea5dfd95 100644
--- a/web/src/__tests__/server/unit/in-app-agent-instrumentation.servertest.ts
+++ b/web/src/__tests__/server/unit/in-app-agent-instrumentation.servertest.ts
@@ -110,7 +110,10 @@ describe("InAppAgentInstrumentation", () => {
expect(mocks.getInternalTracingHandler).toHaveBeenCalledWith(
expect.objectContaining({
environment: "prod",
- metadata: { langfuse_project_id: "project-1" },
+ metadata: {
+ langfuse_project_id: "project-1",
+ langfuse_user_email: "[email protected]",
+ },
targetProjectId: "project-1",
traceId,
traceName: "in-app-agent",
@@ -210,6 +213,7 @@ describe("InAppAgentInstrumentation", () => {
},
metadata: {
langfuse_project_id: "project-1",
+ langfuse_user_email: "[email protected]",
prompt_name: "in-app-agent-system-prompt",
prompt_version: 3,
},
@@ -219,6 +223,7 @@ describe("InAppAgentInstrumentation", () => {
expect.objectContaining({
metadata: {
langfuse_project_id: "project-1",
+ langfuse_user_email: "[email protected]",
prompt_name: "in-app-agent-system-prompt",
prompt_version: 3,
},
@@ -230,6 +235,7 @@ describe("InAppAgentInstrumentation", () => {
input: "hello",
metadata: {
langfuse_project_id: "project-1",
+ langfuse_user_email: "[email protected]",
prompt_name: "in-app-agent-system-prompt",
prompt_version: 3,
},
@@ -395,6 +401,7 @@ function createInstrumentation(
input: { ...input, ...overrides },
metadata: { langfuse_project_id: "project-1" },
userId: "user-1",
+ userEmail: "[email protected]",
traceId,
targetProjectId: "project-1",
environment: "prod",
diff --git a/web/src/ee/features/in-app-agent/server/handler.ts b/web/src/ee/features/in-app-agent/server/handler.ts
index 8a30854734..76621a548b 100644
--- a/web/src/ee/features/in-app-agent/server/handler.ts
+++ b/web/src/ee/features/in-app-agent/server/handler.ts
@@ -350,7 +350,10 @@ export default async function handler(request: Request) {
? {
targetProjectId,
environment: "langfuse-in-app-agent",
- userId: auth.userId,
+ user: {
+ id: auth.userId,
+ email: auth.user.email,
+ },
traceId: conversation.id,
metadata: {
langfuse_ai_feature: "in-app-agent",
diff --git a/web/src/ee/features/in-app-agent/server/instrumentation.ts b/web/src/ee/features/in-app-agent/server/instrumentation.ts
index 096126eb51..db602cece9 100644
--- a/web/src/ee/features/in-app-agent/server/instrumentation.ts
+++ b/web/src/ee/features/in-app-agent/server/instrumentation.ts
@@ -10,7 +10,10 @@ import { compactTextMessageChunks } from "@/src/ee/features/in-app-agent/server/
export type InAppAgentTracingConfig = {
environment: string;
metadata: Record<string, unknown>;
- userId: string;
+ user: {
+ id: string;
+ email?: string | null;
+ };
traceId: string;
targetProjectId: string;
prompt?: InAppAgentPromptMetadata;
@@ -61,7 +64,8 @@ export function createInAppAgentInstrumentation({
return new InAppAgentInstrumentation({
input,
metadata: tracing.metadata,
- userId: tracing.userId,
+ userId: tracing.user.id,
+ userEmail: tracing.user.email,
traceId: tracing.traceId,
targetProjectId: tracing.targetProjectId,
environment: tracing.environment,
@@ -99,6 +103,7 @@ export class InAppAgentInstrumentation {
input: AgUiRunAgentInput;
metadata: Record<string, unknown>;
userId: string;
+ userEmail?: string | null;
traceId: string;
targetProjectId: string;
environment: string;
@@ -106,6 +111,7 @@ export class InAppAgentInstrumentation {
}) {
this.metadata = {
...params.metadata,
+ ...(params.userEmail ? { langfuse_user_email: params.userEmail } : {}),
...(params.prompt
? {
prompt_name: params.prompt.name,