Skip to content

ref(core): Don't start transaction for trpc middleware #11697

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

Merged
merged 3 commits into from
Apr 19, 2024
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,12 @@ import { waitForError, waitForTransaction } from '@sentry-internal/event-proxy-s
import { createTRPCProxyClient, httpBatchLink } from '@trpc/client';
import type { AppRouter } from '../src/app';

const authToken = process.env.E2E_TEST_AUTH_TOKEN;
const sentryTestOrgSlug = process.env.E2E_TEST_SENTRY_ORG_SLUG;
const sentryTestProject = process.env.E2E_TEST_SENTRY_TEST_PROJECT;
const EVENT_POLLING_TIMEOUT = 90_000;

test('Should record transaction for trpc query', async ({ baseURL }) => {
test('Should record span for trpc query', async ({ baseURL }) => {
const transactionEventPromise = waitForTransaction('node-express-app', transactionEvent => {
return transactionEvent.transaction === 'trpc/getSomething';
return (
transactionEvent.transaction === 'GET /trpc' &&
!!transactionEvent.spans?.find(span => span.description === 'trpc/getSomething')
);
});

const trpcClient = createTRPCProxyClient<AppRouter>({
Expand All @@ -26,6 +24,16 @@ test('Should record transaction for trpc query', async ({ baseURL }) => {
await expect(transactionEventPromise).resolves.toBeDefined();
const transaction = await transactionEventPromise;

expect(transaction.spans).toContainEqual(
expect.objectContaining({
data: expect.objectContaining({
'sentry.op': 'rpc.server',
'sentry.origin': 'auto.rpc.trpc',
}),
description: `trpc/getSomething`,
}),
);

expect(transaction.contexts?.trpc).toMatchObject({
procedure_type: 'query',
input: 'foobar',
Expand All @@ -34,7 +42,10 @@ test('Should record transaction for trpc query', async ({ baseURL }) => {

test('Should record transaction for trpc mutation', async ({ baseURL }) => {
const transactionEventPromise = waitForTransaction('node-express-app', transactionEvent => {
return transactionEvent.transaction === 'trpc/createSomething';
return (
transactionEvent.transaction === 'POST /trpc' &&
!!transactionEvent.spans?.find(span => span.description === 'trpc/createSomething')
);
});

const trpcClient = createTRPCProxyClient<AppRouter>({
Expand All @@ -50,14 +61,27 @@ test('Should record transaction for trpc mutation', async ({ baseURL }) => {
await expect(transactionEventPromise).resolves.toBeDefined();
const transaction = await transactionEventPromise;

expect(transaction.spans).toContainEqual(
expect.objectContaining({
data: expect.objectContaining({
'sentry.op': 'rpc.server',
'sentry.origin': 'auto.rpc.trpc',
}),
description: `trpc/createSomething`,
}),
);

expect(transaction.contexts?.trpc).toMatchObject({
procedure_type: 'mutation',
});
});

test('Should record transaction and error for a crashing trpc handler', async ({ baseURL }) => {
const transactionEventPromise = waitForTransaction('node-express-app', transactionEvent => {
return transactionEvent.transaction === 'trpc/crashSomething';
return (
transactionEvent.transaction === 'POST /trpc' &&
!!transactionEvent.spans?.find(span => span.description === 'trpc/crashSomething')
);
});

const errorEventPromise = waitForError('node-express-app', errorEvent => {
Expand All @@ -80,7 +104,10 @@ test('Should record transaction and error for a crashing trpc handler', async ({

test('Should record transaction and error for a trpc handler that returns a status code', async ({ baseURL }) => {
const transactionEventPromise = waitForTransaction('node-express-app', transactionEvent => {
return transactionEvent.transaction === 'trpc/dontFindSomething';
return (
transactionEvent.transaction === 'POST /trpc' &&
!!transactionEvent.spans?.find(span => span.description === 'trpc/dontFindSomething')
);
});

const errorEventPromise = waitForError('node-express-app', errorEvent => {
Expand Down
1 change: 0 additions & 1 deletion packages/core/src/trpc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ export function trpcMiddleware(options: SentryTrpcMiddlewareOptions = {}) {
{
name: `trpc/${path}`,
op: 'rpc.server',
forceTransaction: true,
attributes: {
[SEMANTIC_ATTRIBUTE_SENTRY_SOURCE]: 'route',
[SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]: 'auto.rpc.trpc',
Expand Down
Loading