Skip to content

Commit 7005f10

Browse files
author
Luca Forstner
committed
fix: Wrap all console log instances in console sandbox
1 parent 4c75f85 commit 7005f10

File tree

17 files changed

+110
-64
lines changed

17 files changed

+110
-64
lines changed

packages/core/src/hub.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -376,13 +376,11 @@ export class Hub implements HubInterface {
376376
if (__DEBUG_BUILD__ && !result) {
377377
const client = this.getClient();
378378
if (!client) {
379-
// eslint-disable-next-line no-console
380-
console.warn(
379+
logger.warn(
381380
"Tracing extension 'startTransaction' is missing. You should 'init' the SDK before calling 'startTransaction'",
382381
);
383382
} else {
384-
// eslint-disable-next-line no-console
385-
console.warn(`Tracing extension 'startTransaction' has not been added. Call 'addTracingExtensions' before calling 'init':
383+
logger.warn(`Tracing extension 'startTransaction' has not been added. Call 'addTracingExtensions' before calling 'init':
386384
Sentry.addTracingExtensions();
387385
Sentry.init({...});
388386
`);

packages/core/src/sdk.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import type { Client, ClientOptions } from '@sentry/types';
2-
import { logger } from '@sentry/utils';
2+
import { consoleSandbox, logger } from '@sentry/utils';
33

44
import { getCurrentHub } from './hub';
55

@@ -22,8 +22,10 @@ export function initAndBind<F extends Client, O extends ClientOptions>(
2222
logger.enable();
2323
} else {
2424
// use `console.warn` rather than `logger.warn` since by non-debug bundles have all `logger.x` statements stripped
25-
// eslint-disable-next-line no-console
26-
console.warn('[Sentry] Cannot initialize SDK with `debug` option using a non-debug bundle.');
25+
consoleSandbox(() => {
26+
// eslint-disable-next-line no-console
27+
console.warn('[Sentry] Cannot initialize SDK with `debug` option using a non-debug bundle.');
28+
});
2729
}
2830
}
2931
const hub = getCurrentHub();

packages/deno/src/transports/index.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { createTransport } from '@sentry/core';
22
import type { BaseTransportOptions, Transport, TransportMakeRequestResponse, TransportRequest } from '@sentry/types';
3-
import { rejectedSyncPromise } from '@sentry/utils';
3+
import { consoleSandbox, rejectedSyncPromise } from '@sentry/utils';
44

55
export interface DenoTransportOptions extends BaseTransportOptions {
66
/** Custom headers for the transport. Used by the XHRTransport and FetchTransport */
@@ -14,9 +14,11 @@ export function makeFetchTransport(options: DenoTransportOptions): Transport {
1414
const url = new URL(options.url);
1515

1616
if (Deno.permissions.querySync({ name: 'net', host: url.host }).state !== 'granted') {
17-
// eslint-disable-next-line no-console
18-
console.warn(`Sentry SDK requires 'net' permission to send events.
19-
Run with '--allow-net=${url.host}' to grant the requires permissions.`);
17+
consoleSandbox(() => {
18+
// eslint-disable-next-line no-console
19+
console.warn(`Sentry SDK requires 'net' permission to send events.
20+
Run with '--allow-net=${url.host}' to grant the requires permissions.`);
21+
});
2022
}
2123

2224
function makeRequest(request: TransportRequest): PromiseLike<TransportMakeRequestResponse> {

packages/integration-shims/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,8 @@
4343
"url": "https://github.com/getsentry/sentry-javascript/issues"
4444
},
4545
"dependencies": {
46-
"@sentry/types": "7.81.1"
46+
"@sentry/types": "7.81.1",
47+
"@sentry/utils": "7.81.1"
4748
},
4849
"engines": {
4950
"node": ">=12"

packages/integration-shims/src/BrowserTracing.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import type { Integration } from '@sentry/types';
2+
import { consoleSandbox } from '@sentry/utils';
23

34
/**
45
* This is a shim for the BrowserTracing integration.
@@ -20,8 +21,10 @@ class BrowserTracingShim implements Integration {
2021
public constructor(_options: any) {
2122
this.name = BrowserTracingShim.id;
2223

23-
// eslint-disable-next-line no-console
24-
console.error('You are using new BrowserTracing() even though this bundle does not include tracing.');
24+
consoleSandbox(() => {
25+
// eslint-disable-next-line no-console
26+
console.error('You are using new BrowserTracing() even though this bundle does not include tracing.');
27+
});
2528
}
2629

2730
/** jsdoc */

packages/integration-shims/src/Replay.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import type { Integration } from '@sentry/types';
2+
import { consoleSandbox } from '@sentry/utils';
23

34
/**
45
* This is a shim for the Replay integration.
@@ -20,8 +21,10 @@ class ReplayShim implements Integration {
2021
public constructor(_options: any) {
2122
this.name = ReplayShim.id;
2223

23-
// eslint-disable-next-line no-console
24-
console.error('You are using new Replay() even though this bundle does not include replay.');
24+
consoleSandbox(() => {
25+
// eslint-disable-next-line no-console
26+
console.error('You are using new Replay() even though this bundle does not include replay.');
27+
});
2528
}
2629

2730
/** jsdoc */

packages/nextjs/src/common/wrapApiHandlerWithSentry.ts

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,14 @@ import {
66
startTransaction,
77
} from '@sentry/core';
88
import type { Transaction } from '@sentry/types';
9-
import { isString, logger, objectify, stripUrlQueryAndFragment, tracingContextFromHeaders } from '@sentry/utils';
9+
import {
10+
consoleSandbox,
11+
isString,
12+
logger,
13+
objectify,
14+
stripUrlQueryAndFragment,
15+
tracingContextFromHeaders,
16+
} from '@sentry/utils';
1017

1118
import type { AugmentedNextApiRequest, AugmentedNextApiResponse, NextApiHandler } from './types';
1219
import { platformSupportsStreaming } from './utils/platformSupportsStreaming';
@@ -164,12 +171,14 @@ export function withSentry(apiHandler: NextApiHandler, parameterizedRoute?: stri
164171
// This can only happen (not always) when the user is using `withSentry` manually, which we're deprecating.
165172
// Warning suppression on Next.JS is only necessary in that case.
166173
) {
167-
// eslint-disable-next-line no-console
168-
console.warn(
169-
`[sentry] If Next.js logs a warning "API resolved without sending a response", it's a false positive, which may happen when you use \`withSentry\` manually to wrap your routes.
170-
To suppress this warning, set \`SENTRY_IGNORE_API_RESOLUTION_ERROR\` to 1 in your env.
171-
To suppress the nextjs warning, use the \`externalResolver\` API route option (see https://nextjs.org/docs/api-routes/api-middlewares#custom-config for details).`,
172-
);
174+
consoleSandbox(() => {
175+
// eslint-disable-next-line no-console
176+
console.warn(
177+
`[sentry] If Next.js logs a warning "API resolved without sending a response", it's a false positive, which may happen when you use \`withSentry\` manually to wrap your routes.
178+
To suppress this warning, set \`SENTRY_IGNORE_API_RESOLUTION_ERROR\` to 1 in your env.
179+
To suppress the nextjs warning, use the \`externalResolver\` API route option (see https://nextjs.org/docs/api-routes/api-middlewares#custom-config for details).`,
180+
);
181+
});
173182
}
174183

175184
return handlerResult;

packages/nextjs/src/config/webpack.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1070,7 +1070,7 @@ class SentryCliDownloadPlugin implements WebpackPluginInstance {
10701070
if (!downloadingCliAttempted) {
10711071
downloadingCliAttempted = true;
10721072
// eslint-disable-next-line no-console
1073-
console.log(
1073+
logger.info(
10741074
`\n${chalk.cyan('info')} - ${chalk.bold(
10751075
'Sentry binary to upload source maps not found.',
10761076
)} Package manager post-install scripts are likely disabled or there is a caching issue. Manually downloading instead...`,
@@ -1086,12 +1086,12 @@ class SentryCliDownloadPlugin implements WebpackPluginInstance {
10861086
cliDownloadPromise.then(
10871087
() => {
10881088
// eslint-disable-next-line no-console
1089-
console.log(`${chalk.cyan('info')} - Sentry binary was successfully downloaded.\n`);
1089+
logger.info(`${chalk.cyan('info')} - Sentry binary was successfully downloaded.\n`);
10901090
return callback();
10911091
},
10921092
e => {
10931093
// eslint-disable-next-line no-console
1094-
console.error(`${chalk.red('error')} - Sentry binary download failed:`, e);
1094+
logger.error(`${chalk.red('error')} - Sentry binary download failed:`, e);
10951095
return callback();
10961096
},
10971097
);

packages/node/src/integrations/utils/errorhandling.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { getClient } from '@sentry/core';
2-
import { logger } from '@sentry/utils';
2+
import { consoleSandbox, logger } from '@sentry/utils';
33

44
import type { NodeClient } from '../../client';
55

@@ -9,8 +9,10 @@ const DEFAULT_SHUTDOWN_TIMEOUT = 2000;
99
* @hidden
1010
*/
1111
export function logAndExitProcess(error: Error): void {
12-
// eslint-disable-next-line no-console
13-
console.error(error);
12+
consoleSandbox(() => {
13+
// eslint-disable-next-line no-console
14+
console.error(error);
15+
});
1416

1517
const client = getClient<NodeClient>();
1618

packages/node/src/transports/http.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import type {
66
TransportRequest,
77
TransportRequestExecutor,
88
} from '@sentry/types';
9+
import { consoleSandbox } from '@sentry/utils';
910
import * as http from 'http';
1011
import * as https from 'https';
1112
import { HttpsProxyAgent } from 'https-proxy-agent';
@@ -53,10 +54,12 @@ export function makeNodeTransport(options: NodeTransportOptions): Transport {
5354
try {
5455
urlSegments = new URL(options.url);
5556
} catch (e) {
56-
// eslint-disable-next-line no-console
57-
console.warn(
58-
'[@sentry/node]: Invalid dsn or tunnel option, will not send any events. The tunnel option must be a full URL when used.',
59-
);
57+
consoleSandbox(() => {
58+
// eslint-disable-next-line no-console
59+
console.warn(
60+
'[@sentry/node]: Invalid dsn or tunnel option, will not send any events. The tunnel option must be a full URL when used.',
61+
);
62+
});
6063
return createTransport(options, () => Promise.resolve({}));
6164
}
6265

0 commit comments

Comments
 (0)