From 6c169a3ed9e99bccd8152dd7b6b0a9128d683137 Mon Sep 17 00:00:00 2001 From: Tim Fish Date: Mon, 2 Jun 2025 10:37:33 +0100 Subject: [PATCH 1/3] feat(node): Add `skipIncludingServerName` option --- packages/node/src/sdk/client.ts | 5 ++++- packages/node/src/types.ts | 8 ++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/packages/node/src/sdk/client.ts b/packages/node/src/sdk/client.ts index 0e5718b30207..64aee1d18a5a 100644 --- a/packages/node/src/sdk/client.ts +++ b/packages/node/src/sdk/client.ts @@ -21,7 +21,10 @@ export class NodeClient extends ServerRuntimeClient { private _logOnExitFlushListener: (() => void) | undefined; public constructor(options: NodeClientOptions) { - const serverName = options.serverName || global.process.env.SENTRY_NAME || os.hostname(); + const serverName = options.skipIncludingServerName + ? undefined + : options.serverName || global.process.env.SENTRY_NAME || os.hostname(); + const clientOptions: ServerRuntimeClientOptions = { ...options, platform: 'node', diff --git a/packages/node/src/types.ts b/packages/node/src/types.ts index b99235e78f05..e371bfc2ec9a 100644 --- a/packages/node/src/types.ts +++ b/packages/node/src/types.ts @@ -61,6 +61,14 @@ export interface BaseNodeOptions { */ profileLifecycle?: 'manual' | 'trace'; + /** + * If set to true, the SDK will not automatically detect the `serverName`. + * + * This is useful if you are using the SDK in a CLI app or Electron where the + * hostname might be considered PII. + */ + skipIncludingServerName?: boolean; + /** Sets an optional server name (device name) */ serverName?: string; From c22af282a364bb1414c9fd5db4a5f70fa37ad1b5 Mon Sep 17 00:00:00 2001 From: Tim Fish Date: Mon, 2 Jun 2025 17:58:21 +0100 Subject: [PATCH 2/3] PR review --- packages/node/src/sdk/client.ts | 7 ++++--- packages/node/src/types.ts | 6 ++++-- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/packages/node/src/sdk/client.ts b/packages/node/src/sdk/client.ts index 64aee1d18a5a..9bfb83bc6d99 100644 --- a/packages/node/src/sdk/client.ts +++ b/packages/node/src/sdk/client.ts @@ -21,9 +21,10 @@ export class NodeClient extends ServerRuntimeClient { private _logOnExitFlushListener: (() => void) | undefined; public constructor(options: NodeClientOptions) { - const serverName = options.skipIncludingServerName - ? undefined - : options.serverName || global.process.env.SENTRY_NAME || os.hostname(); + const serverName = + options.includeServerName === false + ? undefined + : options.serverName || global.process.env.SENTRY_NAME || os.hostname(); const clientOptions: ServerRuntimeClientOptions = { ...options, diff --git a/packages/node/src/types.ts b/packages/node/src/types.ts index e371bfc2ec9a..1a2afabdc1c6 100644 --- a/packages/node/src/types.ts +++ b/packages/node/src/types.ts @@ -62,12 +62,14 @@ export interface BaseNodeOptions { profileLifecycle?: 'manual' | 'trace'; /** - * If set to true, the SDK will not automatically detect the `serverName`. + * If set to `false`, the SDK will not automatically detect the `serverName`. * * This is useful if you are using the SDK in a CLI app or Electron where the * hostname might be considered PII. + * + * @default true */ - skipIncludingServerName?: boolean; + includeServerName?: boolean; /** Sets an optional server name (device name) */ serverName?: string; From 37154166fad353689c03493e5fdfb9ed2f9e5c5c Mon Sep 17 00:00:00 2001 From: Tim Fish Date: Mon, 2 Jun 2025 22:08:04 +0100 Subject: [PATCH 3/3] Add test --- packages/node/test/sdk/client.test.ts | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/packages/node/test/sdk/client.test.ts b/packages/node/test/sdk/client.test.ts index 5511f339e8e6..f053b1ba7e0e 100644 --- a/packages/node/test/sdk/client.test.ts +++ b/packages/node/test/sdk/client.test.ts @@ -129,6 +129,18 @@ describe('NodeClient', () => { expect(event.server_name).toEqual(os.hostname()); }); + test('does not add hostname when includeServerName = false', () => { + const options = getDefaultNodeClientOptions({}); + options.includeServerName = false; + const client = new NodeClient(options); + + const event: Event = {}; + const hint: EventHint = {}; + client['_prepareEvent'](event, hint, currentScope, isolationScope); + + expect(event.server_name).toBeUndefined(); + }); + test("doesn't clobber existing runtime data", () => { const options = getDefaultNodeClientOptions({ serverName: 'bar' }); const client = new NodeClient(options);