Skip to content

TRPC Middleware Context not Working as Expected with Batch Requests #16262

Open
@17Amir17

Description

@17Amir17

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

9.17.0

Framework Version

React Next 15.3.1

Link to Sentry event

https://amir-lf.sentry.io/issues/41286609/?project=4509151724830800&query=is%3Aunresolved%20issue.priority%3A%5Bhigh%2C%20medium%5D&referrer=issue-stream&stream_index=0

Reproduction Example/SDK Setup

Create a repo with minimal code that reproduces this https://github.com/17Amir17/SentryBug
Repo contains a simple nextjs app with trpc and sentry

One route called getCats this route accepts two params one which when true throws an exception and the the other contains an id which gets added as a tag - https://github.com/17Amir17/SentryBug/blob/main/src/pages/api/trpc/%5Btrpc%5D.ts

Steps to Reproduce

There are two problem that I see, to reproduce the first

  1. Click "throw error" button
  2. Two calls to the same trpc route will be called in batch with different parameters
  3. A tag is added with the cat id
  4. And error is thrown
  5. 1 sentry event is created
  6. Tag does not match the context

To reproduce the second

  1. Click fetch button
  2. Two calls to the same trpc route will be called in batch with different parameters
  3. A tag is added with the cat id
  4. 2 sentry events are created
  5. Tag does not match context

Expected Result

For both issues I'd expect to see two events and for the context to match the tag

Actual Result

For the first issue the tags do not match the context and there is only 1 event created

For the second issue the there are two events but the tag does not match the context

Image

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    Status

    No status

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions