-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
test(remix): Add server-side instrumentation integration tests. #5538
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
Changes from all commits
b9afed0
d572c1e
7e197cc
f29c0f0
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import { ActionFunction, json, redirect, LoaderFunction } from '@remix-run/node'; | ||
import { useActionData } from '@remix-run/react'; | ||
|
||
export const loader: LoaderFunction = async ({ params: { id } }) => { | ||
if (id === '-1') { | ||
throw new Error('Unexpected Server Error from Loader'); | ||
} | ||
}; | ||
|
||
export const action: ActionFunction = async ({ params: { id } }) => { | ||
if (id === '-1') { | ||
throw new Error('Unexpected Server Error'); | ||
} | ||
|
||
if (id === '-2') { | ||
// Note: This GET request triggers to the `Loader` of the URL, not the `Action`. | ||
throw redirect('/action-json-response/-1'); | ||
} | ||
|
||
return json({ test: 'test' }); | ||
}; | ||
|
||
export default function ActionJSONResponse() { | ||
const data = useActionData(); | ||
|
||
return ( | ||
<div> | ||
<h1>{data && data.test ? data.test : 'Not Found'}</h1> | ||
</div> | ||
); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,131 @@ | ||
import { | ||
assertSentryTransaction, | ||
getEnvelopeRequest, | ||
runServer, | ||
getMultipleEnvelopeRequest, | ||
assertSentryEvent, | ||
} from './utils/helpers'; | ||
|
||
jest.spyOn(console, 'error').mockImplementation(); | ||
|
||
describe('Remix API Actions', () => { | ||
it('correctly instruments a parameterized Remix API action', async () => { | ||
const baseURL = await runServer(); | ||
const url = `${baseURL}/action-json-response/123123`; | ||
const envelope = await getEnvelopeRequest(url, 'post'); | ||
const transaction = envelope[2]; | ||
|
||
assertSentryTransaction(transaction, { | ||
transaction: 'routes/action-json-response/$id', | ||
spans: [ | ||
{ | ||
description: 'routes/action-json-response/$id', | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We should really think about if we can make this name better. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe something like `${action | loader | documentRequest} of ${route}`? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah I like that, even if the info is a bit redundant |
||
op: 'remix.server.action', | ||
}, | ||
{ | ||
description: 'routes/action-json-response/$id', | ||
op: 'remix.server.loader', | ||
}, | ||
{ | ||
description: 'routes/action-json-response/$id', | ||
op: 'remix.server.documentRequest', | ||
}, | ||
], | ||
}); | ||
}); | ||
|
||
it('reports an error thrown from the action', async () => { | ||
const baseURL = await runServer(); | ||
const url = `${baseURL}/action-json-response/-1`; | ||
|
||
const [transaction, event] = await getMultipleEnvelopeRequest(url, 2, 'post'); | ||
|
||
assertSentryTransaction(transaction[2], { | ||
contexts: { | ||
trace: { | ||
status: 'internal_error', | ||
tags: { | ||
'http.status_code': '500', | ||
}, | ||
}, | ||
}, | ||
}); | ||
|
||
assertSentryEvent(event[2], { | ||
exception: { | ||
values: [ | ||
{ | ||
type: 'Error', | ||
value: 'Unexpected Server Error', | ||
stacktrace: expect.any(Object), | ||
mechanism: { | ||
data: { | ||
function: 'action', | ||
}, | ||
handled: true, | ||
type: 'instrument', | ||
}, | ||
}, | ||
], | ||
}, | ||
}); | ||
}); | ||
|
||
it('handles a thrown 500 response', async () => { | ||
const baseURL = await runServer(); | ||
const url = `${baseURL}/action-json-response/-2`; | ||
|
||
const [transaction_1, event, transaction_2] = await getMultipleEnvelopeRequest(url, 3, 'post'); | ||
|
||
assertSentryTransaction(transaction_1[2], { | ||
contexts: { | ||
trace: { | ||
op: 'http.server', | ||
status: 'ok', | ||
tags: { | ||
method: 'POST', | ||
'http.status_code': '302', | ||
}, | ||
}, | ||
}, | ||
tags: { | ||
transaction: 'routes/action-json-response/$id', | ||
}, | ||
}); | ||
|
||
assertSentryTransaction(transaction_2[2], { | ||
contexts: { | ||
trace: { | ||
op: 'http.server', | ||
status: 'internal_error', | ||
tags: { | ||
method: 'GET', | ||
'http.status_code': '500', | ||
}, | ||
}, | ||
}, | ||
tags: { | ||
transaction: 'routes/action-json-response/$id', | ||
}, | ||
}); | ||
|
||
assertSentryEvent(event[2], { | ||
exception: { | ||
values: [ | ||
{ | ||
type: 'Error', | ||
value: 'Unexpected Server Error from Loader', | ||
stacktrace: expect.any(Object), | ||
mechanism: { | ||
data: { | ||
function: 'loader', | ||
}, | ||
handled: true, | ||
type: 'instrument', | ||
}, | ||
}, | ||
], | ||
}, | ||
}); | ||
}); | ||
}); |
Uh oh!
There was an error while loading. Please reload this page.