Skip to content

feat(node): Add includeServerName option #16442

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jun 3, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion packages/node/src/sdk/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,11 @@ export class NodeClient extends ServerRuntimeClient<NodeClientOptions> {
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',
Expand Down
10 changes: 10 additions & 0 deletions packages/node/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
12 changes: 12 additions & 0 deletions packages/node/test/sdk/client.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Loading