12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634 |
- import type React from 'react';
- import {Fragment, useCallback, useEffect, useMemo, useRef, useState} from 'react';
- import {browserHistory} from 'react-router';
- import {AutoSizer, List} from 'react-virtualized';
- import {type Theme, useTheme} from '@emotion/react';
- import styled from '@emotion/styled';
- import * as qs from 'query-string';
- import ProjectAvatar from 'sentry/components/avatar/projectAvatar';
- import Link from 'sentry/components/links/link';
- import LoadingIndicator from 'sentry/components/loadingIndicator';
- import {pickBarColor} from 'sentry/components/performance/waterfall/utils';
- import Placeholder from 'sentry/components/placeholder';
- import {generateIssueEventTarget} from 'sentry/components/quickTrace/utils';
- import {Tooltip} from 'sentry/components/tooltip';
- import {IconChevron, IconFire, IconZoom} from 'sentry/icons';
- import {t} from 'sentry/locale';
- import {space} from 'sentry/styles/space';
- import type {Organization, Project} from 'sentry/types';
- import {getDuration} from 'sentry/utils/formatters';
- import useApi from 'sentry/utils/useApi';
- import {useLocation} from 'sentry/utils/useLocation';
- import useOrganization from 'sentry/utils/useOrganization';
- import useProjects from 'sentry/utils/useProjects';
- import {
- getRovingIndexActionFromEvent,
- type RovingTabIndexAction,
- type RovingTabIndexUserActions,
- } from 'sentry/views/performance/newTraceDetails/rovingTabIndex';
- import {
- isAutogroupedNode,
- isMissingInstrumentationNode,
- isParentAutogroupedNode,
- isSpanNode,
- isTraceErrorNode,
- isTraceNode,
- isTransactionNode,
- } from './guards';
- import {ParentAutogroupNode, type TraceTree, type TraceTreeNode} from './traceTree';
- import {VirtualizedViewManager} from './virtualizedViewManager';
- 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'});
- interface RovingTabIndexState {
- index: number | null;
- items: number | null;
- node: TraceTreeNode<TraceTree.NodeValue> | null;
- }
- 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 maybeFocusRow(
- ref: HTMLDivElement | null,
- index: number,
- previouslyFocusedIndexRef: React.MutableRefObject<number | null>
- ) {
- if (!ref) return;
- if (index === previouslyFocusedIndexRef.current) return;
- ref.focus();
- previouslyFocusedIndexRef.current = index;
- }
- interface TraceProps {
- roving_dispatch: React.Dispatch<RovingTabIndexAction>;
- roving_state: RovingTabIndexState;
- setDetailNode: (node: TraceTreeNode<TraceTree.NodeValue> | null) => void;
- trace: TraceTree;
- trace_id: string;
- }
- function Trace({
- trace,
- trace_id,
- roving_state,
- roving_dispatch,
- setDetailNode,
- }: TraceProps) {
- const theme = useTheme();
- const api = useApi();
- const {projects} = useProjects();
- const organization = useOrganization();
- const location = useLocation();
- const viewManager = useMemo(() => {
- return new VirtualizedViewManager({
- list: {width: 0.5},
- span_list: {width: 0.5},
- });
- }, []);
- const previouslyFocusedIndexRef = useRef<number | null>(null);
- const [_rerender, setRender] = useState(0);
- const scrollQueue = useRef<TraceTree.NodePath[] | null>(null);
- const treeRef = useRef<TraceTree>(trace);
- treeRef.current = trace;
- if (
- trace.root.space &&
- (trace.root.space[0] !== viewManager.to_origin ||
- trace.root.space[1] !== viewManager.trace_space.width)
- ) {
- viewManager.initializeTraceSpace([trace.root.space[0], 0, trace.root.space[1], 1]);
- scrollQueue.current = decodeScrollQueue(qs.parse(location.search).node);
- }
- useEffect(() => {
- if (trace.type === 'loading' || scrollQueue.current === null || !viewManager) {
- return;
- }
- viewManager
- .scrollToPath(trace, scrollQueue.current, () => setRender(a => (a + 1) % 2), {
- api,
- organization,
- })
- .then(maybeNode => {
- scrollQueue.current = null;
- if (!maybeNode) {
- return;
- }
- viewManager.onScrollEndOutOfBoundsCheck();
- setDetailNode(maybeNode.node);
- roving_dispatch({
- type: 'set index',
- index: maybeNode.index,
- node: maybeNode.node,
- });
- });
- }, [api, organization, trace, trace_id, viewManager, setDetailNode, roving_dispatch]);
- const handleZoomIn = useCallback(
- (
- event: React.MouseEvent,
- node: TraceTreeNode<TraceTree.NodeValue>,
- value: boolean
- ) => {
- if (!isTransactionNode(node) && !isSpanNode(node)) {
- throw new TypeError('Node must be a transaction or span');
- }
- event.stopPropagation();
- treeRef.current
- .zoomIn(node, value, {
- api,
- organization,
- })
- .then(() => {
- setRender(a => (a + 1) % 2);
- });
- },
- [api, organization]
- );
- const handleExpandNode = useCallback(
- (
- event: React.MouseEvent<Element>,
- node: TraceTreeNode<TraceTree.NodeValue>,
- value: boolean
- ) => {
- event.stopPropagation();
- treeRef.current.expand(node, value);
- setRender(a => (a + 1) % 2);
- },
- []
- );
- const onRowClick = useCallback(
- (
- _event: React.MouseEvent,
- index: number,
- node: TraceTreeNode<TraceTree.NodeValue>
- ) => {
- browserHistory.push({
- pathname: location.pathname,
- query: {
- ...qs.parse(location.search),
- node: node.path,
- },
- });
- setDetailNode(node);
- roving_dispatch({type: 'set index', index, node});
- },
- // eslint-disable-next-line react-hooks/exhaustive-deps
- [roving_dispatch, setDetailNode]
- );
- const onRowKeyDown = useCallback(
- (
- event: React.KeyboardEvent,
- index: number,
- node: TraceTreeNode<TraceTree.NodeValue>
- ) => {
- if (!viewManager.list) {
- return;
- }
- const action = getRovingIndexActionFromEvent(event);
- if (action) {
- event.preventDefault();
- const nextIndex = computeNextIndexFromAction(
- index,
- action,
- treeRef.current.list.length - 1
- );
- viewManager.list.scrollToRow(nextIndex);
- roving_dispatch({type: 'set index', index: nextIndex, node});
- }
- },
- [viewManager.list, roving_dispatch]
- );
- // @TODO this is the implementation of infinite scroll. Once the user
- // reaches the end of the list, we fetch more data. The data is not yet
- // being appended to the tree as we need to figure out UX for this.
- // onRowsRendered callback should be passed to the List component
- // const limitRef = useRef<number | null>(null);
- // if (limitRef.current === null) {
- // let decodedLimit = getTraceQueryParams(qs.parse(location.search)).limit;
- // if (typeof decodedLimit === 'string') {
- // decodedLimit = parseInt(decodedLimit, 2);
- // }
- // limitRef.current = decodedLimit;
- // }
- // const loadMoreRequestRef =
- // useRef<Promise<TraceSplitResults<TraceFullDetailed> | null> | null>(null);
- // const onRowsRendered = useCallback((rows: RenderedRows) => {
- // if (loadMoreRequestRef.current) {
- // // in flight request
- // return;
- // }
- // if (rows.stopIndex !== treeRef.current.list.length - 1) {
- // // not at the end
- // return;
- // }
- // if (
- // !loadMoreRequestRef.current &&
- // limitRef.current &&
- // rows.stopIndex === treeRef.current.list.length - 1
- // ) {
- // limitRef.current = limitRef.current + 500;
- // const promise = fetchTrace(api, {
- // traceId: trace_id,
- // orgSlug: organization.slug,
- // query: qs.stringify(getTraceQueryParams(location, {limit: limitRef.current})),
- // })
- // .then(data => {
- // return data;
- // })
- // .catch(e => {
- // return e;
- // });
- // loadMoreRequestRef.current = promise;
- // }
- // }, []);
- const projectLookup = useMemo(() => {
- return projects.reduce<Record<Project['slug'], Project>>((acc, project) => {
- acc[project.slug] = project;
- return acc;
- }, {});
- }, [projects]);
- return (
- <Fragment>
- <TraceStylingWrapper
- ref={r => viewManager.onContainerRef(r)}
- className={trace.type === 'loading' ? 'Loading' : ''}
- style={{
- height: '70vh',
- width: '100%',
- margin: 'auto',
- }}
- >
- <TraceDivider
- className="TraceDivider"
- ref={r => viewManager?.registerDividerRef(r)}
- />
- {trace.type === 'loading' ? <TraceLoading /> : null}
- <AutoSizer>
- {({width, height}) => (
- <Fragment>
- <div
- className="TraceIndicatorContainer"
- ref={r => viewManager.registerIndicatorContainerRef(r)}
- >
- {trace.indicators.length > 0
- ? trace.indicators.map((indicator, i) => {
- return (
- <div
- key={i}
- ref={r => viewManager.registerIndicatorRef(r, i, indicator)}
- className="TraceIndicator"
- >
- <div className="TraceIndicatorLabel">{indicator.label}</div>
- <div className="TraceIndicatorLine" />
- </div>
- );
- })
- : null}
- </div>
- <List
- ref={r => viewManager.registerList(r)}
- rowHeight={24}
- height={height}
- width={width}
- scrollToAlignment="center"
- overscanRowCount={5}
- rowCount={treeRef.current.list.length ?? 0}
- rowRenderer={p => {
- return trace.type === 'loading' ? (
- <RenderPlaceholderRow
- style={p.style}
- node={treeRef.current.list[p.index]}
- index={p.index}
- theme={theme}
- projects={projectLookup}
- viewManager={viewManager!}
- startIndex={
- (p.parent as unknown as {_rowStartIndex: number})
- ._rowStartIndex ?? 0
- }
- />
- ) : (
- <RenderRow
- key={p.key}
- theme={theme}
- startIndex={
- (p.parent as unknown as {_rowStartIndex: number})
- ._rowStartIndex ?? 0
- }
- organization={organization}
- previouslyFocusedIndexRef={previouslyFocusedIndexRef}
- tabIndex={roving_state.index ?? -1}
- index={p.index}
- style={p.style}
- trace_id={trace_id}
- projects={projectLookup}
- node={treeRef.current.list[p.index]}
- viewManager={viewManager!}
- onExpand={handleExpandNode}
- onZoomIn={handleZoomIn}
- onRowClick={onRowClick}
- onRowKeyDown={onRowKeyDown}
- />
- );
- }}
- />
- </Fragment>
- )}
- </AutoSizer>
- </TraceStylingWrapper>
- </Fragment>
- );
- }
- export default Trace;
- const TraceDivider = styled('div')`
- position: absolute;
- height: 100%;
- background-color: transparent;
- top: 0;
- z-index: 10;
- cursor: col-resize;
- &:before {
- content: '';
- position: absolute;
- width: 1px;
- height: 100%;
- background-color: ${p => p.theme.border};
- left: 50%;
- }
- &:hover&:before {
- background-color: ${p => p.theme.purple300};
- }
- `;
- function RenderRow(props: {
- index: number;
- node: TraceTreeNode<TraceTree.NodeValue>;
- onExpand: (
- event: React.MouseEvent<Element>,
- node: TraceTreeNode<TraceTree.NodeValue>,
- value: boolean
- ) => void;
- onRowClick: (
- event: React.MouseEvent<Element>,
- index: number,
- node: TraceTreeNode<TraceTree.NodeValue>
- ) => void;
- onRowKeyDown: (
- event: React.KeyboardEvent,
- index: number,
- node: TraceTreeNode<TraceTree.NodeValue>
- ) => void;
- onZoomIn: (
- event: React.MouseEvent<Element>,
- node: TraceTreeNode<TraceTree.NodeValue>,
- value: boolean
- ) => void;
- organization: Organization;
- previouslyFocusedIndexRef: React.MutableRefObject<number | null>;
- projects: Record<Project['slug'], Project>;
- startIndex: number;
- style: React.CSSProperties;
- tabIndex: number;
- theme: Theme;
- trace_id: string;
- viewManager: VirtualizedViewManager;
- }) {
- const virtualizedIndex = props.index - props.startIndex;
- if (!props.node.value) {
- return null;
- }
- if (isAutogroupedNode(props.node)) {
- return (
- <div
- key={props.index}
- ref={r =>
- props.tabIndex === props.index
- ? maybeFocusRow(r, props.index, props.previouslyFocusedIndexRef)
- : null
- }
- tabIndex={props.tabIndex === props.index ? 0 : -1}
- className="TraceRow Autogrouped"
- onClick={e => props.onRowClick(e, props.index, props.node)}
- onKeyDown={event => props.onRowKeyDown(event, props.index, props.node)}
- style={{
- top: props.style.top,
- height: props.style.height,
- }}
- >
- <div
- className="TraceLeftColumn"
- ref={r =>
- props.viewManager.registerColumnRef('list', r, virtualizedIndex, props.node)
- }
- style={{
- width: props.viewManager.columns.list.width * 100 + '%',
- }}
- >
- <div
- className="TraceLeftColumnInner"
- style={{
- paddingLeft: props.node.depth * props.viewManager.row_depth_padding,
- }}
- >
- <div className="TraceChildrenCountWrapper">
- <Connectors node={props.node} viewManager={props.viewManager} />
- <ChildrenCountButton
- expanded={!props.node.expanded}
- onClick={e => props.onExpand(e, props.node, !props.node.expanded)}
- >
- {COUNT_FORMATTER.format(props.node.groupCount)}{' '}
- </ChildrenCountButton>
- </div>
- <span className="TraceOperation">{t('Autogrouped')}</span>
- <strong className="TraceEmDash"> — </strong>
- <span className="TraceDescription">{props.node.value.autogrouped_by.op}</span>
- </div>
- </div>
- <div
- className="TraceRightColumn"
- ref={r =>
- props.viewManager.registerColumnRef(
- 'span_list',
- r,
- virtualizedIndex,
- props.node
- )
- }
- style={{
- width: props.viewManager.columns.span_list.width * 100 + '%',
- backgroundColor:
- props.index % 2 === 0 ? props.theme.backgroundSecondary : undefined,
- }}
- >
- {isParentAutogroupedNode(props.node) ? (
- <TraceBar
- virtualizedIndex={virtualizedIndex}
- viewManager={props.viewManager}
- color={props.theme.blue300}
- node_space={props.node.space}
- />
- ) : (
- <SiblingAutogroupedBar
- virtualizedIndex={virtualizedIndex}
- viewManager={props.viewManager}
- color={props.theme.blue300}
- node={props.node}
- />
- )}
- </div>
- </div>
- );
- }
- if (isTransactionNode(props.node)) {
- return (
- <div
- key={props.index}
- ref={r =>
- props.tabIndex === props.index
- ? maybeFocusRow(r, props.index, props.previouslyFocusedIndexRef)
- : null
- }
- tabIndex={props.tabIndex === props.index ? 0 : -1}
- className="TraceRow"
- onClick={e => props.onRowClick(e, props.index, props.node)}
- onKeyDown={event => props.onRowKeyDown(event, props.index, props.node)}
- style={{
- top: props.style.top,
- height: props.style.height,
- }}
- >
- <div
- className="TraceLeftColumn"
- ref={r =>
- props.viewManager.registerColumnRef('list', r, virtualizedIndex, props.node)
- }
- style={{
- width: props.viewManager.columns.list.width * 100 + '%',
- }}
- >
- <div
- className="TraceLeftColumnInner"
- style={{
- paddingLeft: props.node.depth * props.viewManager.row_depth_padding,
- }}
- >
- <div
- className={`TraceChildrenCountWrapper ${
- props.node.isOrphaned ? 'Orphaned' : ''
- }`}
- >
- <Connectors node={props.node} viewManager={props.viewManager} />
- {props.node.children.length > 0 ? (
- <ChildrenCountButton
- expanded={props.node.expanded || props.node.zoomedIn}
- onClick={e => props.onExpand(e, props.node, !props.node.expanded)}
- >
- {COUNT_FORMATTER.format(props.node.children.length)}{' '}
- </ChildrenCountButton>
- ) : null}
- </div>
- <ProjectBadge project={props.projects[props.node.value.project_slug]} />
- <span className="TraceOperation">{props.node.value['transaction.op']}</span>
- <strong className="TraceEmDash"> — </strong>
- <span>{props.node.value.transaction}</span>
- </div>
- {props.node.canFetchData ? (
- <Tooltip
- title={
- props.node.zoomedIn
- ? t('Hide the span waterfall for this transaction')
- : t('Load the span waterfall for this transaction')
- }
- position="top"
- skipWrapper
- delay={400}
- >
- <IconZoom
- className="IconZoom"
- isZoomIn={!props.node.zoomedIn}
- onClick={e => props.onZoomIn(e, props.node, !props.node.zoomedIn)}
- />
- </Tooltip>
- ) : null}
- </div>
- <div
- ref={r =>
- props.viewManager.registerColumnRef(
- 'span_list',
- r,
- virtualizedIndex,
- props.node
- )
- }
- className="TraceRightColumn"
- style={{
- width: props.viewManager.columns.span_list.width * 100 + '%',
- backgroundColor:
- props.index % 2 === 0 ? props.theme.backgroundSecondary : undefined,
- }}
- >
- <TraceBar
- virtualizedIndex={virtualizedIndex}
- viewManager={props.viewManager}
- color={pickBarColor(props.node.value['transaction.op'])}
- node_space={props.node.space}
- />
- </div>
- </div>
- );
- }
- if (isSpanNode(props.node)) {
- return (
- <div
- key={props.index}
- ref={r =>
- props.tabIndex === props.index
- ? maybeFocusRow(r, props.index, props.previouslyFocusedIndexRef)
- : null
- }
- tabIndex={props.tabIndex === props.index ? 0 : -1}
- className="TraceRow"
- onClick={e => props.onRowClick(e, props.index, props.node)}
- onKeyDown={event => props.onRowKeyDown(event, props.index, props.node)}
- style={{
- top: props.style.top,
- height: props.style.height,
- }}
- >
- <div
- className="TraceLeftColumn"
- ref={r =>
- props.viewManager.registerColumnRef('list', r, virtualizedIndex, props.node)
- }
- style={{
- width: props.viewManager.columns.list.width * 100 + '%',
- }}
- >
- <div
- className="TraceLeftColumnInner"
- style={{
- paddingLeft: props.node.depth * props.viewManager.row_depth_padding,
- }}
- >
- <div
- className={`TraceChildrenCountWrapper ${
- props.node.isOrphaned ? 'Orphaned' : ''
- }`}
- >
- <Connectors node={props.node} viewManager={props.viewManager} />
- {props.node.children.length > 0 ? (
- <ChildrenCountButton
- expanded={props.node.expanded || props.node.zoomedIn}
- onClick={e => props.onExpand(e, props.node, !props.node.expanded)}
- >
- {COUNT_FORMATTER.format(props.node.children.length)}{' '}
- </ChildrenCountButton>
- ) : null}
- </div>
- <span className="TraceOperation">{props.node.value.op ?? '<unknown>'}</span>
- <strong className="TraceEmDash"> — </strong>
- <span className="TraceDescription" title={props.node.value.description}>
- {!props.node.value.description
- ? 'unknown'
- : props.node.value.description.length > 100
- ? props.node.value.description.slice(0, 100).trim() + '\u2026'
- : props.node.value.description}
- </span>
- </div>
- {props.node.canFetchData ? (
- <Tooltip
- title={
- props.node.zoomedIn
- ? t('Hide the span waterfall for this transaction')
- : t('Load the span waterfall for this transaction')
- }
- position="top"
- skipWrapper
- delay={400}
- >
- <IconZoom
- className="IconZoom"
- isZoomIn={!props.node.zoomedIn}
- onClick={e => props.onZoomIn(e, props.node, !props.node.zoomedIn)}
- />
- </Tooltip>
- ) : null}
- </div>
- <div
- ref={r =>
- props.viewManager.registerColumnRef(
- 'span_list',
- r,
- virtualizedIndex,
- props.node
- )
- }
- className="TraceRightColumn"
- style={{
- width: props.viewManager.columns.span_list.width * 100 + '%',
- backgroundColor:
- props.index % 2 === 0 ? props.theme.backgroundSecondary : undefined,
- }}
- >
- <TraceBar
- virtualizedIndex={virtualizedIndex}
- viewManager={props.viewManager}
- color={pickBarColor(props.node.value.op)}
- node_space={props.node.space}
- />
- </div>
- </div>
- );
- }
- if (isMissingInstrumentationNode(props.node)) {
- return (
- <div
- key={props.index}
- ref={r =>
- props.tabIndex === props.index
- ? maybeFocusRow(r, props.index, props.previouslyFocusedIndexRef)
- : null
- }
- tabIndex={props.tabIndex === props.index ? 0 : -1}
- className="TraceRow"
- onClick={e => props.onRowClick(e, props.index, props.node)}
- onKeyDown={event => props.onRowKeyDown(event, props.index, props.node)}
- style={{
- top: props.style.top,
- height: props.style.height,
- }}
- >
- <div
- className="TraceLeftColumn"
- ref={r =>
- props.viewManager.registerColumnRef('list', r, virtualizedIndex, props.node)
- }
- style={{
- width: props.viewManager.columns.list.width * 100 + '%',
- }}
- >
- <div
- className="TraceLeftColumnInner"
- style={{
- paddingLeft: props.node.depth * props.viewManager.row_depth_padding,
- }}
- >
- <div className="TraceChildrenCountWrapper">
- <Connectors node={props.node} viewManager={props.viewManager} />
- </div>
- <span className="TraceOperation">{t('Missing instrumentation')}</span>
- </div>
- </div>
- <div
- ref={r =>
- props.viewManager.registerColumnRef(
- 'span_list',
- r,
- virtualizedIndex,
- props.node
- )
- }
- className="TraceRightColumn"
- style={{
- width: props.viewManager.columns.span_list.width * 100 + '%',
- backgroundColor:
- props.index % 2 === 0 ? props.theme.backgroundSecondary : undefined,
- }}
- >
- <TraceBar
- virtualizedIndex={virtualizedIndex}
- viewManager={props.viewManager}
- color={pickBarColor('missing-instrumentation')}
- node_space={props.node.space}
- />
- </div>
- </div>
- );
- }
- if (isTraceNode(props.node)) {
- return (
- <div
- key={props.index}
- ref={r =>
- props.tabIndex === props.index
- ? maybeFocusRow(r, props.index, props.previouslyFocusedIndexRef)
- : null
- }
- tabIndex={props.tabIndex === props.index ? 0 : -1}
- className="TraceRow"
- onClick={e => props.onRowClick(e, props.index, props.node)}
- onKeyDown={event => props.onRowKeyDown(event, props.index, props.node)}
- style={{
- top: props.style.top,
- height: props.style.height,
- }}
- >
- <div
- className="TraceLeftColumn"
- ref={r =>
- props.viewManager.registerColumnRef('list', r, virtualizedIndex, props.node)
- }
- style={{
- width: props.viewManager.columns.list.width * 100 + '%',
- }}
- >
- <div
- className="TraceLeftColumnInner"
- style={{
- paddingLeft: props.node.depth * props.viewManager.row_depth_padding,
- }}
- >
- <div className="TraceChildrenCountWrapper Root">
- <Connectors node={props.node} viewManager={props.viewManager} />
- {props.node.children.length > 0 ? (
- <ChildrenCountButton
- expanded={props.node.expanded || props.node.zoomedIn}
- onClick={e => props.onExpand(e, props.node, !props.node.expanded)}
- >
- {COUNT_FORMATTER.format(props.node.children.length)}{' '}
- </ChildrenCountButton>
- ) : null}
- </div>
- <span className="TraceOperation">{t('Trace')}</span>
- <strong className="TraceEmDash"> — </strong>
- <span className="TraceDescription">{props.trace_id}</span>
- </div>
- </div>
- <div
- ref={r =>
- props.viewManager.registerColumnRef(
- 'span_list',
- r,
- virtualizedIndex,
- props.node
- )
- }
- className="TraceRightColumn"
- style={{
- width: props.viewManager.columns.span_list.width * 100 + '%',
- backgroundColor:
- props.index % 2 === 0 ? props.theme.backgroundSecondary : undefined,
- }}
- >
- {' '}
- <TraceBar
- virtualizedIndex={virtualizedIndex}
- viewManager={props.viewManager}
- color={pickBarColor('missing-instrumentation')}
- node_space={props.node.space}
- />
- </div>
- </div>
- );
- }
- if (isTraceErrorNode(props.node)) {
- return (
- <div
- key={props.index}
- ref={r =>
- props.tabIndex === props.index
- ? maybeFocusRow(r, props.index, props.previouslyFocusedIndexRef)
- : null
- }
- tabIndex={props.tabIndex === props.index ? 0 : -1}
- className="TraceRow"
- onClick={e => props.onRowClick(e, props.index, props.node)}
- onKeyDown={event => props.onRowKeyDown(event, props.index, props.node)}
- style={{
- top: props.style.top,
- height: props.style.height,
- }}
- >
- <div
- className="TraceLeftColumn"
- ref={r =>
- props.viewManager.registerColumnRef('list', r, virtualizedIndex, props.node)
- }
- style={{
- width: props.viewManager.columns.list.width * 100 + '%',
- }}
- >
- <div
- className="TraceLeftColumnInner"
- style={{
- paddingLeft: props.node.depth * props.viewManager.row_depth_padding,
- }}
- >
- <div className="TraceChildrenCountWrapper">
- <Connectors node={props.node} viewManager={props.viewManager} />
- {props.node.children.length > 0 ? (
- <ChildrenCountButton
- expanded={props.node.expanded || props.node.zoomedIn}
- onClick={e => props.onExpand(e, props.node, !props.node.expanded)}
- >
- {COUNT_FORMATTER.format(props.node.children.length)}{' '}
- </ChildrenCountButton>
- ) : null}
- </div>
- <ProjectBadge project={props.projects[props.node.value.project_slug]} />
- <Link
- className="Errored Link"
- onClick={e => e.stopPropagation()}
- to={generateIssueEventTarget(props.node.value, props.organization)}
- >
- <span className="TraceOperation">{t('Error')}</span>
- <strong className="TraceEmDash"> — </strong>
- <span className="TraceDescription">{props.node.value.title}</span>
- </Link>
- </div>
- </div>
- <div
- ref={r =>
- props.viewManager.registerColumnRef(
- 'span_list',
- r,
- virtualizedIndex,
- props.node
- )
- }
- className="TraceRightColumn"
- style={{
- width: props.viewManager.columns.span_list.width * 100 + '%',
- backgroundColor:
- props.index % 2 === 0 ? props.theme.backgroundSecondary : undefined,
- }}
- >
- {typeof props.node.value.timestamp === 'number' ? (
- <div
- className="ErrorIconBorder"
- style={{
- transform: `translateX(${props.viewManager.computeTransformXFromTimestamp(
- props.node.value.timestamp * 1000
- )}px)`,
- }}
- >
- <IconFire color="errorText" size="xs" />
- </div>
- ) : null}
- </div>
- </div>
- );
- }
- return null;
- }
- function RenderPlaceholderRow(props: {
- index: number;
- node: TraceTreeNode<TraceTree.NodeValue>;
- projects: Record<Project['slug'], Project>;
- startIndex: number;
- style: React.CSSProperties;
- theme: Theme;
- viewManager: VirtualizedViewManager;
- }) {
- return (
- <div
- className="TraceRow"
- style={{
- top: props.style.top,
- height: props.style.height,
- pointerEvents: 'none',
- color: props.theme.subText,
- paddingLeft: space(1),
- }}
- >
- <div
- className="TraceLeftColumn"
- style={{width: props.viewManager.columns.list.width * 100 + '%'}}
- >
- <div
- className="TraceLeftColumnInner"
- style={{
- paddingLeft: props.node.depth * props.viewManager.row_depth_padding,
- }}
- >
- <div
- className={`TraceChildrenCountWrapper ${isTraceNode(props.node) ? 'Root' : ''}`}
- >
- <Connectors node={props.node} viewManager={props.viewManager} />
- {props.node.children.length > 0 ? (
- <ChildrenCountButton
- expanded={props.node.expanded || props.node.zoomedIn}
- onClick={() => void 0}
- >
- {COUNT_FORMATTER.format(props.node.children.length)}{' '}
- </ChildrenCountButton>
- ) : null}
- </div>
- <Placeholder
- className="Placeholder"
- height="12px"
- width={randomBetween(20, 80) + '%'}
- style={{
- transition: 'all 30s ease-out',
- }}
- />
- </div>
- </div>
- <div
- className="TraceRightColumn"
- style={{
- width: props.viewManager.columns.span_list.width * 100 + '%',
- backgroundColor:
- props.index % 2 === 0 ? props.theme.backgroundSecondary : undefined,
- }}
- >
- <Placeholder
- className="Placeholder"
- height="12px"
- width={randomBetween(20, 80) + '%'}
- style={{
- transition: 'all 30s ease-out',
- transform: `translate(${randomBetween(0, 200) + 'px'}, 0)`,
- }}
- />
- </div>
- </div>
- );
- }
- function randomBetween(min: number, max: number) {
- return Math.floor(Math.random() * (max - min + 1) + min);
- }
- function Connectors(props: {
- node: TraceTreeNode<TraceTree.NodeValue>;
- viewManager: VirtualizedViewManager;
- }) {
- const showVerticalConnector =
- ((props.node.expanded || props.node.zoomedIn) && props.node.children.length > 0) ||
- (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;
- return (
- <Fragment>
- {/*
- @TODO count of rendered connectors could be % 3 as we can
- have up to 3 connectors per node, 1 div, 1 before and 1 after
- */}
- {props.node.connectors.map((c, i) => {
- return (
- <div
- key={i}
- style={{
- left: -(
- Math.abs(Math.abs(c) - props.node.depth) *
- props.viewManager.row_depth_padding
- ),
- }}
- data-connector={c}
- className={`TraceVerticalConnector ${c < 0 ? 'Orphaned' : ''}`}
- />
- );
- })}
- {showVerticalConnector && !hideVerticalConnector ? (
- <div className="TraceExpandedVerticalConnector" />
- ) : null}
- {props.node.isLastChild ? (
- <div className="TraceVerticalLastChildConnector" />
- ) : (
- <div className="TraceVerticalConnector" />
- )}
- </Fragment>
- );
- }
- function ProjectBadge(props: {project: Project}) {
- return <ProjectAvatar project={props.project} />;
- }
- function ChildrenCountButton(props: {
- children: React.ReactNode;
- expanded: boolean;
- onClick: (e: React.MouseEvent) => void;
- }) {
- return (
- <button className="TraceChildrenCount" onClick={props.onClick}>
- {props.children}
- <IconChevron
- size="xs"
- direction={props.expanded ? 'up' : 'down'}
- style={{marginLeft: 2}}
- />
- </button>
- );
- }
- interface TraceBarProps {
- color: string;
- node_space: [number, number] | null;
- viewManager: VirtualizedViewManager;
- virtualizedIndex: number;
- duration?: number;
- }
- type SiblingAutogroupedBarProps = Omit<TraceBarProps, 'node_space' | 'duration'> & {
- node: TraceTreeNode<TraceTree.NodeValue>;
- };
- // Render collapsed representation of sibling autogrouping, using multiple bars for when
- // there are gaps between siblings.
- function SiblingAutogroupedBar(props: SiblingAutogroupedBarProps) {
- const bars: React.ReactNode[] = [];
- // Start and end represents the earliest start_timestamp and the latest
- // end_timestamp for a set of overlapping siblings.
- let start = isSpanNode(props.node.children[0])
- ? props.node.children[0].value.start_timestamp
- : Number.POSITIVE_INFINITY;
- let end = isSpanNode(props.node.children[0])
- ? props.node.children[0].value.timestamp
- : Number.NEGATIVE_INFINITY;
- let totalDuration = 0;
- for (let i = 0; i < props.node.children.length; i++) {
- const node = props.node.children[i];
- if (!isSpanNode(node)) {
- throw new TypeError('Invalid type of autogrouped child');
- }
- const hasGap = node.value.start_timestamp > end;
- if (!(hasGap || node.isLastChild)) {
- start = Math.min(start, node.value.start_timestamp);
- end = Math.max(end, node.value.timestamp);
- continue;
- }
- // Render a bar for already collapsed set.
- totalDuration += end - start;
- bars.push(
- <TraceBar
- virtualizedIndex={props.virtualizedIndex}
- viewManager={props.viewManager}
- color={props.color}
- node_space={[start, end - start]}
- duration={!hasGap ? totalDuration : undefined}
- />
- );
- if (hasGap) {
- // Start a new set.
- start = node.value.start_timestamp;
- end = node.value.timestamp;
- // Render a bar if the sibling with a gap is the last sibling.
- if (node.isLastChild) {
- totalDuration += end - start;
- bars.push(
- <TraceBar
- virtualizedIndex={props.virtualizedIndex}
- viewManager={props.viewManager}
- color={props.color}
- duration={totalDuration}
- node_space={[start, end - start]}
- />
- );
- }
- }
- }
- return <Fragment>{bars}</Fragment>;
- }
- function TraceBar(props: TraceBarProps) {
- if (!props.node_space) {
- return null;
- }
- const duration = getDuration(props.node_space[1] / 1000, 2, true);
- const spanTransform = props.viewManager.computeSpanCSSMatrixTransform(props.node_space);
- const [inside, textTransform] = props.viewManager.computeSpanTextPlacement(
- props.node_space,
- duration
- );
- return (
- <Fragment>
- <div
- ref={r =>
- props.viewManager.registerSpanBarRef(
- r,
- props.node_space!,
- props.virtualizedIndex
- )
- }
- className="TraceBar"
- style={{
- transform: `matrix(${spanTransform.join(',')})`,
- backgroundColor: props.color,
- }}
- onDoubleClick={e => {
- e.stopPropagation();
- props.viewManager.onZoomIntoSpace(props.node_space!);
- }}
- />
- <div
- ref={r =>
- props.viewManager.registerSpanBarTextRef(
- r,
- duration,
- props.node_space!,
- props.virtualizedIndex
- )
- }
- className="TraceBarDuration"
- style={{
- color: inside ? 'white' : '',
- transform: `translate(${textTransform ?? 0}px, 0)`,
- }}
- >
- {duration}
- </div>
- </Fragment>
- );
- }
- /**
- * 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')`
- overflow: hidden;
- position: relative;
- box-shadow: 0 0 0 1px ${p => p.theme.border};
- border-radius: ${space(0.5)};
- padding-top: 24px;
- &:before {
- content: '';
- position: absolute;
- left: 0;
- top: 0;
- width: 100%;
- height: 22px;
- background-color: ${p => p.theme.backgroundSecondary};
- border-bottom: 1px solid ${p => p.theme.border};
- }
- .IconZoom {
- height: 16px;
- width: 18px;
- background: ${p => p.theme.background};
- padding: 1px;
- border: 1px solid ${p => p.theme.border};
- border-radius: ${space(0.5)};
- position: absolute;
- right: ${space(0.5)};
- }
- &.Loading {
- .TraceRow {
- .TraceLeftColumnInner {
- width: 100%;
- }
- }
- .TraceRightColumn {
- background-color: transparent !important;
- }
- .TraceDivider {
- pointer-events: none;
- }
- }
- .TraceIndicatorContainer {
- overflow: hidden;
- width: 100%;
- height: 100%;
- position: absolute;
- right: 0;
- top: 0;
- }
- .TraceIndicator {
- z-index: 1;
- width: 3px;
- height: 100%;
- top: 0;
- position: absolute;
- .TraceIndicatorLabel {
- min-width: 34px;
- text-align: center;
- position: absolute;
- font-size: ${p => p.theme.fontSizeExtraSmall};
- 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: ${space(0.25)};
- 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;
- }
- }
- .TraceRow {
- display: flex;
- align-items: center;
- position: absolute;
- width: 100%;
- transition: none;
- font-size: ${p => p.theme.fontSizeSmall};
- .Errored {
- color: ${p => p.theme.error};
- }
- .Link {
- &:hover {
- color: ${p => p.theme.blue300};
- }
- }
- .ErrorIconBorder {
- position: absolute;
- margin: ${space(0.25)};
- left: -12px;
- background: ${p => p.theme.background};
- width: ${space(3)};
- height: ${space(3)};
- border: 1px solid ${p => p.theme.error};
- border-radius: 50%;
- display: flex;
- align-items: center;
- justify-content: center;
- }
- &:hover {
- background-color: ${p => p.theme.backgroundSecondary};
- }
- &:focus {
- transition: none;
- background-color: ${p => p.theme.backgroundTertiary};
- outline: none;
- }
- &.Autogrouped {
- color: ${p => p.theme.blue300};
- .TraceDescription {
- font-weight: bold;
- }
- .TraceChildrenCountWrapper {
- button {
- color: ${p => p.theme.white};
- background-color: ${p => p.theme.blue300};
- }
- }
- }
- }
- .TraceLeftColumn {
- height: 100%;
- white-space: nowrap;
- display: flex;
- align-items: center;
- overflow: hidden;
- will-change: width;
- position: relative;
- .TraceLeftColumnInner {
- height: 100%;
- white-space: nowrap;
- display: flex;
- align-items: center;
- will-change: transform;
- transform-origin: left center;
- transform: translateX(var(--column-translate-x));
- }
- }
- .TraceRightColumn {
- height: 100%;
- overflow: hidden;
- position: relative;
- display: flex;
- align-items: center;
- will-change: width;
- z-index: 1;
- }
- .TraceBar {
- position: absolute;
- height: 64%;
- width: 100%;
- background-color: black;
- transform-origin: left center;
- }
- .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;
- transition: color 0.1s ease-in-out;
- }
- .TraceChildrenCount {
- height: 16px;
- white-space: nowrap;
- min-width: 30px;
- display: flex;
- align-items: center;
- justify-content: center;
- border-radius: 99px;
- padding: 0px ${space(0.5)};
- transition: all 0.15s ease-in-out;
- background: ${p => p.theme.background};
- border: 2px solid ${p => p.theme.border};
- line-height: 0;
- z-index: 1;
- font-size: 10px;
- box-shadow: ${p => p.theme.dropShadowLight};
- margin-right: ${space(1)};
- 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;
- }
- &.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: ${space(0.5)};
- text-overflow: ellipsis;
- white-space: nowrap;
- font-weight: bold;
- }
- .TraceEmDash {
- margin-left: ${space(0.5)};
- margin-right: ${space(0.5)};
- }
- .TraceDescription {
- white-space: nowrap;
- }
- `;
- const LoadingContainer = styled('div')`
- display: flex;
- justify-content: center;
- align-items: center;
- flex-direction: column;
- left: 50%;
- top: 50%;
- transform: translate(-50%, -50%);
- position: absolute;
- height: auto;
- font-size: ${p => p.theme.fontSizeMedium};
- color: ${p => p.theme.gray300};
- z-index: 30;
- padding: 24px;
- background-color: ${p => p.theme.background};
- border-radius: ${p => p.theme.borderRadius};
- border: 1px solid ${p => p.theme.border};
- `;
- function TraceLoading() {
- return (
- <LoadingContainer>
- <NoMarginIndicator size={24}>
- <div>{t('Assembling the trace')}</div>
- </NoMarginIndicator>
- </LoadingContainer>
- );
- }
- const NoMarginIndicator = styled(LoadingIndicator)`
- margin: 0;
- `;
|