diff --git a/packages/node/src/sdk/client.ts b/packages/node/src/sdk/client.ts index 0e5718b30207..9bfb83bc6d99 100644 --- a/packages/node/src/sdk/client.ts +++ b/packages/node/src/sdk/client.ts @@ -21,7 +21,11 @@ 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.includeServerName === false + ? 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..1a2afabdc1c6 100644 --- a/packages/node/src/types.ts +++ b/packages/node/src/types.ts @@ -61,6 +61,16 @@ export interface BaseNodeOptions { */ profileLifecycle?: 'manual' | 'trace'; + /** + * 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 + */ + includeServerName?: boolean; + /** Sets an optional server name (device name) */ serverName?: string; 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);