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
fix(express): Support multiple routers with common paths. #6253
Merged
Merged
Changes from 1 commit
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
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://public@dsn.ingest.sentry.io/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://public@dsn.ingest.sentry.io/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
...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://public@dsn.ingest.sentry.io/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
...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://public@dsn.ingest.sentry.io/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://public@dsn.ingest.sentry.io/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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looking at #6004, this is the order in which the parameterization was incorrect (so this is fixed, great!). Can we also verify that swapping the order still works (as the user originally reported)?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added tests 👍