Skip to content

Commit 6f74ab7

Browse files
committed
Align form data logic with opentelemetry implementation
1 parent 46abaae commit 6f74ab7

File tree

2 files changed

+17
-3
lines changed

2 files changed

+17
-3
lines changed

packages/remix/src/server/errors.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ export async function errorHandleDataFunction(
130130
const options = getClient()?.getOptions() as RemixOptions | undefined;
131131

132132
if (options?.sendDefaultPii && options.captureActionFormDataKeys) {
133-
await storeFormDataKeys(args, span);
133+
await storeFormDataKeys(args, span, options.captureActionFormDataKeys);
134134
}
135135
}
136136

packages/remix/src/utils/utils.ts

+16-2
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,11 @@ import type { ServerRoute, ServerRouteManifest } from './vendor/types';
88
/**
99
*
1010
*/
11-
export async function storeFormDataKeys(args: LoaderFunctionArgs | ActionFunctionArgs, span: Span): Promise<void> {
11+
export async function storeFormDataKeys(
12+
args: LoaderFunctionArgs | ActionFunctionArgs,
13+
span: Span,
14+
formDataKeys?: Record<string, string | boolean> | undefined,
15+
): Promise<void> {
1216
try {
1317
// We clone the request for Remix be able to read the FormData later.
1418
const clonedRequest = args.request.clone();
@@ -19,7 +23,17 @@ export async function storeFormDataKeys(args: LoaderFunctionArgs | ActionFunctio
1923
const formData = await clonedRequest.formData();
2024

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

0 commit comments

Comments
 (0)