import type React from 'react'; import {Fragment, useCallback, useLayoutEffect, useMemo, useRef, useState} from 'react'; import {type Theme, useTheme} from '@emotion/react'; import styled from '@emotion/styled'; import * as Sentry from '@sentry/react'; import {PlatformIcon} from 'platformicons'; import * as qs from 'query-string'; import LoadingIndicator from 'sentry/components/loadingIndicator'; import Placeholder from 'sentry/components/placeholder'; import {t, tct} from 'sentry/locale'; import ConfigStore from 'sentry/stores/configStore'; import {space} from 'sentry/styles/space'; import type {Organization, PlatformKey, Project} from 'sentry/types'; import type { TraceError, TracePerformanceIssue, } from 'sentry/utils/performance/quickTrace/types'; import {clamp} from 'sentry/utils/profiling/colors/utils'; import useApi from 'sentry/utils/useApi'; import useOrganization from 'sentry/utils/useOrganization'; import useProjects from 'sentry/utils/useProjects'; import {formatTraceDuration} from 'sentry/views/performance/newTraceDetails/formatters'; import { useVirtualizedList, type VirtualizedRow, } from 'sentry/views/performance/newTraceDetails/traceRenderers/traceVirtualizedList'; import type {VirtualizedViewManager} from 'sentry/views/performance/newTraceDetails/traceRenderers/virtualizedViewManager'; import type { TraceReducerAction, TraceReducerState, } from 'sentry/views/performance/newTraceDetails/traceState'; import { getRovingIndexActionFromDOMEvent, type RovingTabIndexUserActions, } from 'sentry/views/performance/newTraceDetails/traceState/traceRovingTabIndex'; import { makeTraceNodeBarColor, ParentAutogroupNode, TraceTree, type TraceTreeNode, } from './traceModels/traceTree'; import { isAutogroupedNode, isMissingInstrumentationNode, isNoDataNode, isParentAutogroupedNode, isSpanNode, isTraceErrorNode, isTraceNode, isTransactionNode, } from './guards'; import {TraceIcons} from './icons'; function decodeScrollQueue(maybePath: unknown): TraceTree.NodePath[] | null { if (Array.isArray(maybePath)) { return maybePath; } if (typeof maybePath === 'string') { return [maybePath as TraceTree.NodePath]; } return null; } const COUNT_FORMATTER = Intl.NumberFormat(undefined, {notation: 'compact'}); const NO_ERRORS = new Set(); const NO_PERFORMANCE_ISSUES = new Set(); const NO_PROFILES = []; function computeNextIndexFromAction( current_index: number, action: RovingTabIndexUserActions, items: number ): number { switch (action) { case 'next': if (current_index === items) { return 0; } return current_index + 1; case 'previous': if (current_index === 0) { return items; } return current_index - 1; case 'last': return items; case 'first': return 0; default: throw new TypeError(`Invalid or not implemented reducer action - ${action}`); } } function getMaxErrorSeverity(errors: TraceTree.TraceError[]) { return errors.reduce((acc, error) => { if (error.level === 'fatal') { return 'fatal'; } if (error.level === 'error') { return acc === 'fatal' ? 'fatal' : 'error'; } if (error.level === 'warning') { return acc === 'fatal' || acc === 'error' ? acc : 'warning'; } return acc; }, 'default'); } const RIGHT_COLUMN_EVEN_CLASSNAME = `TraceRightColumn`; const RIGHT_COLUMN_ODD_CLASSNAME = [RIGHT_COLUMN_EVEN_CLASSNAME, 'Odd'].join(' '); const CHILDREN_COUNT_WRAPPER_CLASSNAME = `TraceChildrenCountWrapper`; const CHILDREN_COUNT_WRAPPER_ORPHANED_CLASSNAME = [ CHILDREN_COUNT_WRAPPER_CLASSNAME, 'Orphaned', ].join(' '); const ERROR_LEVEL_LABELS: Record = { sample: t('Sample'), info: t('Info'), warning: t('Warning'), // Hardcoded legacy color (orange400). We no longer use orange anywhere // else in the app (except for the chart palette). This needs to be harcoded // here because existing users may still associate orange with the "error" level. error: t('Error'), fatal: t('Fatal'), default: t('Default'), unknown: t('Unknown'), }; function maybeFocusRow( ref: HTMLDivElement | null, node: TraceTreeNode, previouslyFocusedNodeRef: React.MutableRefObject | null> ) { if (!ref) return; if (node === previouslyFocusedNodeRef.current) return; previouslyFocusedNodeRef.current = node; ref.focus(); } interface TraceProps { forceRerender: number; manager: VirtualizedViewManager; onRowClick: ( node: TraceTreeNode, event: React.MouseEvent, index: number ) => void; onTraceLoad: ( trace: TraceTree, node: TraceTreeNode | null, index: number | null ) => void; onTraceSearch: ( query: string, node: TraceTreeNode, behavior: 'track result' | 'persist' ) => void; previouslyFocusedNodeRef: React.MutableRefObject | null>; rerender: () => void; scrollQueueRef: React.MutableRefObject<{ eventId?: string; path?: TraceTree.NodePath[]; } | null>; trace: TraceTree; trace_dispatch: React.Dispatch; trace_id: string; trace_state: TraceReducerState; } export function Trace({ trace, trace_id, onRowClick, manager, scrollQueueRef, previouslyFocusedNodeRef, onTraceSearch, onTraceLoad, rerender, trace_state, trace_dispatch, forceRerender, }: TraceProps) { const theme = useTheme(); const api = useApi(); const {projects} = useProjects(); const organization = useOrganization(); const rerenderRef = useRef(rerender); rerenderRef.current = rerender; const treePromiseStatusRef = useRef, 'loading' | 'error' | 'success'>>(); if (!treePromiseStatusRef.current) { treePromiseStatusRef.current = new Map(); } const treeRef = useRef(trace); treeRef.current = trace; const traceStateRef = useRef(trace_state); traceStateRef.current = trace_state; if ( trace.root.space && (trace.root.space[0] !== manager.to_origin || trace.root.space[1] !== manager.trace_space.width) ) { manager.initializeTraceSpace([trace.root.space[0], 0, trace.root.space[1], 1]); const maybeQueue = decodeScrollQueue(qs.parse(location.search).node); const maybeEventId = qs.parse(location.search)?.eventId; if (maybeQueue || maybeEventId) { scrollQueueRef.current = { eventId: maybeEventId as string, path: maybeQueue as TraceTreeNode['path'], }; } } const loadedRef = useRef(false); useLayoutEffect(() => { if (loadedRef.current) { return; } if (trace.type !== 'trace' || !manager) { return; } loadedRef.current = true; if (!scrollQueueRef.current) { onTraceLoad(trace, null, null); return; } // Node path has higher specificity than eventId const promise = scrollQueueRef.current?.path ? TraceTree.ExpandToPath(trace, scrollQueueRef.current.path, rerenderRef.current, { api, organization, }) : scrollQueueRef.current.eventId ? TraceTree.ExpandToEventID( scrollQueueRef?.current?.eventId, trace, rerenderRef.current, { api, organization, } ) : Promise.resolve(null); promise .then(maybeNode => { onTraceLoad(trace, maybeNode?.node ?? null, maybeNode?.index ?? null); if (!maybeNode) { Sentry.captureMessage('Failed to find and scroll to node in tree'); return; } }) .finally(() => { // Important to set scrollQueueRef.current to null and trigger a rerender // after the promise resolves as we show a loading state during scroll, // else the screen could jump around while we fetch span data scrollQueueRef.current = null; rerenderRef.current(); }); }, [ api, trace, trace_id, manager, onTraceLoad, trace_dispatch, scrollQueueRef, organization, ]); const onNodeZoomIn = useCallback( ( event: React.MouseEvent | React.KeyboardEvent, node: TraceTreeNode, value: boolean ) => { if (!isTransactionNode(node) && !isSpanNode(node)) { throw new TypeError('Node must be a transaction or span'); } event.stopPropagation(); rerenderRef.current(); treeRef.current .zoomIn(node, value, { api, organization, }) .then(() => { rerenderRef.current(); // If a query exists, we want to reapply the search after zooming in // so that new nodes are also highlighted if they match a query if (traceStateRef.current.search.query) { onTraceSearch(traceStateRef.current.search.query, node, 'persist'); } treePromiseStatusRef.current!.set(node, 'success'); }) .catch(_e => { treePromiseStatusRef.current!.set(node, 'error'); }); }, [api, organization, onTraceSearch] ); const onNodeExpand = useCallback( ( event: React.MouseEvent | React.KeyboardEvent, node: TraceTreeNode, value: boolean ) => { event.stopPropagation(); treeRef.current.expand(node, value); rerenderRef.current(); if (traceStateRef.current.search.query) { // If a query exists, we want to reapply the search after expanding // so that new nodes are also highlighted if they match a query onTraceSearch(traceStateRef.current.search.query, node, 'persist'); } }, [onTraceSearch] ); const onRowKeyDown = useCallback( ( event: React.KeyboardEvent, index: number, node: TraceTreeNode ) => { if (!manager.list) { return; } const action = getRovingIndexActionFromDOMEvent(event); if (action) { event.preventDefault(); const nextIndex = computeNextIndexFromAction( index, action, treeRef.current.list.length - 1 ); trace_dispatch({ type: 'set roving index', index: nextIndex, node: treeRef.current.list[nextIndex], action_source: 'keyboard', }); } if (event.key === 'ArrowLeft') { if (node.zoomedIn) onNodeZoomIn(event, node, false); else if (node.expanded) onNodeExpand(event, node, false); } else if (event.key === 'ArrowRight') { if (!node.expanded) onNodeExpand(event, node, true); else if (node.expanded && node.canFetch) onNodeZoomIn(event, node, true); } }, [manager, onNodeExpand, onNodeZoomIn, trace_dispatch] ); const projectLookup: Record = useMemo(() => { return projects.reduce>( (acc, project) => { acc[project.slug] = project.platform; return acc; }, {} ); }, [projects]); const renderLoadingRow = useCallback( (n: VirtualizedRow) => { return ( ); }, [manager, theme] ); const renderVirtualizedRow = useCallback( (n: VirtualizedRow) => { return ( ); }, // we add forceRerender as a "unnecessary" dependency to trigger the virtualized list rerender // eslint-disable-next-line react-hooks/exhaustive-deps [ onNodeExpand, onNodeZoomIn, manager, scrollQueueRef, previouslyFocusedNodeRef, onRowKeyDown, onRowClick, organization, projectLookup, trace_state.rovingTabIndex.node, trace_state.search.resultIteratorIndex, trace_state.search.resultsLookup, trace_state.search.resultIndex, theme, trace_id, trace.type, forceRerender, ] ); const render = useMemo(() => { return trace.type !== 'trace' || scrollQueueRef.current ? r => renderLoadingRow(r) : r => renderVirtualizedRow(r); }, [renderLoadingRow, renderVirtualizedRow, trace.type, scrollQueueRef]); const [scrollContainer, setScrollContainer] = useState(null); const virtualizedList = useVirtualizedList({ manager, items: trace.list, container: scrollContainer, render: render, }); return ( 0 ? 'WithIndicators' : ''} ${trace.type !== 'trace' || scrollQueueRef.current ? 'Loading' : ''} ${ConfigStore.get('theme')}`} >
{trace.indicators.length > 0 ? trace.indicators.map((indicator, i) => { return (
manager.registerIndicatorRef(r, i, indicator)} className={`TraceIndicator ${indicator.poor ? 'Errored' : ''}`} >
{indicator.label}
); }) : null} {manager.interval_bars.map((_, i) => { const indicatorTimestamp = manager.intervals[i] ?? 0; if (trace.type !== 'trace') { return null; } return (
manager.registerTimelineIndicatorRef(r, i)} className="TraceIndicator Timeline" >
{indicatorTimestamp > 0 ? formatTraceDuration(manager.trace_view.x + indicatorTimestamp) : '0s'}
); })}
{virtualizedList.rendered}
manager.registerGhostRowRef('list', r)} />
manager.registerGhostRowRef('span_list', r)} />
); } function RenderRow(props: { index: number; isSearchResult: boolean; manager: VirtualizedViewManager; node: TraceTreeNode; onExpand: ( event: React.MouseEvent, node: TraceTreeNode, value: boolean ) => void; onRowClick: ( node: TraceTreeNode, event: React.MouseEvent, index: number ) => void; onRowKeyDown: ( event: React.KeyboardEvent, index: number, node: TraceTreeNode ) => void; onZoomIn: ( event: React.MouseEvent, node: TraceTreeNode, value: boolean ) => void; organization: Organization; previouslyFocusedNodeRef: React.MutableRefObject | null>; projects: Record; searchResultsIteratorIndex: number | null; style: React.CSSProperties; tabIndex: number; theme: Theme; trace_id: string; }) { const virtualized_index = props.index - props.manager.start_virtualized_index; const rowSearchClassName = `${props.isSearchResult ? 'SearchResult' : ''} ${props.searchResultsIteratorIndex === props.index ? 'Highlight' : ''}`; const registerListColumnRef = useCallback( (ref: HTMLDivElement | null) => { props.manager.registerColumnRef('list', ref, virtualized_index, props.node); }, [props.manager, props.node, virtualized_index] ); const registerSpanColumnRef = useCallback( (ref: HTMLDivElement | null) => { props.manager.registerColumnRef('span_list', ref, virtualized_index, props.node); }, [props.manager, props.node, virtualized_index] ); const registerSpanArrowRef = useCallback( ref => { props.manager.registerArrowRef(ref, props.node.space!, virtualized_index); }, [props.manager, props.node, virtualized_index] ); const onRowClickProp = props.onRowClick; const onRowClick = useCallback( (event: React.MouseEvent) => { onRowClickProp(props.node, event, props.index); }, [props.index, props.node, onRowClickProp] ); const onKeyDownProp = props.onRowKeyDown; const onRowKeyDown = useCallback( event => onKeyDownProp(event, props.index, props.node), [props.index, props.node, onKeyDownProp] ); const onSpanRowDoubleClick = useCallback( e => { e.stopPropagation(); props.manager.onZoomIntoSpace(props.node.space!); }, [props.node, props.manager] ); const onSpanRowArrowClick = useCallback( _e => { props.manager.onBringRowIntoView(props.node.space!); }, [props.node.space, props.manager] ); const onExpandProp = props.onExpand; const onExpandClick = useCallback( e => onExpandProp(e, props.node, !props.node.expanded), [props.node, onExpandProp] ); const spanColumnClassName = props.index % 2 === 1 ? RIGHT_COLUMN_ODD_CLASSNAME : RIGHT_COLUMN_EVEN_CLASSNAME; const listColumnClassName = props.node.isOrphaned ? CHILDREN_COUNT_WRAPPER_ORPHANED_CLASSNAME : CHILDREN_COUNT_WRAPPER_CLASSNAME; const listColumnStyle: React.CSSProperties = { paddingLeft: props.node.depth * props.manager.row_depth_padding, }; if (isAutogroupedNode(props.node)) { return (
props.tabIndex === 0 ? maybeFocusRow(r, props.node, props.previouslyFocusedNodeRef) : null } tabIndex={props.tabIndex} className={`Autogrouped TraceRow ${rowSearchClassName} ${props.node.has_errors ? props.node.max_severity : ''}`} onClick={onRowClick} onKeyDown={onRowKeyDown} style={props.style} >
} status={props.node.fetchStatus} expanded={!props.node.expanded} onClick={onExpandClick} > {COUNT_FORMATTER.format(props.node.groupCount)}
{t('Autogrouped')} {props.node.value.autogrouped_by.op}
); } if (isTransactionNode(props.node)) { return (
props.tabIndex === 0 ? maybeFocusRow(r, props.node, props.previouslyFocusedNodeRef) : null } tabIndex={props.tabIndex} className={`TraceRow ${rowSearchClassName} ${props.node.has_errors ? props.node.max_severity : ''}`} onKeyDown={onRowKeyDown} onClick={onRowClick} style={props.style} >
{props.node.children.length > 0 || props.node.canFetch ? ( ) : ( '+' ) } status={props.node.fetchStatus} expanded={props.node.expanded || props.node.zoomedIn} onClick={e => { props.node.canFetch ? props.onZoomIn(e, props.node, !props.node.zoomedIn) : props.onExpand(e, props.node, !props.node.expanded); }} > {props.node.children.length > 0 ? COUNT_FORMATTER.format(props.node.children.length) : null} ) : null}
{props.node.value['transaction.op']} {props.node.value.transaction}
); } if (isSpanNode(props.node)) { return (
props.tabIndex === 0 ? maybeFocusRow(r, props.node, props.previouslyFocusedNodeRef) : null } tabIndex={props.tabIndex} className={`TraceRow ${rowSearchClassName} ${props.node.has_errors ? props.node.max_severity : ''}`} onClick={onRowClick} onKeyDown={onRowKeyDown} style={props.style} >
{props.node.children.length > 0 || props.node.canFetch ? ( ) } status={props.node.fetchStatus} expanded={props.node.expanded || props.node.zoomedIn} onClick={e => props.node.canFetch ? props.onZoomIn(e, props.node, !props.node.zoomedIn) : props.onExpand(e, props.node, !props.node.expanded) } > {props.node.children.length > 0 ? COUNT_FORMATTER.format(props.node.children.length) : null} ) : null}
{props.node.value.op ?? ''} {!props.node.value.description ? props.node.value.span_id ?? 'unknown' : props.node.value.description.length > 100 ? props.node.value.description.slice(0, 100).trim() + '\u2026' : props.node.value.description}
); } if (isMissingInstrumentationNode(props.node)) { return (
props.tabIndex === 0 ? maybeFocusRow(r, props.node, props.previouslyFocusedNodeRef) : null } tabIndex={props.tabIndex} className={`TraceRow ${rowSearchClassName}`} onClick={onRowClick} onKeyDown={onRowKeyDown} style={props.style} >
{t('Missing instrumentation')}
); } if (isTraceNode(props.node)) { return (
props.tabIndex === 0 ? maybeFocusRow(r, props.node, props.previouslyFocusedNodeRef) : null } tabIndex={props.tabIndex} className={`TraceRow ${rowSearchClassName} ${props.node.has_errors ? props.node.max_severity : ''}`} onClick={onRowClick} onKeyDown={onRowKeyDown} style={props.style} >
{' '}
{props.node.children.length > 0 || props.node.canFetch ? ( void 0}> {props.node.children.length > 0 ? COUNT_FORMATTER.format(props.node.children.length) : null} ) : null}
{t('Trace')} {props.trace_id}
); } if (isTraceErrorNode(props.node)) { return (
props.tabIndex === 0 ? maybeFocusRow(r, props.node, props.previouslyFocusedNodeRef) : null } tabIndex={props.tabIndex} className={`TraceRow ${rowSearchClassName} ${props.node.max_severity}`} onClick={onRowClick} onKeyDown={onRowKeyDown} style={props.style} >
{' '}
{ERROR_LEVEL_LABELS[props.node.value.level ?? 'error']} {props.node.value.title}
{typeof props.node.value.timestamp === 'number' ? (
) : null}
); } if (isNoDataNode(props.node)) { return (
props.tabIndex === 0 ? maybeFocusRow(r, props.node, props.previouslyFocusedNodeRef) : null } tabIndex={props.tabIndex} className={`TraceRow ${rowSearchClassName}`} onClick={onRowClick} onKeyDown={onRowKeyDown} style={props.style} >
{t('Empty')}{' '} {tct('[type] did not report any span data', { type: props.node.parent ? isTransactionNode(props.node.parent) ? 'Transaction' : isSpanNode(props.node.parent) ? 'Span' : '' : '', })}
); } return null; } function RenderPlaceholderRow(props: { index: number; manager: VirtualizedViewManager; node: TraceTreeNode; style: React.CSSProperties; theme: Theme; }) { return (
{props.node.children.length > 0 || props.node.canFetch ? ( void 0} > {props.node.children.length > 0 ? COUNT_FORMATTER.format(props.node.children.length) : null} ) : null}
); } function randomBetween(min: number, max: number) { return Math.floor(Math.random() * (max - min + 1) + min); } function Connectors(props: { manager: VirtualizedViewManager; node: TraceTreeNode; }) { const hasChildren = (props.node.expanded || props.node.zoomedIn) && props.node.children.length > 0; const showVerticalConnector = hasChildren || (props.node.value && isParentAutogroupedNode(props.node)); // If the tail node of the collapsed node has no children, // we don't want to render the vertical connector as no children // are being rendered as the chain is entirely collapsed const hideVerticalConnector = showVerticalConnector && props.node.value && props.node instanceof ParentAutogroupNode && (!props.node.tail.children.length || (!props.node.tail.expanded && !props.node.expanded)); return ( {props.node.connectors.map((c, i) => { return ( ); })} {showVerticalConnector && !hideVerticalConnector ? ( ) : null} {props.node.isLastChild ? ( ) : ( )} ); } function ChildrenButton(props: { children: React.ReactNode; expanded: boolean; icon: React.ReactNode; onClick: (e: React.MouseEvent) => void; status: TraceTreeNode['fetchStatus'] | undefined; }) { return ( ); } interface TraceBarProps { color: string; errors: TraceTreeNode['errors']; manager: VirtualizedViewManager; node_space: [number, number] | null; performance_issues: TraceTreeNode['performance_issues']; profiles: TraceTreeNode['profiles']; virtualized_index: number; } function TraceBar(props: TraceBarProps) { const duration = props.node_space ? formatTraceDuration(props.node_space[1]) : null; const registerSpanBarRef = useCallback( (ref: HTMLDivElement | null) => { props.manager.registerSpanBarRef( ref, props.node_space!, props.color, props.virtualized_index ); }, [props.manager, props.node_space, props.color, props.virtualized_index] ); const registerSpanBarTextRef = useCallback( (ref: HTMLDivElement | null) => { props.manager.registerSpanBarTextRef( ref, duration!, props.node_space!, props.virtualized_index ); }, [props.manager, props.node_space, props.virtualized_index, duration] ); if (!props.node_space) { return null; } return (
{props.profiles.length > 0 ? ( ) : null} {props.errors.size > 0 ? ( ) : null} {props.performance_issues.size > 0 ? ( ) : null} {props.performance_issues.size > 0 || props.errors.size > 0 || props.profiles.length > 0 ? ( ) : null}
{duration}
); } interface MissingInstrumentationTraceBarProps { color: string; manager: VirtualizedViewManager; node_space: [number, number] | null; virtualized_index: number; } function MissingInstrumentationTraceBar(props: MissingInstrumentationTraceBarProps) { const duration = props.node_space ? formatTraceDuration(props.node_space[1]) : null; const registerSpanBarRef = useCallback( (ref: HTMLDivElement | null) => { props.manager.registerSpanBarRef( ref, props.node_space!, props.color, props.virtualized_index ); }, [props.manager, props.node_space, props.color, props.virtualized_index] ); const registerSpanBarTextRef = useCallback( (ref: HTMLDivElement | null) => { props.manager.registerSpanBarTextRef( ref, duration!, props.node_space!, props.virtualized_index ); }, [props.manager, props.node_space, props.virtualized_index, duration] ); return (
{duration}
); } interface InvisibleTraceBarProps { children: React.ReactNode; manager: VirtualizedViewManager; node_space: [number, number] | null; virtualizedIndex: number; } function InvisibleTraceBar(props: InvisibleTraceBarProps) { const registerInvisibleBarRef = useCallback( (ref: HTMLDivElement | null) => { props.manager.registerInvisibleBarRef( ref, props.node_space!, props.virtualizedIndex ); }, [props.manager, props.node_space, props.virtualizedIndex] ); const onDoubleClick = useCallback( (e: React.MouseEvent) => { e.stopPropagation(); props.manager.onZoomIntoSpace(props.node_space!); }, [props.manager, props.node_space] ); if (!props.node_space || !props.children) { return null; } return (
{props.children}
); } interface BackgroundPatternsProps { errors: TraceTreeNode['errors']; manager: VirtualizedViewManager; node_space: [number, number] | null; performance_issues: TraceTreeNode['performance_issues']; profiles: TraceTree.Profile[]; } function BackgroundPatterns(props: BackgroundPatternsProps) { const performance_issues = useMemo(() => { if (!props.performance_issues.size) return []; return [...props.performance_issues]; }, [props.performance_issues]); const errors = useMemo(() => { if (!props.errors.size) return []; return [...props.errors]; }, [props.errors]); const severity = useMemo(() => { return getMaxErrorSeverity(errors); }, [errors]); if (!props.performance_issues.size && !props.errors.size && !props.profiles.length) { return null; } // If there is an error, render the error pattern across the entire width. // Else if there is a performance issue, render the performance issue pattern // for the duration of the performance issue. If there is a profile, render // the profile pattern for entire duration (we do not have profile durations here) return ( {errors.length > 0 ? (
) : performance_issues.length > 0 ? ( {performance_issues.map((issue, _i) => { const timestamp = issue.start * 1e3; // Clamp the issue timestamp to the span's timestamp const left = props.manager.computeRelativeLeftPositionFromOrigin( clamp( timestamp, props.node_space![0], props.node_space![0] + props.node_space![1] ), props.node_space! ); return (
); })} ) : props.profiles.length > 0 ? (
) : null} ); } interface ErrorIconsProps { errors: TraceTreeNode['errors']; manager: VirtualizedViewManager; node_space: [number, number] | null; } function ErrorIcons(props: ErrorIconsProps) { const errors = useMemo(() => { return [...props.errors]; }, [props.errors]); if (!props.errors.size) { return null; } return ( {errors.map((error, _i) => { const timestamp = error.timestamp ? error.timestamp * 1e3 : props.node_space![0]; // Clamp the error timestamp to the span's timestamp const left = props.manager.computeRelativeLeftPositionFromOrigin( clamp( timestamp, props.node_space![0], props.node_space![0] + props.node_space![1] ), props.node_space! ); return (
); })}
); } interface PerformanceIssueIconsProps { manager: VirtualizedViewManager; node_space: [number, number] | null; performance_issues: TraceTreeNode['performance_issues']; } function PerformanceIssueIcons(props: PerformanceIssueIconsProps) { const performance_issues = useMemo(() => { return [...props.performance_issues]; }, [props.performance_issues]); if (!props.performance_issues.size) { return null; } return ( {performance_issues.map((issue, _i) => { const timestamp = issue.timestamp ? issue.timestamp * 1e3 : issue.start ? issue.start * 1e3 : props.node_space![0]; // Clamp the issue timestamp to the span's timestamp const left = props.manager.computeRelativeLeftPositionFromOrigin( clamp( timestamp, props.node_space![0], props.node_space![0] + props.node_space![1] ), props.node_space! ); return (
); })}
); } interface ProfileIconsProps { manager: VirtualizedViewManager; node_space: [number, number] | null; profiles: TraceTree.Profile[]; } function ProfileIcons(props: ProfileIconsProps) { if (!props.profiles.length) { return null; } return ( {props.profiles.map((profile, _i) => { const timestamp = profile.space[0]; // Clamp the profile timestamp to the span's timestamp const left = props.manager.computeRelativeLeftPositionFromOrigin( clamp( timestamp, props.node_space![0], props.node_space![0] + props.node_space![1] ), props.node_space! ); return (
); })}
); } interface AutogroupedTraceBarProps { color: string; entire_space: [number, number] | null; errors: TraceTreeNode['errors']; manager: VirtualizedViewManager; node_spaces: [number, number][]; performance_issues: TraceTreeNode['performance_issues']; profiles: TraceTreeNode['profiles']; virtualized_index: number; } function AutogroupedTraceBar(props: AutogroupedTraceBarProps) { const duration = props.entire_space ? formatTraceDuration(props.entire_space[1]) : null; const registerInvisibleBarRef = useCallback( (ref: HTMLDivElement | null) => { props.manager.registerInvisibleBarRef( ref, props.entire_space!, props.virtualized_index ); }, [props.manager, props.entire_space, props.virtualized_index] ); const registerSpanBarTextRef = useCallback( (ref: HTMLDivElement | null) => { props.manager.registerSpanBarTextRef( ref, duration!, props.entire_space!, props.virtualized_index ); }, [props.manager, props.entire_space, props.virtualized_index, duration] ); if (props.node_spaces && props.node_spaces.length <= 1) { return ( ); } if (!props.node_spaces || !props.entire_space) { return null; } return (
{props.node_spaces.map((node_space, i) => { const width = node_space[1] / props.entire_space![1]; const left = props.manager.computeRelativeLeftPositionFromOrigin( node_space[0], props.entire_space! ); return (
); })} {/* Autogrouped bars only render icons. That is because in the case of multiple bars with tiny gaps, the background pattern looks broken as it does not repeat nicely */} {props.profiles.length > 0 ? ( ) : null} {props.errors.size > 0 ? ( ) : null} {props.performance_issues.size > 0 ? ( ) : null}
{duration}
); } /** * This is a wrapper around the Trace component to apply styles * to the trace tree. It exists because we _do not_ want to trigger * emotion's css parsing logic as it is very slow and will cause * the scrolling to flicker. */ const TraceStylingWrapper = styled('div')` margin: auto; overscroll-behavior: none; box-shadow: 0 0 0 1px ${p => p.theme.border}; position: absolute; left: 0; top: 0; width: 100%; height: 100%; grid-area: trace; padding-top: 26px; &.WithIndicators { padding-top: 44px; &:before { height: 44px; .TraceScrollbarContainer { height: 44px; } } .TraceIndicator.Timeline { .TraceIndicatorLabel { top: 26px; } .TraceIndicatorLine { top: 30px; } } } &:before { content: ''; position: absolute; left: 0; top: 0; width: 100%; height: 26px; background-color: ${p => p.theme.backgroundSecondary}; border-bottom: 1px solid ${p => p.theme.border}; } &.Loading { .TraceRow { .TraceLeftColumnInner { width: 100%; } } .TraceRightColumn { background-color: transparent !important; } .TraceDivider { pointer-events: none; } } &.Empty { .TraceIcon { left: 50%; } } .TraceScrollbarContainer { left: 0; top: 0; height: 26px; position: absolute; overflow-x: auto; overscroll-behavior: none; will-change: transform; .TraceScrollbarScroller { height: 1px; pointer-events: none; visibility: hidden; } .TraceScrollbarHandle { width: 24px; height: 12px; border-radius: 6px; } } .TraceDivider { position: absolute; height: 100%; background-color: transparent; top: 0; cursor: col-resize; z-index: 10; &:before { content: ''; position: absolute; width: 1px; height: 100%; background-color: ${p => p.theme.border}; left: 50%; } &:hover { &:before { background-color: ${p => p.theme.purple300}; } } } .TraceIndicatorContainer { overflow: hidden; width: 100%; height: 100%; position: absolute; right: 0; top: 0; z-index: 10; pointer-events: none; } .TraceIndicator { z-index: 1; width: 3px; height: 100%; top: 0; position: absolute; &:hover { z-index: 10; } .TraceIndicatorLabel { min-width: 34px; text-align: center; position: absolute; font-size: 10px; font-weight: bold; color: ${p => p.theme.textColor}; background-color: ${p => p.theme.background}; border-radius: ${p => p.theme.borderRadius}; border: 1px solid ${p => p.theme.border}; padding: 2px; display: inline-block; line-height: 1; margin-top: 2px; white-space: nowrap; } .TraceIndicatorLine { width: 1px; height: 100%; top: 20px; position: absolute; left: 50%; transform: translateX(-2px); background: repeating-linear-gradient( to bottom, transparent 0 4px, ${p => p.theme.textColor} 4px 8px ) 80%/2px 100% no-repeat; } &.Errored { .TraceIndicatorLabel { border: 1px solid ${p => p.theme.error}; color: ${p => p.theme.error}; } .TraceIndicatorLine { background: repeating-linear-gradient( to bottom, transparent 0 4px, ${p => p.theme.error} 4px 8px ) 80%/2px 100% no-repeat; } } &.Timeline { opacity: 1; z-index: 1; pointer-events: none; .TraceIndicatorLabel { font-weight: normal; min-width: 0; top: 8px; width: auto; border: none; background-color: transparent; color: ${p => p.theme.subText}; } .TraceIndicatorLine { background: ${p => p.theme.translucentGray100}; top: 8px; } } } &.light { .TracePattern { &.info { --pattern-odd: #d1dff9; --pattern-even: ${p => p.theme.blue300}; } &.warning { --pattern-odd: #a5752c; --pattern-even: ${p => p.theme.yellow300}; } &.performance_issue { --pattern-odd: #063690; --pattern-even: ${p => p.theme.blue300}; } &.profile { --pattern-odd: rgba(58, 17, 95, 0.55); --pattern-even: transparent; } &.missing_instrumentation { --pattern-odd: #4b4550; --pattern-even: rgb(128, 112, 143); } &.error, &.fatal { --pattern-odd: #872d32; --pattern-even: ${p => p.theme.red300}; } /* false positive for grid layout */ /* stylelint-disable */ &.default { } &.unknown { } /* stylelint-enable */ } } &.dark { .TracePattern { &.info { --pattern-odd: #d1dff9; --pattern-even: ${p => p.theme.blue300}; } &.warning { --pattern-odd: #a5752c; --pattern-even: ${p => p.theme.yellow300}; } &.performance_issue { --pattern-odd: #063690; --pattern-even: ${p => p.theme.blue300}; } &.profile { --pattern-odd: rgba(58, 17, 95, 0.55); --pattern-even: transparent; } &.missing_instrumentation { --pattern-odd: #4b4550; --pattern-even: #1c1521; } &.error, &.fatal { --pattern-odd: #510d10; --pattern-even: ${p => p.theme.red300}; } /* stylelint-disable */ &.default { } &.unknown { } /* stylelint-enable */ } } .TraceRow { display: flex; align-items: center; position: absolute; height: 24px; width: 100%; transition: none; font-size: ${p => p.theme.fontSizeSmall}; transform: translateZ(0); --row-background-odd: ${p => p.theme.translucentSurface100}; --row-background-hover: ${p => p.theme.translucentSurface100}; --row-background-focused: ${p => p.theme.translucentSurface200}; --row-outline: ${p => p.theme.blue300}; --row-children-button-border-color: ${p => p.theme.border}; /* allow empty blocks so we can keep an exhaustive list of classnames for future reference */ /* stylelint-disable */ &.info { } &.warning { } &.error, &.fatal, &.performance_issue { color: ${p => p.theme.errorText}; --autogrouped: ${p => p.theme.error}; --row-children-button-border-color: ${p => p.theme.error}; --row-outline: ${p => p.theme.error}; } &.default { } &.unknown { } &.Hidden { position: absolute; height: 100%; width: 100%; top: 0; z-index: -1; &:hover { background-color: transparent; } * { cursor: default !important; } } .TraceIcon { position: absolute; top: 50%; transform: translate(-50%, -50%) scaleX(var(--inverse-span-scale)) translateZ(0); background-color: ${p => p.theme.background}; width: 18px !important; height: 18px !important; border-radius: 50%; display: flex; align-items: center; justify-content: center; z-index: 1; &.info { background-color: var(--info); } &.warning { background-color: var(--warning); } &.error, &.fatal { background-color: var(--error); } &.performance_issue { background-color: var(--performance-issue); } &.default { background-color: var(--default); } &.unknown { background-color: var(--unknown); } &.profile { background-color: var(--profile); } svg { width: 12px; height: 12px; fill: ${p => p.theme.white}; } &.profile svg { margin-left: 2px; } &.info, &.warning, &.performance_issue, &.default, &.unknown { svg { transform: translateY(-1px); } } } .TracePatternContainer { position: absolute; width: 100%; height: 100%; overflow: hidden; } .TracePattern { left: 0; width: 1000000px; height: 100%; position: absolute; transform-origin: left center; transform: scaleX(var(--inverse-span-scale)) translateZ(0); background-image: linear-gradient( 135deg, var(--pattern-even) 1%, var(--pattern-even) 11%, var(--pattern-odd) 11%, var(--pattern-odd) 21%, var(--pattern-even) 21%, var(--pattern-even) 31%, var(--pattern-odd) 31%, var(--pattern-odd) 41%, var(--pattern-even) 41%, var(--pattern-even) 51%, var(--pattern-odd) 51%, var(--pattern-odd) 61%, var(--pattern-even) 61%, var(--pattern-even) 71%, var(--pattern-odd) 71%, var(--pattern-odd) 81%, var(--pattern-even) 81%, var(--pattern-even) 91%, var(--pattern-odd) 91%, var(--pattern-odd) 101% ); background-size: 25.5px 17px; } .TracePerformanceIssue { position: absolute; top: 0; display: flex; align-items: center; justify-content: flex-start; background-color: var(--performance-issue); height: 16px; } .TraceRightColumn.Odd { background-color: var(--row-background-odd); } &:hover { background-color: var(--row-background-hovered); } &.Highlight { box-shadow: inset 0 0 0 1px ${p => p.theme.blue200} !important; .TraceLeftColumn { box-shadow: inset 0px 0 0px 1px ${p => p.theme.blue200} !important; } } &.Highlight, &:focus, &[tabindex='0'] { outline: none; background-color: var(--row-background-focused); .TraceRightColumn.Odd { background-color: transparent !important; } } &:focus, &[tabindex='0'] { background-color: var(--row-background-focused); box-shadow: inset 0 0 0 1px var(--row-outline) !important; .TraceLeftColumn { box-shadow: inset 0px 0 0px 1px var(--row-outline) !important; } .TraceRightColumn.Odd { background-color: transparent !important; } } &.SearchResult { background-color: ${p => p.theme.yellow100}; .TraceRightColumn { background-color: transparent; } } &.Autogrouped { color: ${p => p.theme.blue300}; .TraceDescription { font-weight: bold; } .TraceChildrenCountWrapper { button { color: ${p => p.theme.white}; background-color: ${p => p.theme.blue300}; } svg { fill: ${p => p.theme.white}; } } } } .TraceLeftColumn { height: 100%; white-space: nowrap; display: flex; align-items: center; overflow: hidden; will-change: width; box-shadow: inset 1px 0 0px 0px transparent; cursor: pointer; width: calc(var(--list-column-width) * 100%); .TraceLeftColumnInner { height: 100%; white-space: nowrap; display: flex; align-items: center; will-change: transform; transform-origin: left center; padding-right: ${space(2)}; img { width: 16px; height: 16px; } } } .TraceRightColumn { height: 100%; overflow: hidden; position: relative; display: flex; align-items: center; will-change: width; z-index: 1; cursor: pointer; width: calc(var(--span-column-width) * 100%); &:hover { .TraceArrow.Visible { opacity: 1; transition: 300ms 300ms ease-out; pointer-events: auto; } } } .TraceBar { position: absolute; height: 16px; width: 100%; background-color: black; transform-origin: left center; &.Invisible { background-color: transparent !important; > div { height: 100%; } } svg { width: 14px; height: 14px; } } .TraceArrow { position: absolute; pointer-events: none; top: 0; width: 14px; height: 24px; opacity: 0; background-color: transparent; border: none; transition: 60ms ease-out; font-size: ${p => p.theme.fontSizeMedium}; color: ${p => p.theme.subText}; padding: 0 2px; display: flex; align-items: center; svg { fill: ${p => p.theme.subText}; } &.Left { left: 0; } &.Right { right: 0; transform: rotate(180deg); } } .TraceBarDuration { display: inline-block; transform-origin: left center; font-size: ${p => p.theme.fontSizeExtraSmall}; color: ${p => p.theme.gray300}; white-space: nowrap; font-variant-numeric: tabular-nums; position: absolute; } .TraceChildrenCount { height: 16px; white-space: nowrap; min-width: 30px; display: flex; align-items: center; justify-content: center; border-radius: 99px; padding: 0px 4px; transition: all 0.15s ease-in-out; background: ${p => p.theme.background}; border: 1.5px solid var(--row-children-button-border-color); line-height: 0; z-index: 1; font-size: 10px; box-shadow: ${p => p.theme.dropShadowLight}; margin-right: 8px; .TraceChildrenCountContent { + .TraceChildrenCountAction { margin-left: 2px; } } .TraceChildrenCountAction { position: relative; display: flex; align-items: center; justify-content: center; } .TraceActionsLoadingIndicator { margin: 0; position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%); background-color: ${p => p.theme.background}; animation: show 0.1s ease-in-out forwards; @keyframes show { from { opacity: 0; transform: translate(-50%, -50%) scale(0.86); } to { opacity: 1; transform: translate(-50%, -50%) scale(1); } } .loading-indicator { border-width: 2px; } .loading-message { display: none; } } svg { width: 7px; transition: none; } } .TraceChildrenCountWrapper { display: flex; justify-content: flex-end; align-items: center; min-width: 44px; height: 100%; position: relative; button { transition: none; } svg { fill: currentColor; } &.Orphaned { .TraceVerticalConnector, .TraceVerticalLastChildConnector, .TraceExpandedVerticalConnector { border-left: 2px dashed ${p => p.theme.border}; } &::before { border-bottom: 2px dashed ${p => p.theme.border}; } } &.Root { &:before, .TraceVerticalLastChildConnector { visibility: hidden; } } &::before { content: ''; display: block; width: 50%; height: 2px; border-bottom: 2px solid ${p => p.theme.border}; position: absolute; left: 0; top: 50%; transform: translateY(-50%); } &::after { content: ''; background-color: ${p => p.theme.border}; border-radius: 50%; height: 6px; width: 6px; position: absolute; left: 50%; top: 50%; transform: translateY(-50%); } } .TraceVerticalConnector { position: absolute; left: 0; top: 0; bottom: 0; height: 100%; width: 2px; border-left: 2px solid ${p => p.theme.border}; &.Orphaned { border-left: 2px dashed ${p => p.theme.border}; } } .TraceVerticalLastChildConnector { position: absolute; left: 0; top: 0; bottom: 0; height: 50%; width: 2px; border-left: 2px solid ${p => p.theme.border}; border-bottom-left-radius: 4px; } .TraceExpandedVerticalConnector { position: absolute; bottom: 0; height: 50%; left: 50%; width: 2px; border-left: 2px solid ${p => p.theme.border}; } .TraceOperation { margin-left: 4px; text-overflow: ellipsis; white-space: nowrap; font-weight: bold; } .TraceEmDash { margin-left: 4px; margin-right: 4px; } .TraceDescription { white-space: nowrap; } `;