Skip to content

Commit 6727d24

Browse files
committed
switch serverless to use captureException from @sentry/core
1 parent b211695 commit 6727d24

12 files changed

+38
-61
lines changed

packages/serverless/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
"access": "public"
1717
},
1818
"dependencies": {
19+
"@sentry/core": "7.24.2",
1920
"@sentry/node": "7.24.2",
2021
"@sentry/tracing": "7.24.2",
2122
"@sentry/types": "7.24.2",

packages/serverless/src/awslambda.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
/* eslint-disable max-lines */
2+
import { captureException } from '@sentry/core';
23
import * as Sentry from '@sentry/node';
3-
import { captureException, captureMessage, flush, getCurrentHub, Scope, withScope } from '@sentry/node';
4+
import { captureMessage, flush, getCurrentHub, Scope, withScope } from '@sentry/node';
45
import { extractTraceparentData } from '@sentry/tracing';
56
import { Integration } from '@sentry/types';
67
import { baggageHeaderToDynamicSamplingContext, dsnFromString, dsnToString, isString, logger } from '@sentry/utils';

packages/serverless/src/gcpfunction/cloud_events.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
import { captureException, flush, getCurrentHub } from '@sentry/node';
1+
import { captureException } from '@sentry/core';
2+
import { flush, getCurrentHub } from '@sentry/node';
23
import { logger } from '@sentry/utils';
34

45
import { domainify, getActiveDomain, proxyFunction } from '../utils';

packages/serverless/src/gcpfunction/events.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
import { captureException, flush, getCurrentHub } from '@sentry/node';
1+
import { captureException } from '@sentry/core';
2+
import { flush, getCurrentHub } from '@sentry/node';
23
import { logger } from '@sentry/utils';
34

45
import { domainify, getActiveDomain, proxyFunction } from '../utils';

packages/serverless/src/gcpfunction/http.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
import { AddRequestDataToEventOptions, captureException, flush, getCurrentHub } from '@sentry/node';
1+
import { captureException } from '@sentry/core';
2+
import { AddRequestDataToEventOptions, flush, getCurrentHub } from '@sentry/node';
23
import { extractTraceparentData } from '@sentry/tracing';
34
import { baggageHeaderToDynamicSamplingContext, isString, logger, stripUrlQueryAndFragment } from '@sentry/utils';
45

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
const origSentry = jest.requireActual('@sentry/core');
2+
export const BaseClient = origSentry.BaseClient;
3+
export const Integrations = origSentry.Integrations;
4+
export const getMainCarrier = origSentry.getMainCarrier;
5+
export const captureException = jest.fn();

packages/serverless/test/__mocks__/@sentry/node.ts

Lines changed: 0 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -35,34 +35,6 @@ export const init = jest.fn();
3535
export const addGlobalEventProcessor = jest.fn();
3636
export const getCurrentHub = jest.fn(() => fakeHub);
3737
export const startTransaction = jest.fn(_ => fakeTransaction);
38-
export const captureException = jest.fn();
3938
export const captureMessage = jest.fn();
4039
export const withScope = jest.fn(cb => cb(fakeScope));
4140
export const flush = jest.fn(() => Promise.resolve());
42-
43-
export const resetMocks = (): void => {
44-
fakeTransaction.setHttpStatus.mockClear();
45-
fakeTransaction.finish.mockClear();
46-
fakeTransaction.startChild.mockClear();
47-
fakeSpan.finish.mockClear();
48-
fakeHub.configureScope.mockClear();
49-
fakeHub.pushScope.mockClear();
50-
fakeHub.popScope.mockClear();
51-
fakeHub.getScope.mockClear();
52-
53-
fakeScope.addEventProcessor.mockClear();
54-
fakeScope.setTransactionName.mockClear();
55-
fakeScope.setTag.mockClear();
56-
fakeScope.setContext.mockClear();
57-
fakeScope.setSpan.mockClear();
58-
fakeScope.getTransaction.mockClear();
59-
60-
init.mockClear();
61-
addGlobalEventProcessor.mockClear();
62-
getCurrentHub.mockClear();
63-
startTransaction.mockClear();
64-
captureException.mockClear();
65-
captureMessage.mockClear();
66-
withScope.mockClear();
67-
flush.mockClear();
68-
};

packages/serverless/test/awslambda.test.ts

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import * as SentryCore from '@sentry/core';
12
// NOTE: I have no idea how to fix this right now, and don't want to waste more time, as it builds just fine — Kamil
23
// eslint-disable-next-line import/no-unresolved
34
import { Callback, Handler } from 'aws-lambda';
@@ -76,8 +77,7 @@ describe('AWSLambda', () => {
7677
});
7778

7879
afterEach(() => {
79-
// @ts-ignore see "Why @ts-ignore" note
80-
Sentry.resetMocks();
80+
jest.clearAllMocks();
8181
});
8282

8383
describe('wrapHandler() options', () => {
@@ -159,7 +159,7 @@ describe('AWSLambda', () => {
159159
const handler = () => Promise.resolve([{ status: 'rejected', reason: new Error() }]);
160160
const wrappedHandler = wrapHandler(handler, { flushTimeout: 1337 });
161161
await wrappedHandler(fakeEvent, fakeContext, fakeCallback);
162-
expect(Sentry.captureException).toBeCalledTimes(0);
162+
expect(SentryCore.captureException).toBeCalledTimes(0);
163163
});
164164

165165
test('captureAllSettledReasons enable', async () => {
@@ -173,9 +173,9 @@ describe('AWSLambda', () => {
173173
]);
174174
const wrappedHandler = wrapHandler(handler, { flushTimeout: 1337, captureAllSettledReasons: true });
175175
await wrappedHandler(fakeEvent, fakeContext, fakeCallback);
176-
expect(Sentry.captureException).toHaveBeenNthCalledWith(1, error);
177-
expect(Sentry.captureException).toHaveBeenNthCalledWith(2, error2);
178-
expect(Sentry.captureException).toBeCalledTimes(2);
176+
expect(SentryCore.captureException).toHaveBeenNthCalledWith(1, error);
177+
expect(SentryCore.captureException).toHaveBeenNthCalledWith(2, error2);
178+
expect(SentryCore.captureException).toBeCalledTimes(2);
179179
});
180180
});
181181

@@ -225,7 +225,7 @@ describe('AWSLambda', () => {
225225
// @ts-ignore see "Why @ts-ignore" note
226226
expect(Sentry.fakeHub.startTransaction).toBeCalledWith(fakeTransactionContext);
227227
expectScopeSettings(fakeTransactionContext);
228-
expect(Sentry.captureException).toBeCalledWith(error);
228+
expect(SentryCore.captureException).toBeCalledWith(error);
229229
// @ts-ignore see "Why @ts-ignore" note
230230
expect(Sentry.fakeTransaction.finish).toBeCalled();
231231
expect(Sentry.flush).toBeCalledWith(2000);
@@ -302,7 +302,7 @@ describe('AWSLambda', () => {
302302
// @ts-ignore see "Why @ts-ignore" note
303303
expect(Sentry.fakeHub.startTransaction).toBeCalledWith(fakeTransactionContext);
304304
expectScopeSettings(fakeTransactionContext);
305-
expect(Sentry.captureException).toBeCalledWith(e);
305+
expect(SentryCore.captureException).toBeCalledWith(e);
306306
// @ts-ignore see "Why @ts-ignore" note
307307
expect(Sentry.fakeTransaction.finish).toBeCalled();
308308
expect(Sentry.flush).toBeCalled();
@@ -367,7 +367,7 @@ describe('AWSLambda', () => {
367367
// @ts-ignore see "Why @ts-ignore" note
368368
expect(Sentry.fakeHub.startTransaction).toBeCalledWith(fakeTransactionContext);
369369
expectScopeSettings(fakeTransactionContext);
370-
expect(Sentry.captureException).toBeCalledWith(error);
370+
expect(SentryCore.captureException).toBeCalledWith(error);
371371
// @ts-ignore see "Why @ts-ignore" note
372372
expect(Sentry.fakeTransaction.finish).toBeCalled();
373373
expect(Sentry.flush).toBeCalled();
@@ -447,7 +447,7 @@ describe('AWSLambda', () => {
447447
// @ts-ignore see "Why @ts-ignore" note
448448
expect(Sentry.fakeHub.startTransaction).toBeCalledWith(fakeTransactionContext);
449449
expectScopeSettings(fakeTransactionContext);
450-
expect(Sentry.captureException).toBeCalledWith(error);
450+
expect(SentryCore.captureException).toBeCalledWith(error);
451451
// @ts-ignore see "Why @ts-ignore" note
452452
expect(Sentry.fakeTransaction.finish).toBeCalled();
453453
expect(Sentry.flush).toBeCalled();

packages/serverless/test/awsservices.test.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,7 @@ describe('AWSServices', () => {
1616
new AWSServices().setupOnce();
1717
});
1818
afterEach(() => {
19-
// @ts-ignore see "Why @ts-ignore" note
20-
Sentry.resetMocks();
19+
jest.clearAllMocks();
2120
});
2221
afterAll(() => {
2322
nock.restore();

packages/serverless/test/gcpfunction.test.ts

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import * as SentryCore from '@sentry/core';
12
import * as SentryNode from '@sentry/node';
23
import * as domain from 'domain';
34

@@ -22,8 +23,7 @@ import {
2223

2324
describe('GCPFunction', () => {
2425
afterEach(() => {
25-
// @ts-ignore see "Why @ts-ignore" note
26-
Sentry.resetMocks();
26+
jest.clearAllMocks();
2727
});
2828

2929
async function handleHttp(fn: HttpFunction, trace_headers: { [key: string]: string } | null = null): Promise<void> {
@@ -195,7 +195,7 @@ describe('GCPFunction', () => {
195195
expect(Sentry.fakeHub.startTransaction).toBeCalledWith(fakeTransactionContext);
196196
// @ts-ignore see "Why @ts-ignore" note
197197
expect(Sentry.fakeScope.setSpan).toBeCalledWith(fakeTransaction);
198-
expect(Sentry.captureException).toBeCalledWith(error);
198+
expect(SentryCore.captureException).toBeCalledWith(error);
199199
// @ts-ignore see "Why @ts-ignore" note
200200
expect(Sentry.fakeTransaction.finish).toBeCalled();
201201
expect(Sentry.flush).toBeCalled();
@@ -312,7 +312,7 @@ describe('GCPFunction', () => {
312312
expect(Sentry.fakeHub.startTransaction).toBeCalledWith(fakeTransactionContext);
313313
// @ts-ignore see "Why @ts-ignore" note
314314
expect(Sentry.fakeScope.setSpan).toBeCalledWith(fakeTransaction);
315-
expect(Sentry.captureException).toBeCalledWith(error);
315+
expect(SentryCore.captureException).toBeCalledWith(error);
316316
// @ts-ignore see "Why @ts-ignore" note
317317
expect(Sentry.fakeTransaction.finish).toBeCalled();
318318
expect(Sentry.flush).toBeCalled();
@@ -375,7 +375,7 @@ describe('GCPFunction', () => {
375375
expect(Sentry.fakeHub.startTransaction).toBeCalledWith(fakeTransactionContext);
376376
// @ts-ignore see "Why @ts-ignore" note
377377
expect(Sentry.fakeScope.setSpan).toBeCalledWith(fakeTransaction);
378-
expect(Sentry.captureException).toBeCalledWith(error);
378+
expect(SentryCore.captureException).toBeCalledWith(error);
379379
// @ts-ignore see "Why @ts-ignore" note
380380
expect(Sentry.fakeTransaction.finish).toBeCalled();
381381
expect(Sentry.flush).toBeCalled();
@@ -431,7 +431,7 @@ describe('GCPFunction', () => {
431431
expect(Sentry.fakeHub.startTransaction).toBeCalledWith(fakeTransactionContext);
432432
// @ts-ignore see "Why @ts-ignore" note
433433
expect(Sentry.fakeScope.setSpan).toBeCalledWith(fakeTransaction);
434-
expect(Sentry.captureException).toBeCalledWith(error);
434+
expect(SentryCore.captureException).toBeCalledWith(error);
435435
// @ts-ignore see "Why @ts-ignore" note
436436
expect(Sentry.fakeTransaction.finish).toBeCalled();
437437
expect(Sentry.flush).toBeCalled();
@@ -459,7 +459,7 @@ describe('GCPFunction', () => {
459459
expect(Sentry.fakeHub.startTransaction).toBeCalledWith(fakeTransactionContext);
460460
// @ts-ignore see "Why @ts-ignore" note
461461
expect(Sentry.fakeScope.setSpan).toBeCalledWith(fakeTransaction);
462-
expect(Sentry.captureException).toBeCalledWith(error);
462+
expect(SentryCore.captureException).toBeCalledWith(error);
463463
});
464464
});
465465

@@ -525,7 +525,7 @@ describe('GCPFunction', () => {
525525
expect(Sentry.fakeHub.startTransaction).toBeCalledWith(fakeTransactionContext);
526526
// @ts-ignore see "Why @ts-ignore" note
527527
expect(Sentry.fakeScope.setSpan).toBeCalledWith(fakeTransaction);
528-
expect(Sentry.captureException).toBeCalledWith(error);
528+
expect(SentryCore.captureException).toBeCalledWith(error);
529529
// @ts-ignore see "Why @ts-ignore" note
530530
expect(Sentry.fakeTransaction.finish).toBeCalled();
531531
expect(Sentry.flush).toBeCalled();
@@ -581,7 +581,7 @@ describe('GCPFunction', () => {
581581
expect(Sentry.fakeHub.startTransaction).toBeCalledWith(fakeTransactionContext);
582582
// @ts-ignore see "Why @ts-ignore" note
583583
expect(Sentry.fakeScope.setSpan).toBeCalledWith(fakeTransaction);
584-
expect(Sentry.captureException).toBeCalledWith(error);
584+
expect(SentryCore.captureException).toBeCalledWith(error);
585585
// @ts-ignore see "Why @ts-ignore" note
586586
expect(Sentry.fakeTransaction.finish).toBeCalled();
587587
expect(Sentry.flush).toBeCalled();
@@ -610,7 +610,7 @@ describe('GCPFunction', () => {
610610
// @ts-ignore see "Why @ts-ignore" note
611611
expect(Sentry.fakeScope.setSpan).toBeCalledWith(fakeTransaction);
612612

613-
expect(Sentry.captureException).toBeCalledWith(error);
613+
expect(SentryCore.captureException).toBeCalledWith(error);
614614
});
615615
});
616616

packages/serverless/test/google-cloud-grpc.test.ts

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -85,9 +85,7 @@ describe('GoogleCloudGrpc tracing', () => {
8585
nock('https://www.googleapis.com').post('/oauth2/v4/token').reply(200, []);
8686
});
8787
afterEach(() => {
88-
// @ts-ignore see "Why @ts-ignore" note
89-
Sentry.resetMocks();
90-
spyConnect.mockClear();
88+
jest.clearAllMocks();
9189
});
9290
afterAll(() => {
9391
nock.restore();
@@ -118,8 +116,7 @@ describe('GoogleCloudGrpc tracing', () => {
118116
});
119117

120118
afterEach(() => {
121-
dnsLookup.mockReset();
122-
resolveTxt.mockReset();
119+
jest.resetAllMocks();
123120
});
124121

125122
test('publish', async () => {

packages/serverless/test/google-cloud-http.test.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,7 @@ describe('GoogleCloudHttp tracing', () => {
2323
.reply(200, '{"access_token":"a.b.c","expires_in":3599,"token_type":"Bearer"}');
2424
});
2525
afterEach(() => {
26-
// @ts-ignore see "Why @ts-ignore" note
27-
Sentry.resetMocks();
26+
jest.clearAllMocks();
2827
});
2928
afterAll(() => {
3029
nock.restore();

0 commit comments

Comments
 (0)