Skip to content
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

fix(core): Update trpc middleware types #13859

Merged
merged 5 commits into from
Oct 3, 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 @@ -70,8 +70,8 @@ export const createCallerFactory = t.createCallerFactory;
*/
export const createTRPCRouter = t.router;

const sentryMiddleware = Sentry.trpcMiddleware({
attachRpcInput: true,
});

export const publicProcedure = t.procedure.use(async opts => sentryMiddleware(opts));
export const publicProcedure = t.procedure.use(
Sentry.trpcMiddleware({
attachRpcInput: true,
}),
);
Original file line number Diff line number Diff line change
Expand Up @@ -105,9 +105,7 @@ Sentry.addEventProcessor(event => {

export const t = initTRPC.context<Context>().create();

const sentryMiddleware = Sentry.trpcMiddleware({ attachRpcInput: true });

const procedure = t.procedure.use(async opts => sentryMiddleware(opts));
const procedure = t.procedure.use(Sentry.trpcMiddleware({ attachRpcInput: true }));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we are back baby


export const appRouter = t.router({
getSomething: procedure.input(z.string()).query(opts => {
Expand Down
8 changes: 6 additions & 2 deletions packages/core/src/trpc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,15 @@ function captureIfError(nextResult: unknown): void {
}
}

type SentryTrpcMiddleware<T> = T extends Promise<unknown> ? T : Promise<T>;

/**
* Sentry tRPC middleware that captures errors and creates spans for tRPC procedures.
*/
export function trpcMiddleware(options: SentryTrpcMiddlewareOptions = {}) {
return async function <T>(opts: SentryTrpcMiddlewareArguments<T>): Promise<T> {
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
return async function <T>(opts: SentryTrpcMiddlewareArguments<T>): SentryTrpcMiddleware<T> {
const { path, type, next, rawInput, getRawInput } = opts;

const client = getClient();
Expand Down Expand Up @@ -85,6 +89,6 @@ export function trpcMiddleware(options: SentryTrpcMiddlewareOptions = {}) {
throw e;
}
},
);
) as SentryTrpcMiddleware<T>;
};
}
Loading