1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344 |
- import type React from 'react';
- import {Fragment, useCallback, useLayoutEffect, useMemo, useRef, useState} from 'react';
- import {type Theme, useTheme} from '@emotion/react';
- import styled from '@emotion/styled';
- import * as Sentry from '@sentry/react';
- import {PlatformIcon} from 'platformicons';
- import * as qs from 'query-string';
- import LoadingIndicator from 'sentry/components/loadingIndicator';
- import Placeholder from 'sentry/components/placeholder';
- import {t, tct} from 'sentry/locale';
- import {space} from 'sentry/styles/space';
- import type {Organization, PlatformKey, Project} from 'sentry/types';
- import type {
- TraceError,
- TracePerformanceIssue,
- } from 'sentry/utils/performance/quickTrace/types';
- import {clamp} from 'sentry/utils/profiling/colors/utils';
- import useApi from 'sentry/utils/useApi';
- import useOrganization from 'sentry/utils/useOrganization';
- import useProjects from 'sentry/utils/useProjects';
- import {formatTraceDuration} from 'sentry/views/performance/newTraceDetails/formatters';
- import {
- useVirtualizedList,
- type VirtualizedRow,
- } from 'sentry/views/performance/newTraceDetails/traceRenderers/traceVirtualizedList';
- import type {VirtualizedViewManager} from 'sentry/views/performance/newTraceDetails/traceRenderers/virtualizedViewManager';
- import type {
- TraceReducerAction,
- TraceReducerState,
- } from 'sentry/views/performance/newTraceDetails/traceState';
- import {
- getRovingIndexActionFromDOMEvent,
- type RovingTabIndexUserActions,
- } from 'sentry/views/performance/newTraceDetails/traceState/traceRovingTabIndex';
- import {
- makeTraceNodeBarColor,
- ParentAutogroupNode,
- TraceTree,
- type TraceTreeNode,
- } from './traceModels/traceTree';
- import {
- isAutogroupedNode,
- isMissingInstrumentationNode,
- isNoDataNode,
- isParentAutogroupedNode,
- isSpanNode,
- isTraceErrorNode,
- isTraceNode,
- isTransactionNode,
- } from './guards';
- import {TraceIcons} from './icons';
- function decodeScrollQueue(maybePath: unknown): TraceTree.NodePath[] | null {
- if (Array.isArray(maybePath)) {
- return maybePath;
- }
- if (typeof maybePath === 'string') {
- return [maybePath as TraceTree.NodePath];
- }
- return null;
- }
- const COUNT_FORMATTER = Intl.NumberFormat(undefined, {notation: 'compact'});
- const NO_ERRORS = new Set<TraceError>();
- const NO_PERFORMANCE_ISSUES = new Set<TracePerformanceIssue>();
- const NO_PROFILES = [];
- function computeNextIndexFromAction(
- current_index: number,
- action: RovingTabIndexUserActions,
- items: number
- ): number {
- switch (action) {
- case 'next':
- if (current_index === items) {
- return 0;
- }
- return current_index + 1;
- case 'previous':
- if (current_index === 0) {
- return items;
- }
- return current_index - 1;
- case 'last':
- return items;
- case 'first':
- return 0;
- default:
- throw new TypeError(`Invalid or not implemented reducer action - ${action}`);
- }
- }
- const RIGHT_COLUMN_EVEN_CLASSNAME = `TraceRightColumn`;
- const RIGHT_COLUMN_ODD_CLASSNAME = [RIGHT_COLUMN_EVEN_CLASSNAME, 'Odd'].join(' ');
- const CHILDREN_COUNT_WRAPPER_CLASSNAME = `TraceChildrenCountWrapper`;
- const CHILDREN_COUNT_WRAPPER_ORPHANED_CLASSNAME = [
- CHILDREN_COUNT_WRAPPER_CLASSNAME,
- 'Orphaned',
- ].join(' ');
- function maybeFocusRow(
- ref: HTMLDivElement | null,
- node: TraceTreeNode<TraceTree.NodeValue>,
- previouslyFocusedNodeRef: React.MutableRefObject<TraceTreeNode<TraceTree.NodeValue> | null>
- ) {
- if (!ref) return;
- if (node === previouslyFocusedNodeRef.current) return;
- previouslyFocusedNodeRef.current = node;
- ref.focus();
- }
- interface TraceProps {
- forceRerender: number;
- manager: VirtualizedViewManager;
- onRowClick: (
- node: TraceTreeNode<TraceTree.NodeValue>,
- event: React.MouseEvent<HTMLElement>,
- index: number
- ) => void;
- onTraceLoad: (
- trace: TraceTree,
- node: TraceTreeNode<TraceTree.NodeValue> | null,
- index: number | null
- ) => void;
- onTraceSearch: (
- query: string,
- node: TraceTreeNode<TraceTree.NodeValue>,
- behavior: 'track result' | 'persist'
- ) => void;
- previouslyFocusedNodeRef: React.MutableRefObject<TraceTreeNode<TraceTree.NodeValue> | null>;
- rerender: () => void;
- scrollQueueRef: React.MutableRefObject<{
- eventId?: string;
- path?: TraceTree.NodePath[];
- } | null>;
- trace: TraceTree;
- trace_dispatch: React.Dispatch<TraceReducerAction>;
- trace_id: string;
- trace_state: TraceReducerState;
- }
- export function Trace({
- trace,
- trace_id,
- onRowClick,
- manager,
- scrollQueueRef,
- previouslyFocusedNodeRef,
- onTraceSearch,
- onTraceLoad,
- rerender,
- trace_state,
- trace_dispatch,
- forceRerender,
- }: TraceProps) {
- const theme = useTheme();
- const api = useApi();
- const {projects} = useProjects();
- const organization = useOrganization();
- const containerRef = useRef<HTMLDivElement | null>(null);
- const rerenderRef = useRef<TraceProps['rerender']>(rerender);
- rerenderRef.current = rerender;
- 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;
- const traceStateRef = useRef<TraceReducerState>(trace_state);
- traceStateRef.current = trace_state;
- if (
- trace.root.space &&
- (trace.root.space[0] !== manager.to_origin ||
- trace.root.space[1] !== manager.trace_space.width)
- ) {
- manager.initializeTraceSpace([trace.root.space[0], 0, trace.root.space[1], 1]);
- const maybeQueue = decodeScrollQueue(qs.parse(location.search).node);
- const maybeEventId = qs.parse(location.search)?.eventId;
- if (maybeQueue || maybeEventId) {
- scrollQueueRef.current = {
- eventId: maybeEventId as string,
- path: maybeQueue as TraceTreeNode<TraceTree.NodeValue>['path'],
- };
- }
- }
- const loadedRef = useRef(false);
- useLayoutEffect(() => {
- if (loadedRef.current) {
- return;
- }
- if (trace.type !== 'trace' || !manager) {
- return;
- }
- loadedRef.current = true;
- if (!scrollQueueRef.current) {
- onTraceLoad(trace, null, null);
- return;
- }
- // Node path has higher specificity than eventId
- const promise = scrollQueueRef.current?.path
- ? TraceTree.ExpandToPath(trace, scrollQueueRef.current.path, rerenderRef.current, {
- api,
- organization,
- })
- : scrollQueueRef.current.eventId
- ? TraceTree.ExpandToEventID(
- scrollQueueRef?.current?.eventId,
- trace,
- rerenderRef.current,
- {
- api,
- organization,
- }
- )
- : Promise.resolve(null);
- promise
- .then(maybeNode => {
- onTraceLoad(trace, maybeNode?.node ?? null, maybeNode?.index ?? null);
- if (!maybeNode) {
- Sentry.captureMessage('Failed to find and scroll to node in tree');
- return;
- }
- })
- .finally(() => {
- // Important to set scrollQueueRef.current to null and trigger a rerender
- // after the promise resolves as we show a loading state during scroll,
- // else the screen could jump around while we fetch span data
- scrollQueueRef.current = null;
- rerenderRef.current();
- });
- }, [
- api,
- trace,
- trace_id,
- manager,
- onTraceLoad,
- trace_dispatch,
- scrollQueueRef,
- organization,
- ]);
- const onNodeZoomIn = useCallback(
- (
- event: React.MouseEvent<Element> | React.KeyboardEvent<Element>,
- node: TraceTreeNode<TraceTree.NodeValue>,
- value: boolean
- ) => {
- if (!isTransactionNode(node) && !isSpanNode(node)) {
- throw new TypeError('Node must be a transaction or span');
- }
- event.stopPropagation();
- rerenderRef.current();
- treeRef.current
- .zoomIn(node, value, {
- api,
- organization,
- })
- .then(() => {
- rerenderRef.current();
- // If a query exists, we want to reapply the search after zooming in
- // so that new nodes are also highlighted if they match a query
- if (traceStateRef.current.search.query) {
- onTraceSearch(traceStateRef.current.search.query, node, 'persist');
- }
- treePromiseStatusRef.current!.set(node, 'success');
- })
- .catch(_e => {
- treePromiseStatusRef.current!.set(node, 'error');
- });
- },
- [api, organization, onTraceSearch]
- );
- const onNodeExpand = useCallback(
- (
- event: React.MouseEvent<Element> | React.KeyboardEvent<Element>,
- node: TraceTreeNode<TraceTree.NodeValue>,
- value: boolean
- ) => {
- event.stopPropagation();
- treeRef.current.expand(node, value);
- rerenderRef.current();
- if (traceStateRef.current.search.query) {
- // If a query exists, we want to reapply the search after expanding
- // so that new nodes are also highlighted if they match a query
- onTraceSearch(traceStateRef.current.search.query, node, 'persist');
- }
- },
- [onTraceSearch]
- );
- const onRowKeyDown = useCallback(
- (
- event: React.KeyboardEvent,
- index: number,
- node: TraceTreeNode<TraceTree.NodeValue>
- ) => {
- if (!manager.list) {
- return;
- }
- const action = getRovingIndexActionFromDOMEvent(event);
- if (action) {
- event.preventDefault();
- const nextIndex = computeNextIndexFromAction(
- index,
- action,
- treeRef.current.list.length - 1
- );
- trace_dispatch({
- type: 'set roving index',
- index: nextIndex,
- node: treeRef.current.list[nextIndex],
- action_source: 'keyboard',
- });
- }
- if (event.key === 'ArrowLeft') {
- if (node.zoomedIn) onNodeZoomIn(event, node, false);
- else if (node.expanded) onNodeExpand(event, node, false);
- } else if (event.key === 'ArrowRight') {
- if (!node.expanded) onNodeExpand(event, node, true);
- else if (node.expanded && node.canFetch) onNodeZoomIn(event, node, true);
- }
- },
- [manager, onNodeExpand, onNodeZoomIn, trace_dispatch]
- );
- const projectLookup: Record<string, PlatformKey | undefined> = useMemo(() => {
- return projects.reduce<Record<Project['slug'], Project['platform']>>(
- (acc, project) => {
- acc[project.slug] = project.platform;
- return acc;
- },
- {}
- );
- }, [projects]);
- const renderLoadingRow = useCallback(
- (n: VirtualizedRow) => {
- return (
- <RenderPlaceholderRow
- key={n.key}
- index={n.index}
- style={n.style}
- node={n.item}
- theme={theme}
- manager={manager}
- />
- );
- },
- [manager, theme]
- );
- const renderVirtualizedRow = useCallback(
- (n: VirtualizedRow) => {
- return (
- <RenderRow
- key={n.key}
- index={n.index}
- organization={organization}
- previouslyFocusedNodeRef={previouslyFocusedNodeRef}
- tabIndex={trace_state.rovingTabIndex.node === n.item ? 0 : -1}
- isSearchResult={trace_state.search.resultsLookup.has(n.item)}
- searchResultsIteratorIndex={trace_state.search.resultIndex}
- style={n.style}
- trace_id={trace_id}
- projects={projectLookup}
- node={n.item}
- manager={manager}
- theme={theme}
- onExpand={onNodeExpand}
- onZoomIn={onNodeZoomIn}
- onRowClick={onRowClick}
- onRowKeyDown={onRowKeyDown}
- />
- );
- },
- // we add forceRerender as a "unnecessary" dependency to trigger the virtualized list rerender
- // eslint-disable-next-line react-hooks/exhaustive-deps
- [
- onNodeExpand,
- onNodeZoomIn,
- manager,
- scrollQueueRef,
- previouslyFocusedNodeRef,
- onRowKeyDown,
- onRowClick,
- organization,
- projectLookup,
- trace_state.rovingTabIndex.node,
- trace_state.search.resultIteratorIndex,
- trace_state.search.resultsLookup,
- trace_state.search.resultIndex,
- theme,
- trace_id,
- trace.type,
- forceRerender,
- ]
- );
- const render = useMemo(() => {
- return trace.type !== 'trace' || scrollQueueRef.current
- ? r => renderLoadingRow(r)
- : r => renderVirtualizedRow(r);
- }, [renderLoadingRow, renderVirtualizedRow, trace.type, scrollQueueRef]);
- const [scrollContainer, setScrollContainer] = useState<HTMLElement | null>(null);
- const virtualizedList = useVirtualizedList({
- manager,
- items: trace.list,
- container: scrollContainer,
- render: render,
- });
- return (
- <TraceStylingWrapper
- ref={r => {
- containerRef.current = r;
- manager.registerContainerRef(r);
- }}
- className={`${trace.indicators.length > 0 ? 'WithIndicators' : ''} ${trace.type !== 'trace' || scrollQueueRef.current ? 'Loading' : ''}`}
- >
- <div
- className="TraceScrollbarContainer"
- ref={r => manager.registerHorizontalScrollBarContainerRef(r)}
- >
- <div className="TraceScrollbarScroller" />
- </div>
- <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 ${indicator.poor ? 'Errored' : ''}`}
- >
- <div className="TraceIndicatorLabel">{indicator.label}</div>
- <div className="TraceIndicatorLine" />
- </div>
- );
- })
- : null}
- {manager.interval_bars.map((_, i) => {
- const indicatorTimestamp = manager.intervals[i] ?? 0;
- const timestamp = manager.to_origin + indicatorTimestamp;
- 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
- ? formatTraceDuration(manager.trace_view.x + indicatorTimestamp)
- : '0s'}
- </div>
- <div className="TraceIndicatorLine" />
- </div>
- );
- })}
- </div>
- <div
- ref={r => setScrollContainer(r)}
- data-test-id="trace-virtualized-list-scroll-container"
- >
- <div data-test-id="trace-virtualized-list">{virtualizedList.rendered}</div>
- <div className="TraceRow Hidden">
- <div
- className="TraceLeftColumn"
- ref={r => manager.registerGhostRowRef('list', r)}
- />
- <div
- className="TraceRightColumn"
- ref={r => manager.registerGhostRowRef('span_list', r)}
- />
- </div>
- </div>
- </TraceStylingWrapper>
- );
- }
- 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: (
- node: TraceTreeNode<TraceTree.NodeValue>,
- event: React.MouseEvent<HTMLElement>,
- index: number
- ) => 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;
- previouslyFocusedNodeRef: React.MutableRefObject<TraceTreeNode<TraceTree.NodeValue> | null>;
- projects: Record<Project['slug'], Project['platform']>;
- searchResultsIteratorIndex: number | null;
- style: React.CSSProperties;
- tabIndex: number;
- theme: Theme;
- trace_id: string;
- }) {
- const virtualized_index = props.index - props.manager.start_virtualized_index;
- const rowSearchClassName = `${props.isSearchResult ? 'SearchResult' : ''} ${props.searchResultsIteratorIndex === props.index ? 'Highlight' : ''}`;
- if (isAutogroupedNode(props.node)) {
- return (
- <div
- key={props.index}
- ref={r =>
- props.tabIndex === 0
- ? maybeFocusRow(r, props.node, props.previouslyFocusedNodeRef)
- : null
- }
- tabIndex={props.tabIndex}
- className={`Autogrouped TraceRow ${rowSearchClassName} ${props.node.has_errors ? 'Errored' : ''}`}
- onClick={e => props.onRowClick(props.node, e, props.index)}
- 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)
- }
- >
- <div
- className={`TraceLeftColumnInner`}
- style={{
- paddingLeft: props.node.depth * props.manager.row_depth_padding,
- }}
- >
- <div className="TraceChildrenCountWrapper">
- <Connectors node={props.node} manager={props.manager} />
- <ChildrenButton
- icon={
- <TraceIcons.Chevron direction={props.node.expanded ? 'up' : 'down'} />
- }
- status={props.node.fetchStatus}
- expanded={!props.node.expanded}
- onClick={e => props.onExpand(e, props.node, !props.node.expanded)}
- errored={props.node.has_errors}
- >
- {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={
- props.index % 2 === 1
- ? RIGHT_COLUMN_ODD_CLASSNAME
- : RIGHT_COLUMN_EVEN_CLASSNAME
- }
- ref={r =>
- props.manager.registerColumnRef('span_list', r, virtualized_index, props.node)
- }
- onDoubleClick={e => {
- e.stopPropagation();
- props.manager.onZoomIntoSpace(props.node.space!);
- }}
- >
- <AutogroupedTraceBar
- virtualized_index={virtualized_index}
- manager={props.manager}
- color={makeTraceNodeBarColor(props.theme, props.node)}
- entire_space={props.node.space}
- node_spaces={props.node.autogroupedSegments}
- errors={props.node.errors}
- performance_issues={props.node.performance_issues}
- profiles={props.node.profiles}
- />
- <button
- ref={ref =>
- props.manager.registerArrowRef(ref, props.node.space!, virtualized_index)
- }
- className="TraceArrow"
- onClick={_e => {
- props.manager.onBringRowIntoView(props.node.space!);
- }}
- >
- <TraceIcons.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 === 0
- ? maybeFocusRow(r, props.node, props.previouslyFocusedNodeRef)
- : null
- }
- tabIndex={props.tabIndex}
- className={`TraceRow ${rowSearchClassName} ${errored ? 'Errored' : ''}`}
- onClick={e => props.onRowClick(props.node, e, props.index)}
- 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)
- }
- >
- <div
- className={`TraceLeftColumnInner`}
- style={{
- paddingLeft: props.node.depth * props.manager.row_depth_padding,
- }}
- >
- <div
- className={
- props.node.isOrphaned
- ? CHILDREN_COUNT_WRAPPER_ORPHANED_CLASSNAME
- : CHILDREN_COUNT_WRAPPER_CLASSNAME
- }
- >
- <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 ? (
- <TraceIcons.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={
- props.index % 2 === 1
- ? RIGHT_COLUMN_ODD_CLASSNAME
- : RIGHT_COLUMN_EVEN_CLASSNAME
- }
- onDoubleClick={e => {
- e.stopPropagation();
- props.manager.onZoomIntoSpace(props.node.space!);
- }}
- >
- <TraceBar
- virtualized_index={virtualized_index}
- manager={props.manager}
- color={makeTraceNodeBarColor(props.theme, props.node)}
- node_space={props.node.space}
- errors={props.node.errors}
- performance_issues={props.node.performance_issues}
- profiles={props.node.profiles}
- />
- <button
- ref={ref =>
- props.manager.registerArrowRef(ref, props.node.space!, virtualized_index)
- }
- className="TraceArrow"
- onClick={_e => {
- props.manager.onBringRowIntoView(props.node.space!);
- }}
- >
- <TraceIcons.Chevron direction="left" />
- </button>
- </div>
- </div>
- );
- }
- if (isSpanNode(props.node)) {
- const errored = props.node.errors.size > 0 || props.node.performance_issues.size > 0;
- return (
- <div
- key={props.index}
- ref={r =>
- props.tabIndex === 0
- ? maybeFocusRow(r, props.node, props.previouslyFocusedNodeRef)
- : null
- }
- tabIndex={props.tabIndex}
- className={`TraceRow ${rowSearchClassName} ${errored ? 'Errored' : ''}`}
- onClick={e => props.onRowClick(props.node, e, props.index)}
- 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)
- }
- >
- <div
- className={`TraceLeftColumnInner`}
- style={{
- paddingLeft: props.node.depth * props.manager.row_depth_padding,
- }}
- >
- <div
- className={
- props.node.isOrphaned
- ? CHILDREN_COUNT_WRAPPER_ORPHANED_CLASSNAME
- : CHILDREN_COUNT_WRAPPER_CLASSNAME
- }
- >
- <Connectors node={props.node} manager={props.manager} />
- {props.node.children.length > 0 || props.node.canFetch ? (
- <ChildrenButton
- icon={
- props.node.canFetch ? (
- '+'
- ) : (
- <TraceIcons.Chevron
- direction={props.node.expanded ? 'up' : '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
- ? props.node.value.span_id ?? 'unknown'
- : props.node.value.description.length > 100
- ? props.node.value.description.slice(0, 100).trim() + '\u2026'
- : props.node.value.description}
- </span>
- </div>
- </div>
- <div
- ref={r =>
- props.manager.registerColumnRef('span_list', r, virtualized_index, props.node)
- }
- className={
- props.index % 2 === 1
- ? RIGHT_COLUMN_ODD_CLASSNAME
- : RIGHT_COLUMN_EVEN_CLASSNAME
- }
- onDoubleClick={e => {
- e.stopPropagation();
- props.manager.onZoomIntoSpace(props.node.space!);
- }}
- >
- <TraceBar
- virtualized_index={virtualized_index}
- manager={props.manager}
- color={makeTraceNodeBarColor(props.theme, props.node)}
- node_space={props.node.space}
- errors={props.node.errors}
- performance_issues={props.node.performance_issues}
- profiles={NO_PROFILES}
- />
- <button
- ref={ref =>
- props.manager.registerArrowRef(ref, props.node.space!, virtualized_index)
- }
- className="TraceArrow"
- onClick={_e => {
- props.manager.onBringRowIntoView(props.node.space!);
- }}
- >
- <TraceIcons.Chevron direction="left" />
- </button>
- </div>
- </div>
- );
- }
- if (isMissingInstrumentationNode(props.node)) {
- return (
- <div
- key={props.index}
- ref={r =>
- props.tabIndex === 0
- ? maybeFocusRow(r, props.node, props.previouslyFocusedNodeRef)
- : null
- }
- tabIndex={props.tabIndex}
- className={`TraceRow ${rowSearchClassName}`}
- onClick={e => props.onRowClick(props.node, e, props.index)}
- 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)
- }
- >
- <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={
- props.index % 2 === 1
- ? RIGHT_COLUMN_ODD_CLASSNAME
- : RIGHT_COLUMN_EVEN_CLASSNAME
- }
- onDoubleClick={e => {
- e.stopPropagation();
- props.manager.onZoomIntoSpace(props.node.space!);
- }}
- >
- <TraceBar
- virtualized_index={virtualized_index}
- manager={props.manager}
- color={makeTraceNodeBarColor(props.theme, props.node)}
- node_space={props.node.space}
- performance_issues={NO_PERFORMANCE_ISSUES}
- profiles={NO_PROFILES}
- errors={NO_ERRORS}
- />
- <button
- ref={ref =>
- props.manager.registerArrowRef(ref, props.node.space!, virtualized_index)
- }
- className="TraceArrow"
- onClick={_e => {
- props.manager.onBringRowIntoView(props.node.space!);
- }}
- >
- <TraceIcons.Chevron direction="left" />
- </button>
- </div>
- </div>
- );
- }
- if (isTraceNode(props.node)) {
- return (
- <div
- key={props.index}
- ref={r =>
- props.tabIndex === 0
- ? maybeFocusRow(r, props.node, props.previouslyFocusedNodeRef)
- : null
- }
- tabIndex={props.tabIndex}
- className={`TraceRow ${rowSearchClassName} ${props.node.has_errors ? 'Errored' : ''}`}
- onClick={e => props.onRowClick(props.node, e, props.index)}
- 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)
- }
- >
- <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={
- props.index % 2 === 1
- ? RIGHT_COLUMN_ODD_CLASSNAME
- : RIGHT_COLUMN_EVEN_CLASSNAME
- }
- onDoubleClick={e => {
- e.stopPropagation();
- props.manager.onZoomIntoSpace(props.node.space!);
- }}
- >
- <TraceBar
- virtualized_index={virtualized_index}
- manager={props.manager}
- color={makeTraceNodeBarColor(props.theme, props.node)}
- node_space={props.node.space}
- errors={NO_ERRORS}
- performance_issues={NO_PERFORMANCE_ISSUES}
- profiles={NO_PROFILES}
- />
- <button
- ref={ref =>
- props.manager.registerArrowRef(ref, props.node.space!, virtualized_index)
- }
- className="TraceArrow"
- onClick={_e => {
- props.manager.onBringRowIntoView(props.node.space!);
- }}
- >
- <TraceIcons.Chevron direction="left" />
- </button>
- </div>
- </div>
- );
- }
- if (isTraceErrorNode(props.node)) {
- return (
- <div
- key={props.index}
- ref={r =>
- props.tabIndex === 0
- ? maybeFocusRow(r, props.node, props.previouslyFocusedNodeRef)
- : null
- }
- tabIndex={props.tabIndex}
- className={`TraceRow ${rowSearchClassName} Errored`}
- onClick={e => props.onRowClick(props.node, e, props.index)}
- 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)
- }
- >
- <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">{t('Error')}</span>
- <strong className="TraceEmDash"> — </strong>
- <span className="TraceDescription">{props.node.value.title}</span>
- </div>
- </div>
- <div
- ref={r =>
- props.manager.registerColumnRef('span_list', r, virtualized_index, props.node)
- }
- className={
- props.index % 2 === 1
- ? RIGHT_COLUMN_ODD_CLASSNAME
- : RIGHT_COLUMN_EVEN_CLASSNAME
- }
- 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">
- <TraceIcons.Fire />
- </div>
- ) : null}
- </InvisibleTraceBar>
- </div>
- </div>
- );
- }
- if (isNoDataNode(props.node)) {
- return (
- <div
- key={props.index}
- ref={r =>
- props.tabIndex === 0
- ? maybeFocusRow(r, props.node, props.previouslyFocusedNodeRef)
- : null
- }
- tabIndex={props.tabIndex}
- className={`TraceRow ${rowSearchClassName}`}
- onClick={e => props.onRowClick(props.node, e, props.index)}
- 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)
- }
- >
- <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('Empty')}</span>{' '}
- <strong className="TraceEmDash"> — </strong>
- <span className="TraceDescription">
- {tct('[type] did not report any span data', {
- type: props.node.parent
- ? isTransactionNode(props.node.parent)
- ? 'Transaction'
- : isSpanNode(props.node.parent)
- ? 'Span'
- : ''
- : '',
- })}
- </span>
- </div>
- </div>
- <div
- ref={r =>
- props.manager.registerColumnRef('span_list', r, virtualized_index, props.node)
- }
- className={
- props.index % 2 === 1
- ? RIGHT_COLUMN_ODD_CLASSNAME
- : RIGHT_COLUMN_EVEN_CLASSNAME
- }
- />
- </div>
- );
- }
- return null;
- }
- function RenderPlaceholderRow(props: {
- index: number;
- manager: VirtualizedViewManager;
- node: TraceTreeNode<TraceTree.NodeValue>;
- 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={
- props.index % 2 === 1 ? RIGHT_COLUMN_ODD_CLASSNAME : RIGHT_COLUMN_EVEN_CLASSNAME
- }
- style={{
- width: props.manager.columns.span_list.width * 100 + '%',
- }}
- >
- <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>['errors'];
- manager: VirtualizedViewManager;
- node_space: [number, number] | null;
- performance_issues: TraceTreeNode<TraceTree.Transaction>['performance_issues'];
- profiles: TraceTreeNode<TraceTree.NodeValue>['profiles'];
- virtualized_index: number;
- }
- function TraceBar(props: TraceBarProps) {
- if (!props.node_space) {
- return null;
- }
- const duration = formatTraceDuration(props.node_space[1]);
- 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.profiles.length > 0 ? (
- <Profiles
- node_space={props.node_space}
- profiles={props.profiles}
- manager={props.manager}
- />
- ) : null}
- {props.errors.size > 0 ? (
- <Errors
- node_space={props.node_space}
- errors={props.errors}
- manager={props.manager}
- />
- ) : null}
- {props.performance_issues.size > 0 ? (
- <PerformanceIssues
- node_space={props.node_space}
- performance_issues={props.performance_issues}
- manager={props.manager}
- />
- ) : null}
- </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 spanTransform = `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: spanTransform,
- // undefined css variables break style rules
- '--inverse-span-scale': 1,
- // unknown css variables cannot be part of the style object
- } as React.CSSProperties
- }
- onDoubleClick={e => {
- e.stopPropagation();
- props.manager.onZoomIntoSpace(props.node_space!);
- }}
- >
- {props.children}
- </div>
- );
- }
- interface PerformanceIssuesProps {
- manager: VirtualizedViewManager;
- node_space: [number, number] | null;
- performance_issues: TraceTreeNode<TraceTree.Transaction>['performance_issues'];
- }
- function PerformanceIssues(props: PerformanceIssuesProps) {
- const performance_issues = useMemo(() => {
- return [...props.performance_issues];
- }, [props.performance_issues]);
- if (!props.performance_issues.size) {
- return null;
- }
- return (
- <Fragment>
- {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}}>
- <TraceIcons.Fire />
- </div>
- </div>
- );
- })}
- </Fragment>
- );
- }
- interface ErrorsProps {
- errors: TraceTreeNode<TraceTree.Transaction>['errors'];
- manager: VirtualizedViewManager;
- node_space: [number, number] | null;
- }
- function Errors(props: ErrorsProps) {
- const errors = useMemo(() => {
- return [...props.errors];
- }, [props.errors]);
- if (!props.errors.size) {
- return null;
- }
- return (
- <Fragment>
- {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 + '%'}}
- >
- <TraceIcons.Fire />
- </div>
- );
- })}
- </Fragment>
- );
- }
- interface ProfilesProps {
- manager: VirtualizedViewManager;
- node_space: [number, number] | null;
- profiles: TraceTree.Profile[];
- }
- function Profiles(props: ProfilesProps) {
- if (!props.profiles.length) {
- return null;
- }
- return (
- <Fragment>
- {props.profiles.map((profile, _i) => {
- const timestamp = profile.space[0];
- // Clamp the profile timestamp to the span's timestamp
- const left = props.manager.computeRelativeLeftPositionFromOrigin(
- clamp(
- timestamp,
- props.node_space![0],
- props.node_space![0] + props.node_space![1]
- ),
- props.node_space!
- );
- return (
- <div
- key={profile.profile_id}
- className="TraceProfile"
- style={{left: left * 100 + '%'}}
- >
- <TraceIcons.Profile />
- </div>
- );
- })}
- </Fragment>
- );
- }
- interface AutogroupedTraceBarProps {
- color: string;
- entire_space: [number, number] | null;
- errors: TraceTreeNode<TraceTree.Transaction>['errors'];
- manager: VirtualizedViewManager;
- node_spaces: [number, number][];
- performance_issues: TraceTreeNode<TraceTree.Transaction>['performance_issues'];
- profiles: TraceTreeNode<TraceTree.NodeValue>['profiles'];
- virtualized_index: 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}
- errors={props.errors}
- performance_issues={props.performance_issues}
- profiles={props.profiles}
- />
- );
- }
- if (!props.node_spaces || !props.entire_space) {
- return null;
- }
- const duration = formatTraceDuration(props.entire_space[1]);
- 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 * 100}%`,
- width: `${width * 100}%`,
- backgroundColor: props.color,
- }}
- />
- );
- })}
- {props.profiles.length > 0 ? (
- <Profiles
- node_space={props.entire_space}
- profiles={props.profiles}
- manager={props.manager}
- />
- ) : null}
- {props.errors.size > 0 ? (
- <Errors
- node_space={props.entire_space}
- errors={props.errors}
- manager={props.manager}
- />
- ) : null}
- {props.performance_issues.size > 0 ? (
- <PerformanceIssues
- node_space={props.entire_space}
- performance_issues={props.performance_issues}
- manager={props.manager}
- />
- ) : null}
- </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: 26px;
- &.WithIndicators {
- padding-top: 44px;
- &:before {
- height: 44px;
- .TraceScrollbarContainer {
- height: 44px;
- }
- }
- .TraceIndicator.Timeline {
- .TraceIndicatorLabel {
- top: 26px;
- }
- .TraceIndicatorLine {
- top: 30px;
- }
- }
- }
- &:before {
- content: '';
- position: absolute;
- left: 0;
- top: 0;
- width: 100%;
- height: 26px;
- background-color: ${p => p.theme.backgroundSecondary};
- border-bottom: 1px solid ${p => p.theme.border};
- }
- &.Loading {
- .TraceRow {
- .TraceLeftColumnInner {
- width: 100%;
- }
- }
- .TraceRightColumn {
- background-color: transparent !important;
- }
- .TraceDivider {
- pointer-events: none;
- }
- }
- .TraceScrollbarContainer {
- left: 0;
- top: 0;
- height: 26px;
- position: absolute;
- overflow-x: auto;
- overscroll-behavior: none;
- will-change: transform;
- .TraceScrollbarScroller {
- height: 1px;
- pointer-events: none;
- visibility: hidden;
- }
- .TraceScrollbarHandle {
- width: 24px;
- height: 12px;
- border-radius: 6px;
- }
- }
- .TraceDivider {
- position: absolute;
- height: 100%;
- background-color: transparent;
- top: 0;
- cursor: col-resize;
- z-index: 10;
- transform: translateX(calc(var(--translate-x) * 1px));
- &: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;
- transform: translateX(calc(var(--translate-x) * 1px));
- z-index: 10;
- pointer-events: none;
- }
- .TraceIndicator {
- z-index: 1;
- width: 3px;
- height: 100%;
- top: 0;
- position: absolute;
- .TraceIndicatorLabel {
- min-width: 34px;
- text-align: center;
- position: absolute;
- font-size: 10px;
- font-weight: bold;
- color: ${p => p.theme.textColor};
- background-color: ${p => p.theme.background};
- border-radius: ${p => p.theme.borderRadius};
- border: 1px solid ${p => p.theme.border};
- padding: 2px;
- display: inline-block;
- line-height: 1;
- margin-top: 2px;
- white-space: nowrap;
- }
- .TraceIndicatorLine {
- width: 1px;
- height: 100%;
- top: 20px;
- position: absolute;
- left: 50%;
- transform: translateX(-2px);
- background: repeating-linear-gradient(
- to bottom,
- transparent 0 4px,
- ${p => p.theme.textColor} 4px 8px
- )
- 80%/2px 100% no-repeat;
- }
- &.Errored {
- .TraceIndicatorLabel {
- border: 1px solid ${p => p.theme.error};
- color: ${p => p.theme.error};
- }
- .TraceIndicatorLine {
- background: repeating-linear-gradient(
- to bottom,
- transparent 0 4px,
- ${p => p.theme.error} 4px 8px
- )
- 80%/2px 100% no-repeat;
- }
- }
- &.Timeline {
- opacity: 1;
- z-index: 1;
- pointer-events: none;
- .TraceIndicatorLabel {
- font-weight: normal;
- min-width: 0;
- top: 8px;
- width: auto;
- border: none;
- background-color: transparent;
- color: ${p => p.theme.subText};
- }
- .TraceIndicatorLine {
- background: ${p => p.theme.translucentGray100};
- top: 8px;
- }
- }
- }
- .TraceRow {
- display: flex;
- align-items: center;
- position: absolute;
- height: 24px;
- width: 100%;
- transition: none;
- font-size: ${p => p.theme.fontSizeSmall};
- --row-background-odd: ${p => p.theme.translucentSurface100};
- --row-background-hover: ${p => p.theme.translucentSurface100};
- --row-background-focused: ${p => p.theme.translucentSurface200};
- &.Hidden {
- position: absolute;
- height: 100%;
- width: 100%;
- top: 0;
- z-index: -1;
- &:hover {
- background-color: transparent;
- }
- * {
- cursor: default !important;
- }
- }
- .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};
- }
- }
- .TraceProfile {
- 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.purple300};
- border-radius: 50%;
- display: flex;
- align-items: center;
- justify-content: center;
- svg {
- width: 12px;
- height: 12px;
- margin-left: 2px;
- 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: var(--row-background-odd);
- }
- &:hover {
- background-color: var(--row-background-hovered);
- }
- &.Highlight {
- box-shadow: inset 0 0 0 1px ${p => p.theme.blue200} !important;
- .TraceLeftColumn {
- box-shadow: inset 0px 0 0px 1px ${p => p.theme.blue200} !important;
- }
- }
- &.Highlight,
- &:focus,
- &[tabindex='0'] {
- outline: none;
- background-color: var(--row-background-focused);
- .TraceRightColumn.Odd {
- background-color: transparent !important;
- }
- }
- &:focus,
- &[tabindex='0'] {
- background-color: var(--row-background-focused);
- box-shadow: inset 0 0 0 1px ${p => p.theme.blue300} !important;
- .TraceLeftColumn {
- box-shadow: inset 0px 0 0px 1px ${p => p.theme.blue300} !important;
- }
- .TraceRightColumn.Odd {
- background-color: transparent !important;
- }
- }
- &.Errored {
- color: ${p => p.theme.error};
- .TraceChildrenCount {
- border: 2px solid ${p => p.theme.error};
- svg {
- fill: ${p => p.theme.error};
- }
- }
- &:focus {
- box-shadow: inset 0 0 0 1px ${p => p.theme.red300} !important;
- .TraceLeftColumn {
- box-shadow: inset 0px 0 0px 1px ${p => p.theme.red300} !important;
- }
- }
- }
- &.SearchResult {
- background-color: ${p => p.theme.yellow100};
- .TraceRightColumn {
- background-color: transparent;
- }
- }
- &.Autogrouped {
- color: ${p => p.theme.blue300};
- &.Errored {
- .TraceChildrenCount {
- background-color: ${p => p.theme.error} !important;
- }
- }
- .TraceDescription {
- font-weight: bold;
- }
- .TraceChildrenCountWrapper {
- button {
- color: ${p => p.theme.white};
- background-color: ${p => p.theme.blue300};
- }
- svg {
- fill: ${p => p.theme.white};
- }
- }
- }
- }
- .TraceLeftColumn {
- height: 100%;
- white-space: nowrap;
- display: flex;
- align-items: center;
- overflow: hidden;
- will-change: width;
- box-shadow: inset 1px 0 0px 0px transparent;
- cursor: pointer;
- width: calc(var(--list-column-width) * 100%);
- .TraceLeftColumnInner {
- height: 100%;
- white-space: nowrap;
- display: flex;
- align-items: center;
- will-change: transform;
- transform-origin: left center;
- padding-right: ${space(2)};
- img {
- width: 16px;
- height: 16px;
- }
- }
- }
- .TraceRightColumn {
- height: 100%;
- overflow: hidden;
- position: relative;
- display: flex;
- align-items: center;
- will-change: width;
- z-index: 1;
- cursor: pointer;
- width: calc(var(--span-column-width) * 100%);
- &:hover {
- .TraceArrow.Visible {
- opacity: 1;
- transition: 300ms 300ms ease-out;
- pointer-events: auto;
- }
- }
- }
- .TraceBar {
- position: absolute;
- height: 16px;
- width: 100%;
- background-color: black;
- transform-origin: left center;
- &.Invisible {
- background-color: transparent !important;
- > div {
- height: 100%;
- }
- }
- svg {
- width: 14px;
- height: 14px;
- }
- }
- .TraceArrow {
- position: absolute;
- pointer-events: none;
- top: 0;
- width: 14px;
- height: 24px;
- opacity: 0;
- background-color: transparent;
- border: none;
- transition: 60ms ease-out;
- font-size: ${p => p.theme.fontSizeMedium};
- color: ${p => p.theme.subText};
- padding: 0 2px;
- display: flex;
- align-items: center;
- svg {
- fill: ${p => p.theme.subText};
- }
- &.Left {
- left: 0;
- }
- &.Right {
- right: 0;
- transform: rotate(180deg);
- }
- }
- .TraceBarDuration {
- display: inline-block;
- transform-origin: left center;
- font-size: ${p => p.theme.fontSizeExtraSmall};
- color: ${p => p.theme.gray300};
- white-space: nowrap;
- font-variant-numeric: tabular-nums;
- position: absolute;
- }
- .TraceChildrenCount {
- height: 16px;
- white-space: nowrap;
- min-width: 30px;
- display: flex;
- align-items: center;
- justify-content: center;
- border-radius: 99px;
- padding: 0px 4px;
- transition: all 0.15s ease-in-out;
- background: ${p => p.theme.background};
- border: 2px solid ${p => p.theme.border};
- line-height: 0;
- z-index: 1;
- font-size: 10px;
- box-shadow: ${p => p.theme.dropShadowLight};
- margin-right: 8px;
- .TraceChildrenCountContent {
- + .TraceChildrenCountAction {
- margin-left: 2px;
- }
- }
- .TraceChildrenCountAction {
- position: relative;
- display: flex;
- align-items: center;
- justify-content: center;
- }
- .TraceActionsLoadingIndicator {
- margin: 0;
- position: absolute;
- top: 50%;
- left: 50%;
- transform: translate(-50%, -50%);
- background-color: ${p => p.theme.background};
- animation: show 0.1s ease-in-out forwards;
- @keyframes show {
- from {
- opacity: 0;
- transform: translate(-50%, -50%) scale(0.86);
- }
- to {
- opacity: 1;
- transform: translate(-50%, -50%) scale(1);
- }
- }
- .loading-indicator {
- border-width: 2px;
- }
- .loading-message {
- display: none;
- }
- }
- svg {
- width: 7px;
- transition: none;
- fill: ${p => p.theme.textColor};
- }
- }
- .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;
- }
- `;
|