Skip to content

Commit a1ef165

Browse files
committed
ref(nextjs): Use debug instead of logger
1 parent d1a03e4 commit a1ef165

File tree

10 files changed

+33
-33
lines changed

10 files changed

+33
-33
lines changed

packages/nextjs/src/client/routing/pagesRouterRoutingInstrumentation.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import type { Client, TransactionSource } from '@sentry/core';
22
import {
33
browserPerformanceTimeOrigin,
4-
logger,
4+
debug,
55
parseBaggageHeader,
66
SEMANTIC_ATTRIBUTE_SENTRY_OP,
77
SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN,
@@ -70,7 +70,7 @@ function extractNextDataTagInformation(): NextDataTagInfo {
7070
try {
7171
nextData = JSON.parse(nextDataTag.innerHTML);
7272
} catch {
73-
DEBUG_BUILD && logger.warn('Could not extract __NEXT_DATA__');
73+
DEBUG_BUILD && debug.warn('Could not extract __NEXT_DATA__');
7474
}
7575
}
7676

packages/nextjs/src/client/routing/parameterization.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { GLOBAL_OBJ, logger } from '@sentry/core';
1+
import { GLOBAL_OBJ, debug } from '@sentry/core';
22
import { DEBUG_BUILD } from '../../common/debug-build';
33
import type { RouteManifest } from '../../config/manifest/types';
44

@@ -54,7 +54,7 @@ function getCompiledRegex(regexString: string): RegExp | null {
5454
compiledRegexCache.set(regexString, regex);
5555
return regex;
5656
} catch (error) {
57-
DEBUG_BUILD && logger.warn('Could not compile regex', { regexString, error });
57+
DEBUG_BUILD && debug.warn('Could not compile regex', { regexString, error });
5858
// Cache the failure to avoid repeated attempts by storing undefined
5959
return null;
6060
}
@@ -100,7 +100,7 @@ function getManifest(): RouteManifest | null {
100100
return manifest;
101101
} catch {
102102
// Something went wrong while parsing the manifest, so we'll fallback to no parameterization
103-
DEBUG_BUILD && logger.warn('Could not extract route manifest');
103+
DEBUG_BUILD && debug.warn('Could not extract route manifest');
104104
return null;
105105
}
106106
}

packages/nextjs/src/client/tunnelRoute.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { dsnFromString, GLOBAL_OBJ, logger } from '@sentry/core';
1+
import { debug, dsnFromString, GLOBAL_OBJ } from '@sentry/core';
22
import type { BrowserOptions } from '@sentry/react';
33
import { DEBUG_BUILD } from '../common/debug-build';
44

@@ -25,9 +25,9 @@ export function applyTunnelRouteOption(options: BrowserOptions): void {
2525
tunnelPath += `&r=${regionCode}`;
2626
}
2727
options.tunnel = tunnelPath;
28-
DEBUG_BUILD && logger.info(`Tunneling events to "${tunnelPath}"`);
28+
DEBUG_BUILD && debug.log(`Tunneling events to "${tunnelPath}"`);
2929
} else {
30-
DEBUG_BUILD && logger.warn('Provided DSN is not a Sentry SaaS DSN. Will not tunnel events.');
30+
DEBUG_BUILD && debug.warn('Provided DSN is not a Sentry SaaS DSN. Will not tunnel events.');
3131
}
3232
}
3333
}

packages/nextjs/src/common/devErrorSymbolicationEventProcessor.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import type { Event, EventHint } from '@sentry/core';
2-
import { GLOBAL_OBJ, logger, parseSemver, suppressTracing } from '@sentry/core';
2+
import { GLOBAL_OBJ, debug, parseSemver, suppressTracing } from '@sentry/core';
33
import type { StackFrame } from 'stacktrace-parser';
44
import * as stackTraceParser from 'stacktrace-parser';
55
import { DEBUG_BUILD } from './debug-build';
@@ -150,7 +150,7 @@ async function resolveStackFrame(
150150
originalStackFrame: body.originalStackFrame,
151151
};
152152
} catch (e) {
153-
DEBUG_BUILD && logger.error('Failed to symbolicate event with Next.js dev server', e);
153+
DEBUG_BUILD && debug.error('Failed to symbolicate event with Next.js dev server', e);
154154
return null;
155155
}
156156
}
@@ -224,7 +224,7 @@ async function resolveStackFrames(
224224
};
225225
});
226226
} catch (e) {
227-
DEBUG_BUILD && logger.error('Failed to symbolicate event with Next.js dev server', e);
227+
DEBUG_BUILD && debug.error('Failed to symbolicate event with Next.js dev server', e);
228228
return null;
229229
}
230230
}

