Skip to content

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

fix(public traces): adjust shared trace header controls (#10861)

Michael Fröhlichd69c0ea014bc
diff --git a/web/src/components/layouts/page-header.tsx b/web/src/components/layouts/page-header.tsx
index c03ba0f3b3..59ebbb4cd3 100644
--- a/web/src/components/layouts/page-header.tsx
+++ b/web/src/components/layouts/page-header.tsx
@@ -13,6 +13,7 @@ import { cn } from "@/src/utils/tailwind";
import Link from "next/link";
import { useRouter } from "next/router";
import { type ParsedUrlQuery } from "querystring";
+import { type ReactNode } from "react";
type TabDefinition = {
value: string;
@@ -43,6 +44,10 @@ export type PageHeaderProps = {
container?: boolean;
tabsProps?: PageTabsProps;
className?: string;
+ showSidebarTrigger?: boolean;
+ leadingControl?: ReactNode;
+ titleBadges?: ReactNode;
+ breadcrumbBadges?: ReactNode;
};
const PageHeader = ({
@@ -56,6 +61,10 @@ const PageHeader = ({
tabsProps,
container = false,
className,
+ showSidebarTrigger = true,
+ leadingControl,
+ titleBadges,
+ breadcrumbBadges,
}: PageHeaderProps) => {
const router = useRouter();
return (
@@ -75,11 +84,20 @@ const PageHeader = ({
container && "lg:container",
)}
>
- <SidebarTrigger />
+ {showSidebarTrigger ? (
+ <SidebarTrigger />
+ ) : (
+ leadingControl && (
+ <div className="flex items-center">{leadingControl}</div>
+ )
+ )}
<div>
<EnvLabel />
</div>
- <BreadcrumbComponent items={breadcrumb} />
+ <div className="flex items-center gap-2">
+ <BreadcrumbComponent items={breadcrumb} />
+ {breadcrumbBadges}
+ </div>
</div>
</div>
@@ -148,6 +166,11 @@ const PageHeader = ({
)}
</h2>
</div>
+ {titleBadges && (
+ <div className="ml-1 flex items-center gap-1">
+ {titleBadges}
+ </div>
+ )}
</div>
{actionButtonsLeft && (
<div className="flex flex-wrap items-center gap-1 self-center">
diff --git a/web/src/components/trace2/TracePage.tsx b/web/src/components/trace2/TracePage.tsx
index 77bb99f805..3e22aae257 100644
--- a/web/src/components/trace2/TracePage.tsx
+++ b/web/src/components/trace2/TracePage.tsx
@@ -8,6 +8,12 @@ import { ErrorPage } from "@/src/components/error-page";
import { DeleteTraceButton } from "@/src/components/deleteButton";
import Page from "@/src/components/layouts/page";
import { Trace } from "@/src/components/trace2/Trace";
+import { useSession } from "next-auth/react";
+import { useIsAuthenticatedAndProjectMember } from "@/src/features/auth/hooks";
+import { Button } from "@/src/components/ui/button";
+import Link from "next/link";
+import { stripBasePath } from "@/src/utils/redirect";
+import { Badge } from "@/src/components/ui/badge";
export function TracePage({
traceId,
@@ -17,12 +23,14 @@ export function TracePage({
timestamp?: Date;
}) {
const router = useRouter();
+ const session = useSession();
+ const routeProjectId = (router.query.projectId as string) ?? "";
const trace = api.traces.byIdWithObservationsAndScores.useQuery(
{
traceId,
timestamp,
- projectId: router.query.projectId as string,
+ projectId: routeProjectId,
},
{
retry(failureCount, error) {
@@ -36,6 +44,11 @@ export function TracePage({
},
);
+ const projectIdForAccessCheck = trace.data?.projectId ?? routeProjectId;
+ const hasProjectAccess = useIsAuthenticatedAndProjectMember(
+ projectIdForAccessCheck,
+ );
+
const [selectedTab, setSelectedTab] = useQueryParam(
"display",
withDefault(StringParam, "details"),
@@ -58,6 +71,42 @@ export function TracePage({
if (!trace.data) return <div className="p-3">Loading...</div>;
+ const isSharedTrace = trace.data.public;
+ const showPublicIndicators = isSharedTrace && !hasProjectAccess;
+ const encodedTargetPath = encodeURIComponent(
+ stripBasePath(router.asPath || "/"),
+ );
+ const leadingControl = showPublicIndicators ? (
+ session.status === "authenticated" ? (
+ <Button
+ asChild
+ size="sm"
+ variant="outline"
+ title="Back to Langfuse"
+ className="px-3"
+ >
+ <Link href="/">Langfuse</Link>
+ </Button>
+ ) : (
+ <Button
+ asChild
+ size="sm"
+ variant="default"
+ title="Sign in to Langfuse"
+ className="px-3"
+ >
+ <Link href={`/auth/sign-in?targetPath=${encodedTargetPath}`}>
+ Sign in
+ </Link>
+ </Button>
+ )
+ ) : undefined;
+ const sharedBadge = showPublicIndicators ? (
+ <Badge variant="outline" className="text-xs font-medium">
+ Public
+ </Badge>
+ ) : undefined;
+
return (
<Page
headerProps={{
@@ -71,6 +120,9 @@ export function TracePage({
href: `/project/${router.query.projectId as string}/traces`,
},
],
+ showSidebarTrigger: !showPublicIndicators,
+ leadingControl,
+ breadcrumbBadges: sharedBadge,
actionButtonsLeft: (
<div className="ml-1 flex items-center gap-1">
<div className="flex items-center gap-0">