Skip to content

Commit

Permalink
[APM] Improve span links navigation (#147426)
Browse files Browse the repository at this point in the history
  • Loading branch information
MiriamAparicio committed Dec 19, 2022
1 parent 5d81fc5 commit d1f26f5
Show file tree
Hide file tree
Showing 8 changed files with 126 additions and 78 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,10 @@ interface AccordionWaterfallProps {
waterfallItemId?: string;
waterfall: IWaterfall;
timelineMargins: Margins;
onClickWaterfallItem: (item: IWaterfallSpanOrTransaction) => void;
onClickWaterfallItem: (
item: IWaterfallSpanOrTransaction,
flyoutDetailTab: string
) => void;
showCriticalPath: boolean;
maxLevelOpen: number;
}
Expand Down Expand Up @@ -159,8 +162,8 @@ export function AccordionWaterfall(props: AccordionWaterfallProps) {
isSelected={item.id === waterfallItemId}
errorCount={errorCount}
marginLeftLevel={marginLeftLevel}
onClick={() => {
onClickWaterfallItem(item);
onClick={(flyoutDetailTab: string) => {
onClickWaterfallItem(item, flyoutDetailTab);
}}
segments={criticalPathSegmentsById[item.id]
?.filter((segment) => segment.self)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,21 @@ import { i18n } from '@kbn/i18n';
import React from 'react';
import { SpanLinksCount } from '../waterfall_helpers/waterfall_helpers';

type Props = SpanLinksCount & { id: string };
type Props = SpanLinksCount & {
id: string;
onClick: (flyoutDetailTab: string) => unknown;
};

export function SpanLinksBadge({ linkedParents, linkedChildren, id }: Props) {
export function SpanLinksBadge({
linkedParents,
linkedChildren,
id,
onClick,
}: Props) {
if (!linkedParents && !linkedChildren) {
return null;
}

const spanLinksFlyoutTab = 'span_links';
const total = linkedParents + linkedChildren;
return (
<EuiToolTip
Expand Down Expand Up @@ -47,7 +55,19 @@ export function SpanLinksBadge({ linkedParents, linkedChildren, id }: Props) {
</EuiFlexGroup>
}
>
<EuiBadge data-test-subj={`spanLinksBadge_${id}`}>
<EuiBadge
data-test-subj={`spanLinksBadge_${id}`}
onClick={(e: any) => {
e.stopPropagation();
onClick(spanLinksFlyoutTab);
}}
onClickAriaLabel={i18n.translate(
'xpack.apm.waterfall.spanLinks.badgeAriaLabel',
{
defaultMessage: 'Open span links details',
}
)}
>
{i18n.translate('xpack.apm.waterfall.spanLinks.badge', {
defaultMessage:
'{total} {total, plural, one {Span link} other {Span links}}',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,17 @@ const Container = euiStyled.div`
const toggleFlyout = ({
history,
item,
flyoutDetailTab,
}: {
history: History;
item?: IWaterfallItem;
flyoutDetailTab?: string;
}) => {
history.replace({
...history.location,
search: fromQuery({
...toQuery(location.search),
flyoutDetailTab: undefined,
flyoutDetailTab,
waterfallItemId: item?.id,
}),
});
Expand Down Expand Up @@ -152,9 +154,10 @@ export function Waterfall({
duration={duration}
waterfall={waterfall}
timelineMargins={timelineMargins}
onClickWaterfallItem={(item: IWaterfallItem) =>
toggleFlyout({ history, item })
}
onClickWaterfallItem={(
item: IWaterfallItem,
flyoutDetailTab: string
) => toggleFlyout({ history, item, flyoutDetailTab })}
showCriticalPath={showCriticalPath}
maxLevelOpen={maxLevelOpen}
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ interface Props {
traceId: string;
totalDuration?: number;
spanLinksCount: SpanLinksCount;
flyoutDetailTab?: string;
onClose: () => void;
}

Expand All @@ -107,6 +108,7 @@ export function SpanFlyout({
totalDuration,
onClose,
spanLinksCount,
flyoutDetailTab,
}: Props) {
const { data = INITIAL_DATA, status } = useFetcher(
(callApmApi) => {
Expand Down Expand Up @@ -171,6 +173,7 @@ export function SpanFlyout({
parentTransaction={parentTransaction}
totalDuration={totalDuration}
spanLinksCount={spanLinksCount}
flyoutDetailTab={flyoutDetailTab}
/>
)}
</EuiFlyoutBody>
Expand All @@ -184,11 +187,13 @@ function SpanFlyoutBody({
parentTransaction,
totalDuration,
spanLinksCount,
flyoutDetailTab,
}: {
span: Span;
parentTransaction?: Transaction;
totalDuration?: number;
spanLinksCount: SpanLinksCount;
flyoutDetailTab?: string;
}) {
const stackframes = span.span.stacktrace;
const codeLanguage = parentTransaction?.service.language?.name;
Expand All @@ -205,6 +210,46 @@ function SpanFlyoutBody({
spanId: span.span.id,
processorEvent: ProcessorEvent.span,
});

const tabs = [
{
id: 'metadata',
name: i18n.translate('xpack.apm.propertiesTable.tabs.metadataLabel', {
defaultMessage: 'Metadata',
}),
content: (
<Fragment>
<EuiSpacer size="m" />
<SpanMetadata spanId={span.span.id} />
</Fragment>
),
},
...(!isEmpty(stackframes)
? [
{
id: 'stack-trace',
name: i18n.translate(
'xpack.apm.transactionDetails.spanFlyout.stackTraceTabLabel',
{
defaultMessage: 'Stack Trace',
}
),
content: (
<Fragment>
<EuiSpacer size="l" />
<Stacktrace
stackframes={stackframes}
codeLanguage={codeLanguage}
/>
</Fragment>
),
},
]
: []),
...(spanLinksTabContent ? [spanLinksTabContent] : []),
];

const initialTab = tabs.find(({ id }) => id === flyoutDetailTab) ?? tabs[0];
return (
<>
<StickySpanProperties span={span} transaction={parentTransaction} />
Expand Down Expand Up @@ -270,48 +315,7 @@ function SpanFlyoutBody({
/>
<EuiHorizontalRule />
<SpanDatabase spanDb={spanDb} />
<EuiTabbedContent
tabs={[
{
id: 'metadata',
name: i18n.translate(
'xpack.apm.propertiesTable.tabs.metadataLabel',
{
defaultMessage: 'Metadata',
}
),
content: (
<Fragment>
<EuiSpacer size="m" />
<SpanMetadata spanId={span.span.id} />
</Fragment>
),
},
...(!isEmpty(stackframes)
? [
{
id: 'stack-trace',
name: i18n.translate(
'xpack.apm.transactionDetails.spanFlyout.stackTraceTabLabel',
{
defaultMessage: 'Stack Trace',
}
),
content: (
<Fragment>
<EuiSpacer size="l" />
<Stacktrace
stackframes={stackframes}
codeLanguage={codeLanguage}
/>
</Fragment>
),
},
]
: []),
...(spanLinksTabContent ? [spanLinksTabContent] : []),
]}
/>
<EuiTabbedContent tabs={tabs} initialSelectedTab={initialTab} />
</>
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ interface Props {
errorCount?: number;
rootTransactionDuration?: number;
spanLinksCount: SpanLinksCount;
flyoutDetailTab?: string;
}

export function TransactionFlyout({
Expand All @@ -47,6 +48,7 @@ export function TransactionFlyout({
errorCount = 0,
rootTransactionDuration,
spanLinksCount,
flyoutDetailTab,
}: Props) {
const { data: transaction, status } = useFetcher(
(callApmApi) => {
Expand Down Expand Up @@ -96,6 +98,7 @@ export function TransactionFlyout({
errorCount={errorCount}
rootTransactionDuration={rootTransactionDuration}
spanLinksCount={spanLinksCount}
flyoutDetailTab={flyoutDetailTab}
/>
)}
</EuiFlyoutBody>
Expand All @@ -109,11 +112,13 @@ function TransactionFlyoutBody({
errorCount,
rootTransactionDuration,
spanLinksCount,
flyoutDetailTab,
}: {
transaction: Transaction;
errorCount: number;
rootTransactionDuration?: number;
spanLinksCount: SpanLinksCount;
flyoutDetailTab?: string;
}) {
const spanLinksTabContent = getSpanLinksTabContent({
spanLinksCount,
Expand All @@ -122,6 +127,24 @@ function TransactionFlyoutBody({
processorEvent: ProcessorEvent.transaction,
});

const tabs = [
{
id: 'metadata',
name: i18n.translate('xpack.apm.propertiesTable.tabs.metadataLabel', {
defaultMessage: 'Metadata',
}),
content: (
<>
<EuiSpacer size="m" />
<TransactionMetadata transactionId={transaction.transaction.id} />
</>
),
},
...(spanLinksTabContent ? [spanLinksTabContent] : []),
];

const initialTab = tabs.find(({ id }) => id === flyoutDetailTab) ?? tabs[0];

return (
<>
<FlyoutTopLevelProperties transaction={transaction} />
Expand All @@ -134,28 +157,7 @@ function TransactionFlyoutBody({
/>
<EuiHorizontalRule margin="m" />
<DroppedSpansWarning transactionDoc={transaction} />
<EuiTabbedContent
tabs={[
{
id: 'metadata',
name: i18n.translate(
'xpack.apm.propertiesTable.tabs.metadataLabel',
{
defaultMessage: 'Metadata',
}
),
content: (
<>
<EuiSpacer size="m" />
<TransactionMetadata
transactionId={transaction.transaction.id}
/>
</>
),
},
...(spanLinksTabContent ? [spanLinksTabContent] : []),
]}
/>
<EuiTabbedContent initialSelectedTab={initialTab} tabs={tabs} />
</>
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,21 @@
import { History } from 'history';
import React from 'react';
import { useHistory } from 'react-router-dom';
import { useApmParams } from '../../../../../../hooks/use_apm_params';
import { SpanFlyout } from './span_flyout';
import { TransactionFlyout } from './transaction_flyout';
import { IWaterfall } from './waterfall_helpers/waterfall_helpers';

interface Props {
waterfallItemId?: string;
waterfall: IWaterfall;
toggleFlyout: ({ history }: { history: History }) => void;
toggleFlyout: ({
history,
flyoutDetailTab,
}: {
history: History;
flyoutDetailTab?: string;
}) => void;
}

export function WaterfallFlyout({
Expand All @@ -24,6 +31,9 @@ export function WaterfallFlyout({
toggleFlyout,
}: Props) {
const history = useHistory();
const {
query: { flyoutDetailTab },
} = useApmParams('/services/{serviceName}/transactions/view');
const currentItem = waterfall.items.find(
(item) => item.id === waterfallItemId
);
Expand All @@ -47,6 +57,7 @@ export function WaterfallFlyout({
traceId={currentItem.doc.trace.id}
onClose={() => toggleFlyout({ history })}
spanLinksCount={currentItem.spanLinksCount}
flyoutDetailTab={flyoutDetailTab}
/>
);
case 'transaction':
Expand All @@ -58,6 +69,7 @@ export function WaterfallFlyout({
rootTransactionDuration={waterfall.rootWaterfallTransaction?.duration}
errorCount={waterfall.getErrorCount(currentItem.id)}
spanLinksCount={currentItem.spanLinksCount}
flyoutDetailTab={flyoutDetailTab}
/>
);
default:
Expand Down
Loading

0 comments on commit d1f26f5

Please sign in to comment.