Skip to content

Commit 254fc2c

Browse files
committed
set serverless SDK data globally
1 parent 2f19b32 commit 254fc2c

File tree

4 files changed

+54
-9
lines changed

4 files changed

+54
-9
lines changed

packages/serverless/src/index.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,8 @@ export { AWSLambda, GCPFunction };
55

66
export * from './awsservices';
77
export * from '@sentry/node';
8+
9+
import { SDK_VERSION } from '@sentry/node';
10+
import { setSDKInfo } from '@sentry/utils';
11+
12+
setSDKInfo('sentry.javascript.serverless', 'npm:@sentry/serverless', SDK_VERSION);

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
const origSentry = jest.requireActual('@sentry/node');
22
export const defaultIntegrations = origSentry.defaultIntegrations; // eslint-disable-line @typescript-eslint/no-unsafe-member-access
33
export const Handlers = origSentry.Handlers; // eslint-disable-line @typescript-eslint/no-unsafe-member-access
4-
export const SDK_VERSION = '6.6.6';
4+
export const SDK_VERSION = origSentry.SDK_VERSION; // eslint-disable-line @typescript-eslint/no-unsafe-member-access
55
export const Severity = {
66
Warning: 'warning',
77
};

packages/serverless/test/awslambda.test.ts

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { Event } from '@sentry/types';
2+
import { getGlobalObject } from '@sentry/utils';
23
// 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
34
// eslint-disable-next-line import/no-unresolved
45
import { Callback, Handler } from 'aws-lambda';
@@ -341,6 +342,24 @@ describe('AWSLambda', () => {
341342
});
342343

343344
describe('init()', () => {
345+
it('sets SDK data globally', () => {
346+
// the SDK data is set when we import from (and therefore run) `../src/index.ts` - it sets the serverless part itself,
347+
// and the node part gets set when it imports from @sentry/node - so no action is necessary here before we run
348+
// the `expect`s
349+
350+
const global = getGlobalObject();
351+
352+
expect(global.__SENTRY__?.sdkInfo).toBeDefined();
353+
expect(global.__SENTRY__?.sdkInfo?.name).toEqual('sentry.javascript.serverless');
354+
expect(global.__SENTRY__?.sdkInfo?.version).toEqual(Sentry.SDK_VERSION);
355+
expect(global.__SENTRY__?.sdkInfo?.packages).toEqual(
356+
expect.arrayContaining([
357+
{ name: 'npm:@sentry/serverless', version: Sentry.SDK_VERSION },
358+
{ name: 'npm:@sentry/node', version: Sentry.SDK_VERSION },
359+
]),
360+
);
361+
});
362+
344363
test('enhance event with SDK info and correct mechanism value', async () => {
345364
expect.assertions(1);
346365

@@ -381,10 +400,10 @@ describe('AWSLambda', () => {
381400
},
382401
{
383402
name: 'npm:@sentry/serverless',
384-
version: '6.6.6',
403+
version: Sentry.SDK_VERSION,
385404
},
386405
],
387-
version: '6.6.6',
406+
version: Sentry.SDK_VERSION,
388407
},
389408
});
390409
});
@@ -416,10 +435,10 @@ describe('AWSLambda', () => {
416435
packages: [
417436
{
418437
name: 'npm:@sentry/serverless',
419-
version: '6.6.6',
438+
version: Sentry.SDK_VERSION,
420439
},
421440
],
422-
version: '6.6.6',
441+
version: Sentry.SDK_VERSION,
423442
},
424443
});
425444
});

packages/serverless/test/gcpfunction.test.ts

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { Event } from '@sentry/types';
2+
import { getGlobalObject } from '@sentry/utils';
23
import * as domain from 'domain';
34

45
import * as Sentry from '../src';
@@ -361,6 +362,26 @@ describe('GCPFunction', () => {
361362
});
362363

363364
describe('init()', () => {
365+
// Note: this is the same test that's in the AWS test file, but putting it here also in case AWS and GCP ever get
366+
// split
367+
it('sets SDK data globally', () => {
368+
// the SDK data is set when we import from (and therefore run) `../src/index.ts` - it sets the serverless part itself,
369+
// and the node part gets set when it imports from @sentry/node - so no action is necessary here before we run
370+
// the `expect`s
371+
372+
const global = getGlobalObject();
373+
374+
expect(global.__SENTRY__?.sdkInfo).toBeDefined();
375+
expect(global.__SENTRY__?.sdkInfo?.name).toEqual('sentry.javascript.serverless');
376+
expect(global.__SENTRY__?.sdkInfo?.version).toEqual(Sentry.SDK_VERSION);
377+
expect(global.__SENTRY__?.sdkInfo?.packages).toEqual(
378+
expect.arrayContaining([
379+
{ name: 'npm:@sentry/serverless', version: Sentry.SDK_VERSION },
380+
{ name: 'npm:@sentry/node', version: Sentry.SDK_VERSION },
381+
]),
382+
);
383+
});
384+
364385
test('enhance event with SDK info and correct mechanism value', async () => {
365386
expect.assertions(1);
366387

@@ -401,10 +422,10 @@ describe('GCPFunction', () => {
401422
},
402423
{
403424
name: 'npm:@sentry/serverless',
404-
version: '6.6.6',
425+
version: Sentry.SDK_VERSION,
405426
},
406427
],
407-
version: '6.6.6',
428+
version: Sentry.SDK_VERSION,
408429
},
409430
});
410431
});
@@ -436,10 +457,10 @@ describe('GCPFunction', () => {
436457
packages: [
437458
{
438459
name: 'npm:@sentry/serverless',
439-
version: '6.6.6',
460+
version: Sentry.SDK_VERSION,
440461
},
441462
],
442-
version: '6.6.6',
463+
version: Sentry.SDK_VERSION,
443464
},
444465
});
445466
});

0 commit comments

Comments
 (0)