Skip to content

ref(nuxt): Use debug instead of logger #16991

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 15, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions packages/nuxt/src/runtime/hooks/updateRouteBeforeResponse.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { getActiveSpan, getRootSpan, logger, SEMANTIC_ATTRIBUTE_SENTRY_SOURCE } from '@sentry/core';
import { debug, getActiveSpan, getRootSpan, SEMANTIC_ATTRIBUTE_SENTRY_SOURCE } from '@sentry/core';
import type { H3Event } from 'h3';

/**
Expand Down Expand Up @@ -46,6 +46,6 @@ export function updateRouteBeforeResponse(event: H3Event): void {
});
}

logger.log(`Updated transaction name for parametrized route: ${matchedRoutePath}`);
debug.log(`Updated transaction name for parametrized route: ${matchedRoutePath}`);
}
}
8 changes: 4 additions & 4 deletions packages/nuxt/src/runtime/plugins/route-detector.server.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { getActiveSpan, getRootSpan, logger, SEMANTIC_ATTRIBUTE_SENTRY_SOURCE } from '@sentry/core';
import { debug, getActiveSpan, getRootSpan, SEMANTIC_ATTRIBUTE_SENTRY_SOURCE } from '@sentry/core';
import { defineNuxtPlugin } from 'nuxt/app';
import type { NuxtPageSubset } from '../utils/route-extraction';
import { extractParametrizedRouteFromContext } from '../utils/route-extraction';
Expand All @@ -11,10 +11,10 @@ export default defineNuxtPlugin(nuxtApp => {
// @ts-expect-error This import is dynamically resolved at build time (`addTemplate` in module.ts)
const { default: importedPagesData } = await import('#build/sentry--nuxt-pages-data.mjs');
buildTimePagesData = importedPagesData || [];
logger.log('Imported build-time pages data:', buildTimePagesData);
debug.log('Imported build-time pages data:', buildTimePagesData);
} catch (error) {
buildTimePagesData = [];
logger.warn('Failed to import build-time pages data:', error);
debug.warn('Failed to import build-time pages data:', error);
}

const ssrContext = renderContext.ssrContext;
Expand All @@ -38,7 +38,7 @@ export default defineNuxtPlugin(nuxtApp => {
return;
}

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

rootSpan.setAttributes({
[SEMANTIC_ATTRIBUTE_SENTRY_SOURCE]: 'route',
Expand Down
10 changes: 5 additions & 5 deletions packages/nuxt/src/runtime/plugins/sentry-cloudflare.server.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import type { ExecutionContext, IncomingRequestCfProperties } from '@cloudflare/workers-types';
import type { CloudflareOptions } from '@sentry/cloudflare';
import { setAsyncLocalStorageAsyncContextStrategy, wrapRequestHandler } from '@sentry/cloudflare';
import { getDefaultIsolationScope, getIsolationScope, getTraceData, logger } from '@sentry/core';
import { debug, getDefaultIsolationScope, getIsolationScope, getTraceData } from '@sentry/core';
import type { H3Event } from 'h3';
import type { NitroApp, NitroAppPlugin } from 'nitropack';
import type { NuxtRenderHTMLContext } from 'nuxt/app';
Expand Down Expand Up @@ -99,7 +99,7 @@ export const sentryCloudflareNitroPlugin =
const event = handlerArgs[1];

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

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

if (storedTraceData && Object.keys(storedTraceData).length > 0) {
logger.log('Using stored trace data for HTML meta-tags: ', storedTraceData);
debug.log('Using stored trace data for HTML meta-tags: ', storedTraceData);
addSentryTracingMetaTags(html.head, storedTraceData);
} else {
addSentryTracingMetaTags(html.head);
Expand Down
4 changes: 2 additions & 2 deletions packages/nuxt/src/runtime/plugins/sentry.server.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { getDefaultIsolationScope, getIsolationScope, logger, withIsolationScope } from '@sentry/core';
import { debug, getDefaultIsolationScope, getIsolationScope, withIsolationScope } from '@sentry/core';
// eslint-disable-next-line import/no-extraneous-dependencies
import { type EventHandler } from 'h3';
// eslint-disable-next-line import/no-extraneous-dependencies
Expand Down Expand Up @@ -27,7 +27,7 @@ function patchEventHandler(handler: EventHandler): EventHandler {
const isolationScope = getIsolationScope();
const newIsolationScope = isolationScope === getDefaultIsolationScope() ? isolationScope.clone() : isolationScope;

logger.log(
debug.log(
`Patched h3 event handler. ${
isolationScope === newIsolationScope ? 'Using existing' : 'Created new'
} isolation scope.`,
Expand Down
20 changes: 6 additions & 14 deletions packages/nuxt/src/runtime/utils.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,5 @@
import type { ClientOptions, Context, SerializedTraceData } from '@sentry/core';
import {
captureException,
flush,
getClient,
getTraceMetaTags,
GLOBAL_OBJ,
logger,
vercelWaitUntil,
} from '@sentry/core';
import { captureException, debug, flush, getClient, getTraceMetaTags, GLOBAL_OBJ, vercelWaitUntil } from '@sentry/core';
import type { VueOptions } from '@sentry/vue/src/types';
import type { CapturedErrorContext } from 'nitropack/types';
import type { NuxtRenderHTMLContext } from 'nuxt/app';
Expand Down Expand Up @@ -45,14 +37,14 @@ export function addSentryTracingMetaTags(head: NuxtRenderHTMLContext['head'], tr
const metaTags = getTraceMetaTags(traceData);

if (head.some(tag => tag.includes('meta') && tag.includes('sentry-trace'))) {
logger.warn(
debug.warn(
'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. ',
);
return;
}

if (metaTags) {
logger.log('Adding Sentry tracing meta tags to HTML page:', metaTags);
debug.log('Adding Sentry tracing meta tags to HTML page:', metaTags);
head.push(metaTags);
}
}
Expand Down Expand Up @@ -96,11 +88,11 @@ export function reportNuxtError(options: {

async function flushWithTimeout(): Promise<void> {
try {
logger.log('Flushing events...');
debug.log('Flushing events...');
await flush(2000);
logger.log('Done flushing events');
debug.log('Done flushing events');
} catch (e) {
logger.log('Error while flushing events:\n', e);
debug.log('Error while flushing events:\n', e);
}
}

Expand Down
6 changes: 3 additions & 3 deletions packages/nuxt/src/runtime/utils/route-extraction.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { logger } from '@sentry/core';
import { debug } from '@sentry/core';
import type { NuxtSSRContext } from 'nuxt/app';
import type { NuxtPage } from 'nuxt/schema';

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

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

const modulesArray = Array.from(ssrContextModules);

Expand Down
12 changes: 6 additions & 6 deletions packages/nuxt/src/server/sdk.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as path from 'node:path';
import type { Client, EventProcessor, Integration } from '@sentry/core';
import { applySdkMetadata, flush, getGlobalScope, logger, vercelWaitUntil } from '@sentry/core';
import { applySdkMetadata, debug, flush, getGlobalScope, vercelWaitUntil } from '@sentry/core';
import {
type NodeOptions,
getDefaultIntegrations as getDefaultNodeIntegrations,
Expand Down Expand Up @@ -48,7 +48,7 @@ export function lowQualityTransactionsFilter(options: SentryNuxtServerOptions):
if (path.extname(event.transaction)) {
options.debug &&
DEBUG_BUILD &&
logger.log('NuxtLowQualityTransactionsFilter filtered transaction: ', event.transaction);
debug.log('NuxtLowQualityTransactionsFilter filtered transaction: ', event.transaction);
return null;
}
return event;
Expand All @@ -67,7 +67,7 @@ export function clientSourceMapErrorFilter(options: SentryNuxtServerOptions): Ev
(event => {
const errorMsg = event.exception?.values?.[0]?.value;
if (errorMsg?.match(/^ENOENT: no such file or directory, open '.*\/_nuxt\/.*\.js\.map'/)) {
options.debug && DEBUG_BUILD && logger.log('NuxtClientSourceMapErrorFilter filtered error: ', errorMsg);
options.debug && DEBUG_BUILD && debug.log('NuxtClientSourceMapErrorFilter filtered error: ', errorMsg);
return null;
}
return event;
Expand Down Expand Up @@ -96,10 +96,10 @@ function getNuxtDefaultIntegrations(options: NodeOptions): Integration[] {
*/
export async function flushSafelyWithTimeout(): Promise<void> {
try {
DEBUG_BUILD && logger.log('Flushing events...');
DEBUG_BUILD && debug.log('Flushing events...');
await flush(2000);
DEBUG_BUILD && logger.log('Done flushing events');
DEBUG_BUILD && debug.log('Done flushing events');
} catch (e) {
DEBUG_BUILD && logger.log('Error while flushing events:\n', e);
DEBUG_BUILD && debug.log('Error while flushing events:\n', e);
}
}
8 changes: 4 additions & 4 deletions packages/nuxt/src/vite/addServerConfig.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { existsSync } from 'node:fs';
import { createResolver } from '@nuxt/kit';
import { logger } from '@sentry/core';
import { debug } from '@sentry/core';
import * as fs from 'fs';
import type { Nitro } from 'nitropack';
import type { InputPluginOption } from 'rollup';
Expand Down Expand Up @@ -124,7 +124,7 @@ export function addDynamicImportEntryFileWrapper(
/**
* Rollup plugin to include the Sentry server configuration file to the server build output.
*/
function injectServerConfigPlugin(nitro: Nitro, serverConfigFile: string, debug?: boolean): InputPluginOption {
function injectServerConfigPlugin(nitro: Nitro, serverConfigFile: string, isDebug?: boolean): InputPluginOption {
const filePrefix = '\0virtual:sentry-server-config:';

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

if (!existsSync(configPath)) {
if (debug) {
logger.log(`[Sentry] Sentry server config file not found: ${configPath}`);
if (isDebug) {
debug.log(`[Sentry] Sentry server config file not found: ${configPath}`);
}
return;
}
Expand Down
Loading