Skip to content

Commit d996be7

Browse files
committed
Rebase onto changes
1 parent 02c1d43 commit d996be7

File tree

4 files changed

+38
-24
lines changed

4 files changed

+38
-24
lines changed

packages/nextjs/src/config/wrappers/withSentryGetInitialProps.ts

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,20 @@ type GetInitialProps = Required<NextPage<unknown>>['getInitialProps'];
77
/**
88
* Create a wrapped version of the user's exported `getInitialProps` function
99
*
10-
* @param origGetInitialProps: The user's `getInitialProps` function
11-
* @param origGIPropsHost: The user's object on which `getInitialProps` lives (used for `this`)
10+
* @param origGetInitialProps - The user's `getInitialProps` function
11+
* @param parameterizedRoute - The page's parameterized route
1212
* @returns A wrapped version of the function
1313
*/
14-
export function withSentryGetInitialProps(origGetInitialProps: GetInitialProps, route: string): GetInitialProps {
14+
export function withSentryGetInitialProps(
15+
origGetInitialProps: GetInitialProps,
16+
parameterizedRoute: string,
17+
): GetInitialProps {
1518
return async function (
1619
...getInitialPropsArguments: Parameters<GetInitialProps>
1720
): Promise<ReturnType<GetInitialProps>> {
18-
return await callDataFetcherTraced(origGetInitialProps, getInitialPropsArguments, { route, op: 'getInitialProps' });
21+
return callDataFetcherTraced(origGetInitialProps, getInitialPropsArguments, {
22+
parameterizedRoute,
23+
dataFetchingMethodName: 'getInitialProps',
24+
});
1925
};
2026
}

packages/nextjs/src/config/wrappers/withSentryGetServerSideProps.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,20 +5,20 @@ import { callDataFetcherTraced } from './wrapperUtils';
55
/**
66
* Create a wrapped version of the user's exported `getServerSideProps` function
77
*
8-
* @param origGetServerSideProps: The user's `getServerSideProps` function
9-
* @param route: The page's parameterized route
8+
* @param origGetServerSideProps - The user's `getServerSideProps` function
9+
* @param parameterizedRoute - The page's parameterized route
1010
* @returns A wrapped version of the function
1111
*/
1212
export function withSentryGetServerSideProps(
1313
origGetServerSideProps: GetServerSideProps,
14-
route: string,
14+
parameterizedRoute: string,
1515
): GetServerSideProps {
1616
return async function (
1717
...getServerSidePropsArguments: Parameters<GetServerSideProps>
1818
): ReturnType<GetServerSideProps> {
19-
return await callDataFetcherTraced(origGetServerSideProps, getServerSidePropsArguments, {
20-
route,
21-
op: 'getServerSideProps',
19+
return callDataFetcherTraced(origGetServerSideProps, getServerSidePropsArguments, {
20+
parameterizedRoute,
21+
dataFetchingMethodName: 'getServerSideProps',
2222
});
2323
};
2424
}

packages/nextjs/src/config/wrappers/withSentryGetStaticProps.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,19 @@ type Props = { [key: string]: unknown };
88
* Create a wrapped version of the user's exported `getStaticProps` function
99
*
1010
* @param origGetStaticProps: The user's `getStaticProps` function
11-
* @param route: The page's parameterized route
11+
* @param parameterizedRoute - The page's parameterized route
1212
* @returns A wrapped version of the function
1313
*/
1414
export function withSentryGetStaticProps(
1515
origGetStaticProps: GetStaticProps<Props>,
16-
route: string,
16+
parameterizedRoute: string,
1717
): GetStaticProps<Props> {
1818
return async function (
1919
...getStaticPropsArguments: Parameters<GetStaticProps<Props>>
2020
): ReturnType<GetStaticProps<Props>> {
21-
return await callDataFetcherTraced(origGetStaticProps, getStaticPropsArguments, { route, op: 'getStaticProps' });
21+
return callDataFetcherTraced(origGetStaticProps, getStaticPropsArguments, {
22+
parameterizedRoute,
23+
dataFetchingMethodName: 'getStaticProps',
24+
});
2225
};
2326
}
Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import { captureException } from '@sentry/core';
22
import { getActiveTransaction } from '@sentry/tracing';
3-
import { Span } from '@sentry/types';
43

54
/**
65
* Call a data fetcher and trace it. Only traces the function if there is an active transaction on the scope.
@@ -12,36 +11,42 @@ export async function callDataFetcherTraced<F extends (...args: any[]) => Promis
1211
origFunction: F,
1312
origFunctionArgs: Parameters<F>,
1413
options: {
15-
route: string;
16-
op: string;
14+
parameterizedRoute: string;
15+
dataFetchingMethodName: string;
1716
},
1817
): Promise<ReturnType<F>> {
19-
const { route, op } = options;
18+
const { parameterizedRoute, dataFetchingMethodName } = options;
2019

2120
const transaction = getActiveTransaction();
2221

2322
if (!transaction) {
2423
return origFunction(...origFunctionArgs);
2524
}
2625

27-
// Pull off any leading underscores we've added in the process of wrapping the function
28-
const wrappedFunctionName = origFunction.name.replace(/^_*/, '');
29-
3026
// TODO: Make sure that the given route matches the name of the active transaction (to prevent background data
3127
// fetching from switching the name to a completely other route) -- We'll probably switch to creating a transaction
3228
// right here so making that check will probabably not even be necessary.
3329
// Logic will be: If there is no active transaction, start one with correct name and source. If there is an active
3430
// transaction, create a child span with correct name and source.
35-
transaction.name = route;
31+
transaction.name = parameterizedRoute;
3632
transaction.metadata.source = 'route';
3733

3834
// Capture the route, since pre-loading, revalidation, etc might mean that this span may happen during another
3935
// route's transaction
40-
const span = transaction.startChild({ op: 'nextjs.data', description: `${wrappedFunctionName} (${route})` });
36+
const span = transaction.startChild({
37+
op: 'nextjs.data',
38+
description: `${dataFetchingMethodName} (${parameterizedRoute})`,
39+
});
4140

4241
try {
4342
return await origFunction(...origFunctionArgs);
44-
} finally {
45-
span.finish();
43+
} catch (err) {
44+
if (span) {
45+
span.finish();
46+
}
47+
48+
// TODO Copy more robust error handling over from `withSentry`
49+
captureException(err);
50+
throw err;
4651
}
4752
}

0 commit comments

Comments
 (0)