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

When running sentry.init with opentelemetry in next.js instrumentation, next.route span attributes is lost #15634

Open
3 tasks done
rlawnsxo131 opened this issue Mar 11, 2025 · 4 comments
Labels
Package: nextjs Issues related to the Sentry Nextjs SDK

Comments

@rlawnsxo131
Copy link

rlawnsxo131 commented Mar 11, 2025

Is there an existing issue for this?

How do you use Sentry?

Self-hosted/on-premise

Which SDK are you using?

@sentry/nextjs

SDK Version

8.42.0, 9.5.0

It is reproduced in both versions.

Framework Version

next@15.1.7

Link to Sentry event

No response

Reproduction Example/SDK Setup

github repository link

DSN is internal information so it is not published, but it does not have any effect on reproducing the issue.

Sentry.init({
  dsn: "john-dsn",
  release: "john-release",
});

Steps to Reproduce

  1. project clone
  2. Run without commenting out the line(reproduce the problem) - pnpm dev
  3. Comment out the line and run it (desired behavior) - pnpm dev

Running pnpm dev and build after that gives the same result.

Expected Result

next.route must remain in BaseServer.handleRequest span_type regardless of whether sentry.init is included in the code or not

Actual Result

Additional Details

  1. I am using next.js and opentelemetry and prometheus together.
  2. At this time, we are trying to add metrics to prometheus by utilizing next.route, an opentelemetry span element provided by next.js.
  3. However, when running sentry.init in the instrumentation file like the sentry guide says, the next.route span element is lost in the BaseServer.handleRequest event logged in onEnd.
  4. When sentry.init is excluded from the code, the next.route span element remains normally.

Why does the next.route span element disappear depending on whether sentry.init is present or not?
Not shown in the image, but other span elements also change depending on sentry.init being run.

You can easily reproduce this by cloning the above repository and running the project.

Actual Result

  • When sentry.init is excluded from the line
Image Image
  • When sentry.init is included in the line
Image Image
@getsantry getsantry bot moved this to Waiting for: Product Owner in GitHub Issues with 👀 3 Mar 11, 2025
@github-actions github-actions bot added the Package: nextjs Issues related to the Sentry Nextjs SDK label Mar 11, 2025
@rlawnsxo131
Copy link
Author

Link to issue that looks similar to this: #14660

@lforst
Copy link
Member

lforst commented Mar 12, 2025

Hi, I looked into this a bit and can reproduce. I don't think we are stomping on the attribute directly. Instead what we're doing is hoisting spans above the BaseServer.handleRequest span and Next.js applies the next.route attribute to the "local root span"

Here are the attributes for the same req span before and after adding Sentry.

Before:

[info] span_type: BaseServer.handleRequest route: / {
  'next.span_name': 'RSC GET /',
  'next.span_type': 'BaseServer.handleRequest',
  'http.method': 'GET',
  'http.target': '/?_rsc=5vw47',
  'http.status_code': 200,
  'next.rsc': true,
  'next.route': '/',
  'http.route': '/'
}

After:

[info] span_type: BaseServer.handleRequest route: undefined {
  'next.span_name': 'GET /?_rsc=5vw47',
  'next.span_type': 'BaseServer.handleRequest',
  'http.method': 'GET',
  'http.target': '/?_rsc=5vw47',
  'http.status_code': 200,
  'next.rsc': true
}

I am backlogging for now but also don't think we will fix this soon.

@rlawnsxo131
Copy link
Author

@lforst

Hello!

Before I begin, i would like to express my gratitude for quickly checking my issue and for the effort you put into maintaining this project.

I fully understand that it may not be possible to fix this issue immediately. Houwever, I hope this problem can be resolved as soon as possible.

Although it was unintentional, the interaction between various libraries may add new values, but it seems necessary to improve the situation where they interface with each other and affect the original data.

This is very important metric for monitoring the state and improving the performance of many applications at my current company.

While it is not an issue with Sentry or OpenTelemetry, if we cannot record query string or path parameters by pattern, the cardinality of data in the application memory will continuously increase, which may put a load on the application.

Of course, using regular expressions or specific path patterns can alleviate this to dome extent, but it is not easy for all developers in other teams to create it according to the requirements of the applications they are developing.

I would be very grateful if this could be improved. I hope this issue can be resolved, even if it takes time. Can you notify me when you start working on it?

Once again, thank you for your hard work.

@getsantry getsantry bot moved this to Waiting for: Product Owner in GitHub Issues with 👀 3 Mar 13, 2025
@lforst
Copy link
Member

lforst commented Mar 13, 2025

Hi, I fear we wont be able to pick this up anytime soon. Feel free to contribute a fix to the SDK or Next.js itself!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Package: nextjs Issues related to the Sentry Nextjs SDK
Projects
Status: No status
Development

No branches or pull requests

2 participants