Skip to content

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
lobsterkatie committed Oct 27, 2022
1 parent baf780f commit b08642e
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
7 changes: 4 additions & 3 deletions packages/remix/src/utils/instrumentServer.ts
Expand Up @@ -70,14 +70,15 @@ function extractData(response: Response): Promise<unknown> {
return responseClone.text();
}

function captureRemixServerException(err: Error, name: string): void {
function captureRemixServerException(err: Error, name: string, request: Request): void {
// Skip capturing if the thrown error is not a 5xx response
// https://remix.run/docs/en/v1/api/conventions#throwing-responses-in-loaders
if (isResponse(err) && err.status < 500) {
return;
}

captureException(isResponse(err) ? extractData(err) : err, scope => {
scope.setSDKProcessingMetadata({ request });
scope.addEventProcessor(event => {
addExceptionMechanism(event, {
type: 'instrument',
Expand Down Expand Up @@ -127,7 +128,7 @@ function makeWrappedDocumentRequestFunction(

span?.finish();
} catch (err) {
captureRemixServerException(err, 'documentRequest');
captureRemixServerException(err, 'documentRequest', request);
throw err;
}

Expand Down Expand Up @@ -164,7 +165,7 @@ function makeWrappedDataFunction(origFn: DataFunction, id: string, name: 'action
currentScope.setSpan(activeTransaction);
span?.finish();
} catch (err) {
captureRemixServerException(err, name);
captureRemixServerException(err, name, args.request);
throw err;
}

Expand Down
5 changes: 5 additions & 0 deletions packages/remix/src/utils/serverAdapters/express.ts
Expand Up @@ -60,6 +60,11 @@ function wrapExpressRequestHandler(
const request = extractRequestData(req);
const hub = getCurrentHub();
const options = hub.getClient()?.getOptions();
const scope = hub.getScope();

if (scope) {
scope.setSDKProcessingMetadata({ request });
}

if (!options || !hasTracingEnabled(options) || !request.url || !request.method) {
return origRequestHandler.call(this, req, res, next);
Expand Down

0 comments on commit b08642e

Please sign in to comment.