Skip to content

feat(remix): Vendor in opentelemetry-instrumentation-remix #16145

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 8 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion packages/remix/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -65,14 +65,15 @@
},
"dependencies": {
"@opentelemetry/api": "^1.9.0",
"@opentelemetry/instrumentation": "^0.57.2",
"@opentelemetry/semantic-conventions": "^1.30.0",
"@remix-run/router": "1.x",
"@sentry/cli": "^2.43.0",
"@sentry/core": "9.15.0",
"@sentry/node": "9.15.0",
"@sentry/opentelemetry": "9.15.0",
"@sentry/react": "9.15.0",
"glob": "^10.3.4",
"opentelemetry-instrumentation-remix": "0.8.0",
"yargs": "^17.6.0"
},
"devDependencies": {
Expand Down
2 changes: 1 addition & 1 deletion packages/remix/src/server/errors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ export async function errorHandleDataFunction(
const options = getClient()?.getOptions() as RemixOptions | undefined;

if (options?.sendDefaultPii && options.captureActionFormDataKeys) {
await storeFormDataKeys(args, span);
await storeFormDataKeys(args, span, options.captureActionFormDataKeys);
}
}

Expand Down
2 changes: 1 addition & 1 deletion packages/remix/src/server/integrations/opentelemetry.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import type { Client, IntegrationFn, Span } from '@sentry/core';
import { defineIntegration, SEMANTIC_ATTRIBUTE_SENTRY_OP, SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN } from '@sentry/core';
import { generateInstrumentOnce, getClient, spanToJSON } from '@sentry/node';
import { RemixInstrumentation } from 'opentelemetry-instrumentation-remix';
import type { RemixOptions } from '../../utils/remixOptions';
import { RemixInstrumentation } from '../../vendor/instrumentation';

const INTEGRATION_NAME = 'Remix';

Expand Down
19 changes: 17 additions & 2 deletions packages/remix/src/utils/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,11 @@ import type { ServerRoute, ServerRouteManifest } from './vendor/types';
/**
*
*/
export async function storeFormDataKeys(args: LoaderFunctionArgs | ActionFunctionArgs, span: Span): Promise<void> {
export async function storeFormDataKeys(
args: LoaderFunctionArgs | ActionFunctionArgs,
span: Span,
formDataKeys?: Record<string, string | boolean> | undefined,
): Promise<void> {
try {
// We clone the request for Remix be able to read the FormData later.
const clonedRequest = args.request.clone();
Expand All @@ -19,7 +23,18 @@ export async function storeFormDataKeys(args: LoaderFunctionArgs | ActionFunctio
const formData = await clonedRequest.formData();

formData.forEach((value, key) => {
span.setAttribute(`remix.action_form_data.${key}`, typeof value === 'string' ? value : '[non-string value]');
let attrKey = key;

if (formDataKeys?.[key]) {
if (typeof formDataKeys[key] === 'string') {
attrKey = formDataKeys[key] as string;
}

span.setAttribute(
`remix.action_form_data.${attrKey}`,
typeof value === 'string' ? value : '[non-string value]',
);
}
});
} catch (e) {
DEBUG_BUILD && logger.warn('Failed to read FormData from request', e);
Expand Down
Loading