|
| 1 | +import * as hub from '@sentry/hub'; |
1 | 2 | import * as Sentry from '@sentry/node';
|
| 3 | +import { Client, ClientOptions } from '@sentry/types'; |
2 | 4 | import * as utils from '@sentry/utils';
|
3 | 5 | import { NextApiHandler, NextApiRequest, NextApiResponse } from 'next';
|
4 | 6 |
|
@@ -43,6 +45,7 @@ const flushSpy = jest.spyOn(Sentry, 'flush').mockImplementation(async () => {
|
43 | 45 | await sleep(FLUSH_DURATION);
|
44 | 46 | return true;
|
45 | 47 | });
|
| 48 | +const startTransactionSpy = jest.spyOn(Sentry, 'startTransaction'); |
46 | 49 |
|
47 | 50 | describe('withSentry', () => {
|
48 | 51 | let req: NextApiRequest, res: NextApiResponse;
|
@@ -99,4 +102,27 @@ describe('withSentry', () => {
|
99 | 102 | expect(loggerSpy).toHaveBeenCalledWith('Done flushing events');
|
100 | 103 | });
|
101 | 104 | });
|
| 105 | + |
| 106 | + describe('tracing', () => { |
| 107 | + it('starts a transaction when tracing is enabled', async () => { |
| 108 | + jest |
| 109 | + .spyOn(hub.Hub.prototype, 'getClient') |
| 110 | + .mockReturnValueOnce({ getOptions: () => ({ tracesSampleRate: 1 } as ClientOptions) } as Client); |
| 111 | + |
| 112 | + await callWrappedHandler(wrappedHandlerNoError, req, res); |
| 113 | + |
| 114 | + expect(startTransactionSpy).toHaveBeenCalledWith( |
| 115 | + { |
| 116 | + name: 'GET http://dogs.are.great', |
| 117 | + op: 'http.server', |
| 118 | + |
| 119 | + metadata: { |
| 120 | + baggage: expect.any(Array), |
| 121 | + source: 'route', |
| 122 | + }, |
| 123 | + }, |
| 124 | + { request: expect.objectContaining({ url: 'http://dogs.are.great' }) }, |
| 125 | + ); |
| 126 | + }); |
| 127 | + }); |
102 | 128 | });
|
0 commit comments