8000 node: change applyClientOptions to integration · geigerzaehler/sentry-javascript@101b8d2 · GitHub
[go: up one dir, main page]

Skip to content

Commit 101b8d2

Browse files
committed
node: change applyClientOptions to integration
1 parent a614b52 commit 101b8d2

File tree

4 files changed

+35
-14
lines changed

4 files changed

+35
-14
lines changed

packages/node/src/backend.ts

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -24,17 +24,6 @@ export class NodeBackend implements Backend {
2424
/** Creates a new Node backend instance. */
2525
public constructor(private readonly options: NodeOptions = {}) {}
2626

27-
/**
28-
* Apply Node specific options to event
29-
* For now, it's only `server_name`
30-
*/
31-
private applyClientOptions(event: SentryEvent): SentryEvent {
32-
if (this.options.serverName) {
33-
event.server_name = this.options.serverName;
34-
}
35-
return event;
36-
}
37-
3827
/**
3928
* @inheritDoc
4029
*/
@@ -64,7 +53,7 @@ export class NodeBackend implements Backend {
6453

6554
const event: SentryEvent = await parseError(ex as Error);
6655

67-
return this.applyClientOptions(event);
56+
return event;
6857
}
6958

7059
/**
@@ -84,7 +73,7 @@ export class NodeBackend implements Backend {
8473
};
8574
}
8675

87-
return this.applyClientOptions(event);
76+
return event;
8877
}
8978

9079
/**
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import { getDefaultHub } from '@sentry/hub';
2+
import { Integration, SentryEvent } from '@sentry/types';
3+
import { NodeOptions } from '../backend';
4+
5+
/** Apply Node specific options to event. For now, it's only `server_name`. */
6+
export class ClientOptions implements Integration {
7+
/**
8+
* @inheritDoc
9+
*/
10+
public name: string = 'ClientOptions';
11+
12+
/**
13+
* @inheritDoc
14+
*/
15+
public install(options: NodeOptions = {}): void {
16+
if (options.serverName) {
17+
getDefaultHub().addEventProcessor(async (event: SentryEvent) => ({
18+
...event,
19+
server_name: options.serverName,
20+
}));
21+
}
22+
}
23+
}

packages/node/src/integrations/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,5 @@ export { Console } from './console';
22
export { Http } from './http';
33
export { OnUncaughtException } from './onuncaughtexception';
44
export { OnUnhandledRejection } from './onunhandledrejection';
5+
export { ClientOptions } from './clientoptions';
56
export { SDKInformation } from './sdkinformation';

packages/node/src/sdk.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,21 @@
11
import { initAndBind } from '@sentry/core';
22
import { NodeOptions } from './backend';
33
import { NodeClient } from './client';
4-
import { Console, Http, OnUncaughtException, OnUnhandledRejection, SDKInformation } from './integrations';
4+
import {
5+
ClientOptions,
6+
Console,
7+
Http,
8+
OnUncaughtException,
9+
OnUnhandledRejection,
10+
SDKInformation,
11+
} from './integrations';
512

613
export const defaultIntegrations = [
714
new Console(),
815
new Http(),
916
new OnUncaughtException(),
1017
new OnUnhandledRejection(),
18+
new ClientOptions(),
1119
new SDKInformation(),
1220
];
1321

0 commit comments

Comments
 (0)
0