-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(nextjs): Create spans and route parameterization in server-side …
…`getInitialProps` (#5587)
- Loading branch information
Showing
6 changed files
with
119 additions
and
119 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
24 changes: 18 additions & 6 deletions
24
packages/nextjs/src/config/wrappers/withSentryGetInitialProps.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,26 @@ | ||
import { GIProps } from './types'; | ||
import { NextPage } from 'next'; | ||
|
||
import { callDataFetcherTraced } from './wrapperUtils'; | ||
|
||
type GetInitialProps = Required<NextPage<unknown>>['getInitialProps']; | ||
|
||
/** | ||
* Create a wrapped version of the user's exported `getInitialProps` function | ||
* | ||
* @param origGIProps: The user's `getInitialProps` function | ||
* @param origGIPropsHost: The user's object on which `getInitialProps` lives (used for `this`) | ||
* @param origGetInitialProps The user's `getInitialProps` function | ||
* @param parameterizedRoute The page's parameterized route | ||
* @returns A wrapped version of the function | ||
*/ | ||
export function withSentryGetInitialProps(origGIProps: GIProps['fn']): GIProps['wrappedFn'] { | ||
return async function (this: unknown, ...args: Parameters<GIProps['fn']>) { | ||
return await origGIProps.call(this, ...args); | ||
export function withSentryGetInitialProps( | ||
origGetInitialProps: GetInitialProps, | ||
parameterizedRoute: string, | ||
): GetInitialProps { | ||
return async function ( | ||
...getInitialPropsArguments: Parameters<GetInitialProps> | ||
): Promise<ReturnType<GetInitialProps>> { | ||
return callDataFetcherTraced(origGetInitialProps, getInitialPropsArguments, { | ||
parameterizedRoute, | ||
dataFetchingMethodName: 'getInitialProps', | ||
}); | ||
}; | ||
} |
23 changes: 16 additions & 7 deletions
23
packages/nextjs/src/config/wrappers/withSentryGetServerSideProps.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,24 @@ | ||
import { GSSP } from './types'; | ||
import { wrapperCore } from './wrapperUtils'; | ||
import { GetServerSideProps } from 'next'; | ||
|
||
import { callDataFetcherTraced } from './wrapperUtils'; | ||
|
||
/** | ||
* Create a wrapped version of the user's exported `getServerSideProps` function | ||
* | ||
* @param origGetServerSideProps: The user's `getServerSideProps` function | ||
* @param route: The page's parameterized route | ||
* @param origGetServerSideProps The user's `getServerSideProps` function | ||
* @param parameterizedRoute The page's parameterized route | ||
* @returns A wrapped version of the function | ||
*/ | ||
export function withSentryGetServerSideProps(origGetServerSideProps: GSSP['fn'], route: string): GSSP['wrappedFn'] { | ||
return async function (context: GSSP['context']): Promise<GSSP['result']> { | ||
return wrapperCore<GSSP>(origGetServerSideProps, context, route); | ||
export function withSentryGetServerSideProps( | ||
origGetServerSideProps: GetServerSideProps, | ||
parameterizedRoute: string, | ||
): GetServerSideProps { | ||
return async function ( | ||
...getServerSidePropsArguments: Parameters<GetServerSideProps> | ||
): ReturnType<GetServerSideProps> { | ||
return callDataFetcherTraced(origGetServerSideProps, getServerSidePropsArguments, { | ||
parameterizedRoute, | ||
dataFetchingMethodName: 'getServerSideProps', | ||
}); | ||
}; | ||
} |
25 changes: 18 additions & 7 deletions
25
packages/nextjs/src/config/wrappers/withSentryGetStaticProps.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,26 @@ | ||
import { GSProps } from './types'; | ||
import { wrapperCore } from './wrapperUtils'; | ||
import { GetStaticProps } from 'next'; | ||
|
||
import { callDataFetcherTraced } from './wrapperUtils'; | ||
|
||
type Props = { [key: string]: unknown }; | ||
|
||
/** | ||
* Create a wrapped version of the user's exported `getStaticProps` function | ||
* | ||
* @param origGetStaticProps: The user's `getStaticProps` function | ||
* @param route: The page's parameterized route | ||
* @param origGetStaticProps The user's `getStaticProps` function | ||
* @param parameterizedRoute The page's parameterized route | ||
* @returns A wrapped version of the function | ||
*/ | ||
export function withSentryGetStaticProps(origGetStaticProps: GSProps['fn'], route: string): GSProps['wrappedFn'] { | ||
return async function (context: GSProps['context']): Promise<GSProps['result']> { | ||
return wrapperCore<GSProps>(origGetStaticProps, context, route); | ||
export function withSentryGetStaticProps( | ||
origGetStaticProps: GetStaticProps<Props>, | ||
parameterizedRoute: string, | ||
): GetStaticProps<Props> { | ||
return async function ( | ||
...getStaticPropsArguments: Parameters<GetStaticProps<Props>> | ||
): ReturnType<GetStaticProps<Props>> { | ||
return callDataFetcherTraced(origGetStaticProps, getStaticPropsArguments, { | ||
parameterizedRoute, | ||
dataFetchingMethodName: 'getStaticProps', | ||
}); | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters