Skip to content

Commit 30e418f

Browse files
authored
feat(core): Migrate trpc to dataCollection (#21072)
We now attach the rpc input depending on https://develop.sentry.dev/sdk/foundations/client/data-collection/#body-type-collection. closes #21049
1 parent 2cfabce commit 30e418f

2 files changed

Lines changed: 8 additions & 1 deletion

File tree

packages/core/src/trpc.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ export function trpcMiddleware(options: SentryTrpcMiddlewareOptions = {}) {
4747

4848
const client = getClient();
4949
const clientOptions = client?.getOptions();
50+
const dataCollection = client?.getDataCollectionOptions();
5051

5152
const trpcContext: Record<string, unknown> = {
5253
procedure_path: path,
@@ -59,7 +60,11 @@ export function trpcMiddleware(options: SentryTrpcMiddlewareOptions = {}) {
5960
(clientOptions?.normalizeDepth ?? 5), // 5 is a sane depth
6061
);
6162

62-
if (options.attachRpcInput !== undefined ? options.attachRpcInput : clientOptions?.sendDefaultPii) {
63+
if (
64+
options.attachRpcInput !== undefined
65+
? options.attachRpcInput
66+
: dataCollection?.httpBodies.includes('incomingRequest')
67+
) {
6368
if (rawInput !== undefined) {
6469
trpcContext.input = normalize(rawInput);
6570
}

packages/core/test/lib/trpc.test.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { type Client, setCurrentClient, type Span, trpcMiddleware } from '../../
33
import * as currentScopes from '../../src/currentScopes';
44
import * as exports from '../../src/exports';
55
import * as tracing from '../../src/tracing';
6+
import { resolveDataCollectionOptions } from '../../src/utils/data-collection/resolveDataCollectionOptions';
67
import { getDefaultTestClientOptions, TestClient } from '../mocks/client';
78

89
describe('trpcMiddleware', () => {
@@ -13,6 +14,7 @@ describe('trpcMiddleware', () => {
1314
normalizeDepth: 3,
1415
sendDefaultPii: false,
1516
}),
17+
getDataCollectionOptions: vi.fn().mockReturnValue(resolveDataCollectionOptions({ sendDefaultPii: false })),
1618
captureException: vi.fn(),
1719
} as unknown as Client;
1820

0 commit comments

Comments
 (0)