Description
Is there an existing issue for this?
- I have checked for existing issues https://github.com/getsentry/sentry-javascript/issues
- I have reviewed the documentation https://docs.sentry.io/
- I am using the latest SDK release https://github.com/getsentry/sentry-javascript/releases
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
- Transaction when it was still working: https://lhdev.sentry.io/performance/summary/?environment=PROD&project=5664623&query=http.method%3AGET&referrer=performance-transaction-summary&statsPeriod=90d&transaction=GET+%2Frooms%2F%3AroomPid%28%5BA-Z0-9%5D%7B8%7D%29&unselectedSeries=p100%28%29&unselectedSeries=avg%28%29
- Transaction for the same route after it broke: https://lhdev.sentry.io/performance/summary/?environment=PROD&project=5664623&query=http.method%3AGET&referrer=performance-transaction-summary&statsPeriod=90d&transaction=GET+%2Frooms%2FA6SW5R48&unselectedSeries=p100%28%29&unselectedSeries=avg%28%29
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
- Start the express test server from the code above
node -r dotenv/config index.js
. - Trigger a GET request to the example route
GET http://127.0.0.1:3000/test/hello/world
. - 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:
-
extractPathForTransaction
is called twice (https://github.com/getsentry/sentry-javascript/blob/7.108.0/packages/tracing-internal/src/node/integrations/express.ts), first for thesentryTracingMiddleware
without thereq.route
being undefined, second for theinstrumentRouter
function with thereq.route
being correct. -
extractPathForTransaction
-> https://github.com/getsentry/sentry-javascript/blob/7.108.0/packages/utils/src/requestdata.ts#L107 -
sentryTracingMiddleware
-> https://github.com/getsentry/sentry-javascript/blob/7.108.0/packages/node/src/handlers.ts#L45 -
instrumentRouter
-> https://github.com/getsentry/sentry-javascript/blob/7.108.0/packages/tracing-internal/src/node/integrations/express.ts#L278
Metadata
Metadata
Assignees
Type
Projects
Status
Status