Skip to content

NextJS doesn't wrap API routes so DB Spans are only attached to root transaction #5779

Closed
@silent1mezzo

Description

@silent1mezzo

Is there an existing issue for this?

How do you use Sentry?

Sentry Saas (sentry.io)

Which package are you using?

@sentry/nextjs

SDK Version

7.13

Framework Version

12.3

Link to Sentry event

https://sentry.io/organizations/adam-bl/performance/nextjs:9b1bb4037b9f4df8ab087b6521493df0/?project=6761253&query=&showTransactions=recent&statsPeriod=24h&transaction=GET+%2Fapi%2Freports&unselectedSeries=p100%28%29

Steps to Reproduce

  1. Build an API endpoint in Nextjs
  2. Use Prisma to load data
  3. Look at span in Sentry
// /api/reports.tsx
const handler = async (req, res) => {
    console.log("here");
    let reports = await prisma.report.findMany({
        orderBy: { submittedDate: 'desc' }
      })

    for (const report of reports) {
      const expenses = await prisma.expense.findMany({
        where: { reportId: report.id }
      })
    }
    res.status(200).json({ reports })
}

export default withSentry(handler);

Expected Result

DB spans would be nested under an API route

transaction
/api/reports
db.prisma
db.prisma
db.prisma
db.prisma
...

Actual Result

Screen Shot 2022-09-20 at 7 12 43 AM

Metadata

Metadata

Assignees

No one assigned

    Labels

    Package: nextjsIssues related to the Sentry Nextjs SDK

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions