Skip to content

Commit aa24b14

Browse files
authored
feat(node): Add includeServerName option (#16442)
Helps in scenarios where the `server_name` is possible PII (like in electron or node CLI applications).
1 parent ddec964 commit aa24b14

File tree

3 files changed

+27
-1
lines changed

3 files changed

+27
-1
lines changed

packages/node/src/sdk/client.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,11 @@ export class NodeClient extends ServerRuntimeClient<NodeClientOptions> {
2121
private _logOnExitFlushListener: (() => void) | undefined;
2222

2323
public constructor(options: NodeClientOptions) {
24-
const serverName = options.serverName || global.process.env.SENTRY_NAME || os.hostname();
24+
const serverName =
25+
options.includeServerName === false
26+
? undefined
27+
: options.serverName || global.process.env.SENTRY_NAME || os.hostname();
28+
2529
const clientOptions: ServerRuntimeClientOptions = {
2630
...options,
2731
platform: 'node',

packages/node/src/types.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,16 @@ export interface BaseNodeOptions {
6161
*/
6262
profileLifecycle?: 'manual' | 'trace';
6363

64+
/**
65+
* If set to `false`, the SDK will not automatically detect the `serverName`.
66+
*
67+
* This is useful if you are using the SDK in a CLI app or Electron where the
68+
* hostname might be considered PII.
69+
*
70+
* @default true
71+
*/
72+
includeServerName?: boolean;
73+
6474
/** Sets an optional server name (device name) */
6575
serverName?: string;
6676

packages/node/test/sdk/client.test.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,18 @@ describe('NodeClient', () => {
129129
expect(event.server_name).toEqual(os.hostname());
130130
});
131131

132+
test('does not add hostname when includeServerName = false', () => {
133+
const options = getDefaultNodeClientOptions({});
134+
options.includeServerName = false;
135+
const client = new NodeClient(options);
136+
137+
const event: Event = {};
138+
const hint: EventHint = {};
139+
client['_prepareEvent'](event, hint, currentScope, isolationScope);
140+
141+
expect(event.server_name).toBeUndefined();
142+
});
143+
132144
test("doesn't clobber existing runtime data", () => {
133145
const options = getDefaultNodeClientOptions({ serverName: 'bar' });
134146
const client = new NodeClient(options);

0 commit comments

Comments
 (0)