Skip to content

Commit eb9da37

Browse files
committed
move node-version- and server-name-adding code to client
1 parent ceebefe commit eb9da37

File tree

4 files changed

+9
-33
lines changed

4 files changed

+9
-33
lines changed

packages/node/src/client.ts

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { BaseClient, Scope, SDK_VERSION } from '@sentry/core';
22
import { SessionFlusher } from '@sentry/hub';
33
import { Event, EventHint, Severity, SeverityLevel } from '@sentry/types';
44
import { logger, resolvedSyncPromise } from '@sentry/utils';
5+
import * as os from 'os';
56
import { TextEncoder } from 'util';
67

78
import { eventFromMessage, eventFromUnknownInput } from './eventbuilder';
@@ -139,9 +140,14 @@ export class NodeClient extends BaseClient<NodeClientOptions> {
139140
*/
140141
protected _prepareEvent(event: Event, hint: EventHint, scope?: Scope): PromiseLike<Event | null> {
141142
event.platform = event.platform || 'node';
142-
if (this.getOptions().serverName) {
143-
event.server_name = this.getOptions().serverName;
144-
}
143+
event.contexts = {
144+
...event.contexts,
145+
runtime: {
146+
name: 'node',
147+
version: global.process.version,
148+
},
149+
};
150+
event.server_name = this.getOptions().serverName || global.process.env.SENTRY_NAME || os.hostname();
145151
return super._prepareEvent(event, hint, scope);
146152
}
147153

packages/serverless/src/awslambda.ts

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -182,11 +182,6 @@ function enhanceScopeWithEnvironmentData(scope: Scope, context: Context, startTi
182182
scope.setTag('server_name', process.env._AWS_XRAY_DAEMON_ADDRESS || process.env.SENTRY_NAME || hostname());
183183
scope.setTag('url', `awslambda:///${context.functionName}`);
184184

185-
scope.setContext('runtime', {
186-
name: 'node',
187-
version: global.process.version,
188-
});
189-
190185
scope.setContext('aws.lambda', {
191186
aws_request_id: context.awsRequestId,
192187
function_name: context.functionName,

packages/serverless/src/gcpfunction/general.ts

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import { Scope } from '@sentry/node';
22
import { Context as SentryContext } from '@sentry/types';
33
import type { Request, Response } from 'express';
4-
import { hostname } from 'os';
54

65
export interface HttpFunction {
76
(req: Request, res: Response): any; // eslint-disable-line @typescript-eslint/no-explicit-any
@@ -54,11 +53,6 @@ export interface WrapperOptions {
5453
* @param context event context
5554
*/
5655
export function configureScopeWithContext(scope: Scope, context: Context): void {
57-
scope.setContext('runtime', {
58-
name: 'node',
59-
version: global.process.version,
60-
});
61-
scope.setTag('server_name', process.env.SENTRY_NAME || hostname());
6256
scope.setContext('gcp.function.context', { ...context } as SentryContext);
6357
}
6458

packages/utils/src/requestdata.ts

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313

1414
import { Event, ExtractedNodeRequestData, Transaction } from '@sentry/types';
1515
import * as cookie from 'cookie';
16-
import * as os from 'os';
1716
import * as url from 'url';
1817

1918
import { isPlainObject, isString } from './is';
@@ -236,10 +235,8 @@ export function extractRequestData(
236235
export interface AddRequestDataToEventOptions {
237236
ip?: boolean;
238237
request?: boolean | string[];
239-
serverName?: boolean;
240238
transaction?: boolean | TransactionNamingScheme;
241239
user?: boolean | string[];
242-
version?: boolean;
243240
}
244241

245242
/**
@@ -259,23 +256,11 @@ export function addRequestDataToEvent(
259256
options = {
260257
ip: false,
261258
request: true,
262-
serverName: true,
263259
transaction: true,
264260
user: true,
265-
version: true,
266261
...options,
267262
};
268263

269-
if (options.version) {
270-
event.contexts = {
271-
...event.contexts,
272-
runtime: {
273-
name: 'node',
274-
version: global.process.version,
275-
},
276-
};
277-
}
278-
279264
if (options.request) {
280265
// if the option value is `true`, use the default set of keys by not passing anything to `extractRequestData()`
281266
const extractedRequestData = Array.isArray(options.request)
@@ -287,10 +272,6 @@ export function addRequestDataToEvent(
287272
};
288273
}
289274

290-
if (options.serverName && !event.server_name) {
291-
event.server_name = global.process.env.SENTRY_NAME || os.hostname();
292-
}
293-
294275
if (options.user) {
295276
const extractedUser = req.user && isPlainObject(req.user) ? extractUserData(req.user, options.user) : {};
296277

0 commit comments

Comments
 (0)