Skip to content

Commit b278429

Browse files
authored
fix(serverless): Explicitly export node package exports (#7457)
1 parent dd40b46 commit b278429

File tree

6 files changed

+181
-137
lines changed

6 files changed

+181
-137
lines changed

packages/serverless/src/index.ts

Lines changed: 44 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,47 @@ import * as AWSLambda from './awslambda';
33
import * as GCPFunction from './gcpfunction';
44
export { AWSLambda, GCPFunction };
55

6-
export * from './awsservices';
7-
export * from '@sentry/node';
6+
export { AWSServices } from './awsservices';
7+
8+
// TODO(v8): We have to explicitly export these because of the namespace exports
9+
// above. This is because just doing `export * from '@sentry/node'` will not
10+
// work with Node native esm while we also have namespace exports in a package.
11+
// What we should do is get rid of the namespace exports.
12+
export {
13+
Hub,
14+
SDK_VERSION,
15+
Scope,
16+
addBreadcrumb,
17+
addGlobalEventProcessor,
18+
captureEvent,
19+
captureException,
20+
captureMessage,
21+
configureScope,
22+
createTransport,
23+
getCurrentHub,
24+
getHubFromCarrier,
25+
makeMain,
26+
setContext,
27+
setExtra,
28+
setExtras,
29+
setTag,
30+
setTags,
31+
setUser,
32+
startTransaction,
33+
withScope,
34+
NodeClient,
35+
makeNodeTransport,
36+
close,
37+
defaultIntegrations,
38+
defaultStackParser,
39+
flush,
40+
getSentryRelease,
41+
init,
42+
lastEventId,
43+
DEFAULT_USER_INCLUDES,
44+
addRequestDataToEvent,
45+
extractRequestData,
46+
deepReadDirSync,
47+
Handlers,
48+
Integrations,
49+
} from '@sentry/node';

packages/serverless/test/awslambda.test.ts

Lines changed: 42 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
// 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
22
// eslint-disable-next-line import/no-unresolved
3+
import * as SentryNode from '@sentry/node';
4+
// eslint-disable-next-line import/no-unresolved
35
import type { Callback, Handler } from 'aws-lambda';
46

57
import * as Sentry from '../src';
@@ -40,15 +42,15 @@ const fakeCallback: Callback = (err, result) => {
4042

4143
function expectScopeSettings(fakeTransactionContext: any) {
4244
// @ts-ignore see "Why @ts-ignore" note
43-
const fakeTransaction = { ...Sentry.fakeTransaction, ...fakeTransactionContext };
45+
const fakeTransaction = { ...SentryNode.fakeTransaction, ...fakeTransactionContext };
4446
// @ts-ignore see "Why @ts-ignore" note
45-
expect(Sentry.fakeScope.setSpan).toBeCalledWith(fakeTransaction);
47+
expect(SentryNode.fakeScope.setSpan).toBeCalledWith(fakeTransaction);
4648
// @ts-ignore see "Why @ts-ignore" note
47-
expect(Sentry.fakeScope.setTag).toBeCalledWith('server_name', expect.anything());
49+
expect(SentryNode.fakeScope.setTag).toBeCalledWith('server_name', expect.anything());
4850
// @ts-ignore see "Why @ts-ignore" note
49-
expect(Sentry.fakeScope.setTag).toBeCalledWith('url', 'awslambda:///functionName');
51+
expect(SentryNode.fakeScope.setTag).toBeCalledWith('url', 'awslambda:///functionName');
5052
// @ts-ignore see "Why @ts-ignore" note
51-
expect(Sentry.fakeScope.setContext).toBeCalledWith(
53+
expect(SentryNode.fakeScope.setContext).toBeCalledWith(
5254
'aws.lambda',
5355
expect.objectContaining({
5456
aws_request_id: 'awsRequestId',
@@ -59,7 +61,7 @@ function expectScopeSettings(fakeTransactionContext: any) {
5961
}),
6062
);
6163
// @ts-ignore see "Why @ts-ignore" note
62-
expect(Sentry.fakeScope.setContext).toBeCalledWith(
64+
expect(SentryNode.fakeScope.setContext).toBeCalledWith(
6365
'aws.cloudwatch.logs',
6466
expect.objectContaining({
6567
log_group: 'logGroupName',
@@ -77,7 +79,7 @@ describe('AWSLambda', () => {
7779

7880
afterEach(() => {
7981
// @ts-ignore see "Why @ts-ignore" note
80-
Sentry.resetMocks();
82+
SentryNode.resetMocks();
8183
});
8284

8385
describe('wrapHandler() options', () => {
@@ -88,7 +90,7 @@ describe('AWSLambda', () => {
8890
const wrappedHandler = wrapHandler(handler, { flushTimeout: 1337 });
8991

9092
await wrappedHandler(fakeEvent, fakeContext, fakeCallback);
91-
expect(Sentry.flush).toBeCalledWith(1337);
93+
expect(SentryNode.flush).toBeCalledWith(1337);
9294
});
9395

9496
test('captureTimeoutWarning enabled (default)', async () => {
@@ -104,7 +106,7 @@ describe('AWSLambda', () => {
104106

105107
expect(Sentry.captureMessage).toBeCalled();
106108
// @ts-ignore see "Why @ts-ignore" note
107-
expect(Sentry.fakeScope.setTag).toBeCalledWith('timeout', '1s');
109+
expect(SentryNode.fakeScope.setTag).toBeCalledWith('timeout', '1s');
108110
});
109111

110112
test('captureTimeoutWarning disabled', async () => {
@@ -152,14 +154,14 @@ describe('AWSLambda', () => {
152154

153155
expect(Sentry.captureMessage).toBeCalled();
154156
// @ts-ignore see "Why @ts-ignore" note
155-
expect(Sentry.fakeScope.setTag).toBeCalledWith('timeout', '1m40s');
157+
expect(SentryNode.fakeScope.setTag).toBeCalledWith('timeout', '1m40s');
156158
});
157159

158160
test('captureAllSettledReasons disabled (default)', async () => {
159161
const handler = () => Promise.resolve([{ status: 'rejected', reason: new Error() }]);
160162
const wrappedHandler = wrapHandler(handler, { flushTimeout: 1337 });
161163
await wrappedHandler(fakeEvent, fakeContext, fakeCallback);
162-
expect(Sentry.captureException).toBeCalledTimes(0);
164+
expect(SentryNode.captureException).toBeCalledTimes(0);
163165
});
164166

165167
test('captureAllSettledReasons enable', async () => {
@@ -173,9 +175,9 @@ describe('AWSLambda', () => {
173175
]);
174176
const wrappedHandler = wrapHandler(handler, { flushTimeout: 1337, captureAllSettledReasons: true });
175177
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);
178+
expect(SentryNode.captureException).toHaveBeenNthCalledWith(1, error);
179+
expect(SentryNode.captureException).toHaveBeenNthCalledWith(2, error2);
180+
expect(SentryNode.captureException).toBeCalledTimes(2);
179181
});
180182
});
181183

@@ -197,11 +199,11 @@ describe('AWSLambda', () => {
197199

198200
expect(rv).toStrictEqual(42);
199201
// @ts-ignore see "Why @ts-ignore" note
200-
expect(Sentry.fakeHub.startTransaction).toBeCalledWith(fakeTransactionContext);
202+
expect(SentryNode.fakeHub.startTransaction).toBeCalledWith(fakeTransactionContext);
201203
expectScopeSettings(fakeTransactionContext);
202204
// @ts-ignore see "Why @ts-ignore" note
203-
expect(Sentry.fakeTransaction.finish).toBeCalled();
204-
expect(Sentry.flush).toBeCalledWith(2000);
205+
expect(SentryNode.fakeTransaction.finish).toBeCalled();
206+
expect(SentryNode.flush).toBeCalledWith(2000);
205207
});
206208

207209
test('unsuccessful execution', async () => {
@@ -223,12 +225,12 @@ describe('AWSLambda', () => {
223225
};
224226

225227
// @ts-ignore see "Why @ts-ignore" note
226-
expect(Sentry.fakeHub.startTransaction).toBeCalledWith(fakeTransactionContext);
228+
expect(SentryNode.fakeHub.startTransaction).toBeCalledWith(fakeTransactionContext);
227229
expectScopeSettings(fakeTransactionContext);
228-
expect(Sentry.captureException).toBeCalledWith(error);
230+
expect(SentryNode.captureException).toBeCalledWith(error);
229231
// @ts-ignore see "Why @ts-ignore" note
230-
expect(Sentry.fakeTransaction.finish).toBeCalled();
231-
expect(Sentry.flush).toBeCalledWith(2000);
232+
expect(SentryNode.fakeTransaction.finish).toBeCalled();
233+
expect(SentryNode.flush).toBeCalledWith(2000);
232234
}
233235
});
234236

@@ -254,7 +256,7 @@ describe('AWSLambda', () => {
254256

255257
const handler: Handler = (_event, _context, callback) => {
256258
// @ts-ignore see "Why @ts-ignore" note
257-
expect(Sentry.fakeHub.startTransaction).toBeCalledWith(
259+
expect(SentryNode.fakeHub.startTransaction).toBeCalledWith(
258260
expect.objectContaining({
259261
parentSpanId: '1121201211212012',
260262
parentSampled: false,
@@ -300,12 +302,12 @@ describe('AWSLambda', () => {
300302
};
301303

302304
// @ts-ignore see "Why @ts-ignore" note
303-
expect(Sentry.fakeHub.startTransaction).toBeCalledWith(fakeTransactionContext);
305+
expect(SentryNode.fakeHub.startTransaction).toBeCalledWith(fakeTransactionContext);
304306
expectScopeSettings(fakeTransactionContext);
305-
expect(Sentry.captureException).toBeCalledWith(e);
307+
expect(SentryNode.captureException).toBeCalledWith(e);
306308
// @ts-ignore see "Why @ts-ignore" note
307-
expect(Sentry.fakeTransaction.finish).toBeCalled();
308-
expect(Sentry.flush).toBeCalled();
309+
expect(SentryNode.fakeTransaction.finish).toBeCalled();
310+
expect(SentryNode.flush).toBeCalled();
309311
}
310312
});
311313
});
@@ -328,11 +330,11 @@ describe('AWSLambda', () => {
328330

329331
expect(rv).toStrictEqual(42);
330332
// @ts-ignore see "Why @ts-ignore" note
331-
expect(Sentry.fakeHub.startTransaction).toBeCalledWith(fakeTransactionContext);
333+
expect(SentryNode.fakeHub.startTransaction).toBeCalledWith(fakeTransactionContext);
332334
expectScopeSettings(fakeTransactionContext);
333335
// @ts-ignore see "Why @ts-ignore" note
334-
expect(Sentry.fakeTransaction.finish).toBeCalled();
335-
expect(Sentry.flush).toBeCalled();
336+
expect(SentryNode.fakeTransaction.finish).toBeCalled();
337+
expect(SentryNode.flush).toBeCalled();
336338
});
337339

338340
test('event and context are correctly passed to the original handler', async () => {
@@ -365,12 +367,12 @@ describe('AWSLambda', () => {
365367
};
366368

367369
// @ts-ignore see "Why @ts-ignore" note
368-
expect(Sentry.fakeHub.startTransaction).toBeCalledWith(fakeTransactionContext);
370+
expect(SentryNode.fakeHub.startTransaction).toBeCalledWith(fakeTransactionContext);
369371
expectScopeSettings(fakeTransactionContext);
370-
expect(Sentry.captureException).toBeCalledWith(error);
372+
expect(SentryNode.captureException).toBeCalledWith(error);
371373
// @ts-ignore see "Why @ts-ignore" note
372-
expect(Sentry.fakeTransaction.finish).toBeCalled();
373-
expect(Sentry.flush).toBeCalled();
374+
expect(SentryNode.fakeTransaction.finish).toBeCalled();
375+
expect(SentryNode.flush).toBeCalled();
374376
}
375377
});
376378

@@ -408,11 +410,11 @@ describe('AWSLambda', () => {
408410

409411
expect(rv).toStrictEqual(42);
410412
// @ts-ignore see "Why @ts-ignore" note
411-
expect(Sentry.fakeHub.startTransaction).toBeCalledWith(fakeTransactionContext);
413+
expect(SentryNode.fakeHub.startTransaction).toBeCalledWith(fakeTransactionContext);
412414
expectScopeSettings(fakeTransactionContext);
413415
// @ts-ignore see "Why @ts-ignore" note
414-
expect(Sentry.fakeTransaction.finish).toBeCalled();
415-
expect(Sentry.flush).toBeCalled();
416+
expect(SentryNode.fakeTransaction.finish).toBeCalled();
417+
expect(SentryNode.flush).toBeCalled();
416418
});
417419

418420
test('event and context are correctly passed to the original handler', async () => {
@@ -445,12 +447,12 @@ describe('AWSLambda', () => {
445447
};
446448

447449
// @ts-ignore see "Why @ts-ignore" note
448-
expect(Sentry.fakeHub.startTransaction).toBeCalledWith(fakeTransactionContext);
450+
expect(SentryNode.fakeHub.startTransaction).toBeCalledWith(fakeTransactionContext);
449451
expectScopeSettings(fakeTransactionContext);
450-
expect(Sentry.captureException).toBeCalledWith(error);
452+
expect(SentryNode.captureException).toBeCalledWith(error);
451453
// @ts-ignore see "Why @ts-ignore" note
452-
expect(Sentry.fakeTransaction.finish).toBeCalled();
453-
expect(Sentry.flush).toBeCalled();
454+
expect(SentryNode.fakeTransaction.finish).toBeCalled();
455+
expect(SentryNode.flush).toBeCalled();
454456
}
455457
});
456458
});

packages/serverless/test/awsservices.test.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1+
import * as SentryNode from '@sentry/node';
12
import * as AWS from 'aws-sdk';
23
import * as nock from 'nock';
34

4-
import * as Sentry from '../src';
55
import { AWSServices } from '../src/awsservices';
66

77
/**
@@ -17,7 +17,7 @@ describe('AWSServices', () => {
1717
});
1818
afterEach(() => {
1919
// @ts-ignore see "Why @ts-ignore" note
20-
Sentry.resetMocks();
20+
SentryNode.resetMocks();
2121
});
2222
afterAll(() => {
2323
nock.restore();
@@ -31,12 +31,12 @@ describe('AWSServices', () => {
3131
const data = await s3.getObject({ Bucket: 'foo', Key: 'bar' }).promise();
3232
expect(data.Body?.toString('utf-8')).toEqual('contents');
3333
// @ts-ignore see "Why @ts-ignore" note
34-
expect(Sentry.fakeTransaction.startChild).toBeCalledWith({
34+
expect(SentryNode.fakeTransaction.startChild).toBeCalledWith({
3535
op: 'http.client',
3636
description: 'aws.s3.getObject foo',
3737
});
3838
// @ts-ignore see "Why @ts-ignore" note
39-
expect(Sentry.fakeSpan.finish).toBeCalled();
39+
expect(SentryNode.fakeSpan.finish).toBeCalled();
4040
});
4141

4242
test('getObject with callback', done => {
@@ -48,7 +48,7 @@ describe('AWSServices', () => {
4848
done();
4949
});
5050
// @ts-ignore see "Why @ts-ignore" note
51-
expect(Sentry.fakeTransaction.startChild).toBeCalledWith({
51+
expect(SentryNode.fakeTransaction.startChild).toBeCalledWith({
5252
op: 'http.client',
5353
description: 'aws.s3.getObject foo',
5454
});
@@ -63,7 +63,7 @@ describe('AWSServices', () => {
6363
const data = await lambda.invoke({ FunctionName: 'foo' }).promise();
6464
expect(data.Payload?.toString('utf-8')).toEqual('reply');
6565
// @ts-ignore see "Why @ts-ignore" note
66-
expect(Sentry.fakeTransaction.startChild).toBeCalledWith({
66+
expect(SentryNode.fakeTransaction.startChild).toBeCalledWith({
6767
op: 'http.client',
6868
description: 'aws.lambda.invoke foo',
6969
});

0 commit comments

Comments
 (0)