-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(express): Support multiple routers with common paths. (#6253)
Handles the case when _at the end of reconstruction_ the original URL and the reconstructed URL don't match and there are no parameters.
- Loading branch information
1 parent
daacd38
commit 72c6855
Showing
16 changed files
with
329 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 34 additions & 0 deletions
34
...de-integration-tests/suites/express/multiple-routers/common-infix-parameterized/server.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import * as Sentry from '@sentry/node'; | ||
import * as Tracing from '@sentry/tracing'; | ||
import cors from 'cors'; | ||
import express from 'express'; | ||
|
||
const app = express(); | ||
|
||
Sentry.init({ | ||
dsn: 'https://[email protected]/1337', | ||
release: '1.0', | ||
integrations: [new Sentry.Integrations.Http({ tracing: true }), new Tracing.Integrations.Express({ app })], | ||
tracesSampleRate: 1.0, | ||
}); | ||
|
||
app.use(Sentry.Handlers.requestHandler()); | ||
app.use(Sentry.Handlers.tracingHandler()); | ||
|
||
app.use(cors()); | ||
|
||
const APIv1 = express.Router(); | ||
|
||
APIv1.get('/user/:userId', function (_req, res) { | ||
Sentry.captureMessage('Custom Message'); | ||
res.send('Success'); | ||
}); | ||
|
||
const root = express.Router(); | ||
|
||
app.use('/api2/v1', root); | ||
app.use('/api/v1', APIv1); | ||
|
||
app.use(Sentry.Handlers.errorHandler()); | ||
|
||
export default app; |
11 changes: 11 additions & 0 deletions
11
...node-integration-tests/suites/express/multiple-routers/common-infix-parameterized/test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import { assertSentryEvent, TestEnv } from '../../../../utils/index'; | ||
|
||
test('should construct correct url with common infixes with multiple parameterized routers.', async () => { | ||
const env = await TestEnv.init(__dirname, `${__dirname}/server.ts`); | ||
const event = await env.getEnvelopeRequest({ url: env.url.replace('test', 'api/v1/user/3212') }); | ||
|
||
assertSentryEvent(event[2] as any, { | ||
message: 'Custom Message', | ||
transaction: 'GET /api/v1/user/:userId', | ||
}); | ||
}); |
34 changes: 34 additions & 0 deletions
34
packages/node-integration-tests/suites/express/multiple-routers/common-infix/server.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import * as Sentry from '@sentry/node'; | ||
import * as Tracing from '@sentry/tracing'; | ||
import cors from 'cors'; | ||
import express from 'express'; | ||
|
||
const app = express(); | ||
|
||
Sentry.init({ | ||
dsn: 'https://[email protected]/1337', | ||
release: '1.0', | ||
integrations: [new Sentry.Integrations.Http({ tracing: true }), new Tracing.Integrations.Express({ app })], | ||
tracesSampleRate: 1.0, | ||
}); | ||
|
||
app.use(Sentry.Handlers.requestHandler()); | ||
app.use(Sentry.Handlers.tracingHandler()); | ||
|
||
app.use(cors()); | ||
|
||
const APIv1 = express.Router(); | ||
|
||
APIv1.get('/test', function (_req, res) { | ||
Sentry.captureMessage('Custom Message'); | ||
res.send('Success'); | ||
}); | ||
|
||
const root = express.Router(); | ||
|
||
app.use('/api/v1', root); | ||
app.use('/api2/v1', APIv1); | ||
|
||
app.use(Sentry.Handlers.errorHandler()); | ||
|
||
export default app; |
11 changes: 11 additions & 0 deletions
11
packages/node-integration-tests/suites/express/multiple-routers/common-infix/test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import { assertSentryEvent, TestEnv } from '../../../../utils/index'; | ||
|
||
test('should construct correct url with common infixes with multiple routers.', async () => { | ||
const env = await TestEnv.init(__dirname, `${__dirname}/server.ts`); | ||
const event = await env.getEnvelopeRequest({ url: env.url.replace('test', 'api2/v1/test/') }); | ||
|
||
assertSentryEvent(event[2] as any, { | ||
message: 'Custom Message', | ||
transaction: 'GET /api2/v1/test', | ||
}); | ||
}); |
34 changes: 34 additions & 0 deletions
34
...ation-tests/suites/express/multiple-routers/common-prefix-parameterized-reverse/server.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import * as Sentry from '@sentry/node'; | ||
import * as Tracing from '@sentry/tracing'; | ||
import cors from 'cors'; | ||
import express from 'express'; | ||
|
||
const app = express(); | ||
|
||
Sentry.init({ | ||
dsn: 'https://[email protected]/1337', | ||
release: '1.0', | ||
integrations: [new Sentry.Integrations.Http({ tracing: true }), new Tracing.Integrations.Express({ app })], | ||
tracesSampleRate: 1.0, | ||
}); | ||
|
||
app.use(Sentry.Handlers.requestHandler()); | ||
app.use(Sentry.Handlers.tracingHandler()); | ||
|
||
app.use(cors()); | ||
|
||
const APIv1 = express.Router(); | ||
|
||
APIv1.get('/user/:userId', function (_req, res) { | ||
Sentry.captureMessage('Custom Message'); | ||
res.send('Success'); | ||
}); | ||
|
||
const root = express.Router(); | ||
|
||
app.use('/api/v1', APIv1); | ||
app.use('/api', root); | ||
|
||
app.use(Sentry.Handlers.errorHandler()); | ||
|
||
export default app; |
11 changes: 11 additions & 0 deletions
11
...gration-tests/suites/express/multiple-routers/common-prefix-parameterized-reverse/test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import { assertSentryEvent, TestEnv } from '../../../../utils/index'; | ||
|
||
test('should construct correct urls with multiple parameterized routers (use order reversed).', async () => { | ||
const env = await TestEnv.init(__dirname, `${__dirname}/server.ts`); | ||
const event = await env.getEnvelopeRequest({ url: env.url.replace('test', 'api/v1/user/1234/') }); | ||
|
||
assertSentryEvent(event[2] as any, { | ||
message: 'Custom Message', | ||
transaction: 'GET /api/v1/user/:userId', | ||
}); | ||
}); |
34 changes: 34 additions & 0 deletions
34
...e-integration-tests/suites/express/multiple-routers/common-prefix-parameterized/server.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import * as Sentry from '@sentry/node'; | ||
import * as Tracing from '@sentry/tracing'; | ||
import cors from 'cors'; | ||
import express from 'express'; | ||
|
||
const app = express(); | ||
|
||
Sentry.init({ | ||
dsn: 'https://[email protected]/1337', | ||
release: '1.0', | ||
integrations: [new Sentry.Integrations.Http({ tracing: true }), new Tracing.Integrations.Express({ app })], | ||
tracesSampleRate: 1.0, | ||
}); | ||
|
||
app.use(Sentry.Handlers.requestHandler()); | ||
app.use(Sentry.Handlers.tracingHandler()); | ||
|
||
app.use(cors()); | ||
|
||
const APIv1 = express.Router(); | ||
|
||
APIv1.get('/user/:userId', function (_req, res) { | ||
Sentry.captureMessage('Custom Message'); | ||
res.send('Success'); | ||
}); | ||
|
||
const root = express.Router(); | ||
|
||
app.use('/api', root); | ||
app.use('/api/v1', APIv1); | ||
|
||
app.use(Sentry.Handlers.errorHandler()); | ||
|
||
export default app; |
11 changes: 11 additions & 0 deletions
11
...ode-integration-tests/suites/express/multiple-routers/common-prefix-parameterized/test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import { assertSentryEvent, TestEnv } from '../../../../utils/index'; | ||
|
||
test('should construct correct urls with multiple parameterized routers.', async () => { | ||
const env = await TestEnv.init(__dirname, `${__dirname}/server.ts`); | ||
const event = await env.getEnvelopeRequest({ url: env.url.replace('test', 'api/v1/user/1234/') }); | ||
|
||
assertSentryEvent(event[2] as any, { | ||
message: 'Custom Message', | ||
transaction: 'GET /api/v1/user/:userId', | ||
}); | ||
}); |
34 changes: 34 additions & 0 deletions
34
...ts/suites/express/multiple-routers/common-prefix-same-length-parameterized copy/server.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import * as Sentry from '@sentry/node'; | ||
import * as Tracing from '@sentry/tracing'; | ||
import cors from 'cors'; | ||
import express from 'express'; | ||
|
||
const app = express(); | ||
|
||
Sentry.init({ | ||
dsn: 'https://[email protected]/1337', | ||
release: '1.0', | ||
integrations: [new Sentry.Integrations.Http({ tracing: true }), new Tracing.Integrations.Express({ app })], | ||
tracesSampleRate: 1.0, | ||
}); | ||
|
||
app.use(Sentry.Handlers.requestHandler()); | ||
app.use(Sentry.Handlers.tracingHandler()); | ||
|
||
app.use(cors()); | ||
|
||
const APIv1 = express.Router(); | ||
|
||
APIv1.get('/:userId', function (_req, res) { | ||
Sentry.captureMessage('Custom Message'); | ||
res.send('Success'); | ||
}); | ||
|
||
const root = express.Router(); | ||
|
||
app.use('/api/v1', APIv1); | ||
app.use('/api', root); | ||
|
||
app.use(Sentry.Handlers.errorHandler()); | ||
|
||
export default app; |
11 changes: 11 additions & 0 deletions
11
...ests/suites/express/multiple-routers/common-prefix-same-length-parameterized copy/test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import { assertSentryEvent, TestEnv } from '../../../../utils/index'; | ||
|
||
test('should construct correct url with multiple parameterized routers of the same length (use order reversed).', async () => { | ||
const env = await TestEnv.init(__dirname, `${__dirname}/server.ts`); | ||
const event = await env.getEnvelopeRequest({ url: env.url.replace('test', 'api/v1/1234/') }); | ||
|
||
assertSentryEvent(event[2] as any, { | ||
message: 'Custom Message', | ||
transaction: 'GET /api/v1/:userId', | ||
}); | ||
}); |
34 changes: 34 additions & 0 deletions
34
...n-tests/suites/express/multiple-routers/common-prefix-same-length-parameterized/server.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import * as Sentry from '@sentry/node'; | ||
import * as Tracing from '@sentry/tracing'; | ||
import cors from 'cors'; | ||
import express from 'express'; | ||
|
||
const app = express(); | ||
|
||
Sentry.init({ | ||
dsn: 'https://[email protected]/1337', | ||
release: '1.0', | ||
integrations: [new Sentry.Integrations.Http({ tracing: true }), new Tracing.Integrations.Express({ app })], | ||
tracesSampleRate: 1.0, | ||
}); | ||
|
||
app.use(Sentry.Handlers.requestHandler()); | ||
app.use(Sentry.Handlers.tracingHandler()); | ||
|
||
app.use(cors()); | ||
|
||
const APIv1 = express.Router(); | ||
|
||
APIv1.get('/:userId', function (_req, res) { | ||
Sentry.captureMessage('Custom Message'); | ||
res.send('Success'); | ||
}); | ||
|
||
const root = express.Router(); | ||
|
||
app.use('/api', root); | ||
app.use('/api/v1', APIv1); | ||
|
||
app.use(Sentry.Handlers.errorHandler()); | ||
|
||
export default app; |
11 changes: 11 additions & 0 deletions
11
...ion-tests/suites/express/multiple-routers/common-prefix-same-length-parameterized/test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import { assertSentryEvent, TestEnv } from '../../../../utils/index'; | ||
|
||
test('should construct correct url with multiple parameterized routers of the same length.', async () => { | ||
const env = await TestEnv.init(__dirname, `${__dirname}/server.ts`); | ||
const event = await env.getEnvelopeRequest({ url: env.url.replace('test', 'api/v1/1234/') }); | ||
|
||
assertSentryEvent(event[2] as any, { | ||
message: 'Custom Message', | ||
transaction: 'GET /api/v1/:userId', | ||
}); | ||
}); |
34 changes: 34 additions & 0 deletions
34
packages/node-integration-tests/suites/express/multiple-routers/common-prefix/server.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import * as Sentry from '@sentry/node'; | ||
import * as Tracing from '@sentry/tracing'; | ||
import cors from 'cors'; | ||
import express from 'express'; | ||
|
||
const app = express(); | ||
|
||
Sentry.init({ | ||
dsn: 'https://[email protected]/1337', | ||
release: '1.0', | ||
integrations: [new Sentry.Integrations.Http({ tracing: true }), new Tracing.Integrations.Express({ app })], | ||
tracesSampleRate: 1.0, | ||
}); | ||
|
||
app.use(Sentry.Handlers.requestHandler()); | ||
app.use(Sentry.Handlers.tracingHandler()); | ||
|
||
app.use(cors()); | ||
|
||
const APIv1 = express.Router(); | ||
|
||
APIv1.get('/test', function (_req, res) { | ||
Sentry.captureMessage('Custom Message'); | ||
res.send('Success'); | ||
}); | ||
|
||
const root = express.Router(); | ||
|
||
app.use('/api', root); | ||
app.use('/api/v1', APIv1); | ||
|
||
app.use(Sentry.Handlers.errorHandler()); | ||
|
||
export default app; |
11 changes: 11 additions & 0 deletions
11
packages/node-integration-tests/suites/express/multiple-routers/common-prefix/test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import { assertSentryEvent, TestEnv } from '../../../../utils/index'; | ||
|
||
test('should construct correct urls with multiple routers.', async () => { | ||
const env = await TestEnv.init(__dirname, `${__dirname}/server.ts`); | ||
const event = await env.getEnvelopeRequest({ url: env.url.replace('test', 'api/v1/test/') }); | ||
|
||
assertSentryEvent(event[2] as any, { | ||
message: 'Custom Message', | ||
transaction: 'GET /api/v1/test', | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters