Skip to content

Commit ce18641

Browse files
committed
feat(core): Allow to configure disableIntegrations to opt-out
This new top-level config allows to opt-out of any added integration, ensuring it is not actually added. This is mainly designed to opt-out of default integrations, but will also apply to any manually added integration. There are type hints that should help with usage there, but any key is allowed to keep this flexible. Type hints are manually configured (could not find a way to infer this from integrations, as the names are not statically exposed there...) for now. Usage: ```js Sentry.init({ disableIntegrations: { BrowserSession: true, InboundFilters: false } }); ``` Will disable the browserSessionIntegration but not the inboundFilters one.
1 parent 3e7ac9a commit ce18641

File tree

23 files changed

+226
-25
lines changed

23 files changed

+226
-25
lines changed

packages/aws-serverless/src/sdk.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ export function getDefaultIntegrations(_options: Options): Integration[] {
7171
*
7272
* @param options Configuration options for the SDK, @see {@link AWSLambdaOptions}.
7373
*/
74-
export function init(options: NodeOptions = {}): NodeClient | undefined {
74+
export function init(options: NodeOptions<['Aws', 'AwsLambda']> = {}): NodeClient | undefined {
7575
const opts = {
7676
_metadata: {} as SdkMetadata,
7777
defaultIntegrations: getDefaultIntegrations(options),

packages/browser/src/client.ts

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,22 @@ import type { BrowserTransportOptions } from './transports/types';
2424
* Configuration options for the Sentry Browser SDK.
2525
* @see @sentry/core Options for more information.
2626
*/
27-
export type BrowserOptions = Options<BrowserTransportOptions> &
27+
export type BrowserOptions<AdditionalDefaultIntegrations extends string[] = []> = Options<
28+
BrowserTransportOptions,
29+
[
30+
'InboundFilters',
31+
'FunctionToString',
32+
'BrowserApiErrors',
33+
'Breadcrumbs',
34+
'GlobalHandlers',
35+
'LinkedErrors',
36+
'Dedupe',
37+
'HttpContext',
38+
'BrowserSession',
39+
'BrowserTracing',
40+
...AdditionalDefaultIntegrations,
41+
]
42+
> &
2843
BrowserClientReplayOptions &
2944
BrowserClientProfilingOptions & {
3045
/**

packages/browser/src/sdk.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ export function getDefaultIntegrations(_options: Options): Integration[] {
3232
/**
3333
* Note: Please make sure this stays in sync with Angular SDK, which re-exports
3434
* `getDefaultIntegrations` but with an adjusted set of integrations.
35+
*
36+
* Ensure to keep this in sync with `BrowserOptions`!
3537
*/
3638
return [
3739
inboundFiltersIntegration(),

packages/bun/src/sdk.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,10 @@ import { bunServerIntegration } from './integrations/bunserver';
2323
import { makeFetchTransport } from './transports';
2424
import type { BunOptions } from './types';
2525

26-
/** Get the default integrations for the Bun SDK. */
26+
/**
27+
* Get the default integrations for the Bun SDK.
28+
* Ensure to keep this in sync with `BunOptions`!
29+
*/
2730
export function getDefaultIntegrations(_options: Options): Integration[] {
2831
// We return a copy of the defaultIntegrations here to avoid mutating this
2932
return [

packages/bun/src/types.ts

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,26 @@ export interface BaseBunOptions {
4141
* Configuration options for the Sentry Bun SDK
4242
* @see @sentry/core Options for more information.
4343
*/
44-
export interface BunOptions extends Options<BunTransportOptions>, BaseBunOptions {}
44+
export interface BunOptions
45+
extends Options<
46+
BunTransportOptions,
47+
[
48+
'InboundFilters',
49+
'FunctionToString',
50+
'LinkedErrors',
51+
'RequestData',
52+
'Console',
53+
'Http',
54+
'NodeFetch',
55+
'OnUncaughtException',
56+
'OnUnhandledRejection',
57+
'ContextLines',
58+
'Context',
59+
'Modules',
60+
'BunServer',
61+
]
62+
>,
63+
BaseBunOptions {}
4564

4665
/**
4766
* Configuration options for the Sentry Bun SDK Client class

packages/cloudflare/src/client.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,12 @@ interface BaseCloudflareOptions {}
3737
*
3838
* @see @sentry/core Options for more information.
3939
*/
40-
export interface CloudflareOptions extends Options<CloudflareTransportOptions>, BaseCloudflareOptions {}
40+
export interface CloudflareOptions
41+
extends Options<
42+
CloudflareTransportOptions,
43+
['Dedupe', 'InboundFilters', 'FunctionToString', 'LinkedErrors', 'Fetch', 'RequestData']
44+
>,
45+
BaseCloudflareOptions {}
4146

4247
/**
4348
* Configuration options for the Sentry Cloudflare SDK Client class

packages/cloudflare/src/sdk.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,10 @@ import { fetchIntegration } from './integrations/fetch';
1515
import { makeCloudflareTransport } from './transport';
1616
import { defaultStackParser } from './vendor/stacktrace';
1717

18-
/** Get the default integrations for the Cloudflare SDK. */
18+
/**
19+
* Get the default integrations for the Cloudflare SDK.
20+
* Ensure to keep this in sync with `CloudflareOptions`!
21+
*/
1922
export function getDefaultIntegrations(options: CloudflareOptions): Integration[] {
2023
const sendDefaultPii = options.sendDefaultPii ?? false;
2124
return [

packages/core/src/integration.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,12 @@ function filterDuplicates(integrations: Integration[]): Integration[] {
4040
}
4141

4242
/** Gets integrations to install */
43-
export function getIntegrationsToSetup(options: Pick<Options, 'defaultIntegrations' | 'integrations'>): Integration[] {
43+
export function getIntegrationsToSetup(
44+
options: Pick<Options, 'defaultIntegrations' | 'integrations' | 'disableIntegrations'>,
45+
): Integration[] {
4446
const defaultIntegrations = options.defaultIntegrations || [];
4547
const userIntegrations = options.integrations;
48+
const disableIntegrations = options.disableIntegrations || {};
4649

4750
// We flag default instances, so that later we can tell them apart from any user-created instances of the same class
4851
defaultIntegrations.forEach((integration: IntegrationWithDefaultInstance) => {
@@ -60,6 +63,9 @@ export function getIntegrationsToSetup(options: Pick<Options, 'defaultIntegratio
6063
integrations = defaultIntegrations;
6164
}
6265

66+
// Remove disabled integrations
67+
integrations = integrations.filter(integration => !disableIntegrations[integration.name]);
68+
6369
return filterDuplicates(integrations);
6470
}
6571

packages/core/src/types-hoist/integration.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,3 +48,10 @@ export interface Integration {
4848
* This is expected to return an integration.
4949
*/
5050
export type IntegrationFn<IntegrationType = Integration> = (...rest: any[]) => IntegrationType;
51+
52+
/**
53+
* A map of integration names to true/false.
54+
*/
55+
export type IntegrationsMapping<KnownIntegrationNames extends string[] = []> = Record<string, boolean | undefined> & {
56+
[key in KnownIntegrationNames[number]]?: boolean | undefined;
57+
};

packages/core/src/types-hoist/options.ts

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import type { CaptureContext } from '../scope';
22
import type { Breadcrumb, BreadcrumbHint } from './breadcrumb';
33
import type { ErrorEvent, EventHint, TransactionEvent } from './event';
4-
import type { Integration } from './integration';
4+
import type { Integration, IntegrationsMapping } from './integration';
55
import type { TracesSamplerSamplingContext } from './samplingcontext';
66
import type { SdkMetadata } from './sdkmetadata';
77
import type { SpanJSON } from './span';
@@ -302,14 +302,27 @@ export interface ClientOptions<TO extends BaseTransportOptions = BaseTransportOp
302302
}
303303

304304
/** Base configuration options for every SDK. */
305-
export interface Options<TO extends BaseTransportOptions = BaseTransportOptions>
306-
extends Omit<Partial<ClientOptions<TO>>, 'integrations' | 'transport' | 'stackParser'> {
305+
export interface Options<
306+
TO extends BaseTransportOptions = BaseTransportOptions,
307+
DefaultIntegrationNames extends string[] = [],
308+
> extends Omit<Partial<ClientOptions<TO>>, 'integrations' | 'transport' | 'stackParser'> {
307309
/**
308310
* If this is set to false, default integrations will not be added, otherwise this will internally be set to the
309311
* recommended default integrations.
310312
*/
311313
defaultIntegrations?: false | Integration[];
312314

315+
/**
316+
* Pass a map of integrations that should be explicitly disabled.
317+
* This allows you to e.g. opt out of default integrations easily.
318+
* For example, if you do not want to add the `inboundFiltersIntegration`, you can configure:
319+
*
320+
* ```js
321+
* disableIntegrations: { InboundFilters: true }
322+
* ```
323+
*/
324+
disableIntegrations?: IntegrationsMapping<DefaultIntegrationNames>;
325+
313326
/**
314327
* List of integrations that should be installed after SDK was initialized.
315328
* Accepts either a list of integrations or a function that receives

0 commit comments

Comments
 (0)