Skip to content

Commit

Permalink
fix(nextjs): Apply server action data to correct isolation scope (#10514
Browse files Browse the repository at this point in the history
)
  • Loading branch information
lforst authored Feb 6, 2024
1 parent 01deeac commit fdb1a5c
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -130,11 +130,11 @@ test('Should send a transaction for instrumented server actions', async ({ page
await page.getByText('Run Action').click();

expect(await serverComponentTransactionPromise).toBeDefined();
expect(
(await serverComponentTransactionPromise).contexts?.trace?.data?.['server_action_form_data.some-text-value'],
).toEqual('some-default-value');
expect((await serverComponentTransactionPromise).contexts?.trace?.data?.['server_action_result']).toEqual({
city: 'Vienna',
expect((await serverComponentTransactionPromise).extra).toMatchObject({
'server_action_form_data.some-text-value': 'some-default-value',
server_action_result: {
city: 'Vienna',
},
});

expect(Object.keys((await serverComponentTransactionPromise).request?.headers || {}).length).toBeGreaterThan(0);
Expand Down
5 changes: 3 additions & 2 deletions packages/nextjs/src/common/withServerActionInstrumentation.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { getIsolationScope } from '@sentry/core';
import {
addTracingExtensions,
captureException,
Expand Down Expand Up @@ -115,12 +116,12 @@ async function withServerActionInstrumentationImplementation<A extends (...args:
});

if (options.recordResponse !== undefined ? options.recordResponse : sendDefaultPii) {
isolationScope.setExtra('server_action_result', result);
getIsolationScope().setExtra('server_action_result', result);
}

if (options.formData) {
options.formData.forEach((value, key) => {
isolationScope.setExtra(
getIsolationScope().setExtra(
`server_action_form_data.${key}`,
typeof value === 'string' ? value : '[non-string value]',
);
Expand Down

0 comments on commit fdb1a5c

Please sign in to comment.