Skip to content

Commit 62700cd

Browse files
committed
fix test
1 parent eda891f commit 62700cd

File tree

1 file changed

+39
-37
lines changed

1 file changed

+39
-37
lines changed

packages/nextjs/src/common/withServerActionInstrumentation.ts

Lines changed: 39 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import {
66
handleCallbackErrors,
77
runWithAsyncContext,
88
startSpan,
9+
withScope,
910
} from '@sentry/core';
1011
import { logger, tracingContextFromHeaders } from '@sentry/utils';
1112

@@ -84,47 +85,48 @@ async function withServerActionInstrumentationImplementation<A extends (...args:
8485

8586
let res;
8687
try {
87-
res = await startSpan(
88-
{
89-
op: 'function.server_action',
90-
name: `serverAction/${serverActionName}`,
91-
status: 'ok',
92-
...traceparentData,
93-
metadata: {
94-
source: 'route',
95-
dynamicSamplingContext: traceparentData && !dynamicSamplingContext ? {} : dynamicSamplingContext,
96-
request: {
97-
headers: fullHeadersObject,
98-
},
99-
},
100-
},
101-
async span => {
102-
const result = await handleCallbackErrors(callback, error => {
103-
captureException(error, { mechanism: { handled: false } });
88+
res = await withScope(scope => {
89+
if (options.formData) {
90+
const formDataObject: Record<string, unknown> = {};
91+
options.formData.forEach((value, key) => {
92+
if (typeof value === 'string') {
93+
formDataObject[key] = value;
94+
} else {
95+
formDataObject[key] = '[non-string value]';
96+
}
10497
});
98+
// Since formDataObject is not a primitive, we cannot store it on the span as attributes
99+
// so instead we put it as extra on the scope
100+
scope.setExtra('server_action_form_data', formDataObject);
101+
}
105102

106-
if (options.recordResponse !== undefined ? options.recordResponse : sendDefaultPii) {
107-
span?.setAttribute('server_action_result', result);
108-
}
109-
110-
if (options.formData) {
111-
const formDataObject: Record<string, unknown> = {};
112-
options.formData.forEach((value, key) => {
113-
if (typeof value === 'string') {
114-
formDataObject[key] = value;
115-
} else {
116-
formDataObject[key] = '[non-string value]';
117-
}
103+
return startSpan(
104+
{
105+
op: 'function.server_action',
106+
name: `serverAction/${serverActionName}`,
107+
status: 'ok',
108+
...traceparentData,
109+
metadata: {
110+
source: 'route',
111+
dynamicSamplingContext: traceparentData && !dynamicSamplingContext ? {} : dynamicSamplingContext,
112+
request: {
113+
headers: fullHeadersObject,
114+
},
115+
},
116+
},
117+
async span => {
118+
const result = await handleCallbackErrors(callback, error => {
119+
captureException(error, { mechanism: { handled: false } });
118120
});
119-
// Since formDataObject is not a primitive, we cannot store it on the span as attributes
120-
// so instead we put it as extra on the scope
121-
const scope = getCurrentScope();
122-
scope.setExtra('server_action_form_data', formDataObject);
123-
}
124121

125-
return result;
126-
},
127-
);
122+
if (options.recordResponse !== undefined ? options.recordResponse : sendDefaultPii) {
123+
span?.setAttribute('server_action_result', result);
124+
}
125+
126+
return result;
127+
},
128+
);
129+
});
128130
} finally {
129131
if (!platformSupportsStreaming()) {
130132
// Lambdas require manual flushing to prevent execution freeze before the event is sent

0 commit comments

Comments
 (0)