Skip to content

Commit c23fa70

Browse files
authored
ref(nuxt): Use debug instead of logger (#16991)
resolves #16944
1 parent 5f45a48 commit c23fa70

File tree

8 files changed

+32
-40
lines changed

8 files changed

+32
-40
lines changed

packages/nuxt/src/runtime/hooks/updateRouteBeforeResponse.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { getActiveSpan, getRootSpan, logger, SEMANTIC_ATTRIBUTE_SENTRY_SOURCE } from '@sentry/core';
1+
import { debug, getActiveSpan, getRootSpan, SEMANTIC_ATTRIBUTE_SENTRY_SOURCE } from '@sentry/core';
22
import type { H3Event } from 'h3';
33

44
/**
@@ -46,6 +46,6 @@ export function updateRouteBeforeResponse(event: H3Event): void {
4646
});
4747
}
4848

49-
logger.log(`Updated transaction name for parametrized route: ${matchedRoutePath}`);
49+
debug.log(`Updated transaction name for parametrized route: ${matchedRoutePath}`);
5050
}
5151
}

packages/nuxt/src/runtime/plugins/route-detector.server.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { getActiveSpan, getRootSpan, logger, SEMANTIC_ATTRIBUTE_SENTRY_SOURCE } from '@sentry/core';
1+
import { debug, getActiveSpan, getRootSpan, SEMANTIC_ATTRIBUTE_SENTRY_SOURCE } from '@sentry/core';
22
import { defineNuxtPlugin } from 'nuxt/app';
33
import type { NuxtPageSubset } from '../utils/route-extraction';
44
import { extractParametrizedRouteFromContext } from '../utils/route-extraction';
@@ -11,10 +11,10 @@ export default defineNuxtPlugin(nuxtApp => {
1111
// @ts-expect-error This import is dynamically resolved at build time (`addTemplate` in module.ts)
1212
const { default: importedPagesData } = await import('#build/sentry--nuxt-pages-data.mjs');
1313
buildTimePagesData = importedPagesData || [];
14-
logger.log('Imported build-time pages data:', buildTimePagesData);
14+
debug.log('Imported build-time pages data:', buildTimePagesData);
1515
} catch (error) {
1616
buildTimePagesData = [];
17-
logger.warn('Failed to import build-time pages data:', error);
17+
debug.warn('Failed to import build-time pages data:', error);
1818
}
1919

2020
const ssrContext = renderContext.ssrContext;
@@ -38,7 +38,7 @@ export default defineNuxtPlugin(nuxtApp => {
3838
return;
3939
}
4040

41-
logger.log('Matched parametrized server route:', routeInfo.parametrizedRoute);
41+
debug.log('Matched parametrized server route:', routeInfo.parametrizedRoute);
4242

4343
rootSpan.setAttributes({
4444
[SEMANTIC_ATTRIBUTE_SENTRY_SOURCE]: 'route',

packages/nuxt/src/runtime/plugins/sentry-cloudflare.server.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import type { ExecutionContext, IncomingRequestCfProperties } from '@cloudflare/workers-types';
22
import type { CloudflareOptions } from '@sentry/cloudflare';
33
import { setAsyncLocalStorageAsyncContextStrategy, wrapRequestHandler } from '@sentry/cloudflare';
4-
import { getDefaultIsolationScope, getIsolationScope, getTraceData, logger } from '@sentry/core';
4+
import { debug, getDefaultIsolationScope, getIsolationScope, getTraceData } from '@sentry/core';
55
import type { H3Event } from 'h3';
66
import type { NitroApp, NitroAppPlugin } from 'nitropack';
77
import type { NuxtRenderHTMLContext } from 'nuxt/app';
@@ -99,7 +99,7 @@ export const sentryCloudflareNitroPlugin =
9999
const event = handlerArgs[1];
100100

101101
if (!isEventType(event)) {
102-
logger.log("Nitro Cloudflare plugin did not detect a Cloudflare event type. Won't patch Cloudflare handler.");
102+
debug.log("Nitro Cloudflare plugin did not detect a Cloudflare event type. Won't patch Cloudflare handler.");
103103
return handlerTarget.apply(handlerThisArg, handlerArgs);
104104
} else {
105105
// Usually, the protocol already includes ":"
@@ -125,10 +125,10 @@ export const sentryCloudflareNitroPlugin =
125125
if (traceData && Object.keys(traceData).length > 0) {
126126
// Storing trace data in the WeakMap using event.context.cf as key for later use in HTML meta-tags
127127
traceDataMap.set(event.context.cf, traceData);
128-
logger.log('Stored trace data for later use in HTML meta-tags: ', traceData);
128+
debug.log('Stored trace data for later use in HTML meta-tags: ', traceData);
129129
}
130130

131-
logger.log(
131+
debug.log(
132132
`Patched Cloudflare handler (\`nitroApp.localFetch\`). ${
133133
isolationScope === newIsolationScope ? 'Using existing' : 'Created new'
134134
} isolation scope.`,
@@ -147,7 +147,7 @@ export const sentryCloudflareNitroPlugin =
147147
const storedTraceData = event?.context?.cf ? traceDataMap.get(event.context.cf) : undefined;
148148

149149
if (storedTraceData && Object.keys(storedTraceData).length > 0) {
150-
logger.log('Using stored trace data for HTML meta-tags: ', storedTraceData);
150+
debug.log('Using stored trace data for HTML meta-tags: ', storedTraceData);
151151
addSentryTracingMetaTags(html.head, storedTraceData);
152152
} else {
153153
addSentryTracingMetaTags(html.head);

packages/nuxt/src/runtime/plugins/sentry.server.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { getDefaultIsolationScope, getIsolationScope, logger, withIsolationScope } from '@sentry/core';
1+
import { debug, getDefaultIsolationScope, getIsolationScope, withIsolationScope } from '@sentry/core';
22
// eslint-disable-next-line import/no-extraneous-dependencies
33
import { type EventHandler } from 'h3';
44
// eslint-disable-next-line import/no-extraneous-dependencies
@@ -27,7 +27,7 @@ function patchEventHandler(handler: EventHandler): EventHandler {
2727
const isolationScope = getIsolationScope();
2828
const newIsolationScope = isolationScope === getDefaultIsolationScope() ? isolationScope.clone() : isolationScope;
2929

30-
logger.log(
30+
debug.log(
3131
`Patched h3 event handler. ${
3232
isolationScope === newIsolationScope ? 'Using existing' : 'Created new'
3333
} isolation scope.`,

packages/nuxt/src/runtime/utils.ts

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,5 @@
11
import type { ClientOptions, Context, SerializedTraceData } from '@sentry/core';
2-
import {
3-
captureException,
4-
flush,
5-
getClient,
6-
getTraceMetaTags,
7-
GLOBAL_OBJ,
8-
logger,
9-
vercelWaitUntil,
10-
} from '@sentry/core';
2+
import { captureException, debug, flush, getClient, getTraceMetaTags, GLOBAL_OBJ, vercelWaitUntil } from '@sentry/core';
113
import type { VueOptions } from '@sentry/vue/src/types';
124
import type { CapturedErrorContext } from 'nitropack/types';
135
import type { NuxtRenderHTMLContext } from 'nuxt/app';
@@ -45,14 +37,14 @@ export function addSentryTracingMetaTags(head: NuxtRenderHTMLContext['head'], tr
4537
const metaTags = getTraceMetaTags(traceData);
4638

4739
if (head.some(tag => tag.includes('meta') && tag.includes('sentry-trace'))) {
48-
logger.warn(
40+
debug.warn(
4941
'Skipping addition of meta tags. Sentry tracing meta tags are already present in HTML page. Make sure to only set up Sentry once on the server-side. ',
5042
);
5143
return;
5244
}
5345

5446
if (metaTags) {
55-
logger.log('Adding Sentry tracing meta tags to HTML page:', metaTags);
47+
debug.log('Adding Sentry tracing meta tags to HTML page:', metaTags);
5648
head.push(metaTags);
5749
}
5850
}
@@ -96,11 +88,11 @@ export function reportNuxtError(options: {
9688

9789
async function flushWithTimeout(): Promise<void> {
9890
try {
99-
logger.log('Flushing events...');
91+
debug.log('Flushing events...');
10092
await flush(2000);
101-
logger.log('Done flushing events');
93+
debug.log('Done flushing events');
10294
} catch (e) {
103-
logger.log('Error while flushing events:\n', e);
95+
debug.log('Error while flushing events:\n', e);
10496
}
10597
}
10698

packages/nuxt/src/runtime/utils/route-extraction.ts

Lines changed: 3 additions & 3 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 type { NuxtSSRContext } from 'nuxt/app';
33
import type { NuxtPage } from 'nuxt/schema';
44

@@ -39,11 +39,11 @@ export function extractParametrizedRouteFromContext(
3939
const cacheKey = Array.from(ssrContextModules).sort().join('|');
4040
const cachedResult = extractionResultCache.get(cacheKey);
4141
if (cachedResult !== undefined) {
42-
logger.log('Found cached result for parametrized route:', requestedUrl);
42+
debug.log('Found cached result for parametrized route:', requestedUrl);
4343
return cachedResult;
4444
}
4545

46-
logger.log('No parametrized route found in cache lookup. Extracting parametrized route for:', requestedUrl);
46+
debug.log('No parametrized route found in cache lookup. Extracting parametrized route for:', requestedUrl);
4747

4848
const modulesArray = Array.from(ssrContextModules);
4949

packages/nuxt/src/server/sdk.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import * as path from 'node:path';
22
import type { Client, EventProcessor, Integration } from '@sentry/core';
3-
import { applySdkMetadata, flush, getGlobalScope, logger, vercelWaitUntil } from '@sentry/core';
3+
import { applySdkMetadata, debug, flush, getGlobalScope, vercelWaitUntil } from '@sentry/core';
44
import {
55
type NodeOptions,
66
getDefaultIntegrations as getDefaultNodeIntegrations,
@@ -48,7 +48,7 @@ export function lowQualityTransactionsFilter(options: SentryNuxtServerOptions):
4848
if (path.extname(event.transaction)) {
4949
options.debug &&
5050
DEBUG_BUILD &&
51-
logger.log('NuxtLowQualityTransactionsFilter filtered transaction: ', event.transaction);
51+
debug.log('NuxtLowQualityTransactionsFilter filtered transaction: ', event.transaction);
5252
return null;
5353
}
5454
return event;
@@ -67,7 +67,7 @@ export function clientSourceMapErrorFilter(options: SentryNuxtServerOptions): Ev
6767
(event => {
6868
const errorMsg = event.exception?.values?.[0]?.value;
6969
if (errorMsg?.match(/^ENOENT: no such file or directory, open '.*\/_nuxt\/.*\.js\.map'/)) {
70-
options.debug && DEBUG_BUILD && logger.log('NuxtClientSourceMapErrorFilter filtered error: ', errorMsg);
70+
options.debug && DEBUG_BUILD && debug.log('NuxtClientSourceMapErrorFilter filtered error: ', errorMsg);
7171
return null;
7272
}
7373
return event;
@@ -96,10 +96,10 @@ function getNuxtDefaultIntegrations(options: NodeOptions): Integration[] {
9696
*/
9797
export async function flushSafelyWithTimeout(): Promise<void> {
9898
try {
99-
DEBUG_BUILD && logger.log('Flushing events...');
99+
DEBUG_BUILD && debug.log('Flushing events...');
100100
await flush(2000);
101-
DEBUG_BUILD && logger.log('Done flushing events');
101+
DEBUG_BUILD && debug.log('Done flushing events');
102102
} catch (e) {
103-
DEBUG_BUILD && logger.log('Error while flushing events:\n', e);
103+
DEBUG_BUILD && debug.log('Error while flushing events:\n', e);
104104
}
105105
}

packages/nuxt/src/vite/addServerConfig.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { existsSync } from 'node:fs';
22
import { createResolver } from '@nuxt/kit';
3-
import { logger } from '@sentry/core';
3+
import { debug } from '@sentry/core';
44
import * as fs from 'fs';
55
import type { Nitro } from 'nitropack';
66
import type { InputPluginOption } from 'rollup';
@@ -124,7 +124,7 @@ export function addDynamicImportEntryFileWrapper(
124124
/**
125125
* Rollup plugin to include the Sentry server configuration file to the server build output.
126126
*/
127-
function injectServerConfigPlugin(nitro: Nitro, serverConfigFile: string, debug?: boolean): InputPluginOption {
127+
function injectServerConfigPlugin(nitro: Nitro, serverConfigFile: string, isDebug?: boolean): InputPluginOption {
128128
const filePrefix = '\0virtual:sentry-server-config:';
129129

130130
return {
@@ -134,8 +134,8 @@ function injectServerConfigPlugin(nitro: Nitro, serverConfigFile: string, debug?
134134
const configPath = createResolver(nitro.options.srcDir).resolve(`/${serverConfigFile}`);
135135

136136
if (!existsSync(configPath)) {
137-
if (debug) {
138-
logger.log(`[Sentry] Sentry server config file not found: ${configPath}`);
137+
if (isDebug) {
138+
debug.log(`[Sentry] Sentry server config file not found: ${configPath}`);
139139
}
140140
return;
141141
}

0 commit comments

Comments
 (0)