@@ -76,6 +76,34 @@ test('Should send a transaction for instrumented server actions', async ({ page
76
76
expect ( Object . keys ( transactionEvent . request ?. headers || { } ) . length ) . toBeGreaterThan ( 0 ) ;
77
77
} ) ;
78
78
79
+ test ( 'Should send a wrapped server action as a child of a nextjs transaction' , async ( { page } ) => {
80
+ const nextjsVersion = packageJson . dependencies . next ;
81
+ const nextjsMajor = Number ( nextjsVersion . split ( '.' ) [ 0 ] ) ;
82
+ test . skip ( ! isNaN ( nextjsMajor ) && nextjsMajor < 14 , 'only applies to nextjs apps >= version 14' ) ;
83
+ test . skip ( process . env . TEST_ENV === 'development' , 'this magically only works in production' ) ;
84
+
85
+ const nextjsPostTransactionPromise = waitForTransaction ( 'nextjs-app-dir' , async transactionEvent => {
86
+ return (
87
+ transactionEvent ?. transaction === 'POST /server-action' && transactionEvent . contexts ?. trace ?. origin === 'auto'
88
+ ) ;
89
+ } ) ;
90
+
91
+ const serverActionTransactionPromise = waitForTransaction ( 'nextjs-app-dir' , async transactionEvent => {
92
+ return transactionEvent ?. transaction === 'serverAction/myServerAction' ;
93
+ } ) ;
94
+
95
+ await page . goto ( '/server-action' ) ;
96
+ await page . getByText ( 'Run Action' ) . click ( ) ;
97
+
98
+ const nextjsTransaction = await nextjsPostTransactionPromise ;
99
+ const serverActionTransaction = await serverActionTransactionPromise ;
100
+
101
+ expect ( nextjsTransaction ) . toBeDefined ( ) ;
102
+ expect ( serverActionTransaction ) . toBeDefined ( ) ;
103
+
104
+ expect ( nextjsTransaction . contexts ?. trace ?. span_id ) . toBe ( serverActionTransaction . contexts ?. trace ?. parent_span_id ) ;
105
+ } ) ;
106
+
79
107
test ( 'Should set not_found status for server actions calling notFound()' , async ( { page } ) => {
80
108
const nextjsVersion = packageJson . dependencies . next ;
81
109
const nextjsMajor = Number ( nextjsVersion . split ( '.' ) [ 0 ] ) ;
0 commit comments