Skip to content

Commit 80fcb68

Browse files
committed
move node-version- and server-name-adding code to client
1 parent ec3f9f4 commit 80fcb68

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
@@ -9,7 +9,6 @@
99

1010
import { Event, ExtractedNodeRequestData, Transaction } from '@sentry/types';
1111
import * as cookie from 'cookie';
12-
import * as os from 'os';
1312
import * as url from 'url';
1413

1514
import { isPlainObject, isString } from './is';
@@ -232,10 +231,8 @@ export function extractRequestData(
232231
export interface AddRequestDataToEventOptions {
233232
ip?: boolean;
234233
request?: boolean | string[];
235-
serverName?: boolean;
236234
transaction?: boolean | TransactionNamingScheme;
237235
user?: boolean | string[];
238-
version?: boolean;
239236
}
240237

241238
/**
@@ -255,23 +252,11 @@ export function addRequestDataToEvent(
255252
options = {
256253
ip: false,
257254
request: true,
258-
serverName: true,
259255
transaction: true,
260256
user: true,
261-
version: true,
262257
...options,
263258
};
264259

265-
if (options.version) {
266-
event.contexts = {
267-
...event.contexts,
268-
runtime: {
269-
name: 'node',
270-
version: global.process.version,
271-
},
272-
};
273-
}
274-
275260
if (options.request) {
276261
// if the option value is `true`, use the default set of keys by not passing anything to `extractRequestData()`
277262
const extractedRequestData = Array.isArray(options.request)
@@ -283,10 +268,6 @@ export function addRequestDataToEvent(
283268
};
284269
}
285270

286-
if (options.serverName && !event.server_name) {
287-
event.server_name = global.process.env.SENTRY_NAME || os.hostname();
288-
}
289-
290271
if (options.user) {
291272
const extractedUser = req.user && isPlainObject(req.user) ? extractUserData(req.user, options.user) : {};
292273

0 commit comments

Comments
 (0)