Skip to content

Commit 52e945a

Browse files
authored
Revert "ref(node): Move non-handler code out of handlers module (#5190)" (#5223)
This reverts commit 7c521e3. This PR causes issues with users as reported here: #5222. This is because we added Node library imports in the utils package - which can be consumed in browser contexts.
1 parent fb267e0 commit 52e945a

File tree

17 files changed

+718
-843
lines changed

17 files changed

+718
-843
lines changed

packages/nextjs/src/utils/instrumentServer.ts

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
/* eslint-disable max-lines */
22
import {
3-
addRequestDataToEvent,
43
captureException,
54
configureScope,
65
deepReadDirSync,
76
getCurrentHub,
7+
Handlers,
88
startTransaction,
99
} from '@sentry/node';
1010
import { extractTraceparentData, getActiveTransaction, hasTracingEnabled } from '@sentry/tracing';
@@ -22,6 +22,8 @@ import { default as createNextServer } from 'next';
2222
import * as querystring from 'querystring';
2323
import * as url from 'url';
2424

25+
const { parseRequest } = Handlers;
26+
2527
// eslint-disable-next-line @typescript-eslint/no-explicit-any
2628
type PlainObject<T = any> = { [key: string]: T };
2729

@@ -244,7 +246,7 @@ function makeWrappedReqHandler(origReqHandler: ReqHandler): WrappedReqHandler {
244246
const currentScope = getCurrentHub().getScope();
245247

246248
if (currentScope) {
247-
currentScope.addEventProcessor(event => addRequestDataToEvent(event, nextReq));
249+
currentScope.addEventProcessor(event => parseRequest(event, nextReq));
248250

249251
// We only want to record page and API requests
250252
if (hasTracingEnabled() && shouldTraceRequest(nextReq.url, publicDirFiles)) {

packages/nextjs/src/utils/withSentry.ts

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { addRequestDataToEvent, captureException, flush, getCurrentHub, startTransaction } from '@sentry/node';
1+
import { captureException, flush, getCurrentHub, Handlers, startTransaction } from '@sentry/node';
22
import { extractTraceparentData, hasTracingEnabled } from '@sentry/tracing';
33
import { Transaction } from '@sentry/types';
44
import {
@@ -12,6 +12,8 @@ import {
1212
import * as domain from 'domain';
1313
import { NextApiHandler, NextApiRequest, NextApiResponse } from 'next';
1414

15+
const { parseRequest } = Handlers;
16+
1517
// This is the same as the `NextApiHandler` type, except instead of having a return type of `void | Promise<void>`, it's
1618
// only `Promise<void>`, because wrapped handlers are always async
1719
export type WrappedNextApiHandler = (req: NextApiRequest, res: NextApiResponse) => Promise<void>;
@@ -41,7 +43,7 @@ export const withSentry = (origHandler: NextApiHandler): WrappedNextApiHandler =
4143
const currentScope = getCurrentHub().getScope();
4244

4345
if (currentScope) {
44-
currentScope.addEventProcessor(event => addRequestDataToEvent(event, req));
46+
currentScope.addEventProcessor(event => parseRequest(event, req));
4547

4648
if (hasTracingEnabled()) {
4749
// If there is a trace header set, extract the data from it (parentSpanId, traceId, and sampling decision)

packages/node/src/client.ts

+3-9
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ 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';
65
import { TextEncoder } from 'util';
76

87
import { eventFromMessage, eventFromUnknownInput } from './eventbuilder';
@@ -140,14 +139,9 @@ export class NodeClient extends BaseClient<NodeClientOptions> {
140139
*/
141140
protected _prepareEvent(event: Event, hint: EventHint, scope?: Scope): PromiseLike<Event | null> {
142141
event.platform = event.platform || 'node';
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();
142+
if (this.getOptions().serverName) {
143+
event.server_name = this.getOptions().serverName;
144+
}
151145
return super._prepareEvent(event, hint, scope);
152146
}
153147

0 commit comments

Comments
 (0)