Skip to content

armgit / burr

Public Imported from GitHub
0

Build applications that make decisions (chatbots, agents, simulations, etc...). Monitor, trace, persist, and execute on your own infrastructure.

Updates the UI to display attributes

elijahbenizzyaaba04cc57ed
diff --git a/telemetry/ui/src/api/index.ts b/telemetry/ui/src/api/index.ts
index b0c0638e..5d92fad0 100644
--- a/telemetry/ui/src/api/index.ts
+++ b/telemetry/ui/src/api/index.ts
@@ -11,6 +11,7 @@ export type { ActionModel } from './models/ActionModel';
export type { ApplicationLogs } from './models/ApplicationLogs';
export type { ApplicationModel } from './models/ApplicationModel';
export type { ApplicationSummary } from './models/ApplicationSummary';
+export type { AttributeModel } from './models/AttributeModel';
export type { BackendSpec } from './models/BackendSpec';
export type { BeginEntryModel } from './models/BeginEntryModel';
export type { BeginSpanModel } from './models/BeginSpanModel';
diff --git a/telemetry/ui/src/api/models/AttributeModel.ts b/telemetry/ui/src/api/models/AttributeModel.ts
new file mode 100644
index 00000000..db262eb0
--- /dev/null
+++ b/telemetry/ui/src/api/models/AttributeModel.ts
@@ -0,0 +1,15 @@
+/* generated using openapi-typescript-codegen -- do no edit */
+/* istanbul ignore file */
+/* tslint:disable */
+/* eslint-disable */
+/**
+ * Represents a logged artifact
+ */
+export type AttributeModel = {
+ type?: string;
+ key: string;
+ action_sequence_id: number;
+ span_id: string | null;
+ value: Record<string, any> | string | number | boolean | null;
+ tags: Record<string, string>;
+};
diff --git a/telemetry/ui/src/api/models/Step.ts b/telemetry/ui/src/api/models/Step.ts
index 071d0843..24edf73e 100644
--- a/telemetry/ui/src/api/models/Step.ts
+++ b/telemetry/ui/src/api/models/Step.ts
@@ -2,6 +2,7 @@
/* istanbul ignore file */
/* tslint:disable */
/* eslint-disable */
+import type { AttributeModel } from './AttributeModel';
import type { BeginEntryModel } from './BeginEntryModel';
import type { EndEntryModel } from './EndEntryModel';
import type { Span } from './Span';
@@ -9,8 +10,8 @@ import type { Span } from './Span';
* Log of astep -- has a start and an end.
*/
export type Step = {
- step_start_log: BeginEntryModel;
- step_end_log: (EndEntryModel | null);
- spans: Array<Span>;
+ step_start_log: BeginEntryModel;
+ step_end_log: EndEntryModel | null;
+ spans: Array<Span>;
+ attributes: Array<AttributeModel>;
};
-
diff --git a/telemetry/ui/src/components/routes/app/AppView.tsx b/telemetry/ui/src/components/routes/app/AppView.tsx
index c7ed7620..91ead0ed 100644
--- a/telemetry/ui/src/components/routes/app/AppView.tsx
+++ b/telemetry/ui/src/components/routes/app/AppView.tsx
@@ -1,11 +1,11 @@
import { Navigate, useParams } from 'react-router';
-import { DefaultService, Step } from '../../../api';
+import { AttributeModel, DefaultService, Step } from '../../../api';
import { useQuery } from 'react-query';
import { Loading } from '../../common/loading';
import { StepList } from './StepList';
import { TwoColumnLayout, TwoRowLayout } from '../../common/layout';
import { AppStateView } from './StateMachine';
-import { useEffect, useState } from 'react';
+import { createContext, useEffect, useState } from 'react';
import { Status } from '../../../utils';
import { GraphView } from './GraphView';
@@ -82,6 +82,18 @@ export const backgroundColorsForIndex = (index: number, status: Status) => {
// Default number of previous actions to show
const NUM_PREVIOUS_ACTIONS = 6;
+export type HighlightState = {
+ attributesHighlighted: AttributeModel[];
+ setAttributesHighlighted: (attributes: AttributeModel[]) => void;
+ setTab: (tab: string) => void;
+};
+
+export const AppViewHighlightContext = createContext<HighlightState>({
+ attributesHighlighted: [],
+ setAttributesHighlighted: () => {},
+ setTab: () => {}
+});
+
/**
* View for the "Application" page. This has two columns:
* 1. A list of steps
@@ -100,6 +112,10 @@ export const AppView = (props: {
const [autoRefresh, setAutoRefresh] = useState(props.defaultAutoRefresh || false);
const shouldQuery = projectId !== undefined && appId !== undefined;
const [minimizedTable, setMinimizedTable] = useState(false);
+ const [highlightedAttributes, setHighlightedAttributes] = useState<AttributeModel[]>([]);
+ const displayGraphAsTabs = props.orientation === 'stacked_vertical';
+ const defaultTab = displayGraphAsTabs ? 'graph' : 'data';
+ const [currentTab, setCurrentTab] = useState(defaultTab);
const { data, error } = useQuery(
['steps', appId],
() =>
@@ -201,53 +217,63 @@ export const AppView = (props: {
? stepsSorted.find((step) => step.step_start_log.sequence_id === hoverSequenceID)
: undefined;
return (
- <Layout
- mode={minimizedTable ? 'first-minimal' : 'half'}
- firstItem={
- <div className="w-full h-full flex flex-col">
- <div
- className={`overflow-y-scroll hide-scrollbar w-full ${props.orientation === 'stacked_vertical' ? 'h-full' : 'h-1/2'}`}
- >
- <StepList
- steps={stepsSorted}
- currentHoverIndex={hoverSequenceID}
- setCurrentHoverIndex={setHoverSequenceID}
- currentSelectedIndex={currentActionIndex}
- setCurrentSelectedIndex={setCurrentActionIndex}
- numPriorIndices={NUM_PREVIOUS_ACTIONS}
- autoRefresh={autoRefresh}
- setAutoRefresh={setAutoRefresh}
- minimized={minimizedTable}
- setMinimized={setMinimizedTable}
- projectId={projectId}
- parentPointer={data?.parent_pointer || undefined}
- spawningParentPointer={data?.spawning_parent_pointer || undefined}
- links={data.children || []}
- />
- </div>
- {props.orientation === 'stacked_horizontal' && (
- <div className="h-1/2 w-[full]">
- <GraphView
- stateMachine={data.application}
- currentAction={currentStep}
- highlightedActions={previousActions}
- hoverAction={hoverAction}
+ <AppViewHighlightContext.Provider
+ value={{
+ attributesHighlighted: highlightedAttributes,
+ setAttributesHighlighted: setHighlightedAttributes,
+ setTab: setCurrentTab
+ }}
+ >
+ <Layout
+ mode={minimizedTable ? 'first-minimal' : 'half'}
+ firstItem={
+ <div className="w-full h-full flex flex-col">
+ <div
+ className={`overflow-y-scroll hide-scrollbar w-full ${props.orientation === 'stacked_vertical' ? 'h-full' : 'h-1/2'}`}
+ >
+ <StepList
+ steps={stepsSorted}
+ currentHoverIndex={hoverSequenceID}
+ setCurrentHoverIndex={setHoverSequenceID}
+ currentSelectedIndex={currentActionIndex}
+ setCurrentSelectedIndex={setCurrentActionIndex}
+ numPriorIndices={NUM_PREVIOUS_ACTIONS}
+ autoRefresh={autoRefresh}
+ setAutoRefresh={setAutoRefresh}
+ minimized={minimizedTable}
+ setMinimized={setMinimizedTable}
+ projectId={projectId}
+ parentPointer={data?.parent_pointer || undefined}
+ spawningParentPointer={data?.spawning_parent_pointer || undefined}
+ links={data.children || []}
/>
</div>
- )}
- </div>
- }
- secondItem={
- <AppStateView
- steps={stepsSorted}
- stateMachine={data.application}
- highlightedActions={previousActions}
- hoverAction={hoverAction}
- currentSequenceID={currentActionIndex}
- displayGraphAsTab={props.orientation === 'stacked_vertical'} // in this case we want the graph as a tab
- />
- }
- />
+ {props.orientation === 'stacked_horizontal' && (
+ <div className="h-1/2 w-[full]">
+ <GraphView
+ stateMachine={data.application}
+ currentAction={currentStep}
+ highlightedActions={previousActions}
+ hoverAction={hoverAction}
+ />
+ </div>
+ )}
+ </div>
+ }
+ secondItem={
+ <AppStateView
+ steps={stepsSorted}
+ stateMachine={data.application}
+ highlightedActions={previousActions}
+ hoverAction={hoverAction}
+ currentSequenceID={currentActionIndex}
+ displayGraphAsTab={displayGraphAsTabs} // in this case we want the graph as a tab
+ currentTab={currentTab}
+ setCurrentTab={setCurrentTab}
+ />
+ }
+ />
+ </AppViewHighlightContext.Provider>
);
};
diff --git a/telemetry/ui/src/components/routes/app/DataView.tsx b/telemetry/ui/src/components/routes/app/DataView.tsx
index ddccbcbf..1a3861e3 100644
--- a/telemetry/ui/src/components/routes/app/DataView.tsx
+++ b/telemetry/ui/src/components/routes/app/DataView.tsx
@@ -1,11 +1,13 @@
-import React, { useEffect, useState } from 'react';
-import { Step } from '../../../api';
+import React, { useContext, useEffect, useState } from 'react';
+import { AttributeModel, Step } from '../../../api';
import JsonView from '@uiw/react-json-view';
import { Button } from '../../common/button';
import { Switch, SwitchField } from '../../common/switch';
import { Label } from '../../common/fieldset';
import { classNames } from '../../../utils/tailwind';
import { ChevronDownIcon, ChevronUpIcon } from '@heroicons/react/20/solid';
+import { getUniqueAttributeID } from '../../../utils';
+import { AppViewHighlightContext } from './AppView';
/**
* Common JSON view so we can make everything look the same.
@@ -116,6 +118,8 @@ export const DataView = (props: { currentStep: Step | undefined; priorStep: Step
const [allResultExpanded, setAllResultExpanded] = useState(true);
const [allInputExpanded, setAllInputExpanded] = useState(true);
+ const attributes = stepToExamine?.attributes || [];
+
return (
<div className="pl-1 flex flex-col gap-2 hide-scrollbar">
<div className="flex flex-row justify-between sticky top-0 z-20 bg-white">
@@ -207,6 +211,24 @@ export const DataView = (props: { currentStep: Step | undefined; priorStep: Step
{/* <FormRenderer data={inputs as DataType} isDefaultExpanded={allInputExpanded} /> */}
</>
)}
+ {attributes && attributes.length > 0 && (
+ <>
+ <SectionHeaderWithExpand
+ name="Attributes"
+ defaultExpanded={allInputExpanded}
+ setDefaultExpanded={setAllInputExpanded}
+ enableExpansion={viewRawData === 'render'}
+ />
+ {attributes.map((attribute, i) => (
+ <AttributeView
+ key={i}
+ attribute={attribute}
+ isExpanded={allInputExpanded}
+ viewRawData={viewRawData}
+ />
+ ))}
+ </>
+ )}
</div>
);
};
@@ -319,6 +341,37 @@ export const ResultView = (props: {
);
};
+export const AttributeView = (props: {
+ attribute: AttributeModel;
+ viewRawData: 'render' | 'raw';
+ isExpanded: boolean;
+}) => {
+ const { attribute, viewRawData, isExpanded } = props;
+ const attributeAsObject = { [attribute.key]: attribute.value };
+ const { attributesHighlighted } = useContext(AppViewHighlightContext);
+ const uniqueID = getUniqueAttributeID(attribute);
+ const attributeHighlighted = attributesHighlighted
+ .map((item) => getUniqueAttributeID(item))
+ .includes(uniqueID);
+ return (
+ <div
+ id={getUniqueAttributeID(attribute)}
+ className={`${attributeHighlighted ? 'bg-pink-100' : ''}`}
+ >
+ {viewRawData === 'render' && (
+ <>
+ <FormRenderer data={attributeAsObject} isDefaultExpanded={isExpanded} />
+ </>
+ )}
+ {viewRawData === 'raw' && (
+ <>
+ <CommonJsonView value={attributeAsObject} />{' '}
+ </>
+ )}
+ </div>
+ );
+};
+
export const InputsView = (props: {
inputs: object;
isExpanded: boolean;
@@ -368,7 +421,7 @@ const Header = (props: {
);
};
const RenderedField = (props: {
- value: string | number | boolean | object;
+ value: string | number | boolean | object | null;
keyName: string;
level: number;
defaultExpanded: boolean;
@@ -459,7 +512,7 @@ const RenderedField = (props: {
};
interface FormRendererProps {
- data: Record<string, string | number | boolean | object>;
+ data: Record<string, string | number | boolean | object | null>;
isDefaultExpanded: boolean;
}
diff --git a/telemetry/ui/src/components/routes/app/StateMachine.tsx b/telemetry/ui/src/components/routes/app/StateMachine.tsx
index ca234aa0..1c0f1491 100644
--- a/telemetry/ui/src/components/routes/app/StateMachine.tsx
+++ b/telemetry/ui/src/components/routes/app/StateMachine.tsx
@@ -1,4 +1,3 @@
-import { useState } from 'react';
import { ApplicationModel, Step } from '../../../api';
import { Tabs } from '../../common/tabs';
import { DataView } from './DataView';
@@ -11,10 +10,11 @@ export const AppStateView = (props: {
highlightedActions: Step[] | undefined;
hoverAction: Step | undefined;
currentSequenceID: number | undefined;
- displayGraphAsTab: boolean; // for sideways view
+ currentTab: string;
+ setCurrentTab: (tab: string) => void;
+ displayGraphAsTab: boolean;
}) => {
- const defaultTab = props.displayGraphAsTab ? 'graph' : 'data';
- const [currentTab, setCurrentTab] = useState(defaultTab);
+ const { currentTab, setCurrentTab } = props;
const currentStep = props.steps.find(
(step) => step.step_start_log.sequence_id === props.currentSequenceID
);
diff --git a/telemetry/ui/src/components/routes/app/StepList.tsx b/telemetry/ui/src/components/routes/app/StepList.tsx
index a361765d..2b451254 100644
--- a/telemetry/ui/src/components/routes/app/StepList.tsx
+++ b/telemetry/ui/src/components/routes/app/StepList.tsx
@@ -1,11 +1,16 @@
-import { ChildApplicationModel, PointerModel, Span, Step } from '../../../api';
+import { AttributeModel, ChildApplicationModel, PointerModel, Span, Step } from '../../../api';
import { Table, TableBody, TableCell, TableHead, TableHeader, TableRow } from '../../common/table';
import { DateTimeDisplay, DurationDisplay, TimeDisplay } from '../../common/dates';
-import { backgroundColorsForIndex, backgroundColorsForStatus } from './AppView';
-import { Status, getActionStatus } from '../../../utils';
+import {
+ AppViewHighlightContext,
+ backgroundColorsForIndex,
+ backgroundColorsForStatus
+} from './AppView';
+import { Status, getActionStatus, getUniqueAttributeID } from '../../../utils';
import { Chip } from '../../common/chip';
-import { useRef, useState } from 'react';
+import { useContext, useRef, useState } from 'react';
import { TbGrillFork } from 'react-icons/tb';
+import { FiEye } from 'react-icons/fi';
import {
ArrowPathIcon,
@@ -138,6 +143,7 @@ const ActionTableRow = (props: {
sequenceID >= props.currentSelectedIndex - props.numPriorIndices;
const TraceExpandIcon = props.isTracesExpanded ? MinusIcon : PlusIcon;
const LinkExpandIcon = props.isLinksExpanded ? MinusIcon : PlusIcon;
+ const attributes = props.step.attributes || [];
return (
<CommonTableRow
sequenceID={sequenceID}
@@ -149,7 +155,7 @@ const ActionTableRow = (props: {
setCurrentSelectedIndex={props.setCurrentSelectedIndex}
>
<TableCell className="text-gray-500 w-12 max-w-12 min-w-12">{sequenceID}</TableCell>
- <TableCell className="truncate w-48 min-w-48">{props.step.step_start_log.action}</TableCell>
+ <TableCell className="truncate w-40 min-w-40">{props.step.step_start_log.action}</TableCell>
{!props.minimized && (
<>
<TableCell>
@@ -166,21 +172,27 @@ const ActionTableRow = (props: {
{props.displaySpansCol && (
<TableCell>
{spanCount > 0 ? (
- <div className="flex gap-1 items-center">
- <TraceExpandIcon
- className="h-4 w-4 text-gray-600 hover:scale-110 cursor-pointer"
- onClick={(e) => {
- props.toggleTraceExpanded(sequenceID);
- e.stopPropagation();
- }}
- />
- <span className="text-gray-600">{spanCount}</span>
+ <div className="flex flex-row justify-between items-center">
+ <div className="flex gap-1 items-center">
+ <TraceExpandIcon
+ className="h-4 w-4 text-gray-600 hover:scale-110 cursor-pointer"
+ onClick={(e) => {
+ props.toggleTraceExpanded(sequenceID);
+ e.stopPropagation();
+ }}
+ />
+ <span className="text-gray-600">{spanCount}</span>
+ </div>
+ {/* {attributes.length > 0 ? <AttributeLink attributes={attributes} /> : <></>} */}
</div>
) : (
<span></span>
)}
</TableCell>
)}
+ <TableCell className="w-5 min-w-5">
+ {attributes.length > 0 ? <AttributeLink attributes={attributes} /> : <></>}
+ </TableCell>
{props.displayLinksCol && (
<TableCell>
{childCount > 0 ? (
@@ -277,6 +289,35 @@ const LinkSubTable = (props: {
);
};
+const scrollToAttribute = (attribute: AttributeModel) => {
+ const element = document.getElementById(getUniqueAttributeID(attribute));
+ if (element) {
+ const scroll = () => {
+ element.scrollIntoView({ behavior: 'smooth', block: 'start', inline: 'nearest' });
+ };
+ scroll();
+ const observer = new ResizeObserver(() => {
+ scroll();
+ });
+ observer.observe(element);
+ setTimeout(() => observer.disconnect(), 1000); // Adjust timeout as needed
+ }
+};
+
+const AttributeLink = (props: { attributes: AttributeModel[] }) => {
+ const { setAttributesHighlighted, setTab } = useContext(AppViewHighlightContext);
+ return (
+ <FiEye
+ className="text-xl cursor-pointer hover:scale-125"
+ onClick={() => {
+ scrollToAttribute(props.attributes[0]);
+ setAttributesHighlighted(props.attributes);
+ setTab('data');
+ }}
+ />
+ );
+};
+
const TraceSubTable = (props: {
spans: Span[];
step: Step;
@@ -305,6 +346,9 @@ const TraceSubTable = (props: {
sequenceID >= props.currentSelectedIndex - props.numPriorIndices;
const lightText = 'text-gray-300';
const normalText = shouldBeHighlighted ? 'text-gray-100' : 'text-gray-400';
+ const attrsForSpan = props.step.attributes.filter(
+ (attr) => attr.span_id === span.begin_entry.span_id
+ );
return (
<CommonTableRow
key={`${span.begin_entry.span_id}-trace-table-row`}
@@ -342,12 +386,17 @@ const TraceSubTable = (props: {
/>
</TableCell>
<TableCell colSpan={1} className="h-full">
- <WaterfallPiece
- step={props.step}
- span={span}
- bgColor={backgroundColorsForStatus(getActionStatus(props.step))}
- isHighlighted={shouldBeHighlighted}
- />
+ <div className="flex flex-row justify-between">
+ <WaterfallPiece
+ step={props.step}
+ span={span}
+ bgColor={backgroundColorsForStatus(getActionStatus(props.step))}
+ isHighlighted={shouldBeHighlighted}
+ />
+ </div>
+ </TableCell>
+ <TableCell className="w-5 min-w-5">
+ {attrsForSpan.length > 0 ? <AttributeLink attributes={attrsForSpan} /> : <></>}
</TableCell>
<TableCell />
</>
@@ -527,6 +576,8 @@ export const StepList = (props: {
</div>
</TableHeader>
)}
+ <TableHeader className="w-5"></TableHeader>
+
{displayLinksCol && (
<TableHeader>
<div className="flex flex-row items-center gap-2">
diff --git a/telemetry/ui/src/utils.tsx b/telemetry/ui/src/utils.tsx
index 9b34ff25..0530c132 100644
--- a/telemetry/ui/src/utils.tsx
+++ b/telemetry/ui/src/utils.tsx
@@ -1,4 +1,4 @@
-import { Step } from './api';
+import { AttributeModel, Step } from './api';
export type Status = 'success' | 'failure' | 'running';
/*
@@ -14,3 +14,7 @@ export const getActionStatus = (action: Step) => {
}
return 'success';
};
+
+export const getUniqueAttributeID = (attribute: AttributeModel) => {
+ return `${attribute.action_sequence_id}-${attribute.span_id}`;
+};