Skip to content
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
6 changes: 2 additions & 4 deletions packages/core/src/hub.ts
Original file line number Diff line number Diff line change
Expand Up @@ -377,13 +377,11 @@ export class Hub implements HubInterface {
if (DEBUG_BUILD && !result) {
const client = this.getClient();
if (!client) {
// eslint-disable-next-line no-console
console.warn(
logger.warn(
"Tracing extension 'startTransaction' is missing. You should 'init' the SDK before calling 'startTransaction'",
);
} else {
// eslint-disable-next-line no-console
console.warn(`Tracing extension 'startTransaction' has not been added. Call 'addTracingExtensions' before calling 'init':
logger.warn(`Tracing extension 'startTransaction' has not been added. Call 'addTracingExtensions' before calling 'init':
Sentry.addTracingExtensions();
Sentry.init({...});
`);
Expand Down
8 changes: 5 additions & 3 deletions packages/core/src/sdk.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { Client, ClientOptions } from '@sentry/types';
import { logger } from '@sentry/utils';
import { consoleSandbox, logger } from '@sentry/utils';

import { DEBUG_BUILD } from './debug-build';
import { getCurrentHub } from './hub';
Expand All @@ -23,8 +23,10 @@ export function initAndBind<F extends Client, O extends ClientOptions>(
logger.enable();
} else {
// use `console.warn` rather than `logger.warn` since by non-debug bundles have all `logger.x` statements stripped
// eslint-disable-next-line no-console
console.warn('[Sentry] Cannot initialize SDK with `debug` option using a non-debug bundle.');
consoleSandbox(() => {
// eslint-disable-next-line no-console
console.warn('[Sentry] Cannot initialize SDK with `debug` option using a non-debug bundle.');
});
}
}
const hub = getCurrentHub();
Expand Down
10 changes: 6 additions & 4 deletions packages/deno/src/transports/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { createTransport } from '@sentry/core';
import type { BaseTransportOptions, Transport, TransportMakeRequestResponse, TransportRequest } from '@sentry/types';
import { rejectedSyncPromise } from '@sentry/utils';
import { consoleSandbox, rejectedSyncPromise } from '@sentry/utils';

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

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

function makeRequest(request: TransportRequest): PromiseLike<TransportMakeRequestResponse> {
Expand Down
3 changes: 2 additions & 1 deletion packages/integration-shims/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@
"url": "https://github.com/getsentry/sentry-javascript/issues"
},
"dependencies": {
"@sentry/types": "7.81.1"
"@sentry/types": "7.81.1",
"@sentry/utils": "7.81.1"
},
"engines": {
"node": ">=12"
Expand Down
7 changes: 5 additions & 2 deletions packages/integration-shims/src/BrowserTracing.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import type { Integration } from '@sentry/types';
import { consoleSandbox } from '@sentry/utils';

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

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

/** jsdoc */
Expand Down
7 changes: 5 additions & 2 deletions packages/integration-shims/src/Replay.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import type { Integration } from '@sentry/types';
import { consoleSandbox } from '@sentry/utils';

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

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

/** jsdoc */
Expand Down
23 changes: 16 additions & 7 deletions packages/nextjs/src/common/wrapApiHandlerWithSentry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,14 @@ import {
startTransaction,
} from '@sentry/core';
import type { Transaction } from '@sentry/types';
import { isString, logger, objectify, stripUrlQueryAndFragment, tracingContextFromHeaders } from '@sentry/utils';
import {
consoleSandbox,
isString,
logger,
objectify,
stripUrlQueryAndFragment,
tracingContextFromHeaders,
} from '@sentry/utils';

import { DEBUG_BUILD } from './debug-build';
import type { AugmentedNextApiRequest, AugmentedNextApiResponse, NextApiHandler } from './types';
Expand Down Expand Up @@ -165,12 +172,14 @@ export function withSentry(apiHandler: NextApiHandler, parameterizedRoute?: stri
// This can only happen (not always) when the user is using `withSentry` manually, which we're deprecating.
// Warning suppression on Next.JS is only necessary in that case.
) {
// eslint-disable-next-line no-console
console.warn(
`[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.
To suppress this warning, set \`SENTRY_IGNORE_API_RESOLUTION_ERROR\` to 1 in your env.
To suppress the nextjs warning, use the \`externalResolver\` API route option (see https://nextjs.org/docs/api-routes/api-middlewares#custom-config for details).`,
);
consoleSandbox(() => {
// eslint-disable-next-line no-console
console.warn(
`[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.
To suppress this warning, set \`SENTRY_IGNORE_API_RESOLUTION_ERROR\` to 1 in your env.
To suppress the nextjs warning, use the \`externalResolver\` API route option (see https://nextjs.org/docs/api-routes/api-middlewares#custom-config for details).`,
);
});
}

return handlerResult;
Expand Down
6 changes: 3 additions & 3 deletions packages/nextjs/src/config/webpack.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1071,7 +1071,7 @@ class SentryCliDownloadPlugin implements WebpackPluginInstance {
if (!downloadingCliAttempted) {
downloadingCliAttempted = true;
// eslint-disable-next-line no-console
console.log(
logger.info(
`\n${chalk.cyan('info')} - ${chalk.bold(
'Sentry binary to upload source maps not found.',
)} Package manager post-install scripts are likely disabled or there is a caching issue. Manually downloading instead...`,
Expand All @@ -1087,12 +1087,12 @@ class SentryCliDownloadPlugin implements WebpackPluginInstance {
cliDownloadPromise.then(
() => {
// eslint-disable-next-line no-console
console.log(`${chalk.cyan('info')} - Sentry binary was successfully downloaded.\n`);
logger.info(`${chalk.cyan('info')} - Sentry binary was successfully downloaded.\n`);
return callback();
},
e => {
// eslint-disable-next-line no-console
console.error(`${chalk.red('error')} - Sentry binary download failed:`, e);
logger.error(`${chalk.red('error')} - Sentry binary download failed:`, e);
return callback();
},
);
Expand Down
8 changes: 5 additions & 3 deletions packages/node/src/integrations/utils/errorhandling.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { getClient } from '@sentry/core';
import { logger } from '@sentry/utils';
import { consoleSandbox, logger } from '@sentry/utils';

import type { NodeClient } from '../../client';
import { DEBUG_BUILD } from '../../debug-build';
Expand All @@ -10,8 +10,10 @@ const DEFAULT_SHUTDOWN_TIMEOUT = 2000;
* @hidden
*/
export function logAndExitProcess(error: Error): void {
// eslint-disable-next-line no-console
console.error(error);
consoleSandbox(() => {
// eslint-disable-next-line no-console
console.error(error);
});

const client = getClient<NodeClient>();

Expand Down
11 changes: 7 additions & 4 deletions packages/node/src/transports/http.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import type {
TransportRequest,
TransportRequestExecutor,
} from '@sentry/types';
import { consoleSandbox } from '@sentry/utils';
import * as http from 'http';
import * as https from 'https';
import { HttpsProxyAgent } from 'https-proxy-agent';
Expand Down Expand Up @@ -53,10 +54,12 @@ export function makeNodeTransport(options: NodeTransportOptions): Transport {
try {
urlSegments = new URL(options.url);
} catch (e) {
// eslint-disable-next-line no-console
console.warn(
'[@sentry/node]: Invalid dsn or tunnel option, will not send any events. The tunnel option must be a full URL when used.',
);
consoleSandbox(() => {
// eslint-disable-next-line no-console
console.warn(
'[@sentry/node]: Invalid dsn or tunnel option, will not send any events. The tunnel option must be a full URL when used.',
);
});
return createTransport(options, () => Promise.resolve({}));
}

Expand Down
7 changes: 5 additions & 2 deletions packages/opentelemetry/src/custom/hubextensions.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { addTracingExtensions as _addTracingExtensions, getMainCarrier } from '@sentry/core';
import type { CustomSamplingContext, TransactionContext } from '@sentry/types';
import { consoleSandbox } from '@sentry/utils';

/**
* Add tracing extensions, ensuring a patched `startTransaction` to work with OTEL.
Expand All @@ -22,8 +23,10 @@ function startTransactionNoop(
_transactionContext: TransactionContext,
_customSamplingContext?: CustomSamplingContext,
): unknown {
// eslint-disable-next-line no-console
console.warn('startTransaction is a noop in @sentry/opentelemetry. Use `startSpan` instead.');
consoleSandbox(() => {
// eslint-disable-next-line no-console
console.warn('startTransaction is a noop in @sentry/opentelemetry. Use `startSpan` instead.');
});
// We return an object here as hub.ts checks for the result of this
// and renders a different warning if this is empty
return {};
Expand Down
2 changes: 1 addition & 1 deletion packages/remix/src/utils/instrumentServer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ export async function captureRemixServerException(err: unknown, name: string, re
// Skip capturing if the request is aborted as Remix docs suggest
// Ref: https://remix.run/docs/en/main/file-conventions/entry.server#handleerror
if (request.signal.aborted) {
__DEBUG_BUILD__ && logger.warn('Skipping capture of aborted request');
DEBUG_BUILD && logger.warn('Skipping capture of aborted request');
return;
}

Expand Down
18 changes: 11 additions & 7 deletions packages/replay/src/integration.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { getClient } from '@sentry/core';
import type { BrowserClientReplayOptions, Integration } from '@sentry/types';
import { dropUndefinedKeys, isBrowser } from '@sentry/utils';
import { consoleSandbox, dropUndefinedKeys, isBrowser } from '@sentry/utils';

import {
DEFAULT_FLUSH_MAX_DELAY,
Expand Down Expand Up @@ -349,8 +349,10 @@ function loadReplayOptionsFromClient(initialOptions: InitialReplayPluginOptions)
const finalOptions = { sessionSampleRate: 0, errorSampleRate: 0, ...dropUndefinedKeys(initialOptions) };

if (!opt) {
// eslint-disable-next-line no-console
console.warn('SDK client is not available.');
consoleSandbox(() => {
// eslint-disable-next-line no-console
console.warn('SDK client is not available.');
});
return finalOptions;
}

Expand All @@ -360,10 +362,12 @@ function loadReplayOptionsFromClient(initialOptions: InitialReplayPluginOptions)
opt.replaysSessionSampleRate == null &&
opt.replaysOnErrorSampleRate == null
) {
// eslint-disable-next-line no-console
console.warn(
'Replay is disabled because neither `replaysSessionSampleRate` nor `replaysOnErrorSampleRate` are set.',
);
consoleSandbox(() => {
// eslint-disable-next-line no-console
console.warn(
'Replay is disabled because neither `replaysSessionSampleRate` nor `replaysOnErrorSampleRate` are set.',
);
});
}

if (typeof opt.replaysSessionSampleRate === 'number') {
Expand Down
12 changes: 8 additions & 4 deletions packages/replay/src/util/getPrivacyOptions.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { consoleSandbox } from '@sentry/utils';

import type { DeprecatedPrivacyOptions, ReplayIntegrationPrivacyOptions } from '../types';

type GetPrivacyOptions = Required<Omit<ReplayIntegrationPrivacyOptions, 'maskFn'>> &
Expand Down Expand Up @@ -37,10 +39,12 @@ function getOption(
allSelectors.push(`.${deprecatedClassOption}`);
}

// eslint-disable-next-line no-console
console.warn(
'[Replay] You are using a deprecated configuration item for privacy. Read the documentation on how to use the new privacy configuration.',
);
consoleSandbox(() => {
// eslint-disable-next-line no-console
console.warn(
'[Replay] You are using a deprecated configuration item for privacy. Read the documentation on how to use the new privacy configuration.',
);
});
}

return allSelectors.join(',');
Expand Down
7 changes: 5 additions & 2 deletions packages/sveltekit/src/client/handleError.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { captureException } from '@sentry/svelte';
import { consoleSandbox } from '@sentry/utils';
// For now disable the import/no-unresolved rule, because we don't have a way to
// tell eslint that we are only importing types from the @sveltejs/kit package without
// adding a custom resolver, which will take too much time.
Expand All @@ -8,8 +9,10 @@ import type { HandleClientError, NavigationEvent } from '@sveltejs/kit';
// The SvelteKit default error handler just logs the error to the console
// see: https://github.com/sveltejs/kit/blob/369e7d6851f543a40c947e033bfc4a9506fdc0a8/packages/kit/src/core/sync/write_client_manifest.js#LL127C2-L127C2
function defaultErrorHandler({ error }: Parameters<HandleClientError>[0]): ReturnType<HandleClientError> {
// eslint-disable-next-line no-console
console.error(error);
consoleSandbox(() => {
// eslint-disable-next-line no-console
console.error(error);
});
}

/**
Expand Down
8 changes: 5 additions & 3 deletions packages/utils/src/dsn.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import type { DsnComponents, DsnLike, DsnProtocol } from '@sentry/types';

import { DEBUG_BUILD } from './debug-build';
import { logger } from './logger';
import { consoleSandbox, logger } from './logger';

/** Regular expression used to parse a Dsn. */
const DSN_REGEX = /^(?:(\w+):)\/\/(?:(\w+)(?::(\w+)?)?@)([\w.-]+)(?::(\d+))?\/(.+)/;
Expand Down Expand Up @@ -38,8 +38,10 @@ export function dsnFromString(str: string): DsnComponents | undefined {

if (!match) {
// This should be logged to the console
// eslint-disable-next-line no-console
console.error(`Invalid Sentry Dsn: ${str}`);
consoleSandbox(() => {
// eslint-disable-next-line no-console
console.error(`Invalid Sentry Dsn: ${str}`);
});
return undefined;
}

Expand Down
7 changes: 5 additions & 2 deletions packages/vue/src/errorhandler.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { getCurrentHub } from '@sentry/browser';
import { consoleSandbox } from '@sentry/utils';

import type { ViewModel, Vue, VueOptions } from './types';
import { formatComponentName, generateComponentTrace } from './vendor/components';
Expand Down Expand Up @@ -46,8 +47,10 @@ export const attachErrorHandler = (app: Vue, options: VueOptions): void => {
if (warnHandler) {
(warnHandler as UnknownFunc).call(null, message, vm, trace);
} else if (hasConsole && !silent) {
// eslint-disable-next-line no-console
console.error(`[Vue warn]: ${message}${trace}`);
consoleSandbox(() => {
// eslint-disable-next-line no-console
console.error(`[Vue warn]: ${message}${trace}`);
});
}
}
};
Expand Down
Loading