Skip to content

Commit 1b41126

Browse files
AbhiPrasadmydea
andauthored
feat(core): Deprecate logger in favor of debug (#17040)
resolves #16905 also renames the file to be `debug-logger.ts` instead of `logger.ts` to make usage inside `@sentry/core` a little easier to understand. Added a note to `MIGRATION.md`, but let me know if I should remove that. --------- Co-authored-by: Francesco Gringl-Novy <francesco.novy@sentry.io>
1 parent 75439ef commit 1b41126

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

61 files changed

+135
-162
lines changed

MIGRATION.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,22 @@ These docs walk through how to migrate our JavaScript SDKs through different maj
77
- Upgrading from [SDK 7.x to 8.x](./docs/migration/v7-to-v8.md)
88
- Upgrading from [SDK 8.x to 9.x](#upgrading-from-8x-to-9x)
99

10+
# Deprecations in 9.x
11+
12+
## Deprecated `@sentry/core` SDK internal `logger` export
13+
14+
The internal SDK `logger` export from `@sentry/core` has been deprecated in favor of the `debug` export. `debug` only exposes `log`, `warn`, and `error` methods but is otherwise identical to `logger`. Note that this deprecation does not affect the `logger` export from other packages (like `@sentry/browser` or `@sentry/node`) which is used for Sentry Logging.
15+
16+
```js
17+
import { logger, debug } from '@sentry/core';
18+
19+
// before
20+
logger.info('This is an info message');
21+
22+
// after
23+
debug.log('This is an info message');
24+
```
25+
1026
# Upgrading from 8.x to 9.x
1127

1228
Version 9 of the Sentry JavaScript SDK primarily introduces API cleanup and version support changes.

dev-packages/opentelemetry-v2-tests/test/helpers/initOtel.ts

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import {
77
ATTR_SERVICE_VERSION,
88
SEMRESATTRS_SERVICE_NAMESPACE,
99
} from '@opentelemetry/semantic-conventions';
10-
import { getClient, logger, SDK_VERSION } from '@sentry/core';
10+
import { debug as debugLogger, getClient, SDK_VERSION } from '@sentry/core';
1111
import { wrapContextManagerClass } from '../../../../packages/opentelemetry/src/contextManager';
1212
import { DEBUG_BUILD } from '../../../../packages/opentelemetry/src/debug-build';
1313
import { SentryPropagator } from '../../../../packages/opentelemetry/src/propagator';
@@ -25,21 +25,23 @@ export function initOtel(): void {
2525

2626
if (!client) {
2727
DEBUG_BUILD &&
28-
logger.warn(
28+
debugLogger.warn(
2929
'No client available, skipping OpenTelemetry setup. This probably means that `Sentry.init()` was not called before `initOtel()`.',
3030
);
3131
return;
3232
}
3333

3434
if (client.getOptions().debug) {
35-
const otelLogger = new Proxy(logger as typeof logger & { verbose: (typeof logger)['debug'] }, {
36-
get(target, prop, receiver) {
37-
const actualProp = prop === 'verbose' ? 'debug' : prop;
38-
return Reflect.get(target, actualProp, receiver);
35+
diag.setLogger(
36+
{
37+
error: debugLogger.error,
38+
warn: debugLogger.warn,
39+
info: debugLogger.log,
40+
debug: debugLogger.log,
41+
verbose: debugLogger.log,
3942
},
40-
});
41-
42-
diag.setLogger(otelLogger, DiagLogLevel.DEBUG);
43+
DiagLogLevel.DEBUG,
44+
);
4345
}
4446

4547
setupEventContextTrace(client);

dev-packages/opentelemetry-v2-tests/test/integration/transactions.test.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import {
66
addBreadcrumb,
77
debug,
88
getClient,
9-
logger,
109
SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN,
1110
SEMANTIC_ATTRIBUTE_SENTRY_SOURCE,
1211
setTag,
@@ -503,7 +502,7 @@ describe('Integration | Transactions', () => {
503502
vi.setSystemTime(now);
504503

505504
const logs: unknown[] = [];
506-
vi.spyOn(logger, 'log').mockImplementation(msg => logs.push(msg));
505+
vi.spyOn(debug, 'log').mockImplementation(msg => logs.push(msg));
507506

508507
const transactions: Event[] = [];
509508

@@ -555,7 +554,7 @@ describe('Integration | Transactions', () => {
555554
vi.setSystemTime(now);
556555

557556
const logs: unknown[] = [];
558-
vi.spyOn(logger, 'log').mockImplementation(msg => logs.push(msg));
557+
vi.spyOn(debug, 'log').mockImplementation(msg => logs.push(msg));
559558

560559
const transactions: Event[] = [];
561560

@@ -606,7 +605,7 @@ describe('Integration | Transactions', () => {
606605
vi.setSystemTime(now);
607606

608607
const logs: unknown[] = [];
609-
vi.spyOn(logger, 'log').mockImplementation(msg => logs.push(msg));
608+
vi.spyOn(debug, 'log').mockImplementation(msg => logs.push(msg));
610609

611610
const transactions: Event[] = [];
612611

packages/core/src/breadcrumbs.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { getClient, getIsolationScope } from './currentScopes';
22
import type { Breadcrumb, BreadcrumbHint } from './types-hoist/breadcrumb';
3-
import { consoleSandbox } from './utils/logger';
3+
import { consoleSandbox } from './utils/debug-logger';
44
import { dateTimestampInSeconds } from './utils/time';
55

66
/**

packages/core/src/carrier.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import type { AsyncContextStrategy } from './asyncContext/types';
33
import type { Client } from './client';
44
import type { Scope } from './scope';
55
import type { SerializedLog } from './types-hoist/log';
6-
import type { Logger } from './utils/logger';
6+
import type { Logger } from './utils/debug-logger';
77
import { SDK_VERSION } from './utils/version';
88
import { GLOBAL_OBJ } from './utils/worldwide';
99

@@ -27,6 +27,7 @@ export interface SentryCarrier {
2727
defaultIsolationScope?: Scope;
2828
defaultCurrentScope?: Scope;
2929
/** @deprecated Logger is no longer set. Instead, we keep enabled state in loggerSettings. */
30+
// eslint-disable-next-line deprecation/deprecation
3031
logger?: Logger;
3132
loggerSettings?: { enabled: boolean };
3233
/**

packages/core/src/client.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,11 @@ import type { Span, SpanAttributes, SpanContextData, SpanJSON } from './types-ho
3333
import type { StartSpanOptions } from './types-hoist/startSpanOptions';
3434
import type { Transport, TransportMakeRequestResponse } from './types-hoist/transport';
3535
import { createClientReportEnvelope } from './utils/clientreport';
36+
import { debug } from './utils/debug-logger';
3637
import { dsnToString, makeDsn } from './utils/dsn';
3738
import { addItemToEnvelope, createAttachmentEnvelopeItem } from './utils/envelope';
3839
import { getPossibleEventMessages } from './utils/eventUtils';
3940
import { isParameterizedString, isPlainObject, isPrimitive, isThenable } from './utils/is';
40-
import { debug } from './utils/logger';
4141
import { merge } from './utils/merge';
4242
import { checkOrSetAlreadyCaught, uuid4 } from './utils/misc';
4343
import { parseSampleRate } from './utils/parseSampleRate';

packages/core/src/eventProcessors.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import { DEBUG_BUILD } from './debug-build';
22
import type { Event, EventHint } from './types-hoist/event';
33
import type { EventProcessor } from './types-hoist/eventprocessor';
4+
import { debug } from './utils/debug-logger';
45
import { isThenable } from './utils/is';
5-
import { debug } from './utils/logger';
66
import { SyncPromise } from './utils/syncpromise';
77

88
/**

packages/core/src/exports.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ import type { Primitive } from './types-hoist/misc';
1010
import type { Session, SessionContext } from './types-hoist/session';
1111
import type { SeverityLevel } from './types-hoist/severity';
1212
import type { User } from './types-hoist/user';
13+
import { debug } from './utils/debug-logger';
1314
import { isThenable } from './utils/is';
14-
import { debug } from './utils/logger';
1515
import { uuid4 } from './utils/misc';
1616
import type { ExclusiveEventHintOrCaptureContext } from './utils/prepareEvent';
1717
import { parseEventHintOrCaptureContext } from './utils/prepareEvent';

packages/core/src/index.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -165,8 +165,10 @@ export {
165165
isVueViewModel,
166166
} from './utils/is';
167167
export { isBrowser } from './utils/isBrowser';
168-
export { CONSOLE_LEVELS, consoleSandbox, debug, logger, originalConsoleMethods } from './utils/logger';
169-
export type { Logger } from './utils/logger';
168+
// eslint-disable-next-line deprecation/deprecation
169+
export { CONSOLE_LEVELS, consoleSandbox, debug, logger, originalConsoleMethods } from './utils/debug-logger';
170+
// eslint-disable-next-line deprecation/deprecation
171+
export type { Logger } from './utils/debug-logger';
170172
export {
171173
addContextToFrame,
172174
addExceptionMechanism,

packages/core/src/instrument/console.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/* eslint-disable @typescript-eslint/no-explicit-any */
22
/* eslint-disable @typescript-eslint/ban-types */
33
import type { ConsoleLevel, HandlerDataConsole } from '../types-hoist/instrument';
4-
import { CONSOLE_LEVELS, originalConsoleMethods } from '../utils/logger';
4+
import { CONSOLE_LEVELS, originalConsoleMethods } from '../utils/debug-logger';
55
import { fill } from '../utils/object';
66
import { GLOBAL_OBJ } from '../utils/worldwide';
77
import { addHandler, maybeInstrument, triggerHandlers } from './handlers';

0 commit comments

Comments
 (0)