|
6 | 6 | handleCallbackErrors, |
7 | 7 | runWithAsyncContext, |
8 | 8 | startSpan, |
9 | | - withScope, |
10 | 9 | } from '@sentry/core'; |
11 | 10 | import { logger, tracingContextFromHeaders } from '@sentry/utils'; |
12 | 11 |
|
@@ -85,48 +84,41 @@ async function withServerActionInstrumentationImplementation<A extends (...args: |
85 | 84 |
|
86 | 85 | let res; |
87 | 86 | try { |
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 | | - } |
97 | | - }); |
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 | | - } |
102 | | - |
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 | | - }, |
| 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, |
115 | 98 | }, |
116 | 99 | }, |
117 | | - async span => { |
118 | | - const result = await handleCallbackErrors(callback, error => { |
119 | | - captureException(error, { mechanism: { handled: false } }); |
120 | | - }); |
| 100 | + }, |
| 101 | + async span => { |
| 102 | + const result = await handleCallbackErrors(callback, error => { |
| 103 | + captureException(error, { mechanism: { handled: false } }); |
| 104 | + }); |
121 | 105 |
|
122 | | - if (options.recordResponse !== undefined ? options.recordResponse : sendDefaultPii) { |
123 | | - span?.setAttribute('server_action_result', result); |
124 | | - } |
| 106 | + if (options.recordResponse !== undefined ? options.recordResponse : sendDefaultPii) { |
| 107 | + span?.setAttribute('server_action_result', result); |
| 108 | + } |
125 | 109 |
|
126 | | - return result; |
127 | | - }, |
128 | | - ); |
129 | | - }); |
| 110 | + if (options.formData) { |
| 111 | + options.formData.forEach((value, key) => { |
| 112 | + span?.setAttribute( |
| 113 | + `server_action_form_data.${key}`, |
| 114 | + typeof value === 'string' ? value : '[non-string value]', |
| 115 | + ); |
| 116 | + }); |
| 117 | + } |
| 118 | + |
| 119 | + return result; |
| 120 | + }, |
| 121 | + ); |
130 | 122 | } finally { |
131 | 123 | if (!platformSupportsStreaming()) { |
132 | 124 | // Lambdas require manual flushing to prevent execution freeze before the event is sent |
|
0 commit comments