-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
fix(node): Remove deprecated routerPath
warning of fastify request object
#13043
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
Changes from all commits
dc30143
0f3dd48
c8daf65
d48d0d5
e8388e8
5827a7b
09cf4bf
5b144f6
f131c74
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import { loggingTransport } from '@sentry-internal/node-integration-tests'; | ||
import * as Sentry from '@sentry/node'; | ||
|
||
Sentry.init({ | ||
dsn: 'https://[email protected]/1337', | ||
release: '1.0', | ||
transport: loggingTransport, | ||
}); | ||
|
||
import { startFastifyServerAndSendPortToRunner } from '@sentry-internal/node-integration-tests'; | ||
import fastify from 'fastify'; | ||
|
||
const app = fastify(); | ||
|
||
app.get('/test/deprecated', (_req, res) => { | ||
// eslint-disable-next-line @typescript-eslint/no-floating-promises | ||
res.send({}); | ||
}); | ||
|
||
Sentry.setupFastifyErrorHandler(app); | ||
|
||
startFastifyServerAndSendPortToRunner(app); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import { AxiosError } from 'axios'; | ||
import { cleanupChildProcesses, createRunner } from '../../../utils/runner'; | ||
|
||
afterAll(() => { | ||
cleanupChildProcesses(); | ||
}); | ||
|
||
/** | ||
* AxiosError throws before the deprecation warning code is invoked, | ||
* so mocking it would have no effect. | ||
* | ||
* But the deprecation warning is successfully suppressed. | ||
* This can be verified by running the example code as in the original | ||
* issue (https://github.com/getsentry/sentry-javascript/issues/12844) | ||
*/ | ||
test('suppress fastify deprecation warning when `routerPath` property is accessed', async () => { | ||
// ensures that the assertions in the catch block are called | ||
expect.assertions(3); | ||
|
||
const runner = createRunner(__dirname, 'server.ts').start(); | ||
|
||
try { | ||
// Axios from `makeRequest` will throw 404. | ||
await runner.makeRequest('get', '/test/deprecated/does-not-exist'); | ||
} catch (error) { | ||
expect(error).toBeInstanceOf(AxiosError); | ||
if (error instanceof AxiosError) { | ||
expect(error.message).toBe('Request failed with status code 404'); | ||
expect(error.response?.status).toBe(404); | ||
} | ||
} | ||
}); |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -30,6 +30,7 @@ interface FastifyRequestRouteInfo { | |
url?: string; | ||
method?: string; | ||
}; | ||
// will deprecate in Fastify 5 | ||
routerPath?: string; | ||
} | ||
|
||
|
@@ -79,7 +80,10 @@ export function setupFastifyErrorHandler(fastify: Fastify): void { | |
|
||
// Taken from Otel Fastify instrumentation: | ||
// https://github.com/open-telemetry/opentelemetry-js-contrib/blob/main/plugins/node/opentelemetry-instrumentation-fastify/src/instrumentation.ts#L94-L96 | ||
const routeName = reqWithRouteInfo.routeOptions?.url || reqWithRouteInfo.routerPath; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hey, thanks for the PR! Could we do the same change as they did in OTEL: const routeName = reqWithRouteInfo.routeOptions ? reqWithRouteInfo.routeOptions.url : reqWithRouteInfo.routerPath; Otherwise, this stops working on older fastify versions, I guess, which we do not want! There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oh i see! So the |
||
const routeName = reqWithRouteInfo.routeOptions | ||
? reqWithRouteInfo.routeOptions.url | ||
: reqWithRouteInfo.routerPath; | ||
|
||
const method = reqWithRouteInfo.routeOptions?.method || 'GET'; | ||
|
||
getIsolationScope().setTransactionName(`${method} ${routeName}`); | ||
|
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.
For future readers - we had to pin this at
~4.23.2
because4.33+
only works with TS 5, which breaks the rest of our tests 😬