Skip to content

ref(react-router): Use debug instead of logger #16989

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
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ import type { InstrumentationConfig } from '@opentelemetry/instrumentation';
import { InstrumentationBase, InstrumentationNodeModuleDefinition } from '@opentelemetry/instrumentation';
import { SEMATTRS_HTTP_TARGET } from '@opentelemetry/semantic-conventions';
import {
debug,
getActiveSpan,
getRootSpan,
logger,
SDK_VERSION,
SEMANTIC_ATTRIBUTE_SENTRY_OP,
SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN,
Expand Down Expand Up @@ -80,7 +80,7 @@ export class ReactRouterInstrumentation extends InstrumentationBase<Instrumentat
const rootSpan = activeSpan && getRootSpan(activeSpan);

if (!rootSpan) {
DEBUG_BUILD && logger.debug('No active root span found, skipping tracing for data request');
DEBUG_BUILD && debug.log('No active root span found, skipping tracing for data request');
return originalRequestHandler(request, initialContext);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { type Client, type Event, type EventHint, defineIntegration, logger } from '@sentry/core';
import { type Client, type Event, type EventHint, debug, defineIntegration } from '@sentry/core';
import type { NodeOptions } from '@sentry/node';

/**
Expand All @@ -23,7 +23,7 @@ function _lowQualityTransactionsFilterIntegration(options: NodeOptions): {
const transaction = event.transaction;

if (matchedRegexes.some(regex => transaction.match(regex))) {
options.debug && logger.log('[ReactRouter] Filtered node_modules transaction:', event.transaction);
options.debug && debug.log('[ReactRouter] Filtered node_modules transaction:', event.transaction);
return null;
}

Expand Down
6 changes: 3 additions & 3 deletions packages/react-router/src/server/sdk.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { Integration } from '@sentry/core';
import { applySdkMetadata, logger, setTag } from '@sentry/core';
import { applySdkMetadata, debug, setTag } from '@sentry/core';
import type { NodeClient, NodeOptions } from '@sentry/node';
import { getDefaultIntegrations as getNodeDefaultIntegrations, init as initNodeSdk } from '@sentry/node';
import { DEBUG_BUILD } from '../common/debug-build';
Expand Down Expand Up @@ -27,15 +27,15 @@ export function init(options: NodeOptions): NodeClient | undefined {
defaultIntegrations: getDefaultReactRouterServerIntegrations(options),
};

DEBUG_BUILD && logger.log('Initializing SDK...');
DEBUG_BUILD && debug.log('Initializing SDK...');

applySdkMetadata(opts, 'react-router', ['react-router', 'node']);

const client = initNodeSdk(opts);

setTag('runtime', 'node');

DEBUG_BUILD && logger.log('SDK successfully initialized');
DEBUG_BUILD && debug.log('SDK successfully initialized');

return client;
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ vi.mock('@sentry/core', async () => {
getRootSpan: vi.fn(),
spanToJSON: vi.fn(),
updateSpanName: vi.fn(),
logger: {
debug: vi.fn(),
debug: {
log: vi.fn(),
},
SDK_VERSION: '1.0.0',
SEMANTIC_ATTRIBUTE_SENTRY_OP: 'sentry.op',
Expand Down Expand Up @@ -82,9 +82,7 @@ describe('ReactRouterInstrumentation', () => {
const req = createRequest('https://test.com/data');
await wrappedHandler(req);

expect(SentryCore.logger.debug).toHaveBeenCalledWith(
'No active root span found, skipping tracing for data request',
);
expect(SentryCore.debug.log).toHaveBeenCalledWith('No active root span found, skipping tracing for data request');
expect(originalHandler).toHaveBeenCalledWith(req, undefined);
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import * as SentryNode from '@sentry/node';
import { afterEach, describe, expect, it, vi } from 'vitest';
import { lowQualityTransactionsFilterIntegration } from '../../src/server/integration/lowQualityTransactionsFilterIntegration';

const loggerLog = vi.spyOn(SentryCore.logger, 'log').mockImplementation(() => {});
const debugLoggerLogSpy = vi.spyOn(SentryCore.debug, 'log').mockImplementation(() => {});

describe('Low Quality Transactions Filter Integration', () => {
afterEach(() => {
Expand All @@ -30,7 +30,7 @@ describe('Low Quality Transactions Filter Integration', () => {

expect(result).toBeNull();

expect(loggerLog).toHaveBeenCalledWith('[ReactRouter] Filtered node_modules transaction:', transaction);
expect(debugLoggerLogSpy).toHaveBeenCalledWith('[ReactRouter] Filtered node_modules transaction:', transaction);
});
});

Expand Down
Loading