@@ -8,27 +8,28 @@ import { DataFetchingFunction } from './types';
8
8
* @template T Types for `getInitialProps`, `getStaticProps`, and `getServerSideProps`
9
9
* @param origFunction The user's exported `getInitialProps`, `getStaticProps`, or `getServerSideProps` function
10
10
* @param context The context object passed by nextjs to the function
11
+ * @param route The route currently being served
11
12
* @returns The result of calling the user's function
12
13
*/
13
- export async function wrapperCore < T extends DataFetchingFunction > ( options : {
14
- origFunction : T [ 'fn' ] ;
15
- context : T [ 'context' ] ;
16
- route : string ;
17
- op : string ;
18
- } ) : Promise < T [ 'result' ] > {
19
- const { origFunction, context, route, op } = options ;
20
-
14
+ export async function wrapperCore < T extends DataFetchingFunction > (
15
+ origFunction : T [ 'fn' ] ,
16
+ context : T [ 'context' ] ,
17
+ route : string ,
18
+ ) : Promise < T [ 'result' ] > {
21
19
const transaction = getActiveTransaction ( ) ;
22
20
23
21
if ( transaction ) {
22
+ // Pull off any leading underscores we've added in the process of wrapping the function
23
+ const wrappedFunctionName = origFunction . name . replace ( / ^ _ * / , '' ) ;
24
+
24
25
// TODO: Make sure that the given route matches the name of the active transaction (to prevent background data
25
26
// fetching from switching the name to a completely other route)
26
27
transaction . name = route ;
27
28
transaction . metadata . source = 'route' ;
28
29
29
30
// Capture the route, since pre-loading, revalidation, etc might mean that this span may happen during another
30
31
// route's transaction
31
- const span = transaction . startChild ( { op, data : { route } } ) ;
32
+ const span = transaction . startChild ( { op : 'nextjs. data' , description : ` ${ wrappedFunctionName } ( ${ route } )` } ) ;
32
33
33
34
// TODO: Can't figure out how to tell TS that the types are correlated - that a `GSPropsFunction` will only get passed
34
35
// `GSPropsContext` and never, say, `GSSPContext`. That's what wrapping everything in objects and using the generic
0 commit comments