diff --git a/packages/nextjs/src/config/templates/apiWrapperTemplate.ts b/packages/nextjs/src/config/templates/apiWrapperTemplate.ts index 969d433f126f..91cf5ef1e0c6 100644 --- a/packages/nextjs/src/config/templates/apiWrapperTemplate.ts +++ b/packages/nextjs/src/config/templates/apiWrapperTemplate.ts @@ -54,7 +54,7 @@ export const config = { }, }; -export default userProvidedHandler ? Sentry.withSentryAPI(userProvidedHandler, '__ROUTE__') : undefined; +export default userProvidedHandler ? Sentry.wrapApiHandlerWithSentry(userProvidedHandler, '__ROUTE__') : undefined; // Re-export anything exported by the page module we're wrapping. When processing this code, Rollup is smart enough to // not include anything whose name matchs something we've explicitly exported above. diff --git a/packages/nextjs/src/config/templates/middlewareWrapperTemplate.ts b/packages/nextjs/src/config/templates/middlewareWrapperTemplate.ts index 373f63646933..0c833023cffe 100644 --- a/packages/nextjs/src/config/templates/middlewareWrapperTemplate.ts +++ b/packages/nextjs/src/config/templates/middlewareWrapperTemplate.ts @@ -40,8 +40,10 @@ if ('middleware' in userApiModule && typeof userApiModule.middleware === 'functi userProvidedDefaultHandler = userApiModule; } -export const middleware = userProvidedNamedHandler ? Sentry.withSentryMiddleware(userProvidedNamedHandler) : undefined; -export default userProvidedDefaultHandler ? Sentry.withSentryMiddleware(userProvidedDefaultHandler) : undefined; +export const middleware = userProvidedNamedHandler + ? Sentry.wrapMiddlewareWithSentry(userProvidedNamedHandler) + : undefined; +export default userProvidedDefaultHandler ? Sentry.wrapMiddlewareWithSentry(userProvidedDefaultHandler) : undefined; // Re-export anything exported by the page module we're wrapping. When processing this code, Rollup is smart enough to // not include anything whose name matchs something we've explicitly exported above. diff --git a/packages/nextjs/src/config/templates/pageWrapperTemplate.ts b/packages/nextjs/src/config/templates/pageWrapperTemplate.ts index 955e920552d1..12b8429bc7d4 100644 --- a/packages/nextjs/src/config/templates/pageWrapperTemplate.ts +++ b/packages/nextjs/src/config/templates/pageWrapperTemplate.ts @@ -28,12 +28,12 @@ const origGetStaticProps = userPageModule.getStaticProps; const origGetServerSideProps = userPageModule.getServerSideProps; const getInitialPropsWrappers: Record = { - '/_app': Sentry.withSentryServerSideAppGetInitialProps, - '/_document': Sentry.withSentryServerSideDocumentGetInitialProps, - '/_error': Sentry.withSentryServerSideErrorGetInitialProps, + '/_app': Sentry.wrapAppGetInitialPropsWithSentry, + '/_document': Sentry.wrapDocumentGetInitialPropsWithSentry, + '/_error': Sentry.wrapErrorGetInitialPropsWithSentry, }; -const getInitialPropsWrapper = getInitialPropsWrappers['__ROUTE__'] || Sentry.withSentryServerSideGetInitialProps; +const getInitialPropsWrapper = getInitialPropsWrappers['__ROUTE__'] || Sentry.wrapGetInitialPropsWithSentry; if (typeof origGetInitialProps === 'function') { pageComponent.getInitialProps = getInitialPropsWrapper(origGetInitialProps) as NextPageComponent['getInitialProps']; @@ -41,11 +41,11 @@ if (typeof origGetInitialProps === 'function') { export const getStaticProps = typeof origGetStaticProps === 'function' - ? Sentry.withSentryGetStaticProps(origGetStaticProps, '__ROUTE__') + ? Sentry.wrapGetStaticPropsWithSentry(origGetStaticProps, '__ROUTE__') : undefined; export const getServerSideProps = typeof origGetServerSideProps === 'function' - ? Sentry.withSentryGetServerSideProps(origGetServerSideProps, '__ROUTE__') + ? Sentry.wrapGetServerSidePropsWithSentry(origGetServerSideProps, '__ROUTE__') : undefined; export default pageComponent; diff --git a/packages/nextjs/src/edge/index.ts b/packages/nextjs/src/edge/index.ts index b0ad8ec23901..712b0f61a81f 100644 --- a/packages/nextjs/src/edge/index.ts +++ b/packages/nextjs/src/edge/index.ts @@ -131,5 +131,11 @@ export function lastEventId(): string | undefined { export { flush } from './utils/flush'; export * from '@sentry/core'; -export { withSentryAPI } from './withSentryAPI'; -export { withSentryMiddleware } from './withSentryMiddleware'; + +export { + // eslint-disable-next-line deprecation/deprecation + withSentryAPI, + wrapApiHandlerWithSentry, +} from './wrapApiHandlerWithSentry'; + +export { wrapMiddlewareWithSentry } from './wrapMiddlewareWithSentry'; diff --git a/packages/nextjs/src/edge/withSentryAPI.ts b/packages/nextjs/src/edge/wrapApiHandlerWithSentry.ts similarity index 78% rename from packages/nextjs/src/edge/withSentryAPI.ts rename to packages/nextjs/src/edge/wrapApiHandlerWithSentry.ts index d18deac1c3c4..7e87c6a5e607 100644 --- a/packages/nextjs/src/edge/withSentryAPI.ts +++ b/packages/nextjs/src/edge/wrapApiHandlerWithSentry.ts @@ -6,7 +6,7 @@ import { withEdgeWrapping } from './utils/edgeWrapperUtils'; /** * Wraps a Next.js edge route handler with Sentry error and performance instrumentation. */ -export function withSentryAPI( +export function wrapApiHandlerWithSentry( handler: H, parameterizedRoute: string, ): (...params: Parameters) => Promise> { @@ -21,9 +21,14 @@ export function withSentryAPI( ? `handler (${parameterizedRoute})` : `${req.method} ${parameterizedRoute}`, spanOp: activeSpan ? 'function' : 'http.server', - mechanismFunctionName: 'withSentryAPI', + mechanismFunctionName: 'wrapApiHandlerWithSentry', }); return await wrappedHandler.apply(this, args); }; } + +/** + * @deprecated Use `wrapApiHandlerWithSentry` instead. + */ +export const withSentryAPI = wrapApiHandlerWithSentry; diff --git a/packages/nextjs/src/edge/withSentryMiddleware.ts b/packages/nextjs/src/edge/wrapMiddlewareWithSentry.ts similarity index 73% rename from packages/nextjs/src/edge/withSentryMiddleware.ts rename to packages/nextjs/src/edge/wrapMiddlewareWithSentry.ts index 74dd6619ed62..cb535c41b28d 100644 --- a/packages/nextjs/src/edge/withSentryMiddleware.ts +++ b/packages/nextjs/src/edge/wrapMiddlewareWithSentry.ts @@ -3,8 +3,11 @@ import { withEdgeWrapping } from './utils/edgeWrapperUtils'; /** * Wraps Next.js middleware with Sentry error and performance instrumentation. + * + * @param middleware The middleware handler. + * @returns a wrapped middleware handler. */ -export function withSentryMiddleware( +export function wrapMiddlewareWithSentry( middleware: H, ): (...params: Parameters) => Promise> { return withEdgeWrapping(middleware, { diff --git a/packages/nextjs/src/index.types.ts b/packages/nextjs/src/index.types.ts index 9f82be80a67c..fbc3bec2d71b 100644 --- a/packages/nextjs/src/index.types.ts +++ b/packages/nextjs/src/index.types.ts @@ -30,9 +30,26 @@ export declare function flush(timeout?: number | undefined): PromiseLike any>( handler: APIHandler, parameterizedRoute: string, ): ( ...args: Parameters ) => ReturnType extends Promise ? ReturnType : Promise>; + +/** + * Wraps a Next.js API handler with Sentry error and performance instrumentation. + * + * @param handler The handler exported from the API route file. + * @param parameterizedRoute The page's parameterized route. + * @returns The wrapped handler. + */ +export declare function wrapApiHandlerWithSentry any>( + handler: APIHandler, + parameterizedRoute: string, +): ( + ...args: Parameters +) => ReturnType extends Promise ? ReturnType : Promise>; diff --git a/packages/nextjs/src/server/index.ts b/packages/nextjs/src/server/index.ts index 340f4100d611..8ab42f9aa829 100644 --- a/packages/nextjs/src/server/index.ts +++ b/packages/nextjs/src/server/index.ts @@ -148,10 +148,44 @@ const deprecatedIsBuild = (): boolean => isBuild(); // eslint-disable-next-line deprecation/deprecation export { deprecatedIsBuild as isBuild }; -export { withSentryGetStaticProps } from './withSentryGetStaticProps'; -export { withSentryServerSideGetInitialProps } from './withSentryServerSideGetInitialProps'; -export { withSentryServerSideAppGetInitialProps } from './withSentryServerSideAppGetInitialProps'; -export { withSentryServerSideDocumentGetInitialProps } from './withSentryServerSideDocumentGetInitialProps'; -export { withSentryServerSideErrorGetInitialProps } from './withSentryServerSideErrorGetInitialProps'; -export { withSentryGetServerSideProps } from './withSentryGetServerSideProps'; -export { withSentry, withSentryAPI } from './withSentryAPI'; +export { + // eslint-disable-next-line deprecation/deprecation + withSentryGetStaticProps, + wrapGetStaticPropsWithSentry, +} from './wrapGetStaticPropsWithSentry'; + +export { + // eslint-disable-next-line deprecation/deprecation + withSentryServerSideGetInitialProps, + wrapGetInitialPropsWithSentry, +} from './wrapGetInitialPropsWithSentry'; + +export { + // eslint-disable-next-line deprecation/deprecation + withSentryServerSideAppGetInitialProps, + wrapAppGetInitialPropsWithSentry, +} from './wrapAppGetInitialPropsWithSentry'; +export { + // eslint-disable-next-line deprecation/deprecation + withSentryServerSideDocumentGetInitialProps, + wrapDocumentGetInitialPropsWithSentry, +} from './wrapDocumentGetInitialPropsWithSentry'; +export { + // eslint-disable-next-line deprecation/deprecation + withSentryServerSideErrorGetInitialProps, + wrapErrorGetInitialPropsWithSentry, +} from './wrapErrorGetInitialPropsWithSentry'; + +export { + // eslint-disable-next-line deprecation/deprecation + withSentryGetServerSideProps, + wrapGetServerSidePropsWithSentry, +} from './wrapGetServerSidePropsWithSentry'; + +export { + // eslint-disable-next-line deprecation/deprecation + withSentry, + // eslint-disable-next-line deprecation/deprecation + withSentryAPI, + wrapApiHandlerWithSentry, +} from './wrapApiHandlerWithSentry'; diff --git a/packages/nextjs/src/server/withSentryAPI.ts b/packages/nextjs/src/server/wrapApiHandlerWithSentry.ts similarity index 95% rename from packages/nextjs/src/server/withSentryAPI.ts rename to packages/nextjs/src/server/wrapApiHandlerWithSentry.ts index 5d5180dd741e..44cad73e6e81 100644 --- a/packages/nextjs/src/server/withSentryAPI.ts +++ b/packages/nextjs/src/server/wrapApiHandlerWithSentry.ts @@ -25,7 +25,7 @@ import { autoEndTransactionOnResponseEnd, finishTransaction, flushQueue } from ' * @param parameterizedRoute The page's route, passed in via the proxy loader * @returns The wrapped handler */ -export function withSentryAPI( +export function wrapApiHandlerWithSentry( maybeWrappedHandler: NextApiHandler | WrappedNextApiHandler, parameterizedRoute: string, ): WrappedNextApiHandler { @@ -47,20 +47,28 @@ export function withSentryAPI( ); } + // eslint-disable-next-line deprecation/deprecation return withSentry(maybeWrappedHandler, parameterizedRoute); } /** - * Legacy function for manually wrapping API route handlers, now used as the innards of `withSentryAPI`. + * @deprecated Use `wrapApiHandlerWithSentry()` instead + */ +export const withSentryAPI = wrapApiHandlerWithSentry; + +/** + * Legacy function for manually wrapping API route handlers, now used as the innards of `wrapApiHandlerWithSentry`. * * @param origHandler The user's original API route handler * @param parameterizedRoute The route whose handler is being wrapped. Meant for internal use only. * @returns A wrapped version of the handler + * + * @deprecated Use `wrapApiWithSentry()` instead */ export function withSentry(origHandler: NextApiHandler, parameterizedRoute?: string): WrappedNextApiHandler { // eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types return async function sentryWrappedHandler(req: AugmentedNextApiRequest, res: AugmentedNextApiResponse) { - // We're now auto-wrapping API route handlers using `withSentryAPI` (which uses `withSentry` under the hood), but + // We're now auto-wrapping API route handlers using `wrapApiHandlerWithSentry` (which uses `withSentry` under the hood), but // users still may have their routes manually wrapped with `withSentry`. This check makes `sentryWrappedHandler` // idempotent so that those cases don't break anything. if (req.__withSentry_applied__) { diff --git a/packages/nextjs/src/server/withSentryServerSideAppGetInitialProps.ts b/packages/nextjs/src/server/wrapAppGetInitialPropsWithSentry.ts similarity index 91% rename from packages/nextjs/src/server/withSentryServerSideAppGetInitialProps.ts rename to packages/nextjs/src/server/wrapAppGetInitialPropsWithSentry.ts index 1508661db73e..d21ecfc0a44e 100644 --- a/packages/nextjs/src/server/withSentryServerSideAppGetInitialProps.ts +++ b/packages/nextjs/src/server/wrapAppGetInitialPropsWithSentry.ts @@ -19,7 +19,7 @@ type AppGetInitialProps = typeof App['getInitialProps']; * @param parameterizedRoute The page's parameterized route * @returns A wrapped version of the function */ -export function withSentryServerSideAppGetInitialProps(origAppGetInitialProps: AppGetInitialProps): AppGetInitialProps { +export function wrapAppGetInitialPropsWithSentry(origAppGetInitialProps: AppGetInitialProps): AppGetInitialProps { return async function (this: unknown, ...args: Parameters): ReturnType { if (isBuild()) { return origAppGetInitialProps.apply(this, args); @@ -72,3 +72,8 @@ export function withSentryServerSideAppGetInitialProps(origAppGetInitialProps: A } }; } + +/** + * @deprecated Use `wrapAppGetInitialPropsWithSentry` instead. + */ +export const withSentryServerSideAppGetInitialProps = wrapAppGetInitialPropsWithSentry; diff --git a/packages/nextjs/src/server/withSentryServerSideDocumentGetInitialProps.ts b/packages/nextjs/src/server/wrapDocumentGetInitialPropsWithSentry.ts similarity index 89% rename from packages/nextjs/src/server/withSentryServerSideDocumentGetInitialProps.ts rename to packages/nextjs/src/server/wrapDocumentGetInitialPropsWithSentry.ts index 95c45da095aa..7052250275d7 100644 --- a/packages/nextjs/src/server/withSentryServerSideDocumentGetInitialProps.ts +++ b/packages/nextjs/src/server/wrapDocumentGetInitialPropsWithSentry.ts @@ -14,7 +14,7 @@ type DocumentGetInitialProps = typeof Document.getInitialProps; * @param parameterizedRoute The page's parameterized route * @returns A wrapped version of the function */ -export function withSentryServerSideDocumentGetInitialProps( +export function wrapDocumentGetInitialPropsWithSentry( origDocumentGetInitialProps: DocumentGetInitialProps, ): DocumentGetInitialProps { return async function ( @@ -47,3 +47,8 @@ export function withSentryServerSideDocumentGetInitialProps( } }; } + +/** + * @deprecated Use `wrapDocumentGetInitialPropsWithSentry` instead. + */ +export const withSentryServerSideDocumentGetInitialProps = wrapDocumentGetInitialPropsWithSentry; diff --git a/packages/nextjs/src/server/withSentryServerSideErrorGetInitialProps.ts b/packages/nextjs/src/server/wrapErrorGetInitialPropsWithSentry.ts similarity index 92% rename from packages/nextjs/src/server/withSentryServerSideErrorGetInitialProps.ts rename to packages/nextjs/src/server/wrapErrorGetInitialPropsWithSentry.ts index 8208c46762a9..54f52ef8dfc9 100644 --- a/packages/nextjs/src/server/withSentryServerSideErrorGetInitialProps.ts +++ b/packages/nextjs/src/server/wrapErrorGetInitialPropsWithSentry.ts @@ -20,7 +20,7 @@ type ErrorGetInitialProps = (context: NextPageContext) => Promise; * @param parameterizedRoute The page's parameterized route * @returns A wrapped version of the function */ -export function withSentryServerSideErrorGetInitialProps( +export function wrapErrorGetInitialPropsWithSentry( origErrorGetInitialProps: ErrorGetInitialProps, ): ErrorGetInitialProps { return async function (this: unknown, ...args: Parameters): ReturnType { @@ -63,3 +63,8 @@ export function withSentryServerSideErrorGetInitialProps( } }; } + +/** + * @deprecated Use `wrapErrorGetInitialPropsWithSentry` instead. + */ +export const withSentryServerSideErrorGetInitialProps = wrapErrorGetInitialPropsWithSentry; diff --git a/packages/nextjs/src/server/withSentryServerSideGetInitialProps.ts b/packages/nextjs/src/server/wrapGetInitialPropsWithSentry.ts similarity index 90% rename from packages/nextjs/src/server/withSentryServerSideGetInitialProps.ts rename to packages/nextjs/src/server/wrapGetInitialPropsWithSentry.ts index 9cf7cef3db03..aed6829a6cb4 100644 --- a/packages/nextjs/src/server/withSentryServerSideGetInitialProps.ts +++ b/packages/nextjs/src/server/wrapGetInitialPropsWithSentry.ts @@ -18,7 +18,7 @@ type GetInitialProps = Required['getInitialProps']; * @param parameterizedRoute The page's parameterized route * @returns A wrapped version of the function */ -export function withSentryServerSideGetInitialProps(origGetInitialProps: GetInitialProps): GetInitialProps { +export function wrapGetInitialPropsWithSentry(origGetInitialProps: GetInitialProps): GetInitialProps { return async function (this: unknown, ...args: Parameters): Promise> { if (isBuild()) { return origGetInitialProps.apply(this, args); @@ -59,3 +59,8 @@ export function withSentryServerSideGetInitialProps(origGetInitialProps: GetInit } }; } + +/** + * @deprecated Use `wrapGetInitialPropsWithSentry` instead. + */ +export const withSentryServerSideGetInitialProps = wrapGetInitialPropsWithSentry; diff --git a/packages/nextjs/src/server/withSentryGetServerSideProps.ts b/packages/nextjs/src/server/wrapGetServerSidePropsWithSentry.ts similarity index 91% rename from packages/nextjs/src/server/withSentryGetServerSideProps.ts rename to packages/nextjs/src/server/wrapGetServerSidePropsWithSentry.ts index 1f41e91ab3e9..dc3640b6dfe9 100644 --- a/packages/nextjs/src/server/withSentryGetServerSideProps.ts +++ b/packages/nextjs/src/server/wrapGetServerSidePropsWithSentry.ts @@ -16,7 +16,7 @@ import { * @param parameterizedRoute The page's parameterized route * @returns A wrapped version of the function */ -export function withSentryGetServerSideProps( +export function wrapGetServerSidePropsWithSentry( origGetServerSideProps: GetServerSideProps, parameterizedRoute: string, ): GetServerSideProps { @@ -57,3 +57,8 @@ export function withSentryGetServerSideProps( } }; } + +/** + * @deprecated Use `withSentryGetServerSideProps` instead. + */ +export const withSentryGetServerSideProps = wrapGetServerSidePropsWithSentry; diff --git a/packages/nextjs/src/server/withSentryGetStaticProps.ts b/packages/nextjs/src/server/wrapGetStaticPropsWithSentry.ts similarity index 85% rename from packages/nextjs/src/server/withSentryGetStaticProps.ts rename to packages/nextjs/src/server/wrapGetStaticPropsWithSentry.ts index 96e6f2b81db9..727e4a69c224 100644 --- a/packages/nextjs/src/server/withSentryGetStaticProps.ts +++ b/packages/nextjs/src/server/wrapGetStaticPropsWithSentry.ts @@ -12,7 +12,7 @@ type Props = { [key: string]: unknown }; * @param parameterizedRoute The page's parameterized route * @returns A wrapped version of the function */ -export function withSentryGetStaticProps( +export function wrapGetStaticPropsWithSentry( origGetStaticProps: GetStaticProps, parameterizedRoute: string, ): GetStaticProps { @@ -31,3 +31,8 @@ export function withSentryGetStaticProps( }); }; } + +/** + * @deprecated Use `wrapGetStaticPropsWithSentry` instead. + */ +export const withSentryGetStaticProps = wrapGetStaticPropsWithSentry; diff --git a/packages/nextjs/test/config/withSentry.test.ts b/packages/nextjs/test/config/withSentry.test.ts index 6cbf4ac02c09..75709d3f0bea 100644 --- a/packages/nextjs/test/config/withSentry.test.ts +++ b/packages/nextjs/test/config/withSentry.test.ts @@ -45,6 +45,7 @@ describe('withSentry', () => { res.send('Good dog, Maisey!'); }; + // eslint-disable-next-line deprecation/deprecation const wrappedHandlerNoError = withSentry(origHandlerNoError); beforeEach(() => { diff --git a/packages/nextjs/test/config/wrappers.test.ts b/packages/nextjs/test/config/wrappers.test.ts index 8edf2de57567..4824d6dc1573 100644 --- a/packages/nextjs/test/config/wrappers.test.ts +++ b/packages/nextjs/test/config/wrappers.test.ts @@ -2,7 +2,7 @@ import * as SentryCore from '@sentry/core'; import * as SentryTracing from '@sentry/tracing'; import type { IncomingMessage, ServerResponse } from 'http'; -import { withSentryGetServerSideProps, withSentryServerSideGetInitialProps } from '../../src/server'; +import { wrapGetInitialPropsWithSentry, wrapGetServerSidePropsWithSentry } from '../../src/server'; const startTransactionSpy = jest.spyOn(SentryCore, 'startTransaction'); @@ -23,10 +23,10 @@ describe('data-fetching function wrappers', () => { jest.clearAllMocks(); }); - test('withSentryGetServerSideProps', async () => { + test('wrapGetServerSidePropsWithSentry', async () => { const origFunction = jest.fn(async () => ({ props: {} })); - const wrappedOriginal = withSentryGetServerSideProps(origFunction, route); + const wrappedOriginal = wrapGetServerSidePropsWithSentry(origFunction, route); await wrappedOriginal({ req, res } as any); expect(startTransactionSpy).toHaveBeenCalledWith( @@ -43,10 +43,10 @@ describe('data-fetching function wrappers', () => { ); }); - test('withSentryServerSideGetInitialProps', async () => { + test('wrapGetInitialPropsWithSentry', async () => { const origFunction = jest.fn(async () => ({})); - const wrappedOriginal = withSentryServerSideGetInitialProps(origFunction); + const wrappedOriginal = wrapGetInitialPropsWithSentry(origFunction); await wrappedOriginal({ req, res, pathname: route } as any); expect(startTransactionSpy).toHaveBeenCalledWith( diff --git a/packages/nextjs/test/edge/withSentryAPI.test.ts b/packages/nextjs/test/edge/withSentryAPI.test.ts index aacef0fa3f79..1981220b50f0 100644 --- a/packages/nextjs/test/edge/withSentryAPI.test.ts +++ b/packages/nextjs/test/edge/withSentryAPI.test.ts @@ -1,7 +1,7 @@ import * as coreSdk from '@sentry/core'; import * as sentryTracing from '@sentry/tracing'; -import { withSentryAPI } from '../../src/edge'; +import { wrapApiHandlerWithSentry } from '../../src/edge'; // @ts-ignore Request does not exist on type Global const origRequest = global.Request; @@ -35,14 +35,14 @@ beforeEach(() => { jest.spyOn(sentryTracing, 'hasTracingEnabled').mockImplementation(() => true); }); -describe('withSentryAPI', () => { +describe('wrapApiHandlerWithSentry', () => { it('should return a function that starts a transaction with the correct name when there is no active transaction and a request is being passed', async () => { const startTransactionSpy = jest.spyOn(coreSdk, 'startTransaction'); const origFunctionReturnValue = new Response(); const origFunction = jest.fn(_req => origFunctionReturnValue); - const wrappedFunction = withSentryAPI(origFunction, '/user/[userId]/post/[postId]'); + const wrappedFunction = wrapApiHandlerWithSentry(origFunction, '/user/[userId]/post/[postId]'); const request = new Request('https://sentry.io/'); await wrappedFunction(request); @@ -63,7 +63,7 @@ describe('withSentryAPI', () => { const origFunctionReturnValue = new Response(); const origFunction = jest.fn(() => origFunctionReturnValue); - const wrappedFunction = withSentryAPI(origFunction, '/user/[userId]/post/[postId]'); + const wrappedFunction = wrapApiHandlerWithSentry(origFunction, '/user/[userId]/post/[postId]'); await wrappedFunction(); expect(startTransactionSpy).not.toHaveBeenCalled(); @@ -78,7 +78,7 @@ describe('withSentryAPI', () => { const origFunctionReturnValue = new Response(); const origFunction = jest.fn(() => origFunctionReturnValue); - const wrappedFunction = withSentryAPI(origFunction, '/user/[userId]/post/[postId]'); + const wrappedFunction = wrapApiHandlerWithSentry(origFunction, '/user/[userId]/post/[postId]'); await wrappedFunction(); expect(startChildSpy).toHaveBeenCalledTimes(1); diff --git a/packages/nextjs/test/integration/pages/api/withSentryAPI/unwrapped/[...pathParts].ts b/packages/nextjs/test/integration/pages/api/wrapApiHandlerWithSentry/unwrapped/[...pathParts].ts similarity index 100% rename from packages/nextjs/test/integration/pages/api/withSentryAPI/unwrapped/[...pathParts].ts rename to packages/nextjs/test/integration/pages/api/wrapApiHandlerWithSentry/unwrapped/[...pathParts].ts diff --git a/packages/nextjs/test/integration/pages/api/withSentryAPI/unwrapped/[animal].ts b/packages/nextjs/test/integration/pages/api/wrapApiHandlerWithSentry/unwrapped/[animal].ts similarity index 100% rename from packages/nextjs/test/integration/pages/api/withSentryAPI/unwrapped/[animal].ts rename to packages/nextjs/test/integration/pages/api/wrapApiHandlerWithSentry/unwrapped/[animal].ts diff --git a/packages/nextjs/test/integration/pages/api/withSentryAPI/unwrapped/cjsExport.ts b/packages/nextjs/test/integration/pages/api/wrapApiHandlerWithSentry/unwrapped/cjsExport.ts similarity index 100% rename from packages/nextjs/test/integration/pages/api/withSentryAPI/unwrapped/cjsExport.ts rename to packages/nextjs/test/integration/pages/api/wrapApiHandlerWithSentry/unwrapped/cjsExport.ts diff --git a/packages/nextjs/test/integration/pages/api/withSentryAPI/unwrapped/noParams.ts b/packages/nextjs/test/integration/pages/api/wrapApiHandlerWithSentry/unwrapped/noParams.ts similarity index 100% rename from packages/nextjs/test/integration/pages/api/withSentryAPI/unwrapped/noParams.ts rename to packages/nextjs/test/integration/pages/api/wrapApiHandlerWithSentry/unwrapped/noParams.ts diff --git a/packages/nextjs/test/integration/pages/api/withSentryAPI/wrapped/[...pathParts].ts b/packages/nextjs/test/integration/pages/api/wrapApiHandlerWithSentry/wrapped/[...pathParts].ts similarity index 100% rename from packages/nextjs/test/integration/pages/api/withSentryAPI/wrapped/[...pathParts].ts rename to packages/nextjs/test/integration/pages/api/wrapApiHandlerWithSentry/wrapped/[...pathParts].ts diff --git a/packages/nextjs/test/integration/pages/api/withSentryAPI/wrapped/[animal].ts b/packages/nextjs/test/integration/pages/api/wrapApiHandlerWithSentry/wrapped/[animal].ts similarity index 100% rename from packages/nextjs/test/integration/pages/api/withSentryAPI/wrapped/[animal].ts rename to packages/nextjs/test/integration/pages/api/wrapApiHandlerWithSentry/wrapped/[animal].ts diff --git a/packages/nextjs/test/integration/pages/api/withSentryAPI/wrapped/cjsExport.ts b/packages/nextjs/test/integration/pages/api/wrapApiHandlerWithSentry/wrapped/cjsExport.ts similarity index 100% rename from packages/nextjs/test/integration/pages/api/withSentryAPI/wrapped/cjsExport.ts rename to packages/nextjs/test/integration/pages/api/wrapApiHandlerWithSentry/wrapped/cjsExport.ts diff --git a/packages/nextjs/test/integration/pages/api/withSentryAPI/wrapped/noParams.ts b/packages/nextjs/test/integration/pages/api/wrapApiHandlerWithSentry/wrapped/noParams.ts similarity index 100% rename from packages/nextjs/test/integration/pages/api/withSentryAPI/wrapped/noParams.ts rename to packages/nextjs/test/integration/pages/api/wrapApiHandlerWithSentry/wrapped/noParams.ts diff --git a/packages/nextjs/test/integration/test/server/cjsApiEndpoints.js b/packages/nextjs/test/integration/test/server/cjsApiEndpoints.js index e154599fcbd7..3b25a405589a 100644 --- a/packages/nextjs/test/integration/test/server/cjsApiEndpoints.js +++ b/packages/nextjs/test/integration/test/server/cjsApiEndpoints.js @@ -4,7 +4,7 @@ const { sleep } = require('../utils/common'); const { getAsync, interceptTracingRequest } = require('../utils/server'); module.exports = async ({ url: urlBase, argv }) => { - const unwrappedRoute = '/api/withSentryAPI/unwrapped/cjsExport'; + const unwrappedRoute = '/api/wrapApiHandlerWithSentry/unwrapped/cjsExport'; const interceptedUnwrappedRequest = interceptTracingRequest( { contexts: { @@ -26,7 +26,7 @@ module.exports = async ({ url: urlBase, argv }) => { const responseUnwrapped = await getAsync(`${urlBase}${unwrappedRoute}`); assert.equal(responseUnwrapped, '{"success":true}'); - const wrappedRoute = '/api/withSentryAPI/wrapped/cjsExport'; + const wrappedRoute = '/api/wrapApiHandlerWithSentry/wrapped/cjsExport'; const interceptedWrappedRequest = interceptTracingRequest( { contexts: { diff --git a/packages/nextjs/test/integration/test/server/tracingWithSentryAPI.js b/packages/nextjs/test/integration/test/server/tracingWithSentryAPI.js index a9ceebc835c6..a630e5b97e00 100644 --- a/packages/nextjs/test/integration/test/server/tracingWithSentryAPI.js +++ b/packages/nextjs/test/integration/test/server/tracingWithSentryAPI.js @@ -6,12 +6,27 @@ const { getAsync, interceptTracingRequest } = require('../utils/server'); module.exports = async ({ url: urlBase, argv }) => { const urls = { // testName: [url, route] - unwrappedNoParamURL: [`/api/withSentryAPI/unwrapped/noParams`, '/api/withSentryAPI/unwrapped/noParams'], - unwrappedDynamicURL: [`/api/withSentryAPI/unwrapped/dog`, '/api/withSentryAPI/unwrapped/[animal]'], - unwrappedCatchAllURL: [`/api/withSentryAPI/unwrapped/dog/facts`, '/api/withSentryAPI/unwrapped/[...pathParts]'], - wrappedNoParamURL: [`/api/withSentryAPI/wrapped/noParams`, '/api/withSentryAPI/wrapped/noParams'], - wrappedDynamicURL: [`/api/withSentryAPI/wrapped/dog`, '/api/withSentryAPI/wrapped/[animal]'], - wrappedCatchAllURL: [`/api/withSentryAPI/wrapped/dog/facts`, '/api/withSentryAPI/wrapped/[...pathParts]'], + unwrappedNoParamURL: [ + `/api/wrapApiHandlerWithSentry/unwrapped/noParams`, + '/api/wrapApiHandlerWithSentry/unwrapped/noParams', + ], + unwrappedDynamicURL: [ + `/api/wrapApiHandlerWithSentry/unwrapped/dog`, + '/api/wrapApiHandlerWithSentry/unwrapped/[animal]', + ], + unwrappedCatchAllURL: [ + `/api/wrapApiHandlerWithSentry/unwrapped/dog/facts`, + '/api/wrapApiHandlerWithSentry/unwrapped/[...pathParts]', + ], + wrappedNoParamURL: [ + `/api/wrapApiHandlerWithSentry/wrapped/noParams`, + '/api/wrapApiHandlerWithSentry/wrapped/noParams', + ], + wrappedDynamicURL: [`/api/wrapApiHandlerWithSentry/wrapped/dog`, '/api/wrapApiHandlerWithSentry/wrapped/[animal]'], + wrappedCatchAllURL: [ + `/api/wrapApiHandlerWithSentry/wrapped/dog/facts`, + '/api/wrapApiHandlerWithSentry/wrapped/[...pathParts]', + ], }; const interceptedRequests = {};