Skip to content

Commit f41f20c

Browse files
committed
Align form data logic with opentelemetry implementation
1 parent 8fa0d9c commit f41f20c

File tree

2 files changed

+17
-3
lines changed

2 files changed

+17
-3
lines changed

packages/remix/src/server/errors.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ export async function errorHandleDataFunction(
134134
const options = getClient()?.getOptions() as RemixOptions | undefined;
135135

136136
if (options?.sendDefaultPii && options.captureActionFormDataKeys) {
137-
await storeFormDataKeys(args, span);
137+
await storeFormDataKeys(args, span, options.captureActionFormDataKeys);
138138
}
139139
}
140140

packages/remix/src/utils/utils.ts

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,11 @@ type ServerRouteManifest = ServerBuild['routes'];
1010
/**
1111
*
1212
*/
13-
export async function storeFormDataKeys(args: LoaderFunctionArgs | ActionFunctionArgs, span: Span): Promise<void> {
13+
export async function storeFormDataKeys(
14+
args: LoaderFunctionArgs | ActionFunctionArgs,
15+
span: Span,
16+
formDataKeys?: Record<string, string | boolean> | undefined,
17+
): Promise<void> {
1418
try {
1519
// We clone the request for Remix be able to read the FormData later.
1620
const clonedRequest = args.request.clone();
@@ -21,7 +25,17 @@ export async function storeFormDataKeys(args: LoaderFunctionArgs | ActionFunctio
2125
const formData = await clonedRequest.formData();
2226

2327
formData.forEach((value, key) => {
24-
span.setAttribute(`remix.action_form_data.${key}`, typeof value === 'string' ? value : '[non-string value]');
28+
let attrKey = key;
29+
30+
if (formDataKeys?.[key]) {
31+
if (formDataKeys[key] === false) {
32+
return;
33+
} else if (typeof value === 'string') {
34+
attrKey = key;
35+
}
36+
37+
span.setAttribute(`remix.action_form_data.${attrKey}`, typeof value === 'string' ? value : '[non-string value]');
38+
}
2539
});
2640
} catch (e) {
2741
DEBUG_BUILD && logger.warn('Failed to read FormData from request', e);

0 commit comments

Comments
 (0)