Skip to content

[7.108.0] Sentry.Handlers.tracingHandler uses incorret route name in Express server  #11337

Closed
@lhermann

Description

@lhermann

Is there an existing issue for this?

How do you use Sentry?

Sentry Saas (sentry.io)

Which SDK are you using?

@sentry/node

SDK Version

7.108.0

Framework Version

Node 18, Express 4.19.2

Link to Sentry event

SDK Setup

import * as Sentry from '@sentry/node'
import { nodeProfilingIntegration } from '@sentry/profiling-node'
import express from 'express'

const app = express()

Sentry.init({
  dsn: process.env.SENTRY_DSN,
  enabled: Boolean(process.env.SENTRY_DSN),
  release: process.env.npm_package_version,
  environment: process.env.SENTRY_ENV,
  serverName: process.env.SERVER_ID,
  integrations: [
    new Sentry.Integrations.Express({ app }),
    nodeProfilingIntegration(),
  ],
  sampleRate: 1,
  tracesSampler: (samplingContext) => {
    console.log('[Sentry]', { samplingContext: samplingContext.transactionContext.name })
    return 0.05
  },
  profilesSampleRate: 0.2,
})

const router = express.Router()

router.use(Sentry.Handlers.requestHandler())
router.use(Sentry.Handlers.tracingHandler())

router.get('/test/:first/:second', (req, res) => {
  console.log('[Test Route]', { 'req.route.path': req.route.path })
  console.log('[Test Route]', { 'req.originalUrl': req.originalUrl })
  res.sendStatus(200)
})

router.use(Sentry.Handlers.errorHandler())

app.use(router)

app.listen(process.env.PORT, () => {
  console.log(`Example app listening on port ${process.env.PORT}`)
})

Steps to Reproduce

  1. Start the express test server from the code above node -r dotenv/config index.js.
  2. Trigger a GET request to the example route GET http://127.0.0.1:3000/test/hello/world.
  3. Observe the console output.

Expected Result

[Sentry] { samplingContext: 'GET /test/:first/:second' }
[Test Route] { 'req.route.path': '/test/:first/:second' }
[Test Route] { 'req.originalUrl': '/test/hello/world' }

I expect the Sentry Trace to use the route name /test/:first/:second.

Actual Result

[Sentry] { samplingContext: 'GET /test/hello/world' }
[Test Route] { 'req.route.path': '/test/:first/:second' }
[Test Route] { 'req.originalUrl': '/test/hello/world' }

The Sentry Trace uses the originalUrl /test/hello/world instead of the router path name.
As an effect, the performance dashboard is nearly useless, because all requests are filed under different names.

Observations:

Metadata

Metadata

Assignees

No one assigned

    Labels

    Package: nodeIssues related to the Sentry Node SDK

    Type

    Projects

    Status

    No status

    Status

    No status

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions