123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193 |
- import type React from 'react';
- import {
- Fragment,
- useCallback,
- useEffect,
- useLayoutEffect,
- useMemo,
- useRef,
- useState,
- } from 'react';
- import {browserHistory} from 'react-router';
- 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 {pickBarColor} from 'sentry/components/performance/waterfall/utils';
- import Placeholder from 'sentry/components/placeholder';
- import {IconFire} from 'sentry/icons';
- import {t} from 'sentry/locale';
- import type {Organization, PlatformKey, Project} from 'sentry/types';
- import {getDuration} from 'sentry/utils/formatters';
- 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 {
- getRovingIndexActionFromEvent,
- type RovingTabIndexAction,
- type RovingTabIndexUserActions,
- } from 'sentry/views/performance/newTraceDetails/rovingTabIndex';
- import type {
- TraceSearchAction,
- TraceSearchState,
- } from 'sentry/views/performance/newTraceDetails/traceSearch';
- import {
- isAutogroupedNode,
- isMissingInstrumentationNode,
- isParentAutogroupedNode,
- isSpanNode,
- isTraceErrorNode,
- isTraceNode,
- isTransactionNode,
- } from './guards';
- import {ParentAutogroupNode, type TraceTree, type TraceTreeNode} from './traceTree';
- import {
- useVirtualizedList,
- type VirtualizedRow,
- type VirtualizedViewManager,
- } from './virtualizedViewManager';
- function Chevron(props: {direction: 'up' | 'down' | 'left'}) {
- return (
- <svg
- viewBox="0 0 16 16"
- style={{
- fill: 'currentcolor',
- color: 'currentcolor',
- transition: 'transform 120ms ease-in-out',
- transform: `rotate(${props.direction === 'up' ? 0 : props.direction === 'down' ? 180 : -90}deg)`,
- }}
- >
- <path d="M14,11.75a.74.74,0,0,1-.53-.22L8,6.06,2.53,11.53a.75.75,0,0,1-1.06-1.06l6-6a.75.75,0,0,1,1.06,0l6,6a.75.75,0,0,1,0,1.06A.74.74,0,0,1,14,11.75Z" />
- </svg>
- );
- }
- 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 = [];
- 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 {
- manager: VirtualizedViewManager;
- onTraceSearch: (query: string) => void;
- previouslyFocusedIndexRef: React.MutableRefObject<number | null>;
- roving_dispatch: React.Dispatch<RovingTabIndexAction>;
- roving_state: RovingTabIndexState;
- scrollQueueRef: React.MutableRefObject<TraceTree.NodePath[] | null>;
- searchResultsIteratorIndex: number | undefined;
- searchResultsMap: Map<TraceTreeNode<TraceTree.NodeValue>, number>;
- search_dispatch: React.Dispatch<TraceSearchAction>;
- search_state: TraceSearchState;
- setClickedNode: (node: TraceTreeNode<TraceTree.NodeValue> | null) => void;
- trace: TraceTree;
- trace_id: string;
- }
- function Trace({
- trace,
- trace_id,
- roving_state,
- roving_dispatch,
- search_state,
- search_dispatch,
- setClickedNode: setDetailNode,
- manager,
- scrollQueueRef,
- searchResultsIteratorIndex,
- searchResultsMap,
- previouslyFocusedIndexRef,
- onTraceSearch,
- }: TraceProps) {
- const theme = useTheme();
- const api = useApi();
- const {projects} = useProjects();
- const organization = useOrganization();
- const containerRef = useRef<HTMLDivElement | null>(null);
- const [_rerender, setRender] = useState(0);
- const treePromiseStatusRef =
- useRef<Map<TraceTreeNode<TraceTree.NodeValue>, 'loading' | 'error' | 'success'>>();
- if (!treePromiseStatusRef.current) {
- treePromiseStatusRef.current = new Map();
- }
- const treeRef = useRef<TraceTree>(trace);
- treeRef.current = trace;
- 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]);
- scrollQueueRef.current = decodeScrollQueue(qs.parse(location.search).node);
- }
- const loadedRef = useRef(false);
- useEffect(() => {
- if (loadedRef.current) {
- return;
- }
- if (trace.type !== 'trace' || !manager) {
- return;
- }
- loadedRef.current = true;
- const eventId = qs.parse(location.search)?.eventId;
- if (!scrollQueueRef.current && !scrollQueueRef.current && !eventId) {
- if (search_state.query) {
- onTraceSearch(search_state.query);
- }
- return;
- }
- const promise =
- eventId && typeof eventId === 'string'
- ? manager.scrollToEventID(eventId, trace, () => setRender(a => (a + 1) % 2), {
- api,
- organization,
- })
- : scrollQueueRef.current
- ? manager.scrollToPath(
- trace,
- scrollQueueRef.current,
- () => setRender(a => (a + 1) % 2),
- {
- api,
- organization,
- }
- )
- : Promise.resolve(null);
- promise.then(maybeNode => {
- // 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;
- if (!maybeNode) {
- Sentry.captureMessage('Failled to find and scroll to node in tree');
- return;
- }
- if (maybeNode.node.space) {
- manager.animateViewTo(maybeNode.node.space);
- }
- manager.onScrollEndOutOfBoundsCheck();
- setDetailNode(maybeNode.node);
- roving_dispatch({
- type: 'set index',
- index: maybeNode.index,
- node: maybeNode.node,
- });
- manager.list?.scrollToRow(maybeNode.index, 'top');
- manager.scrollRowIntoViewHorizontally(maybeNode.node, 0);
- if (search_state.query) {
- onTraceSearch(search_state.query);
- }
- });
- }, [
- api,
- scrollQueueRef,
- organization,
- trace,
- trace_id,
- manager,
- search_state.query,
- onTraceSearch,
- setDetailNode,
- roving_dispatch,
- ]);
- const previousSearchResultIndexRef = useRef<number | undefined>(
- search_state.resultIndex
- );
- useLayoutEffect(() => {
- if (previousSearchResultIndexRef.current === search_state.resultIndex) {
- return;
- }
- if (!manager.list) {
- return;
- }
- if (typeof search_state.resultIndex !== 'number') {
- return;
- }
- manager.scrollToRow(search_state.resultIndex);
- if (previousSearchResultIndexRef.current === undefined) {
- return;
- }
- const previousNode = treeRef.current.list[previousSearchResultIndexRef.current!];
- previousSearchResultIndexRef.current = search_state.resultIndex;
- if (previousNode) {
- const nextNode = treeRef.current.list[search_state.resultIndex];
- const offset =
- nextNode.depth >= previousNode.depth ? manager.trace_physical_space.width / 2 : 0;
- if (
- manager.isOutsideOfViewOnKeyDown(
- treeRef.current.list[search_state.resultIndex],
- offset
- )
- ) {
- manager.scrollRowIntoViewHorizontally(
- treeRef.current.list[search_state.resultIndex],
- 0,
- offset
- );
- }
- }
- }, [search_state.resultIndex, manager]);
- 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();
- setRender(a => (a + 1) % 2);
- treeRef.current
- .zoomIn(node, value, {
- api,
- organization,
- })
- .then(() => {
- setRender(a => (a + 1) % 2);
- if (search_state.query) {
- onTraceSearch(search_state.query);
- }
- if (search_state.resultsLookup.has(node)) {
- const idx = search_state.resultsLookup.get(node)!;
- search_dispatch({
- type: 'set iterator index',
- resultIndex: search_state.results?.[idx]?.index!,
- resultIteratorIndex: idx,
- });
- } else {
- search_dispatch({type: 'clear iterator index'});
- }
- treePromiseStatusRef.current!.set(node, 'success');
- })
- .catch(_e => {
- treePromiseStatusRef.current!.set(node, 'error');
- });
- },
- [api, organization, search_state, search_dispatch, onTraceSearch]
- );
- 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);
- if (search_state.query) {
- onTraceSearch(search_state.query);
- }
- if (search_state.resultsLookup.has(node)) {
- const idx = search_state.resultsLookup.get(node)!;
- search_dispatch({
- type: 'set iterator index',
- resultIndex: search_state.results?.[idx]?.index!,
- resultIteratorIndex: idx,
- });
- } else {
- search_dispatch({type: 'clear iterator index'});
- }
- },
- [search_state, search_dispatch, onTraceSearch]
- );
- const onRowClick = useCallback(
- (
- _event: React.MouseEvent,
- index: number,
- node: TraceTreeNode<TraceTree.NodeValue>
- ) => {
- previousSearchResultIndexRef.current = index;
- previouslyFocusedIndexRef.current = index;
- const {eventId: _eventId, ...query} = qs.parse(location.search);
- browserHistory.replace({
- pathname: location.pathname,
- query: {
- ...query,
- node: node.path,
- },
- });
- setDetailNode(node);
- roving_dispatch({type: 'set index', index, node});
- if (search_state.resultsLookup.has(node)) {
- const idx = search_state.resultsLookup.get(node)!;
- search_dispatch({
- type: 'set iterator index',
- resultIndex: index,
- resultIteratorIndex: idx,
- });
- } else {
- search_dispatch({type: 'clear iterator index'});
- }
- },
- [
- roving_dispatch,
- setDetailNode,
- search_state,
- search_dispatch,
- previouslyFocusedIndexRef,
- previousSearchResultIndexRef,
- ]
- );
- const onRowKeyDown = useCallback(
- (
- event: React.KeyboardEvent,
- index: number,
- node: TraceTreeNode<TraceTree.NodeValue>
- ) => {
- if (!manager.list) {
- return;
- }
- const action = getRovingIndexActionFromEvent(event);
- if (action) {
- event.preventDefault();
- const nextIndex = computeNextIndexFromAction(
- index,
- action,
- treeRef.current.list.length - 1
- );
- manager.scrollToRow(nextIndex);
- roving_dispatch({type: 'set index', index: nextIndex, node});
- const nextNode = treeRef.current.list[nextIndex];
- const offset =
- nextNode.depth >= node.depth ? manager.trace_physical_space.width / 2 : 0;
- if (manager.isOutsideOfViewOnKeyDown(trace.list[nextIndex], offset)) {
- manager.scrollRowIntoViewHorizontally(trace.list[nextIndex], 0, offset);
- }
- if (search_state.resultsLookup.has(trace.list[nextIndex])) {
- const idx = search_state.resultsLookup.get(trace.list[nextIndex])!;
- search_dispatch({
- type: 'set iterator index',
- resultIndex: nextIndex,
- resultIteratorIndex: idx,
- });
- } else {
- search_dispatch({type: 'clear iterator index'});
- }
- }
- },
- [manager, roving_dispatch, search_state, search_dispatch, trace.list]
- );
- // @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: Record<string, PlatformKey | undefined> = useMemo(() => {
- return projects.reduce<Record<Project['slug'], Project['platform']>>(
- (acc, project) => {
- acc[project.slug] = project.platform;
- return acc;
- },
- {}
- );
- }, [projects]);
- const render = useCallback(
- (n: VirtualizedRow) => {
- return trace.type !== 'trace' || scrollQueueRef.current ? (
- <RenderPlaceholderRow
- key={n.key}
- index={n.index}
- style={n.style}
- node={n.item}
- theme={theme}
- projects={projectLookup}
- manager={manager}
- />
- ) : (
- <RenderRow
- key={n.key}
- index={n.index}
- organization={organization}
- previouslyFocusedIndexRef={previouslyFocusedIndexRef}
- tabIndex={roving_state.index ?? -1}
- isSearchResult={searchResultsMap.has(n.item)}
- searchResultsIteratorIndex={searchResultsIteratorIndex}
- style={n.style}
- trace_id={trace_id}
- projects={projectLookup}
- node={n.item}
- manager={manager}
- theme={theme}
- onExpand={handleExpandNode}
- onZoomIn={handleZoomIn}
- onRowClick={onRowClick}
- onRowKeyDown={onRowKeyDown}
- />
- );
- },
- // we add _rerender as a dependency to trigger the virtualized list rerender
- // eslint-disable-next-line react-hooks/exhaustive-deps
- [
- handleExpandNode,
- handleZoomIn,
- manager,
- onRowClick,
- onRowKeyDown,
- organization,
- projectLookup,
- roving_state.index,
- searchResultsIteratorIndex,
- searchResultsMap,
- theme,
- trace_id,
- trace.type,
- _rerender,
- ]
- );
- const [scrollContainer, setScrollContainer] = useState<HTMLElement | null>(null);
- const virtualizedList = useVirtualizedList({
- manager,
- items: trace.list,
- container: scrollContainer,
- render,
- });
- return (
- <TraceStylingWrapper
- ref={r => {
- containerRef.current = r;
- manager.onContainerRef(r);
- }}
- className={`${trace.indicators.length > 0 ? 'WithIndicators' : ''} ${trace.type !== 'trace' || scrollQueueRef.current ? 'Loading' : ''}`}
- >
- <div className="TraceDivider" ref={r => manager?.registerDividerRef(r)} />
- <div
- className="TraceIndicatorContainer"
- ref={r => manager.registerIndicatorContainerRef(r)}
- >
- {trace.indicators.length > 0
- ? trace.indicators.map((indicator, i) => {
- return (
- <div
- key={i}
- ref={r => manager.registerIndicatorRef(r, i, indicator)}
- className="TraceIndicator"
- >
- <div className="TraceIndicatorLabel">{indicator.label}</div>
- <div className="TraceIndicatorLine" />
- </div>
- );
- })
- : null}
- {manager.interval_bars.map((_, i) => {
- const indicatorTimestamp = manager.intervals[i];
- const timestamp = manager.to_origin + indicatorTimestamp ?? 0;
- if (trace.type !== 'trace') {
- return null;
- }
- return (
- <div
- key={i}
- ref={r => manager.registerTimelineIndicatorRef(r, i)}
- className="TraceIndicator Timeline"
- style={{
- transform: `translate(${manager.computeTransformXFromTimestamp(timestamp)}px, 0)`,
- }}
- >
- <div className="TraceIndicatorLabel">
- {indicatorTimestamp > 0
- ? getDuration(
- (manager.trace_view.x + indicatorTimestamp) / 1000,
- 2,
- true
- )
- : '0s'}
- </div>
- <div className="TraceIndicatorLine" />
- </div>
- );
- })}
- </div>
- <div ref={r => setScrollContainer(r)}>
- <div>{virtualizedList.rendered}</div>
- </div>
- </TraceStylingWrapper>
- );
- }
- export default Trace;
- function RenderRow(props: {
- index: number;
- isSearchResult: boolean;
- manager: VirtualizedViewManager;
- 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['platform']>;
- searchResultsIteratorIndex: number | undefined;
- style: React.CSSProperties;
- tabIndex: number;
- theme: Theme;
- trace_id: string;
- }) {
- const virtualized_index = props.index - props.manager.start_virtualized_index;
- if (!props.node.value) {
- return null;
- }
- const rowSearchClassName = `${props.isSearchResult ? 'SearchResult' : ''} ${props.searchResultsIteratorIndex === props.index ? 'Highlight' : ''}`;
- 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={`Autogrouped TraceRow ${rowSearchClassName}`}
- 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.manager.registerColumnRef('list', r, virtualized_index, props.node)
- }
- style={{
- width: props.manager.columns.list.width * 100 + '%',
- }}
- >
- <div
- className={`TraceLeftColumnInner ${props.node.has_error ? 'Errored' : ''}`}
- style={{
- paddingLeft: props.node.depth * props.manager.row_depth_padding,
- }}
- >
- <div className="TraceChildrenCountWrapper">
- <Connectors node={props.node} manager={props.manager} />
- <ChildrenButton
- icon={
- props.node.expanded ? (
- <Chevron direction="up" />
- ) : (
- <Chevron direction="down" />
- )
- }
- status={props.node.fetchStatus}
- expanded={!props.node.expanded}
- onClick={e => props.onExpand(e, props.node, !props.node.expanded)}
- errored={props.node.has_error}
- >
- {COUNT_FORMATTER.format(props.node.groupCount)}
- </ChildrenButton>
- </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 ${props.index % 2 === 0 ? 0 : 'Odd'}`}
- ref={r =>
- props.manager.registerColumnRef('span_list', r, virtualized_index, props.node)
- }
- style={{
- width: props.manager.columns.span_list.width * 100 + '%',
- }}
- onDoubleClick={e => {
- e.stopPropagation();
- props.manager.onZoomIntoSpace(props.node.space!);
- }}
- >
- <AutogroupedTraceBar
- virtualized_index={virtualized_index}
- manager={props.manager}
- color={props.theme.blue300}
- entire_space={props.node.space}
- node_spaces={props.node.autogroupedSegments}
- />
- <button
- ref={ref =>
- props.manager.registerArrowRef(ref, props.node.space!, virtualized_index)
- }
- className="TraceArrow"
- onClick={_e => {
- props.manager.onBringRowIntoView(props.node.space!);
- }}
- >
- <Chevron direction="left" />
- </button>
- </div>
- </div>
- );
- }
- if (isTransactionNode(props.node)) {
- const errored =
- props.node.value.errors.length > 0 ||
- props.node.value.performance_issues.length > 0;
- 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 ${rowSearchClassName}`}
- 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.manager.registerColumnRef('list', r, virtualized_index, props.node)
- }
- style={{
- width: props.manager.columns.list.width * 100 + '%',
- }}
- >
- <div
- className={`TraceLeftColumnInner ${errored ? 'Errored' : ''}`}
- style={{
- paddingLeft: props.node.depth * props.manager.row_depth_padding,
- }}
- >
- <div
- className={`TraceChildrenCountWrapper ${
- props.node.isOrphaned ? 'Orphaned' : ''
- }
- `}
- >
- <Connectors node={props.node} manager={props.manager} />
- {props.node.children.length > 0 || props.node.canFetch ? (
- <ChildrenButton
- icon={
- props.node.canFetch && props.node.fetchStatus === 'idle' ? (
- '+'
- ) : props.node.canFetch && props.node.zoomedIn ? (
- <Chevron direction="down" />
- ) : (
- '+'
- )
- }
- 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)
- }
- errored={errored}
- >
- {props.node.children.length > 0
- ? COUNT_FORMATTER.format(props.node.children.length)
- : null}
- </ChildrenButton>
- ) : null}
- </div>
- <PlatformIcon
- platform={props.projects[props.node.value.project_slug] ?? 'default'}
- />
- <span className="TraceOperation">{props.node.value['transaction.op']}</span>
- <strong className="TraceEmDash"> — </strong>
- <span>{props.node.value.transaction}</span>
- </div>
- </div>
- <div
- ref={r =>
- props.manager.registerColumnRef('span_list', r, virtualized_index, props.node)
- }
- className={`TraceRightColumn ${props.index % 2 === 0 ? 0 : 'Odd'}`}
- style={{
- width: props.manager.columns.span_list.width * 100 + '%',
- }}
- onDoubleClick={e => {
- e.stopPropagation();
- props.manager.onZoomIntoSpace(props.node.space!);
- }}
- >
- <TraceBar
- virtualized_index={virtualized_index}
- manager={props.manager}
- color={pickBarColor(props.node.value['transaction.op'])}
- node_space={props.node.space}
- errors={props.node.value.errors}
- performance_issues={props.node.value.performance_issues}
- />
- <button
- ref={ref =>
- props.manager.registerArrowRef(ref, props.node.space!, virtualized_index)
- }
- className="TraceArrow"
- onClick={_e => {
- props.manager.onBringRowIntoView(props.node.space!);
- }}
- >
- <Chevron direction="left" />
- </button>
- </div>
- </div>
- );
- }
- if (isSpanNode(props.node)) {
- const errored =
- props.node.value.errors.length > 0 ||
- props.node.value.performance_issues.length > 0;
- 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 ${rowSearchClassName}`}
- 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.manager.registerColumnRef('list', r, virtualized_index, props.node)
- }
- style={{
- width: props.manager.columns.list.width * 100 + '%',
- }}
- >
- <div
- className={`TraceLeftColumnInner ${errored ? 'Errored' : ''}`}
- style={{
- paddingLeft: props.node.depth * props.manager.row_depth_padding,
- }}
- >
- <div
- className={`TraceChildrenCountWrapper ${
- props.node.isOrphaned ? 'Orphaned' : ''
- }`}
- >
- <Connectors node={props.node} manager={props.manager} />
- {props.node.children.length > 0 || props.node.canFetch ? (
- <ChildrenButton
- icon={
- props.node.canFetch ? (
- '+'
- ) : props.node.expanded ? (
- <Chevron direction="up" />
- ) : (
- <Chevron direction="down" />
- )
- }
- 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)
- }
- errored={errored}
- >
- {props.node.children.length > 0
- ? COUNT_FORMATTER.format(props.node.children.length)
- : null}
- </ChildrenButton>
- ) : 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>
- </div>
- <div
- ref={r =>
- props.manager.registerColumnRef('span_list', r, virtualized_index, props.node)
- }
- className={`TraceRightColumn ${props.index % 2 === 0 ? 0 : 'Odd'}`}
- style={{
- width: props.manager.columns.span_list.width * 100 + '%',
- }}
- onDoubleClick={e => {
- e.stopPropagation();
- props.manager.onZoomIntoSpace(props.node.space!);
- }}
- >
- <TraceBar
- virtualized_index={virtualized_index}
- manager={props.manager}
- color={pickBarColor(props.node.value.op)}
- node_space={props.node.space}
- errors={props.node.value.errors}
- performance_issues={props.node.value.performance_issues}
- />
- <button
- ref={ref =>
- props.manager.registerArrowRef(ref, props.node.space!, virtualized_index)
- }
- className="TraceArrow"
- onClick={_e => {
- props.manager.onBringRowIntoView(props.node.space!);
- }}
- >
- <Chevron direction="left" />
- </button>
- </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 ${rowSearchClassName}`}
- 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.manager.registerColumnRef('list', r, virtualized_index, props.node)
- }
- style={{
- width: props.manager.columns.list.width * 100 + '%',
- }}
- >
- <div
- className="TraceLeftColumnInner"
- style={{
- paddingLeft: props.node.depth * props.manager.row_depth_padding,
- }}
- >
- <div className="TraceChildrenCountWrapper">
- <Connectors node={props.node} manager={props.manager} />
- </div>
- <span className="TraceOperation">{t('Missing instrumentation')}</span>
- </div>
- </div>
- <div
- ref={r =>
- props.manager.registerColumnRef('span_list', r, virtualized_index, props.node)
- }
- className={`TraceRightColumn ${props.index % 2 === 0 ? 0 : 'Odd'}`}
- style={{
- width: props.manager.columns.span_list.width * 100 + '%',
- }}
- onDoubleClick={e => {
- e.stopPropagation();
- props.manager.onZoomIntoSpace(props.node.space!);
- }}
- >
- <TraceBar
- virtualized_index={virtualized_index}
- manager={props.manager}
- color={pickBarColor('missing-instrumentation')}
- node_space={props.node.space}
- errors={NO_ERRORS}
- performance_issues={NO_ERRORS}
- />
- <button
- ref={ref =>
- props.manager.registerArrowRef(ref, props.node.space!, virtualized_index)
- }
- className="TraceArrow"
- onClick={_e => {
- props.manager.onBringRowIntoView(props.node.space!);
- }}
- >
- <Chevron direction="left" />
- </button>
- </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 ${rowSearchClassName}`}
- 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.manager.registerColumnRef('list', r, virtualized_index, props.node)
- }
- style={{
- width: props.manager.columns.list.width * 100 + '%',
- }}
- >
- <div
- className="TraceLeftColumnInner"
- style={{
- paddingLeft: props.node.depth * props.manager.row_depth_padding,
- }}
- >
- <div className="TraceChildrenCountWrapper Root">
- <Connectors node={props.node} manager={props.manager} />
- {props.node.children.length > 0 || props.node.canFetch ? (
- <ChildrenButton icon={''} status={'idle'} expanded onClick={() => void 0}>
- {props.node.children.length > 0
- ? COUNT_FORMATTER.format(props.node.children.length)
- : null}
- </ChildrenButton>
- ) : 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.manager.registerColumnRef('span_list', r, virtualized_index, props.node)
- }
- className={`TraceRightColumn ${props.index % 2 === 0 ? 0 : 'Odd'}`}
- style={{
- width: props.manager.columns.span_list.width * 100 + '%',
- }}
- onDoubleClick={e => {
- e.stopPropagation();
- props.manager.onZoomIntoSpace(props.node.space!);
- }}
- >
- <TraceBar
- virtualized_index={virtualized_index}
- manager={props.manager}
- color={pickBarColor('missing-instrumentation')}
- node_space={props.node.space}
- errors={NO_ERRORS}
- performance_issues={NO_ERRORS}
- />
- <button
- ref={ref =>
- props.manager.registerArrowRef(ref, props.node.space!, virtualized_index)
- }
- className="TraceArrow"
- onClick={_e => {
- props.manager.onBringRowIntoView(props.node.space!);
- }}
- >
- <Chevron direction="left" />
- </button>
- </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 ${rowSearchClassName}`}
- 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.manager.registerColumnRef('list', r, virtualized_index, props.node)
- }
- style={{
- width: props.manager.columns.list.width * 100 + '%',
- }}
- >
- <div
- className="TraceLeftColumnInner"
- style={{
- paddingLeft: props.node.depth * props.manager.row_depth_padding,
- }}
- >
- <div className="TraceChildrenCountWrapper">
- <Connectors node={props.node} manager={props.manager} />
- </div>
- <PlatformIcon
- platform={props.projects[props.node.value.project_slug] ?? 'default'}
- />
- <span className="TraceOperation Errored">{t('Error')}</span>
- <strong className="TraceEmDash Errored"> — </strong>
- <span className="TraceDescription Errored">{props.node.value.title}</span>
- </div>
- </div>
- <div
- ref={r =>
- props.manager.registerColumnRef('span_list', r, virtualized_index, props.node)
- }
- className={`TraceRightColumn ${props.index % 2 === 0 ? 0 : 'Odd'}`}
- style={{
- width: props.manager.columns.span_list.width * 100 + '%',
- }}
- onDoubleClick={e => {
- e.stopPropagation();
- props.manager.onZoomIntoSpace(props.node.space!);
- }}
- >
- <InvisibleTraceBar
- node_space={props.node.space}
- manager={props.manager}
- virtualizedIndex={virtualized_index}
- >
- {typeof props.node.value.timestamp === 'number' ? (
- <div className="TraceError">
- <IconFire color="errorText" size="xs" />
- </div>
- ) : null}
- </InvisibleTraceBar>
- </div>
- </div>
- );
- }
- return null;
- }
- function RenderPlaceholderRow(props: {
- index: number;
- manager: VirtualizedViewManager;
- node: TraceTreeNode<TraceTree.NodeValue>;
- projects: Record<Project['slug'], Project['platform']>;
- style: React.CSSProperties;
- theme: Theme;
- }) {
- return (
- <div
- key={props.index}
- className="TraceRow"
- style={{
- top: props.style.top,
- height: props.style.height,
- pointerEvents: 'none',
- color: props.theme.subText,
- paddingLeft: 8,
- }}
- >
- <div
- className="TraceLeftColumn"
- style={{width: props.manager.columns.list.width * 100 + '%'}}
- >
- <div
- className="TraceLeftColumnInner"
- style={{
- paddingLeft: props.node.depth * props.manager.row_depth_padding,
- }}
- >
- <div
- className={`TraceChildrenCountWrapper ${isTraceNode(props.node) ? 'Root' : ''}`}
- >
- <Connectors node={props.node} manager={props.manager} />
- {props.node.children.length > 0 || props.node.canFetch ? (
- <ChildrenButton
- icon="+"
- status={props.node.fetchStatus}
- expanded={props.node.expanded || props.node.zoomedIn}
- onClick={() => void 0}
- >
- {props.node.children.length > 0
- ? COUNT_FORMATTER.format(props.node.children.length)
- : null}
- </ChildrenButton>
- ) : null}
- </div>
- <Placeholder
- className="Placeholder"
- height="12px"
- width={randomBetween(20, 80) + '%'}
- style={{
- transition: 'all 30s ease-out',
- }}
- />
- </div>
- </div>
- <div
- className={`TraceRightColumn ${props.index % 2 === 0 ? 0 : 'Odd'}`}
- style={{
- width: props.manager.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: {
- manager: VirtualizedViewManager;
- node: TraceTreeNode<TraceTree.NodeValue>;
- }) {
- 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>
- {props.node.connectors.map((c, i) => {
- return (
- <div
- key={i}
- style={{
- left: -(
- Math.abs(Math.abs(c) - props.node.depth) * props.manager.row_depth_padding
- ),
- }}
- className={`TraceVerticalConnector ${c < 0 ? 'Orphaned' : ''}`}
- />
- );
- })}
- {showVerticalConnector && !hideVerticalConnector ? (
- <div className="TraceExpandedVerticalConnector" />
- ) : null}
- {props.node.isLastChild ? (
- <div className="TraceVerticalLastChildConnector" />
- ) : (
- <div className="TraceVerticalConnector" />
- )}
- </Fragment>
- );
- }
- function ChildrenButton(props: {
- children: React.ReactNode;
- expanded: boolean;
- icon: React.ReactNode;
- onClick: (e: React.MouseEvent) => void;
- status: TraceTreeNode<any>['fetchStatus'] | undefined;
- errored?: boolean;
- }) {
- return (
- <button
- className={`TraceChildrenCount ${props.errored ? 'Errored' : ''}`}
- onClick={props.onClick}
- >
- <div className="TraceChildrenCountContent">{props.children}</div>
- <div className="TraceChildrenCountAction">
- {props.icon}
- {props.status === 'loading' ? (
- <LoadingIndicator className="TraceActionsLoadingIndicator" size={8} />
- ) : null}
- </div>
- </button>
- );
- }
- interface TraceBarProps {
- color: string;
- errors: TraceTreeNode<TraceTree.Transaction>['value']['errors'];
- manager: VirtualizedViewManager;
- node_space: [number, number] | null;
- performance_issues: TraceTreeNode<TraceTree.Transaction>['value']['performance_issues'];
- virtualized_index: number;
- duration?: number;
- }
- function TraceBar(props: TraceBarProps) {
- if (!props.node_space) {
- return null;
- }
- const duration = getDuration(props.node_space[1] / 1000, 2, true);
- const spanTransform = props.manager.computeSpanCSSMatrixTransform(props.node_space);
- const [inside, textTransform] = props.manager.computeSpanTextPlacement(
- props.node_space,
- duration
- );
- return (
- <Fragment>
- <div
- ref={r =>
- props.manager.registerSpanBarRef(r, props.node_space!, props.virtualized_index)
- }
- className="TraceBar"
- style={
- {
- transform: `matrix(${spanTransform.join(',')})`,
- '--inverse-span-scale': 1 / spanTransform[0],
- backgroundColor: props.color,
- // unknown css variables cannot be part of the style object
- } as React.CSSProperties
- }
- >
- {props.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 (
- <div
- key={error.event_id}
- className="TraceError"
- style={{left: left * 100 + '%'}}
- >
- <IconFire color="errorText" size="xs" />
- </div>
- );
- })}
- {props.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!
- );
- const max_width = 100 - left;
- const issue_duration = (issue.end - issue.start) * 1e3;
- const width = clamp(
- (issue_duration / props.node_space![1]) * 100,
- 0,
- max_width
- );
- return (
- <div
- key={issue.event_id}
- className="TracePerformanceIssue"
- style={{left: left * 100 + '%', width: width + '%'}}
- >
- <div className="TraceError" style={{left: 0}}>
- <IconFire color="errorText" size="xs" />
- </div>
- </div>
- );
- })}
- </div>
- <div
- ref={r =>
- props.manager.registerSpanBarTextRef(
- r,
- duration,
- props.node_space!,
- props.virtualized_index
- )
- }
- className="TraceBarDuration"
- style={{
- color: inside ? 'white' : '',
- transform: `translate(${textTransform ?? 0}px, 0)`,
- }}
- >
- {duration}
- </div>
- </Fragment>
- );
- }
- interface InvisibleTraceBarProps {
- children: React.ReactNode;
- manager: VirtualizedViewManager;
- node_space: [number, number] | null;
- virtualizedIndex: number;
- }
- function InvisibleTraceBar(props: InvisibleTraceBarProps) {
- if (!props.node_space || !props.children) {
- return null;
- }
- const transform = `translateX(${props.manager.computeTransformXFromTimestamp(props.node_space[0])}px)`;
- return (
- <div
- ref={r =>
- props.manager.registerInvisibleBarRef(
- r,
- props.node_space!,
- props.virtualizedIndex
- )
- }
- className="TraceBar Invisible"
- style={{
- transform,
- }}
- onDoubleClick={e => {
- e.stopPropagation();
- props.manager.onZoomIntoSpace(props.node_space!);
- }}
- >
- {props.children}
- </div>
- );
- }
- interface AutogroupedTraceBarProps {
- color: string;
- entire_space: [number, number] | null;
- manager: VirtualizedViewManager;
- node_spaces: [number, number][];
- virtualized_index: number;
- duration?: number;
- }
- function AutogroupedTraceBar(props: AutogroupedTraceBarProps) {
- if (props.node_spaces && props.node_spaces.length <= 1) {
- return (
- <TraceBar
- color={props.color}
- node_space={props.entire_space}
- manager={props.manager}
- virtualized_index={props.virtualized_index}
- duration={props.duration}
- errors={NO_ERRORS}
- performance_issues={NO_ERRORS}
- />
- );
- }
- if (!props.node_spaces || !props.entire_space) {
- return null;
- }
- const duration = getDuration(props.entire_space[1] / 1000, 2, true);
- const spanTransform = props.manager.computeSpanCSSMatrixTransform(props.entire_space);
- const [inside, textTransform] = props.manager.computeSpanTextPlacement(
- props.entire_space,
- duration
- );
- return (
- <Fragment>
- <div
- ref={r =>
- props.manager.registerSpanBarRef(
- r,
- props.entire_space!,
- props.virtualized_index
- )
- }
- className="TraceBar Invisible"
- style={{
- transform: `matrix(${spanTransform.join(',')})`,
- backgroundColor: props.color,
- }}
- >
- {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 (
- <div
- key={i}
- className="TraceBar"
- style={{
- left: `${left * 1000}%`,
- width: `${width * 100}%`,
- backgroundColor: props.color,
- }}
- />
- );
- })}
- </div>
- <div
- ref={r =>
- props.manager.registerSpanBarTextRef(
- r,
- duration,
- props.entire_space!,
- props.virtualized_index
- )
- }
- 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')`
- 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: 22px;
- &.WithIndicators {
- padding-top: 44px;
- &:before {
- height: 44px;
- }
- .TraceIndicator.Timeline {
- .TraceIndicatorLabel {
- top: 26px;
- }
- .TraceIndicatorLine {
- top: 30px;
- }
- }
- }
- &: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};
- }
- &.Loading {
- .TraceRow {
- .TraceLeftColumnInner {
- width: 100%;
- }
- }
- .TraceRightColumn {
- background-color: transparent !important;
- }
- .TraceDivider {
- pointer-events: none;
- }
- }
- .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;
- }
- .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: 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;
- }
- &.Timeline {
- opacity: 1;
- z-index: 1;
- pointer-events: none;
- .TraceIndicatorLabel {
- font-weight: normal;
- min-width: 0;
- top: 2px;
- width: auto;
- border: none;
- background-color: transparent;
- color: ${p => p.theme.subText};
- }
- .TraceIndicatorLine {
- background: ${p => p.theme.translucentGray100};
- top: 4px;
- }
- }
- }
- .TraceRow {
- display: flex;
- align-items: center;
- position: absolute;
- height: 24px;
- width: 100%;
- transition: none;
- font-size: ${p => p.theme.fontSizeSmall};
- .Errored {
- color: ${p => p.theme.error};
- }
- .TraceError {
- position: absolute;
- top: 50%;
- transform: translate(-50%, -50%) scaleX(var(--inverse-span-scale));
- background: ${p => p.theme.background};
- width: 18px !important;
- height: 18px !important;
- background-color: ${p => p.theme.error};
- border-radius: 50%;
- display: flex;
- align-items: center;
- justify-content: center;
- svg {
- fill: ${p => p.theme.white};
- }
- }
- .TracePerformanceIssue {
- position: absolute;
- top: 0;
- display: flex;
- align-items: center;
- justify-content: flex-start;
- background-color: ${p => p.theme.error};
- height: 16px;
- }
- .TraceRightColumn.Odd {
- background-color: ${p => p.theme.backgroundSecondary};
- }
- &:hover {
- background-color: ${p => p.theme.backgroundSecondary};
- }
- &.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 {
- outline: none;
- background-color: ${p => p.theme.backgroundTertiary};
- .TraceRightColumn.Odd {
- background-color: transparent !important;
- }
- }
- &:focus,
- &[tabindex='0'] {
- background-color: ${p => p.theme.backgroundTertiary};
- box-shadow: inset 0 0 0 1px ${p => p.theme.blue300} !important;
- .TraceLeftColumn {
- box-shadow: inset 0px 0 0px 1px ${p => p.theme.blue300} !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};
- }
- }
- }
- }
- .TraceLeftColumn {
- height: 100%;
- white-space: nowrap;
- display: flex;
- align-items: center;
- overflow: hidden;
- will-change: width;
- box-shadow: inset 1px 0 0px 0px transparent;
- .TraceLeftColumnInner {
- height: 100%;
- white-space: nowrap;
- display: flex;
- align-items: center;
- will-change: transform;
- transform-origin: left center;
- 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;
- &: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%;
- }
- .TraceError {
- top: -1px;
- transform: translate(-50%, 0);
- }
- }
- }
- .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;
- &.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;
- 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 4px;
- 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: 8px;
- &.Errored {
- border: 2px solid ${p => p.theme.error};
- }
- .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;
- }
- &.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;
- }
- `;
|