getsentry / sentry-javascript

Official Sentry SDKs for JavaScript
https://sentry.io
MIT License
8.02k stars 1.59k forks source link

attachRpcInput not working for trpc v11 #13795

Closed DawnMD closed 2 months ago

DawnMD commented 2 months ago

Is there an existing issue for this?

How do you use Sentry?

Sentry Saas (sentry.io)

Which SDK are you using?

@sentry/nextjs

SDK Version

8.30.0

Framework Version

Next 14.2.11

Link to Sentry event

No response

Reproduction Example/SDK Setup

I have added this in tprc.ts file

const timingMiddleware = t.middleware(async ({ next, path }) => {
  const start = Date.now();

  if (t._config.isDev) {
    // artificial delay in dev
    const waitMs = Math.floor(Math.random() * 400) + 100;
    await new Promise((resolve) => setTimeout(resolve, waitMs));
  }

  const result = await next();

  const end = Date.now();
  console.log(`[TRPC] ${path} took ${end - start}ms to execute`);

  return result;
});

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

export const publicProcedure = t.procedure
  .use(sentryMiddleware)
  .use(timingMiddleware);

Also sentry.init is as follows

// This file configures the initialization of Sentry on the client.
// The config you add here will be used whenever a users loads a page in their browser.
// https://docs.sentry.io/platforms/javascript/guides/nextjs/

import * as Sentry from "@sentry/nextjs";
import { env } from "./env";

Sentry.init({
  dsn: env.NEXT_PUBLIC_SENTRY_DSN,
  environment: env.NEXT_PUBLIC_SENTRY_ENV,

  // Adjust this value in production, or use tracesSampler for greater control
  tracesSampleRate: 1,

  // Setting this option to true will print useful information to the console while you're setting up Sentry.
  debug: false,

  replaysOnErrorSampleRate: 1.0,

  // This sets the sample rate to be 10%. You may want this to be 100% while
  // in development and sample at a lower rate in production
  replaysSessionSampleRate: 0.1,

  // You can remove this option if you're not planning to use the Sentry Session Replay feature:
  integrations: [
    Sentry.replayIntegration({
      // Additional Replay configuration goes in here, for example:
      maskAllText: true,
      blockAllMedia: true,
    }),
  ],
});

Steps to Reproduce

  1. Create a new repo with t3 stack
  2. add sentry
  3. add sentry trpc middleware
  4. throw a error from mutation procedure

I can only see the error that is thrown from trpc procedure with throw new Error(.....) but the inputs are not passed to sentry!

Expected Result

I expect to see the input passed on to the mutation procedure!

Actual Result

Image

DawnMD commented 2 months ago

Or maybe it is sending the input but its hidden somewhere in the UI I'm not seeing! πŸ€”πŸ€”

chargome commented 2 months ago

@DawnMD thanks for reaching out – could you send me a link to a specific event? If you don't want to share it here you can send me an email to [myfirstname].[mylastname]@sentry.io or on Discord.

DawnMD commented 2 months ago

@chargome Discord would be nice actually. Can I get your ID?

chargome commented 2 months ago

@DawnMD https://discord.com/invite/sentry my id is chargome_

DawnMD commented 2 months ago

@DawnMD https://discord.com/invite/sentry my id is chargome_

DM'd you with the issue link from sentry!

chargome commented 2 months ago

Follow up: this was due to a change in the trpc middleware in v11 – the fix will be released soon.

github-actions[bot] commented 1 month ago

A PR closing this issue has just been released πŸš€

This issue was referenced by PR #13831, which was included in the 8.33.0 release.

JoeKarow commented 1 month ago

The PR associated with this issue (#13831) may have introduced type errors for tRPC v10. When upgrading Sentry from v8.32.0 to v8.33.0, I get this TypeScript error when initializing the tRPC middleware: Image

It looks like this may be the culprit, causing a double wrapped promise for tRPC v10. https://github.com/getsentry/sentry-javascript/blob/febdfc6ef8c2ae8eddd825163b9a8b175acbe3f7/packages/core/src/trpc.ts#L40