Skip to content

Commit

Permalink
[APM] Transaction page throws unhandled exception if transactions doe…
Browse files Browse the repository at this point in the history
…sn't have `http.request` (elastic#53760)

* Making http.request optional

* changing unit test
  • Loading branch information
cauemarcondes committed Dec 24, 2019
1 parent 2c6ed6d commit 0d3d057
Show file tree
Hide file tree
Showing 6 changed files with 68 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -126,4 +126,31 @@ describe('DetailView', () => {
expect(wrapper.exists()).toBe(true);
expect(wrapper).toMatchSnapshot();
});

it('should render without http request info', () => {
const errorGroup = {
occurrencesCount: 10,
transaction: undefined,
error: {
timestamp: {
us: 0
},
http: { response: { status_code: 404 } },
url: { full: 'myUrl' },
service: { name: 'myService' },
user: { id: 'myUserId' },
error: { exception: { handled: true } },
transaction: { id: 'myTransactionId', sampled: true }
} as any
};
expect(() =>
shallow(
<DetailView
errorGroup={errorGroup}
urlParams={{}}
location={{} as Location}
/>
)
).not.toThrowError();
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ export function DetailView({ errorGroup, urlParams, location }: Props) {

const errorUrl = error.error.page?.url || error.url?.full;

const method = error.http?.request.method;
const method = error.http?.request?.method;
const status = error.http?.response?.status_code;

return (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,26 @@
import { shallow } from 'enzyme';
import React from 'react';
import { TransactionSummary } from './TransactionSummary';
import { Transaction } from '../../../../typings/es_schemas/ui/Transaction';
import * as exampleTransactions from './__fixtures__/transactions';

describe('TransactionSummary', () => {
describe('render', () => {
const transaction: Transaction = exampleTransactions.httpOk;
const transaction = exampleTransactions.httpOk;

const props = {
errorCount: 0,
totalDuration: 0,
transaction
};

it('renders', () => {
expect(() =>
shallow(<TransactionSummary {...props} />)
).not.toThrowError();
});
});
describe('renders RUM transaction without request info', () => {
const transaction = exampleTransactions.httpRumOK;

const props = {
errorCount: 0,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ const getTransactionResultSummaryItem = (transaction: Transaction) => {
: transaction.url?.full;

if (url) {
const method = transaction.http?.request.method;
const method = transaction.http?.request?.method;
const status = transaction.http?.response?.status_code;

return <HttpInfoSummaryItem method={method} status={status} url={url} />;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,25 @@ export const httpOk: Transaction = {
duration: { us: 0 }
}
};

export const httpRumOK: Transaction = {
'@timestamp': '0',
agent: { name: 'rum-js', version: '0' },
http: {
response: { status_code: 200 }
},
processor: { event: 'transaction', name: 'transaction' },
service: { name: 'testServiceName' },
timestamp: { us: 0 },
trace: { id: 'testTrace' },
transaction: {
page: {
url: 'elastic.co'
},
name: 'testTransaction',
id: 'testId',
sampled: false,
type: 'testType',
duration: { us: 0 }
}
};
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
*/

export interface Http {
request: { method: string; [key: string]: unknown };
request?: { method: string; [key: string]: unknown };
response?: { status_code: number; [key: string]: unknown };
version?: string;
}

0 comments on commit 0d3d057

Please sign in to comment.