packages/nextjs/src/common/pages-router-instrumentation/wrapApiHandlerWithSentry.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
import {
22
captureException,
33
continueTrace,
4+
debug,
45
getActiveSpan,
56
httpRequestToRequestData,
67
isString,
7-
logger,
88
objectify,
99
SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN,
1010
SEMANTIC_ATTRIBUTE_SENTRY_SOURCE,
@@ -42,12 +42,12 @@ export function wrapApiHandlerWithSentry(apiHandler: NextApiHandler, parameteriz
4242
const [req, res] = args;
4343

4444
if (!req) {
45-
logger.debug(
45+
debug.log(
4646
`Wrapped API handler on route "${parameterizedRoute}" was not passed a request object. Will not instrument.`,
4747
);
4848
return wrappingTarget.apply(thisArg, args);
4949
} else if (!res) {
50-
logger.debug(
50+
debug.log(
5151
`Wrapped API handler on route "${parameterizedRoute}" was not passed a response object. Will not instrument.`,
5252
);
5353
return wrappingTarget.apply(thisArg, args);

packages/nextjs/src/common/utils/responseEnd.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import type { Span } from '@sentry/core';
2-
import { fill, flush, logger, setHttpStatus } from '@sentry/core';
2+
import { debug, fill, flush, setHttpStatus } from '@sentry/core';
33
import type { ServerResponse } from 'http';
44
import { DEBUG_BUILD } from '../debug-build';
55
import type { ResponseEndMethod, WrappedResponseEndMethod } from '../types';
@@ -47,10 +47,10 @@ export function finishSpan(span: Span, res: ServerResponse): void {
4747
*/
4848
export async function flushSafelyWithTimeout(): Promise<void> {
4949
try {
50-
DEBUG_BUILD && logger.log('Flushing events...');
50+
DEBUG_BUILD && debug.log('Flushing events...');
5151
await flush(2000);
52-
DEBUG_BUILD && logger.log('Done flushing events');
52+
DEBUG_BUILD && debug.log('Done flushing events');
5353
} catch (e) {
54-
DEBUG_BUILD && logger.log('Error while flushing events:\n', e);
54+
DEBUG_BUILD && debug.log('Error while flushing events:\n', e);
5555
}
5656
}

packages/nextjs/src/common/utils/tracingUtils.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import type { PropagationContext } from '@sentry/core';
2-
import { getActiveSpan, getRootSpan, GLOBAL_OBJ, logger, Scope, spanToJSON, startNewTrace } from '@sentry/core';
2+
import { debug, getActiveSpan, getRootSpan, GLOBAL_OBJ, Scope, spanToJSON, startNewTrace } from '@sentry/core';
33
import { DEBUG_BUILD } from '../debug-build';
44
import { TRANSACTION_ATTR_SHOULD_DROP_TRANSACTION } from '../span-attributes-with-logic-attached';
55

@@ -72,7 +72,7 @@ export function escapeNextjsTracing<T>(cb: () => T): T {
7272

7373
if (!MaybeGlobalAsyncLocalStorage) {
7474
DEBUG_BUILD &&
75-
logger.warn(
75+
debug.warn(
7676
"Tried to register AsyncLocalStorage async context strategy in a runtime that doesn't support AsyncLocalStorage.",
7777
);
7878
return cb();

packages/nextjs/src/config/turbopack/constructTurbopackConfig.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { logger } from '@sentry/core';
1+
import { debug } from '@sentry/core';
22
import * as chalk from 'chalk';
33
import * as path from 'path';
44
import type { RouteManifest } from '../manifest/types';
@@ -63,7 +63,7 @@ export function safelyAddTurbopackRule(
6363

6464
// If the rule already exists, we don't want to mess with it.
6565
if (existingRules[matcher]) {
66-
logger.info(
66+
debug.info(
6767
`${chalk.cyan(
6868
'info',
6969
)} - Turbopack rule already exists for ${matcher}. Please remove it from your Next.js config in order for Sentry to work properly.`,

packages/nextjs/src/config/webpack.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/* eslint-disable complexity */
22
/* eslint-disable max-lines */
33

4-
import { escapeStringForRegex, loadModule, logger, parseSemver } from '@sentry/core';
4+
import { debug, escapeStringForRegex, loadModule, parseSemver } from '@sentry/core';
55
import * as chalk from 'chalk';
66
import * as fs from 'fs';
77
import * as path from 'path';
@@ -219,7 +219,7 @@ export function constructWebpackConfigFunction(
219219
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
220220
vercelCronsConfig = JSON.parse(fs.readFileSync(path.join(process.cwd(), 'vercel.json'), 'utf8')).crons;
221221
if (vercelCronsConfig) {
222-
logger.info(
222+
debug.log(
223223
`${chalk.cyan(
224224
'info',
225225
)} - Creating Sentry cron monitors for your Vercel Cron Jobs. You can disable this feature by setting the ${chalk.bold.cyan(
@@ -233,7 +233,7 @@ export function constructWebpackConfigFunction(
233233
// noop if file does not exist
234234
} else {
235235
// log but noop
236-
logger.error(
236+
debug.error(
237237
`${chalk.red(
238238
'error',
239239
)} - Sentry failed to read vercel.json for automatic cron job monitoring instrumentation`,
@@ -368,7 +368,7 @@ export function constructWebpackConfigFunction(
368368
// We only update this if no explicit value is set
369369
// (Next.js defaults to `false`: https://github.com/vercel/next.js/blob/5f4f96c133bd6b10954812cc2fef6af085b82aa5/packages/next/src/build/webpack/config/blocks/base.ts#L61)
370370
if (!newConfig.devtool) {
371-
logger.info(`[@sentry/nextjs] Automatically enabling source map generation for ${runtime} build.`);
371+
debug.log(`[@sentry/nextjs] Automatically enabling source map generation for ${runtime} build.`);
372372
// `hidden-source-map` produces the same sourcemaps as `source-map`, but doesn't include the `sourceMappingURL`
373373
// comment at the bottom. For folks who aren't publicly hosting their sourcemaps, this is helpful because then
374374
// the browser won't look for them and throw errors into the console when it can't find them. Because this is a
@@ -383,7 +383,7 @@ export function constructWebpackConfigFunction(
383383

384384
// enable source map deletion if not explicitly disabled
385385
if (!isServer && userSentryOptions.sourcemaps?.deleteSourcemapsAfterUpload === undefined) {
386-
logger.warn(
386+
debug.warn(
387387
'[@sentry/nextjs] Source maps will be automatically deleted after being uploaded to Sentry. If you want to keep the source maps, set the `sourcemaps.deleteSourcemapsAfterUpload` option to false in `withSentryConfig()`. If you do not want to generate and upload sourcemaps at all, set the `sourcemaps.disable` option to true.',
388388
);
389389
userSentryOptions.sourcemaps = {
@@ -643,7 +643,7 @@ function addFilesToWebpackEntryPoint(
643643
import: newImportValue,
644644
};
645645
}
646-
// malformed entry point (use `console.error` rather than `logger.error` because it will always be printed, regardless
646+
// malformed entry point (use `console.error` rather than `debug.error` because it will always be printed, regardless
647647
// of SDK settings)
648648
else {
649649
// eslint-disable-next-line no-console

packages/nextjs/src/server/index.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import {
99
import type { EventProcessor } from '@sentry/core';
1010
import {
1111
applySdkMetadata,
12+
debug,
1213
extractTraceparentData,
1314
getCapturedScopesOnSpan,
1415
getClient,
@@ -17,7 +18,6 @@ import {
1718
getIsolationScope,
1819
getRootSpan,
1920
GLOBAL_OBJ,
20-
logger,
2121
SEMANTIC_ATTRIBUTE_SENTRY_OP,
2222
SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN,
2323
SEMANTIC_ATTRIBUTE_SENTRY_SOURCE,
@@ -125,13 +125,13 @@ export function init(options: NodeOptions): NodeClient | undefined {
125125
};
126126

127127
if (DEBUG_BUILD && opts.debug) {
128-
logger.enable();
128+
debug.enable();
129129
}
130130

131-
DEBUG_BUILD && logger.log('Initializing SDK...');
131+
DEBUG_BUILD && debug.log('Initializing SDK...');
132132

133133
if (sdkAlreadyInitialized()) {
134-
DEBUG_BUILD && logger.log('SDK already initialized');
134+
DEBUG_BUILD && debug.log('SDK already initialized');
135135
return;
136136
}
137137

@@ -377,7 +377,7 @@ export function init(options: NodeOptions): NodeClient | undefined {
377377
// The statement above can throw because process is not defined on the client
378378
}
379379

380-
DEBUG_BUILD && logger.log('SDK successfully initialized');
380+
DEBUG_BUILD && debug.log('SDK successfully initialized');
381381

382382
return client;
383383
}

0 commit comments

Comments
 (0)