diff --git a/packages/nextjs/test/integration/pages/api/withSentryAPI/unwrapped/[...pathParts].ts b/packages/nextjs/test/integration/pages/api/withSentryAPI/unwrapped/[...pathParts].ts new file mode 100644 index 000000000000..3307b12037d5 --- /dev/null +++ b/packages/nextjs/test/integration/pages/api/withSentryAPI/unwrapped/[...pathParts].ts @@ -0,0 +1,7 @@ +import { NextApiRequest, NextApiResponse } from 'next'; + +const handler = async (_req: NextApiRequest, res: NextApiResponse): Promise => { + res.status(200).json({}); +}; + +export default handler; diff --git a/packages/nextjs/test/integration/pages/api/withSentryAPI/unwrapped/[animal].ts b/packages/nextjs/test/integration/pages/api/withSentryAPI/unwrapped/[animal].ts new file mode 100644 index 000000000000..3307b12037d5 --- /dev/null +++ b/packages/nextjs/test/integration/pages/api/withSentryAPI/unwrapped/[animal].ts @@ -0,0 +1,7 @@ +import { NextApiRequest, NextApiResponse } from 'next'; + +const handler = async (_req: NextApiRequest, res: NextApiResponse): Promise => { + res.status(200).json({}); +}; + +export default handler; diff --git a/packages/nextjs/test/integration/pages/api/withSentryAPI/unwrapped/noParams.ts b/packages/nextjs/test/integration/pages/api/withSentryAPI/unwrapped/noParams.ts new file mode 100644 index 000000000000..3307b12037d5 --- /dev/null +++ b/packages/nextjs/test/integration/pages/api/withSentryAPI/unwrapped/noParams.ts @@ -0,0 +1,7 @@ +import { NextApiRequest, NextApiResponse } from 'next'; + +const handler = async (_req: NextApiRequest, res: NextApiResponse): Promise => { + res.status(200).json({}); +}; + +export default handler; diff --git a/packages/nextjs/test/integration/pages/api/withSentryAPI/wrapped/[...pathParts].ts b/packages/nextjs/test/integration/pages/api/withSentryAPI/wrapped/[...pathParts].ts new file mode 100644 index 000000000000..e048d9d27c0f --- /dev/null +++ b/packages/nextjs/test/integration/pages/api/withSentryAPI/wrapped/[...pathParts].ts @@ -0,0 +1,8 @@ +import { withSentry } from '@sentry/nextjs'; +import { NextApiRequest, NextApiResponse } from 'next'; + +const handler = async (_req: NextApiRequest, res: NextApiResponse): Promise => { + res.status(200).json({}); +}; + +export default withSentry(handler); diff --git a/packages/nextjs/test/integration/pages/api/withSentryAPI/wrapped/[animal].ts b/packages/nextjs/test/integration/pages/api/withSentryAPI/wrapped/[animal].ts new file mode 100644 index 000000000000..e048d9d27c0f --- /dev/null +++ b/packages/nextjs/test/integration/pages/api/withSentryAPI/wrapped/[animal].ts @@ -0,0 +1,8 @@ +import { withSentry } from '@sentry/nextjs'; +import { NextApiRequest, NextApiResponse } from 'next'; + +const handler = async (_req: NextApiRequest, res: NextApiResponse): Promise => { + res.status(200).json({}); +}; + +export default withSentry(handler); diff --git a/packages/nextjs/test/integration/pages/api/withSentryAPI/wrapped/noParams.ts b/packages/nextjs/test/integration/pages/api/withSentryAPI/wrapped/noParams.ts new file mode 100644 index 000000000000..e048d9d27c0f --- /dev/null +++ b/packages/nextjs/test/integration/pages/api/withSentryAPI/wrapped/noParams.ts @@ -0,0 +1,8 @@ +import { withSentry } from '@sentry/nextjs'; +import { NextApiRequest, NextApiResponse } from 'next'; + +const handler = async (_req: NextApiRequest, res: NextApiResponse): Promise => { + res.status(200).json({}); +}; + +export default withSentry(handler); diff --git a/packages/nextjs/test/integration/test/server/tracingWithSentryAPI.js b/packages/nextjs/test/integration/test/server/tracingWithSentryAPI.js new file mode 100644 index 000000000000..a9ceebc835c6 --- /dev/null +++ b/packages/nextjs/test/integration/test/server/tracingWithSentryAPI.js @@ -0,0 +1,54 @@ +const assert = require('assert'); + +const { sleep } = require('../utils/common'); +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]'], + }; + + const interceptedRequests = {}; + + Object.entries(urls).forEach(([testName, [url, route]]) => { + interceptedRequests[testName] = interceptTracingRequest( + { + contexts: { + trace: { + op: 'http.server', + status: 'ok', + tags: { 'http.status_code': '200' }, + }, + }, + transaction: `GET ${route}`, + type: 'transaction', + request: { + url: `${urlBase}${url}`, + }, + }, + argv, + testName, + ); + }); + + // Wait until all requests have completed + await Promise.all(Object.values(urls).map(([url]) => getAsync(`${urlBase}${url}`))); + + await sleep(250); + + const failingTests = Object.entries(interceptedRequests).reduce( + (failures, [testName, request]) => (!request.isDone() ? failures.concat(testName) : failures), + [], + ); + + assert.ok( + failingTests.length === 0, + `Did not intercept transaction request for the following tests: ${failingTests.join(', ')}.`, + ); +};