Skip to content
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/

import { EuiEmptyPrompt } from '@elastic/eui';
import React from 'react';
import { Redirect, RouteComponentProps } from 'react-router-dom';
import { euiStyled } from '../../../../../../../src/plugins/kibana_react/common';
import { FETCH_STATUS, useFetcher } from '../../../hooks/use_fetcher';
import { useUrlParams } from '../../../context/url_params_context/use_url_params';
import { getRedirectToTransactionDetailPageUrl } from '../TraceLink/get_redirect_to_transaction_detail_page_url';

const CentralizedContainer = euiStyled.div`
height: 100%;
display: flex;
`;

export function TransactionLink({
match,
}: RouteComponentProps<{ transactionId: string }>) {
const { transactionId } = match.params;
const { urlParams } = useUrlParams();
const { rangeFrom, rangeTo } = urlParams;

const { data = { transaction: null }, status } = useFetcher(
(callApmApi) => {
if (transactionId) {
return callApmApi({
endpoint: 'GET /api/apm/transactions/{transactionId}',
params: {
path: {
transactionId,
},
},
});
}
},
[transactionId]
);
if (transactionId && status === FETCH_STATUS.SUCCESS) {
if (data.transaction) {
return (
<Redirect
to={getRedirectToTransactionDetailPageUrl({
transaction: data.transaction,
rangeFrom,
rangeTo,
})}
/>
);
}

return <CentralizedContainer />;
}

return (
<CentralizedContainer>
<EuiEmptyPrompt
iconType="apmTrace"
title={<h2>Fetching transaction...</h2>}
Copy link
Contributor

Choose a reason for hiding this comment

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

i18n this?

/>
</CentralizedContainer>
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import { AnomalyDetection } from '../app/Settings/anomaly_detection';
import { ApmIndices } from '../app/Settings/ApmIndices';
import { CustomizeUI } from '../app/Settings/CustomizeUI';
import { TraceLink } from '../app/TraceLink';
import { TransactionLink } from '../app/transaction_link';
import { TransactionDetails } from '../app/transaction_details';
import { enableServiceOverview } from '../../../common/ui_settings_keys';
import { redirectTo } from './redirect_to';
Expand Down Expand Up @@ -510,6 +511,12 @@ export const apmRouteConfig: APMRouteDefinition[] = [
component: TraceLink,
breadcrumb: null,
},
{
exact: true,
path: '/link-to/transaction/:transactionId',
component: TransactionLink,
breadcrumb: null,
},
];

function RedirectToDefaultServiceRouteView(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@ export function getTransaction({
setup,
}: {
transactionId: string;
traceId: string;
setup: Setup & SetupTimeRange;
traceId?: string;
setup: Setup | (Setup & SetupTimeRange);
}) {
return withApmSpan('get_transaction', async () => {
const { start, end, apmEventClient } = setup;
const { apmEventClient } = setup;

const resp = await apmEventClient.search({
apm: {
Expand All @@ -37,8 +37,8 @@ export function getTransaction({
bool: {
filter: asMutableArray([
{ term: { [TRANSACTION_ID]: transactionId } },
{ term: { [TRACE_ID]: traceId } },
...rangeQuery(start, end),
...(traceId ? [{ term: { [TRACE_ID]: traceId } }] : []),
...('start' in setup ? rangeQuery(setup.start, setup.end) : []),
Copy link
Member

Choose a reason for hiding this comment

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

Are setup.start and setup.end typed as optionals here? Would be great if they were but I seem to recall we require them on every api

Copy link
Member

Choose a reason for hiding this comment

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

(or maybe it's the opposite problem I'm thinking about where they are always optional, even when they are required on the api)

Copy link
Member Author

Choose a reason for hiding this comment

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

This function is used in different endpoints, one that does have a start/end query parameter, and one that doesn't. The type for setup here is a union type of setup without start/end (not defined) and setup with start end (always defined).

]),
},
},
Expand Down
20 changes: 19 additions & 1 deletion x-pack/plugins/apm/server/routes/traces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import { environmentRt, kueryRt, rangeRt } from './default_api_types';
import { getSearchAggregatedTransactions } from '../lib/helpers/aggregated_transactions';
import { getRootTransactionByTraceId } from '../lib/transactions/get_transaction_by_trace';
import { createApmServerRouteRepository } from './create_apm_server_route_repository';
import { getTransaction } from '../lib/transactions/get_transaction';

const tracesRoute = createApmServerRoute({
endpoint: 'GET /api/apm/traces',
Expand Down Expand Up @@ -70,7 +71,24 @@ const rootTransactionByTraceIdRoute = createApmServerRoute({
},
});

const transactionByIdRoute = createApmServerRoute({
endpoint: 'GET /api/apm/transactions/{transactionId}',
params: t.type({
path: t.type({
transactionId: t.string,
}),
}),
options: { tags: ['access:apm'] },
handler: async (resources) => {
const { params } = resources;
const { transactionId } = params.path;
const setup = await setupRequest(resources);
return { transaction: await getTransaction({ transactionId, setup }) };
},
});

export const traceRouteRepository = createApmServerRouteRepository()
.add(tracesByIdRoute)
.add(tracesRoute)
.add(rootTransactionByTraceIdRoute);
.add(rootTransactionByTraceIdRoute)
.add(transactionByIdRoute);