Skip to content

Commit a1fab14

Browse files
authored
feat: Add module integration (#1533)
1 parent d195992 commit a1fab14

File tree

5 files changed

+55
-14
lines changed

5 files changed

+55
-14
lines changed

packages/core/src/baseclient.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ import {
99
Severity,
1010
Status,
1111
} from '@sentry/types';
12-
import { getGlobalObject, uuid4 } from '@sentry/utils/misc';
1312
import { forget } from '@sentry/utils/async';
13+
import { getGlobalObject, uuid4 } from '@sentry/utils/misc';
1414
import { truncate } from '@sentry/utils/string';
1515
import { BackendClass } from './basebackend';
1616
import { Dsn } from './dsn';

packages/node/src/handlers.ts

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5,25 +5,13 @@ import { forget } from '@sentry/utils/async';
55
import { serialize } from '@sentry/utils/object';
66
import { parse as parseCookie } from 'cookie';
77
import * as domain from 'domain';
8-
import * as lsmod from 'lsmod';
98
import { hostname } from 'os';
109
import { parse as parseUrl } from 'url';
1110
import { NodeClient } from './client';
1211
import { getCurrentHub } from './hub';
1312

1413
const DEFAULT_SHUTDOWN_TIMEOUT = 2000;
1514

16-
let moduleCache: { [key: string]: string };
17-
18-
/** JSDoc */
19-
function getModules(): { [key: string]: string } {
20-
if (!moduleCache) {
21-
// tslint:disable-next-line:no-unsafe-any
22-
moduleCache = lsmod();
23-
}
24-
return moduleCache;
25-
}
26-
2715
/** JSDoc */
2816
function extractRequestData(req: { [key: string]: any }): { [key: string]: string } {
2917
// headers:
@@ -129,7 +117,6 @@ function parseRequest(
129117
...event.extra,
130118
node: global.process.version,
131119
},
132-
modules: getModules(),
133120
request: {
134121
...event.request,
135122
...extractRequestData(req),

packages/node/src/integrations/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,4 @@ export { OnUnhandledRejection } from './onunhandledrejection';
55
export { ClientOptions } from './clientoptions';
66
export { SDKInformation } from './sdkinformation';
77
export { LinkedErrors } from './linkederrors';
8+
export { Modules } from './modules';
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
import { Scope } from '@sentry/hub';
2+
import { Integration } from '@sentry/types';
3+
import * as lsmod from 'lsmod';
4+
import { NodeOptions } from '../backend';
5+
import { getCurrentHub } from '../hub';
6+
7+
let moduleCache: { [key: string]: string };
8+
9+
/** Add node modules / packages to the event */
10+
export class Modules implements Integration {
11+
/**
12+
* @inheritDoc
13+
*/
14+
public name: string = 'Modules';
15+
16+
/**
17+
* @inheritDoc
18+
*/
19+
public install(_: NodeOptions = {}): void {
20+
getCurrentHub().configureScope((scope: Scope) => {
21+
scope.addEventProcessor(async event => ({
22+
...event,
23+
modules: this.getModules(),
24+
}));
25+
});
26+
}
27+
28+
/** Fetches the list of modules and the versions loaded by the entry file for your node.js app. */
29+
private getModules(): { [key: string]: string } {
30+
if (!moduleCache) {
31+
// tslint:disable-next-line:no-unsafe-any
32+
moduleCache = lsmod();
33+
}
34+
return moduleCache;
35+
}
36+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import { captureMessage, configureScope, init, Integrations, SentryEvent } from '../../src';
2+
3+
const dsn = 'https://[email protected]/4291';
4+
5+
describe('Modules Integration', () => {
6+
test('modules are added to an event', done => {
7+
init({ dsn, integrations: () => [new Integrations.Modules()] });
8+
configureScope(scope => {
9+
scope.addEventProcessor(async (event: SentryEvent) => {
10+
expect(event).toHaveProperty('modules');
11+
done();
12+
return null;
13+
});
14+
});
15+
captureMessage('test');
16+
});
17+
});

0 commit comments

Comments
 (0)