Skip to content

Same agent Smaller bill. The tools and infrastructure to get more work from your AI. Fewer tokens. Less compute. Lower cost.

[Fix]: span hierarchy ui on the request page (#851)

Aman Agarwal0b209924dd53
diff --git a/src/client/package-lock.json b/src/client/package-lock.json
index 7765f50f..e7c70fd7 100644
--- a/src/client/package-lock.json
+++ b/src/client/package-lock.json
@@ -1,12 +1,12 @@
{
"name": "openlit",
- "version": "1.14.2",
+ "version": "1.14.3",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "openlit",
- "version": "1.14.2",
+ "version": "1.14.3",
"dependencies": {
"@anthropic-ai/sdk": "^0.21.1",
"@clickhouse/client": "^1.1.0",
@@ -61,7 +61,6 @@
"react-dom": "^18.3.1",
"react-grid-layout": "^1.5.1",
"react-markdown": "^10.1.0",
- "react-resizable-panels": "^2.0.19",
"react-syntax-highlighter": "^15.5.0",
"recharts": "^2.12.7",
"sonner": "^1.5.0",
@@ -10504,15 +10503,6 @@
"react": ">= 16.3"
}
},
- "node_modules/react-resizable-panels": {
- "version": "2.0.19",
- "resolved": "https://registry.npmjs.org/react-resizable-panels/-/react-resizable-panels-2.0.19.tgz",
- "integrity": "sha512-v3E41kfKSuCPIvJVb4nL4mIZjjKIn/gh6YqZF/gDfQDolv/8XnhJBek4EiV2gOr3hhc5A3kOGOayk3DhanpaQw==",
- "peerDependencies": {
- "react": "^16.14.0 || ^17.0.0 || ^18.0.0",
- "react-dom": "^16.14.0 || ^17.0.0 || ^18.0.0"
- }
- },
"node_modules/react-smooth": {
"version": "4.0.1",
"resolved": "https://registry.npmjs.org/react-smooth/-/react-smooth-4.0.1.tgz",
diff --git a/src/client/package.json b/src/client/package.json
index e48ccbcc..d50f4d69 100644
--- a/src/client/package.json
+++ b/src/client/package.json
@@ -1,6 +1,6 @@
{
"name": "openlit",
- "version": "1.14.2",
+ "version": "1.14.3",
"private": true,
"scripts": {
"dev": "next dev",
@@ -63,7 +63,6 @@
"react-dom": "^18.3.1",
"react-grid-layout": "^1.5.1",
"react-markdown": "^10.1.0",
- "react-resizable-panels": "^2.0.19",
"react-syntax-highlighter": "^15.5.0",
"recharts": "^2.12.7",
"sonner": "^1.5.0",
diff --git a/src/client/src/components/(playground)/filter/slider-with-value.tsx b/src/client/src/components/(playground)/filter/slider-with-value.tsx
index 6325749c..6617f9a9 100644
--- a/src/client/src/components/(playground)/filter/slider-with-value.tsx
+++ b/src/client/src/components/(playground)/filter/slider-with-value.tsx
@@ -46,7 +46,6 @@ export default function SlideWithValue({
aria-label={label}
/>
<Input
- defaultValue={value}
step={stepValue}
value={value}
onChange={onInputValueChange}
diff --git a/src/client/src/components/(playground)/request/heirarchy-display.tsx b/src/client/src/components/(playground)/request/heirarchy-display.tsx
index a0863705..777398ad 100644
--- a/src/client/src/components/(playground)/request/heirarchy-display.tsx
+++ b/src/client/src/components/(playground)/request/heirarchy-display.tsx
@@ -1,7 +1,7 @@
import { useRequest } from "./request-context";
-import React, { useEffect } from "react";
-import { TangentIcon } from "lucide-react";
+import React, { useEffect, useState } from "react";
+import { FolderTree, Zap, Clock, Activity, Minus, Plus } from "lucide-react";
import {
findSpanInHierarchyLodash,
getNormalizedTraceAttribute,
@@ -10,91 +10,178 @@ import { TraceHeirarchySpan } from "@/types/trace";
import useFetchWrapper from "@/utils/hooks/useFetchWrapper";
import { toast } from "sonner";
import { TraceMapping } from "@/constants/traces";
+import { Accordion, AccordionContent, AccordionItem, AccordionTrigger } from "@/components/ui/accordion";
+import { ScrollArea } from "@/components/ui/scroll-area";
+import { ResizeablePanel } from "@/components/ui/resizeable-panel";
interface TreeNodeProps {
span: TraceHeirarchySpan;
level: number;
+ isLast?: boolean;
+ parentPath?: boolean[];
}
-export function TreeNode({ span, level }: TreeNodeProps) {
+export function TreeNode({ span, level, isLast = false, parentPath = [] }: TreeNodeProps) {
const [request, updateRequest] = useRequest();
+ const [isExpanded, setIsExpanded] = useState(true);
+ const hasChildren = span.children && span.children.length > 0;
+ const isSelected = request?.spanId === span.SpanId;
+
const onClick = () => {
if (request?.spanId !== span.SpanId) {
updateRequest({
spanId: span.SpanId,
});
}
- return;
};
- const spacingParent = level * 20 + 10;
+ const toggleExpanded = (e: React.MouseEvent) => {
+ e.stopPropagation();
+ setIsExpanded(!isExpanded);
+ };
+
+ const duration = parseFloat(
+ getNormalizedTraceAttribute("requestDuration", span.Duration) as string
+ ).toFixed(2);
+
+ const getSpanTypeIcon = (spanName: string) => {
+ if (spanName.includes('browser_action')) return <Activity className="h-3.5 w-3.5" />;
+ if (spanName.includes('model_request')) return <Zap className="h-3.5 w-3.5" />;
+ if (spanName.includes('execute_task')) return <Clock className="h-3.5 w-3.5" />;
+ return <Zap className="h-3.5 w-3.5" />;
+ };
+
+ const getTimingColor = () => {
+ const time = parseFloat(duration);
+ if (time > 10) return "text-red-600 dark:text-red-400";
+ if (time > 5) return "text-yellow-600 dark:text-yellow-400";
+ if (time > 1) return "text-blue-600 dark:text-blue-400";
+ return "text-green-600 dark:text-green-400";
+ };
+
+ const CONNECTION_LINES_CLASSES = "absolute left-3 bg-stone-400 dark:bg-stone-700"
return (
- <>
+ <div className="relative">
+ {/* Connection lines */}
+ {/* {level > 0 && renderConnectionLines()} */}
+ <div className="absolute left-0 top-0 bottom-0 flex">
+ {parentPath.map((showLine, index) => (
+ <div key={index} className="w-6 relative">
+ {showLine && (
+ <div className={`${CONNECTION_LINES_CLASSES} top-0 bottom-0 w-px`} />
+ )}
+ </div>
+ ))}
+
+ {level > 0 && (
+ <div className="w-6 relative">
+ {/* Vertical line */}
+ <div className={`${CONNECTION_LINES_CLASSES} top-0 h-6 w-px`} />
+ {/* Horizontal line */}
+ <div className={`${CONNECTION_LINES_CLASSES} top-6 w-3 h-px`} />
+ {/* Corner connector for non-last items */}
+ {!isLast && (
+ <div className={`${CONNECTION_LINES_CLASSES} top-6 bottom-0 w-px`} />
+ )}
+ </div>
+ )}
+ </div>
+
+ {/* Node content */}
<div
- className={`flex justify-start p-1 font-normal hover:bg-stone-300 dark:hover:bg-stone-800 rounded-xs items-start cursor-pointer relative ${
- request?.spanId === span.SpanId
- ? "bg-stone-300 dark:bg-stone-800"
- : ""
- }`}
+ className={`flex items-center gap-3 py-2 pr-4 rounded-md transition-colors cursor-pointer group ${level === 0 ? 'ml-0' : `ml-${(level + 1) * 6}`
+ }
+ ${isSelected
+ ? "bg-primary/[0.05] dark:bg-primary/[0.05] text-primary dark:text-primary"
+ : "hover:bg-stone-200/[0.5] dark:hover:bg-stone-800 text-stone-700 dark:text-stone-300"
+ }
+ `}
+ style={{ marginLeft: level > 0 ? `${(level + 1) * 24}px` : '0' }}
onClick={onClick}
- style={{
- paddingLeft: `${spacingParent}px`,
- }}
+ title={span.SpanName}
>
- {level > 0 && (
- <div
- className="absolute w-[10px] h-[1px] bg-stone-800 dark:bg-stone-300 z-10"
- style={{
- left: `${spacingParent - 15}px`,
- top: "15px",
- }}
- />
+ {/* Expand/collapse button for parents */}
+ {hasChildren && (
+ <button
+ onClick={toggleExpanded}
+ className={`flex items-center justify-center w-5 h-5 rounded border
+ ${isSelected
+ ? "text-primary/[0.5] dark:text-primary/[0.5] border-primary/[0.5] dark:border-primary/[0.5]"
+ : "text-stone-400 dark:text-stone-700 border-stone-400 dark:border-stone-700 "
+ }
+ `}
+ aria-label={isExpanded ? 'Collapse' : 'Expand'}
+ >
+ {isExpanded ? (
+ <Minus className="w-3 h-3" />
+ ) : (
+ <Plus className="w-3 h-3" />
+ )}
+ </button>
)}
- <TangentIcon className={`mr-2 h-4 w-4 shrink-0 mt-1`} />
- <div className="flex flex-col grow text-left overflow-hidden">
- <span className="block text-ellipsis overflow-hidden text-sm">
- {span.SpanName}
- </span>
- <span className="text-xs">
- (
- {parseFloat(
- getNormalizedTraceAttribute(
- "requestDuration",
- span.Duration
- ) as string
- ).toFixed(2)}
- {TraceMapping.requestDuration.valueSuffix})
- </span>
+
+ {/* Icon */}
+ <div className={`flex items-center justify-center w-6 h-6 rounded
+ ${isSelected
+ ? "bg-primary/[0.2] dark:bg-primary/[0.2] text-primary dark:text-primary"
+ : "bg-stone-100 dark:bg-stone-800 text-stone-600 dark:text-stone-400"
+ }`}>
+ {getSpanTypeIcon(span.SpanName)}
</div>
+
+ {/* Title */}
+ <span className={`text-sm flex-1 overflow-hidden text-ellipsis whitespace-nowrap`}>
+ {span.SpanName}
+ </span>
+
+ {/* Timing */}
+ <span className={`text-sm ${getTimingColor()}`}>
+ {duration}{TraceMapping.requestDuration.valueSuffix}
+ </span>
</div>
- {span.children && span.children.length > 0 && (
- <div className="flex flex-col w-full relative">
- <div
- className="absolute w-[1px] h-full bg-stone-800 dark:bg-stone-300 z-10"
- style={{
- left: `${spacingParent + 5}px`,
- top: "-15px",
- }}
- />
- {span.children.map((child) => (
- <TreeNode key={child.SpanId} span={child} level={level + 1} />
- ))}
+
+ {/* Children */}
+ {hasChildren && isExpanded && (
+ <div className="relative">
+ {span?.children!.map((child, index) => {
+ const isLastChild = index === span.children!.length - 1;
+
+ return (
+ <TreeNode
+ key={child.SpanId}
+ span={child}
+ level={level + 1}
+ isLast={isLastChild}
+ parentPath={[...parentPath, !isLast]}
+ />
+ );
+ })}
</div>
)}
- </>
+ </div>
);
}
+const DEFAULT_WIDTH = 46;
+
export default function HeirarchyDisplay() {
const [request] = useRequest();
- const { data, fireRequest, isLoading } = useFetchWrapper();
+ const { data, fireRequest, isLoading, error } = useFetchWrapper();
+ const [accordionValue, setAccordionValue] = useState("");
+
+ useEffect(() => {
+ if (!isLoading) {
+ setAccordionValue("debug");
+ }
+ }, [isLoading]);
const typedData =
(data as { record: TraceHeirarchySpan; err?: string }) || {};
useEffect(() => {
if (
+ !error &&
!findSpanInHierarchyLodash(typedData.record || {}, request?.spanId) &&
request?.spanId &&
!isLoading
@@ -109,21 +196,59 @@ export default function HeirarchyDisplay() {
},
});
}
- }, [request, typedData, isLoading]);
+ }, [request, typedData, isLoading, error]);
const { record } = typedData;
- if (isLoading || typedData.err || !record) {
+ if (isLoading || typedData.err || !record || !record.SpanId) {
return null;
}
return (
- <div className="absolute left-0 -translate-x-full w-2/3 bg-stone-100 dark:bg-stone-900 border border-stone-200 border-t-0 dark:border-stone-900 border-r-0 text-stone-800 dark:text-stone-300 flex flex-col max-h-1/2">
- <p className="flex-row bg-stone-950 px-3 py-2 items-center space-y-0 text-sm font-bold leading-7 text-stone-200">
- Span Heirarchy
- </p>
- <div className="flex flex-col p-2 overflow-y-auto">
- <TreeNode span={record} level={0} />
- </div>
- </div>
+ <ResizeablePanel
+ defaultWidth={accordionValue ? 450 : DEFAULT_WIDTH}
+ minWidth={DEFAULT_WIDTH}
+ maxWidth={700}
+ handlePosition="left"
+ className="absolute left-0 top-0 -translate-x-full h-full bg-stone-100 dark:bg-stone-900 border border-stone-200 border-t-0 dark:border-stone-800 border-r-0 shadow-lg"
+ >
+ <Accordion type="single" collapsible className="flex flex-1 h-full" value={accordionValue}>
+ <AccordionItem value="debug" className="border-0 flex flex-1 w-full">
+ <AccordionTrigger
+ className="flex flex-col items-center gap-3 px-3 py-6 hover:no-underline hover:bg-stone-100 dark:hover:bg-stone-900 [&[data-state=open]]:bg-stone-100 dark:[&[data-state=open]]:bg-stone-900/50 [&[data-state=open]>svg]:rotate-90 [&[data-state=closed]>svg]:rotate-[-90deg] border-r border-stone-200 dark:border-stone-700 transition-colors"
+ onClick={() => setAccordionValue(accordionValue === "debug" ? "" : "debug")}
+ >
+ <div className="flex flex-col items-center gap-3">
+ <FolderTree className="h-5 w-5 text-stone-600 dark:text-stone-400" />
+ <span className="text-sm font-semibold [writing-mode:vertical-lr] rotate-180 transform text-stone-700 dark:text-stone-300">
+ Span Hierarchy
+ </span>
+ {isLoading && (
+ <div className="flex flex-col items-center gap-1">
+ <div className="w-6 h-6 border-2 border-stone-300 border-t-stone-600 rounded-full animate-spin" />
+ <span className="text-xs text-stone-500 [writing-mode:vertical-lr] rotate-180">
+ Loading...
+ </span>
+ </div>
+ )}
+ </div>
+ </AccordionTrigger>
+ <AccordionContent className="data-[state=closed]:animate-accordion-up data-[state=open]:animate-accordion-down transition-all h-full pb-0" parentClassName="h-full w-full">
+ <ScrollArea className="h-full w-full">
+ <div className="p-3">
+ <div className="mb-3 pb-2 border-b border-stone-200 dark:border-stone-700">
+ <h3 className="text-sm font-semibold text-stone-900 dark:text-stone-100">
+ Trace Execution Flow
+ </h3>
+ <p className="text-xs text-stone-500 dark:text-stone-400 mt-1">
+ Click spans to view details
+ </p>
+ </div>
+ <TreeNode span={record} level={0} />
+ </div>
+ </ScrollArea>
+ </AccordionContent>
+ </AccordionItem>
+ </Accordion>
+ </ResizeablePanel>
);
-}
+}
\ No newline at end of file
diff --git a/src/client/src/components/(playground)/request/request-details.tsx b/src/client/src/components/(playground)/request/request-details.tsx
index 478b298a..8d488b3a 100644
--- a/src/client/src/components/(playground)/request/request-details.tsx
+++ b/src/client/src/components/(playground)/request/request-details.tsx
@@ -55,7 +55,7 @@ export default function RequestDetails() {
if (request?.spanId) {
fetchData();
}
- }, [fetchData, request]);
+ }, [request?.spanId, fetchData]);
useEffect(() => {
if (isOpen) {
@@ -114,7 +114,7 @@ export default function RequestDetails() {
return (
<Sheet open={isOpen}>
<SheetContent
- className="max-w-none sm:max-w-none w-2/5 p-0 gap-0 flex flex-col border-l border-stone-200 dark:border-stone-800 top-[57px] h-auto"
+ className="max-w-none sm:max-w-none w-2/5 p-0 gap-0 flex flex-col border-l border-stone-200 dark:border-stone-800 top-[57px] h-auto focus-visible:outline-none"
displayOverlay={false}
displayClose={false}
>
diff --git a/src/client/src/components/data-table/table.tsx b/src/client/src/components/data-table/table.tsx
index adf52dd6..6e26ccea 100644
--- a/src/client/src/components/data-table/table.tsx
+++ b/src/client/src/components/data-table/table.tsx
@@ -90,6 +90,7 @@ export default function Table({
const onClickHandler = (rowItem: any) =>
typeof onClick === "function" ? onClick(rowItem) : noop();
+
return (
<div className="flex flex-col w-full overflow-auto border dark:border-stone-800 rounded-md">
<RowWrapper className={`sticky top-0 z-10`} style={style}>
@@ -110,17 +111,17 @@ export default function Table({
{(!isFetched || (isLoading && !data?.length)) && (
<RenderLoader columns={visibleColumns} style={style} />
)}
- {data?.map((rowItem) => {
+ {data?.map((rowItem, index) => {
return (
<RowWrapper
- key={rowItem.id}
+ key={`row-${index}`}
className={`group text-sm text-stone-700 dark:text-stone-300`}
onClick={() => onClickHandler(rowItem)}
style={style}
>
- {visibleColumns.map((column) => (
+ {visibleColumns.map((column, cIdx) => (
<ColumnRowItem
- key={`${column}-${rowItem.id}`}
+ key={`row-${index}-column-${cIdx}`}
className={`group-last-of-type:border-b-0 group-hover:bg-stone-100 dark:group-hover:bg-stone-800 cursor-pointer`}
>
{columns[column]?.cell({
diff --git a/src/client/src/components/ui/accordion.tsx b/src/client/src/components/ui/accordion.tsx
index 24c788c2..16281845 100644
--- a/src/client/src/components/ui/accordion.tsx
+++ b/src/client/src/components/ui/accordion.tsx
@@ -42,11 +42,11 @@ AccordionTrigger.displayName = AccordionPrimitive.Trigger.displayName
const AccordionContent = React.forwardRef<
React.ElementRef<typeof AccordionPrimitive.Content>,
- React.ComponentPropsWithoutRef<typeof AccordionPrimitive.Content>
->(({ className, children, ...props }, ref) => (
+ React.ComponentPropsWithoutRef<typeof AccordionPrimitive.Content> & { parentClassName?: string }
+>(({ className, children, parentClassName, ...props }, ref) => (
<AccordionPrimitive.Content
ref={ref}
- className="overflow-hidden text-sm transition-all data-[state=closed]:animate-accordion-up data-[state=open]:animate-accordion-down"
+ className={cn("overflow-hidden text-sm transition-all data-[state=closed]:animate-accordion-up data-[state=open]:animate-accordion-down", parentClassName)}
{...props}
>
<div className={cn("pb-4 pt-0", className)}>{children}</div>
diff --git a/src/client/src/components/ui/resizable.tsx b/src/client/src/components/ui/resizable.tsx
deleted file mode 100644
index b5081e8c..00000000
--- a/src/client/src/components/ui/resizable.tsx
+++ /dev/null
@@ -1,45 +0,0 @@
-"use client"
-
-import { GripVertical } from "lucide-react"
-import * as ResizablePrimitive from "react-resizable-panels"
-
-import { cn } from "@/lib/utils"
-
-const ResizablePanelGroup = ({
- className,
- ...props
-}: React.ComponentProps<typeof ResizablePrimitive.PanelGroup>) => (
- <ResizablePrimitive.PanelGroup
- className={cn(
- "flex h-full w-full data-[panel-group-direction=vertical]:flex-col",
- className
- )}
- {...props}
- />
-)
-
-const ResizablePanel = ResizablePrimitive.Panel
-
-const ResizableHandle = ({
- withHandle,
- className,
- ...props
-}: React.ComponentProps<typeof ResizablePrimitive.PanelResizeHandle> & {
- withHandle?: boolean
-}) => (
- <ResizablePrimitive.PanelResizeHandle
- className={cn(
- "relative flex w-px items-center justify-center bg-stone-200 after:absolute after:inset-y-0 after:left-1/2 after:w-1 after:-translate-x-1/2 focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-stone-950 focus-visible:ring-offset-1 data-[panel-group-direction=vertical]:h-px data-[panel-group-direction=vertical]:w-full data-[panel-group-direction=vertical]:after:left-0 data-[panel-group-direction=vertical]:after:h-1 data-[panel-group-direction=vertical]:after:w-full data-[panel-group-direction=vertical]:after:-translate-y-1/2 data-[panel-group-direction=vertical]:after:translate-x-0 [&[data-panel-group-direction=vertical]>div]:rotate-90 dark:bg-stone-800 dark:focus-visible:ring-stone-300",
- className
- )}
- {...props}
- >
- {withHandle && (
- <div className="z-10 flex h-4 w-3 items-center justify-center rounded-sm border border-stone-200 bg-stone-200 dark:border-stone-800 dark:bg-stone-800">
- <GripVertical className="h-2.5 w-2.5" />
- </div>
- )}
- </ResizablePrimitive.PanelResizeHandle>
-)
-
-export { ResizablePanelGroup, ResizablePanel, ResizableHandle }
diff --git a/src/client/src/components/ui/resizeable-panel.tsx b/src/client/src/components/ui/resizeable-panel.tsx
new file mode 100644
index 00000000..f31e0fa7
--- /dev/null
+++ b/src/client/src/components/ui/resizeable-panel.tsx
@@ -0,0 +1,284 @@
+"use client";
+
+import React, { useState, useCallback, useRef, useEffect } from "react";
+import { cn } from "@/lib/utils";
+
+interface ResizeableHandleProps {
+ /** Position of the resize handle relative to its container */
+ position?: "left" | "right" | "top" | "bottom";
+ /** Custom CSS classes for the handle */
+ className?: string;
+ /** Callback fired during resize with delta movement and resize state */
+ onResize: (delta: number, isResizing: boolean) => void;
+ /** Whether the handle is disabled */
+ disabled?: boolean;
+}
+
+/**
+ * A reusable resize handle component that can be positioned on any side of a container.
+ *
+ * @example
+ * ```tsx
+ * // Basic horizontal resizing
+ * <ResizableHandle
+ * position="right"
+ * onResize={(delta, isResizing) => {
+ * if (delta !== 0) {
+ * setWidth(prev => prev + delta);
+ * }
+ * }}
+ * />
+ *
+ * // Vertical resizing
+ * <ResizableHandle
+ * position="bottom"
+ * onResize={(delta, isResizing) => {
+ * if (delta !== 0) {
+ * setHeight(prev => prev + delta);
+ * }
+ * }}
+ * />
+ * ```
+ */
+export function ResizeableHandle({
+ position = "right",
+ className,
+ onResize,
+ disabled = false,
+}: ResizeableHandleProps) {
+ const [isResizing, setIsResizing] = useState(false);
+ const startMousePos = useRef<{ x: number; y: number }>({ x: 0, y: 0 });
+ const lastMousePos = useRef<{ x: number; y: number }>({ x: 0, y: 0 });
+
+ const isHorizontal = position === "left" || position === "right";
+ const isVertical = position === "top" || position === "bottom";
+
+ // Handle mouse down on resize handle
+ const handleMouseDown = useCallback(
+ (e: React.MouseEvent) => {
+ if (disabled) return;
+
+ setIsResizing(true);
+ startMousePos.current = { x: e.clientX, y: e.clientY };
+ lastMousePos.current = { x: e.clientX, y: e.clientY };
+ onResize(0, true);
+ e.preventDefault();
+ },
+ [disabled, onResize]
+ );
+
+ // Handle mouse move for resizing
+ const handleMouseMove = useCallback(
+ (e: MouseEvent) => {
+ if (!isResizing) return;
+
+ const currentPos = { x: e.clientX, y: e.clientY };
+
+ let delta = 0;
+ if (isHorizontal) {
+ const mouseDelta = currentPos.x - lastMousePos.current.x;
+ delta = position === "left" ? -mouseDelta : mouseDelta;
+ } else if (isVertical) {
+ const mouseDelta = currentPos.y - lastMousePos.current.y;
+ delta = position === "top" ? -mouseDelta : mouseDelta;
+ }
+
+ lastMousePos.current = currentPos;
+ onResize(delta, true);
+ },
+ [isResizing, position, isHorizontal, isVertical, onResize]
+ );
+
+ // Handle mouse up to stop resizing
+ const handleMouseUp = useCallback(() => {
+ if (isResizing) {
+ setIsResizing(false);
+ onResize(0, false);
+ }
+ }, [isResizing, onResize]);
+
+ // Add global event listeners for mouse move and mouse up
+ useEffect(() => {
+ if (isResizing) {
+ document.addEventListener("mousemove", handleMouseMove);
+ document.addEventListener("mouseup", handleMouseUp);
+
+ const cursor = isHorizontal ? "col-resize" : "row-resize";
+ document.body.style.cursor = cursor;
+ document.body.style.userSelect = "none";
+
+ return () => {
+ document.removeEventListener("mousemove", handleMouseMove);
+ document.removeEventListener("mouseup", handleMouseUp);
+ document.body.style.cursor = "";
+ document.body.style.userSelect = "";
+ };
+ }
+ }, [isResizing, handleMouseMove, handleMouseUp, isHorizontal]);
+
+ const getPositionClasses = () => {
+ switch (position) {
+ case "left":
+ return "left-0 top-1/2 -translate-y-1/2 -translate-x-1/2 cursor-col-resize";
+ case "right":
+ return "right-0 top-1/2 -translate-y-1/2 translate-x-1/2 cursor-col-resize";
+ case "top":
+ return "top-0 left-1/2 -translate-x-1/2 -translate-y-1/2 cursor-row-resize";
+ case "bottom":
+ return "bottom-0 left-1/2 -translate-x-1/2 translate-y-1/2 cursor-row-resize";
+ default:
+ return "right-0 top-1/2 -translate-y-1/2 translate-x-1/2 cursor-col-resize";
+ }
+ };
+
+ const isHorizontalHandle = position === "left" || position === "right";
+
+ const defaultHandleClass = cn(
+ "absolute rounded border border-stone-200 dark:border-stone-700 bg-white dark:bg-stone-800 opacity-0 group-hover:opacity-100 transition-all duration-200 group-hover:border-stone-400 dark:group-hover:border-stone-500 group-hover:scale-110",
+ isResizing && "opacity-100 border-stone-400 dark:border-stone-500 scale-110 bg-stone-50 dark:bg-stone-700",
+ disabled && "cursor-not-allowed opacity-30",
+ isHorizontalHandle ? "w-3 h-6 p-0.5" : "w-6 h-3 p-0.5",
+ getPositionClasses()
+ );
+
+ // SVG grip pattern with 6 circles
+ const GripIcon = () => (
+ <svg
+ viewBox="0 0 12 12"
+ className={cn(
+ "w-full h-full",
+ isHorizontalHandle ? "rotate-90" : ""
+ )}
+ >
+ {/* First row of 3 circles */}
+ <circle cx="2" cy="3" r="1" className="fill-stone-400 dark:fill-stone-500" />
+ <circle cx="6" cy="3" r="1" className="fill-stone-400 dark:fill-stone-500" />
+ <circle cx="10" cy="3" r="1" className="fill-stone-400 dark:fill-stone-500" />
+
+ {/* Second row of 3 circles */}
+ <circle cx="2" cy="9" r="1" className="fill-stone-400 dark:fill-stone-500" />
+ <circle cx="6" cy="9" r="1" className="fill-stone-400 dark:fill-stone-500" />
+ <circle cx="10" cy="9" r="1" className="fill-stone-400 dark:fill-stone-500" />
+ </svg>
+ );
+
+ return (
+ <div
+ className={cn(defaultHandleClass, className)}
+ onMouseDown={handleMouseDown}
+ >
+ <GripIcon />
+ </div>
+ );
+}
+
+interface ResizeablePanelProps {
+ /** Content to render inside the panel */
+ children: React.ReactNode;
+ /** Initial width of the panel in pixels */
+ defaultWidth?: number;
+ /** Minimum allowed width in pixels */
+ minWidth?: number;
+ /** Maximum allowed width in pixels */
+ maxWidth?: number;
+ /** Custom CSS classes for the panel container */
+ className?: string;
+ /** Position of the resize handle */
+ handlePosition?: "left" | "right";
+ /** Custom CSS classes for the resize handle */
+ handleClassName?: string;
+ /** Callback fired when the width changes */
+ onWidthChange?: (width: number) => void;
+ /** Whether resizing is disabled */
+ disabled?: boolean;
+}
+
+/**
+ * A resizable panel component with built-in width management and constraints.
+ * Uses ResizableHandle internally for the drag functionality.
+ *
+ * @example
+ * ```tsx
+ * // Basic resizable sidebar
+ * <ResizablePanel
+ * defaultWidth={300}
+ * minWidth={200}
+ * maxWidth={500}
+ * handlePosition="right"
+ * onWidthChange={(width) => console.log('New width:', width)}
+ * >
+ * <div>Sidebar content</div>
+ * </ResizablePanel>
+ *
+ * // Custom styling
+ * <ResizablePanel
+ * className="bg-gray-100 border"
+ * handleClassName="bg-blue-500"
+ * handlePosition="left"
+ * >
+ * <div>Panel content</div>
+ * </ResizablePanel>
+ * ```
+ */
+export function ResizeablePanel({
+ children,
+ defaultWidth = 400,
+ minWidth = 200,
+ maxWidth = 600,
+ className,
+ handlePosition = "right",
+ handleClassName,
+ onWidthChange,
+ disabled = false,
+}: ResizeablePanelProps) {
+ const [width, setWidth] = useState(defaultWidth);
+
+ // Handle resize from the ResizableHandle component
+ const handleResize = useCallback(
+ (delta: number, isResizing: boolean) => {
+ if (!isResizing && delta === 0) {
+ // Resize ended, no action needed
+ return;
+ }
+
+ if (delta !== 0) {
+ setWidth((prevWidth) => {
+ const newWidth = prevWidth + delta;
+ const constrainedWidth = Math.max(minWidth, Math.min(maxWidth, newWidth));
+
+ // Only call onWidthChange if width actually changed
+ if (constrainedWidth !== prevWidth) {
+ onWidthChange?.(constrainedWidth);
+ }
+
+ return constrainedWidth;
+ });
+ }
+ },
+ [minWidth, maxWidth, onWidthChange]
+ );
+
+ useEffect(() => {
+ setWidth(defaultWidth);
+ }, [defaultWidth])
+
+ return (
+ <div
+ className={cn("relative flex group", className)}
+ style={{ width: `${width}px` }}
+ >
+ {/* Resize handle */}
+ <ResizeableHandle
+ position={handlePosition}
+ className={handleClassName}
+ onResize={handleResize}
+ disabled={disabled}
+ />
+
+ {/* Content */}
+ <div className="flex-1 overflow-hidden">
+ {children}
+ </div>
+ </div>
+ );
+}
\ No newline at end of file
diff --git a/src/client/src/components/ui/scroll-area.tsx b/src/client/src/components/ui/scroll-area.tsx
index bb6a11c9..4b8c564b 100644
--- a/src/client/src/components/ui/scroll-area.tsx
+++ b/src/client/src/components/ui/scroll-area.tsx
@@ -14,7 +14,7 @@ const ScrollArea = React.forwardRef<
className={cn("relative overflow-hidden", className)}
{...props}
>
- <ScrollAreaPrimitive.Viewport className="h-full w-full rounded-[inherit]">
+ <ScrollAreaPrimitive.Viewport className="h-full w-full rounded-[inherit] !flex !flex-col" asChild>
{children}
</ScrollAreaPrimitive.Viewport>
<ScrollBar />
@@ -33,9 +33,9 @@ const ScrollBar = React.forwardRef<
className={cn(
"flex touch-none select-none transition-colors",
orientation === "vertical" &&
- "h-full w-2.5 border-l border-l-transparent p-[1px]",
+ "h-full w-2.5 border-l border-l-transparent p-[1px]",
orientation === "horizontal" &&
- "h-2.5 flex-col border-t border-t-transparent p-[1px]",
+ "h-2.5 flex-col border-t border-t-transparent p-[1px]",
className
)}
{...props}
diff --git a/src/client/src/lib/platform/request/index.ts b/src/client/src/lib/platform/request/index.ts
index 0c40652e..4587beae 100644
--- a/src/client/src/lib/platform/request/index.ts
+++ b/src/client/src/lib/platform/request/index.ts
@@ -97,11 +97,11 @@ export async function getRequestsConfig(params: MetricParams) {
select.push(
`arrayConcat(
arrayFilter(x -> x != '', groupArray(DISTINCT SpanAttributes['${getTraceMappingKeyFullPath(
- "provider"
- )}'])),
+ "provider"
+ )}'])),
arrayFilter(x -> x != '', groupArray(DISTINCT SpanAttributes['${getTraceMappingKeyFullPath(
- "system"
- )}']))
+ "system"
+ )}']))
) AS providers`
);
@@ -160,14 +160,13 @@ export async function getRequests(params: MetricParams) {
const query = `SELECT * FROM ${OTEL_TRACES_TABLE_NAME}
WHERE ${getFilterWhereCondition(params, true)}
- ${
- params.sorting
- ? params.sorting.type.includes("cost")
- ? `ORDER BY toFloat64OrZero(${params.sorting.type}) ${params.sorting.direction} `
- : params.sorting.type.includes("tokens")
+ ${params.sorting
+ ? params.sorting.type.includes("cost")
+ ? `ORDER BY toFloat64OrZero(${params.sorting.type}) ${params.sorting.direction} `
+ : params.sorting.type.includes("tokens")
? `ORDER BY toInt32OrZero(${params.sorting.type}) ${params.sorting.direction} `
: `ORDER BY ${params.sorting.type} ${params.sorting.direction} `
- : `ORDER BY Timestamp desc `
+ : `ORDER BY Timestamp desc `
}
LIMIT ${limit}
OFFSET ${offset}`;
@@ -234,15 +233,14 @@ export async function getHeirarchyViaSpanId(spanId: string) {
INNER JOIN
trace_hierarchy th
ON
- ${
- dir === "upward"
- ? `ot.${getTraceMappingKeyFullPath(
- "spanId"
- )} = th.${getTraceMappingKeyFullPath("parentSpanId")}`
- : `ot.${getTraceMappingKeyFullPath(
- "parentSpanId"
- )} = th.${getTraceMappingKeyFullPath("spanId")}`
- }
+ ${dir === "upward"
+ ? `ot.${getTraceMappingKeyFullPath(
+ "spanId"
+ )} = th.${getTraceMappingKeyFullPath("parentSpanId")}`
+ : `ot.${getTraceMappingKeyFullPath(
+ "parentSpanId"
+ )} = th.${getTraceMappingKeyFullPath("spanId")}`
+ }
)
SELECT *
FROM trace_hierarchy
@@ -257,14 +255,16 @@ export async function getHeirarchyViaSpanId(spanId: string) {
query: commonQuery("downward", (upwardData as any[])?.[0]?.SpanId),
});
+ const heirarchy = buildHierarchy(downwardData as any[]);
+
return {
- err: upwardErr || downwardErr,
- record: buildHierarchy(downwardData as any[]),
+ err: upwardErr || downwardErr || (heirarchy ? null : "Error in fetching heirarchy"),
+ record: heirarchy,
};
}
return {
err: "Error in fetching heirarchy",
- record: [],
+ record: {},
};
}