Skip to content

Commit bd9ead6

Browse files
mydeaLms24
andauthored
feat(serverless): Do not include performance integrations by default (#11998)
In order to keep bundle size compact, performance integrations (except for http & fetch) have to be manually added for serverless packages. This means that users will have to do e.g. this if they want to have mysql instrumented: ```js import * as Sentry from '@sentry/aws-serverless'; Sentry.init({ integrations: [Sentry.mysqlIntegration()] }); ``` Closes #11991 --------- Co-authored-by: Lukas Stracke <[email protected]>
1 parent 7a01742 commit bd9ead6

File tree

6 files changed

+49
-15
lines changed

6 files changed

+49
-15
lines changed

dev-packages/e2e-tests/test-applications/node-exports-test-app/scripts/consistentExports.ts

+1
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ const NODE_EXPORTS_IGNORE = [
1616
'__esModule',
1717
// Only required from the Node package
1818
'setNodeAsyncContextStrategy',
19+
'getDefaultIntegrationsWithoutPerformance',
1920
];
2021

2122
const nodeExports = Object.keys(SentryNode).filter(e => !NODE_EXPORTS_IGNORE.includes(e));

packages/aws-serverless/src/awslambda-auto.ts

+14-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { getDefaultIntegrations as getNodeDefaultIntegrations } from '@sentry/node';
12
import { init, tryPatchHandler } from './sdk';
23

34
const lambdaTaskRoot = process.env.LAMBDA_TASK_ROOT;
@@ -7,7 +8,19 @@ if (lambdaTaskRoot) {
78
throw Error(`LAMBDA_TASK_ROOT is non-empty(${lambdaTaskRoot}) but _HANDLER is not set`);
89
}
910

10-
init();
11+
init({
12+
// We want to load the performance integrations here, if the tracesSampleRate is set for the layer in env vars
13+
// Sentry node's `getDefaultIntegrations` will load them if tracing is enabled,
14+
// which is the case if `tracesSampleRate` is set.
15+
// We can safely add all the node default integrations
16+
integrations: getNodeDefaultIntegrations(
17+
process.env.SENTRY_TRACES_SAMPLE_RATE
18+
? {
19+
tracesSampleRate: parseFloat(process.env.SENTRY_TRACES_SAMPLE_RATE),
20+
}
21+
: {},
22+
),
23+
});
1124

1225
tryPatchHandler(lambdaTaskRoot, handlerString);
1326
} else {

packages/aws-serverless/src/sdk.ts

+8-4
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import {
1010
continueTrace,
1111
flush,
1212
getCurrentScope,
13-
getDefaultIntegrations as getNodeDefaultIntegrations,
13+
getDefaultIntegrationsWithoutPerformance,
1414
init as initNode,
1515
startSpanManual,
1616
withScope,
@@ -60,9 +60,13 @@ export interface WrapperOptions {
6060
startTrace: boolean;
6161
}
6262

63-
/** Get the default integrations for the AWSLambda SDK. */
64-
export function getDefaultIntegrations(options: Options): Integration[] {
65-
return [...getNodeDefaultIntegrations(options), awsIntegration(), awsLambdaIntegration()];
63+
/**
64+
* Get the default integrations for the AWSLambda SDK.
65+
*/
66+
// NOTE: in awslambda-auto.ts, we also call the original `getDefaultIntegrations` from `@sentry/node` to load performance integrations.
67+
// If at some point we need to filter a node integration out for good, we need to make sure to also filter it out there.
68+
export function getDefaultIntegrations(_options: Options): Integration[] {
69+
return [...getDefaultIntegrationsWithoutPerformance(), awsIntegration(), awsLambdaIntegration()];
6670
}
6771

6872
/**

packages/google-cloud-serverless/src/sdk.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
import type { NodeOptions } from '@sentry/node';
2-
import { SDK_VERSION, getDefaultIntegrations as getDefaultNodeIntegrations, init as initNode } from '@sentry/node';
2+
import { SDK_VERSION, getDefaultIntegrationsWithoutPerformance, init as initNode } from '@sentry/node';
33
import type { Integration, Options, SdkMetadata } from '@sentry/types';
44

55
import { googleCloudGrpcIntegration } from './integrations/google-cloud-grpc';
66
import { googleCloudHttpIntegration } from './integrations/google-cloud-http';
77

88
/** Get the default integrations for the GCP SDK. */
9-
export function getDefaultIntegrations(options: Options): Integration[] {
9+
export function getDefaultIntegrations(_options: Options): Integration[] {
1010
return [
11-
...getDefaultNodeIntegrations(options),
11+
...getDefaultIntegrationsWithoutPerformance(),
1212
googleCloudHttpIntegration({ optional: true }), // We mark this integration optional since '@google-cloud/common' module could be missing.
1313
googleCloudGrpcIntegration({ optional: true }), // We mark this integration optional since 'google-gax' module could be missing.
1414
];

packages/node/src/index.ts

+5-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,11 @@ export { koaIntegration, setupKoaErrorHandler } from './integrations/tracing/koa
2626
export { connectIntegration, setupConnectErrorHandler } from './integrations/tracing/connect';
2727
export { spotlightIntegration } from './integrations/spotlight';
2828

29-
export { init, getDefaultIntegrations } from './sdk/init';
29+
export {
30+
init,
31+
getDefaultIntegrations,
32+
getDefaultIntegrationsWithoutPerformance,
33+
} from './sdk/init';
3034
export { initOpenTelemetry } from './sdk/initOtel';
3135
export { getAutoPerformanceIntegrations } from './integrations/tracing';
3236
export { getSentryRelease, defaultStackParser } from './sdk/api';

packages/node/src/sdk/init.ts

+18-6
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,10 @@ function getCjsOnlyIntegrations(): Integration[] {
4949
return isCjs() ? [modulesIntegration()] : [];
5050
}
5151

52-
/** Get the default integrations for the Node Experimental SDK. */
53-
export function getDefaultIntegrations(options: Options): Integration[] {
52+
/**
53+
* Get default integrations, excluding performance.
54+
*/
55+
export function getDefaultIntegrationsWithoutPerformance(): Integration[] {
5456
return [
5557
// Common
5658
inboundFiltersIntegration(),
@@ -69,6 +71,13 @@ export function getDefaultIntegrations(options: Options): Integration[] {
6971
localVariablesIntegration(),
7072
nodeContextIntegration(),
7173
...getCjsOnlyIntegrations(),
74+
];
75+
}
76+
77+
/** Get the default integrations for the Node SDK. */
78+
export function getDefaultIntegrations(options: Options): Integration[] {
79+
return [
80+
...getDefaultIntegrationsWithoutPerformance(),
7281
...(hasTracingEnabled(options) ? getAutoPerformanceIntegrations() : []),
7382
];
7483
}
@@ -183,10 +192,6 @@ function validateOpenTelemetrySetup(): void {
183192
}
184193

185194
function getClientOptions(options: NodeOptions): NodeClientOptions {
186-
if (options.defaultIntegrations === undefined) {
187-
options.defaultIntegrations = getDefaultIntegrations(options);
188-
}
189-
190195
const release = getRelease(options.release);
191196

192197
const autoSessionTracking =
@@ -210,6 +215,13 @@ function getClientOptions(options: NodeOptions): NodeClientOptions {
210215
tracesSampleRate,
211216
});
212217

218+
if (options.defaultIntegrations === undefined) {
219+
options.defaultIntegrations = getDefaultIntegrations({
220+
...options,
221+
...overwriteOptions,
222+
});
223+
}
224+
213225
const clientOptions: NodeClientOptions = {
214226
...baseOptions,
215227
...options,

0 commit comments

Comments
 (0)