Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[APM] Adds "Logs" tab to transaction details for related trace logs #85859

Merged
merged 1 commit into from
Dec 15, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion x-pack/plugins/apm/kibana.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
"data",
"licensing",
"triggersActionsUi",
"embeddable"
"embeddable",
"infra"
],
"optionalPlugins": [
"cloud",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,27 +9,14 @@ import { i18n } from '@kbn/i18n';
import { Location } from 'history';
import React from 'react';
import { useHistory } from 'react-router-dom';
import { LogStream } from '../../../../../../infra/public';
import { Transaction } from '../../../../../typings/es_schemas/ui/transaction';
import type { IUrlParams } from '../../../../context/url_params_context/types';
import { fromQuery, toQuery } from '../../../shared/Links/url_helpers';
import { TransactionMetadata } from '../../../shared/MetadataTable/TransactionMetadata';
import { WaterfallContainer } from './WaterfallContainer';
import { IWaterfall } from './WaterfallContainer/Waterfall/waterfall_helpers/waterfall_helpers';

const timelineTab = {
key: 'timeline',
label: i18n.translate('xpack.apm.propertiesTable.tabs.timelineLabel', {
defaultMessage: 'Timeline',
}),
};

const metadataTab = {
key: 'metadata',
label: i18n.translate('xpack.apm.propertiesTable.tabs.metadataLabel', {
defaultMessage: 'Metadata',
}),
};

interface Props {
location: Location;
transaction: Transaction;
Expand All @@ -46,9 +33,10 @@ export function TransactionTabs({
exceedsMax,
}: Props) {
const history = useHistory();
const tabs = [timelineTab, metadataTab];
const tabs = [timelineTab, metadataTab, logsTab];
Copy link
Member

@sorenlouv sorenlouv Dec 14, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: might want to define this outside the component to indicate that it is static.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nvm, I see a green build. Feel free to merge.

const currentTab =
urlParams.detailTab === metadataTab.key ? metadataTab : timelineTab;
tabs.find(({ key }) => key === urlParams.detailTab) ?? timelineTab;
const TabContent = currentTab.component;

return (
<React.Fragment>
Expand Down Expand Up @@ -76,16 +64,77 @@ export function TransactionTabs({

<EuiSpacer />

{currentTab.key === timelineTab.key ? (
<WaterfallContainer
location={location}
urlParams={urlParams}
waterfall={waterfall}
exceedsMax={exceedsMax}
/>
) : (
<TransactionMetadata transaction={transaction} />
)}
<TabContent
location={location}
urlParams={urlParams}
waterfall={waterfall}
exceedsMax={exceedsMax}
transaction={transaction}
/>
</React.Fragment>
);
}

const timelineTab = {
key: 'timeline',
label: i18n.translate('xpack.apm.propertiesTable.tabs.timelineLabel', {
defaultMessage: 'Timeline',
}),
component: TimelineTabContent,
};

const metadataTab = {
key: 'metadata',
label: i18n.translate('xpack.apm.propertiesTable.tabs.metadataLabel', {
defaultMessage: 'Metadata',
}),
component: MetadataTabContent,
};

const logsTab = {
key: 'logs',
label: i18n.translate('xpack.apm.propertiesTable.tabs.logsLabel', {
defaultMessage: 'Logs',
}),
component: LogsTabContent,
};

function TimelineTabContent({
location,
urlParams,
waterfall,
exceedsMax,
}: {
location: Location<any>;
urlParams: IUrlParams;
waterfall: IWaterfall;
exceedsMax: boolean;
}) {
return (
<WaterfallContainer
location={location}
urlParams={urlParams}
waterfall={waterfall}
exceedsMax={exceedsMax}
/>
);
}

function MetadataTabContent({ transaction }: { transaction: Transaction }) {
return <TransactionMetadata transaction={transaction} />;
}

function LogsTabContent({ transaction }: { transaction: Transaction }) {
const startTimestamp = Math.floor(transaction.timestamp.us / 1000);
const endTimestamp = Math.ceil(
startTimestamp + transaction.transaction.duration.us / 1000
);
const framePaddingMs = 1000 * 60 * 60 * 24; // 24 hours
return (
<LogStream
startTimestamp={startTimestamp - framePaddingMs}
endTimestamp={endTimestamp + framePaddingMs}
query={`trace.id:"${transaction.trace.id}" OR "${transaction.trace.id}"`}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This matches the filter for the "Trace logs" link in the action menu: https://github.com/elastic/kibana/blob/master/x-pack/plugins/apm/public/components/shared/TransactionActionMenu/sections.ts#L183, but i'm not sure why this needs to be an OR, is it just me or is this redundant?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My guess is that is will pick up entries that don't have the trace.id attribute set but contain the trace id in other fields, but first matching with the field name gives exact matches.

/>
);
}