From 4cd28fa10b16a41d9032ccdcd3020be216ee3740 Mon Sep 17 00:00:00 2001 From: Katie Byers Date: Mon, 13 Sep 2021 21:38:54 -0700 Subject: [PATCH 1/5] move node tracing integrations into node folder --- packages/tracing/src/integrations/index.ts | 8 ++++---- packages/tracing/src/integrations/{ => node}/express.ts | 0 packages/tracing/src/integrations/{ => node}/mongo.ts | 0 packages/tracing/src/integrations/{ => node}/mysql.ts | 0 packages/tracing/src/integrations/{ => node}/postgres.ts | 0 packages/tracing/test/integrations/mongo.test.ts | 2 +- packages/tracing/test/integrations/postgres.test.ts | 2 +- 7 files changed, 6 insertions(+), 6 deletions(-) rename packages/tracing/src/integrations/{ => node}/express.ts (100%) rename packages/tracing/src/integrations/{ => node}/mongo.ts (100%) rename packages/tracing/src/integrations/{ => node}/mysql.ts (100%) rename packages/tracing/src/integrations/{ => node}/postgres.ts (100%) diff --git a/packages/tracing/src/integrations/index.ts b/packages/tracing/src/integrations/index.ts index 5a9bd10b2d3c..4231abf350e6 100644 --- a/packages/tracing/src/integrations/index.ts +++ b/packages/tracing/src/integrations/index.ts @@ -1,4 +1,4 @@ -export { Express } from './express'; -export { Postgres } from './postgres'; -export { Mysql } from './mysql'; -export { Mongo } from './mongo'; +export { Express } from './node/express'; +export { Postgres } from './node/postgres'; +export { Mysql } from './node/mysql'; +export { Mongo } from './node/mongo'; diff --git a/packages/tracing/src/integrations/express.ts b/packages/tracing/src/integrations/node/express.ts similarity index 100% rename from packages/tracing/src/integrations/express.ts rename to packages/tracing/src/integrations/node/express.ts diff --git a/packages/tracing/src/integrations/mongo.ts b/packages/tracing/src/integrations/node/mongo.ts similarity index 100% rename from packages/tracing/src/integrations/mongo.ts rename to packages/tracing/src/integrations/node/mongo.ts diff --git a/packages/tracing/src/integrations/mysql.ts b/packages/tracing/src/integrations/node/mysql.ts similarity index 100% rename from packages/tracing/src/integrations/mysql.ts rename to packages/tracing/src/integrations/node/mysql.ts diff --git a/packages/tracing/src/integrations/postgres.ts b/packages/tracing/src/integrations/node/postgres.ts similarity index 100% rename from packages/tracing/src/integrations/postgres.ts rename to packages/tracing/src/integrations/node/postgres.ts diff --git a/packages/tracing/test/integrations/mongo.test.ts b/packages/tracing/test/integrations/mongo.test.ts index fa7b91ee681f..0d4473f53dad 100644 --- a/packages/tracing/test/integrations/mongo.test.ts +++ b/packages/tracing/test/integrations/mongo.test.ts @@ -1,7 +1,7 @@ /* eslint-disable @typescript-eslint/unbound-method */ import { Hub, Scope } from '@sentry/hub'; -import { Mongo } from '../../src/integrations/mongo'; +import { Mongo } from '../../src/integrations/node/mongo'; import { Span } from '../../src/span'; class Collection { diff --git a/packages/tracing/test/integrations/postgres.test.ts b/packages/tracing/test/integrations/postgres.test.ts index 98bb45357783..6aa5e5e5b63b 100644 --- a/packages/tracing/test/integrations/postgres.test.ts +++ b/packages/tracing/test/integrations/postgres.test.ts @@ -1,7 +1,7 @@ /* eslint-disable @typescript-eslint/unbound-method */ import { Hub, Scope } from '@sentry/hub'; -import { Postgres } from '../../src/integrations/postgres'; +import { Postgres } from '../../src/integrations/node/postgres'; import { Span } from '../../src/span'; class PgClient { From 045707b461243965d1448506b4d3d46583283dbc Mon Sep 17 00:00:00 2001 From: Katie Byers Date: Mon, 13 Sep 2021 21:39:18 -0700 Subject: [PATCH 2/5] add `resolve` to webpack config type --- packages/nextjs/src/config/types.ts | 3 +++ 1 file changed, 3 insertions(+) diff --git a/packages/nextjs/src/config/types.ts b/packages/nextjs/src/config/types.ts index b577268f41cb..89f2d3f57e33 100644 --- a/packages/nextjs/src/config/types.ts +++ b/packages/nextjs/src/config/types.ts @@ -42,6 +42,9 @@ export type WebpackConfigObject = { output: { filename: string; path: string }; target: string; context: string; + resolve?: { + alias?: { [key: string]: string | boolean }; + }; } & { // other webpack options [key: string]: unknown; From 5605133ae8cf6759e168d89f22f2a09837b88969 Mon Sep 17 00:00:00 2001 From: Katie Byers Date: Mon, 13 Sep 2021 21:39:59 -0700 Subject: [PATCH 3/5] exclude unneeded tracing files from bundles --- packages/nextjs/src/config/webpack.ts | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/packages/nextjs/src/config/webpack.ts b/packages/nextjs/src/config/webpack.ts index cc1ee7f2898e..6a1efaca3af7 100644 --- a/packages/nextjs/src/config/webpack.ts +++ b/packages/nextjs/src/config/webpack.ts @@ -60,6 +60,22 @@ export function constructWebpackConfigFunction( const origEntryProperty = newConfig.entry; newConfig.entry = async () => addSentryToEntryProperty(origEntryProperty, buildContext); + // In webpack 5, you can get webpack to replace any module you'd like with an empty object, just by setting its + // `resolve.alias` value to `false`. Not much of our code is neatly separated into "things node needs" and "things + // the browser needs," but where it is, we can save ~1.6 kb in eventual bundle size by excluding code we know we + // don't need. (Normally this would only matter for the client side, but because vercel turns backend code into + // serverless functions, it's worthwhile to do it for both.) + if (buildContext.webpack.version.startsWith('5')) { + const excludedTracingDir = buildContext.isServer ? 'browser' : 'integrations/node'; + newConfig.resolve = { + ...newConfig.resolve, + alias: { + ...newConfig.resolve?.alias, + [path.resolve(buildContext.dir, `./node_modules/@sentry/tracing/esm/${excludedTracingDir}`)]: false, + }, + }; + } + // Enable the Sentry plugin (which uploads source maps to Sentry when not in dev) by default const enableWebpackPlugin = buildContext.isServer ? !userNextConfig.sentry?.disableServerWebpackPlugin From 8cb10cd2a4d9eacd9688a58b557fc11a52c3c78d Mon Sep 17 00:00:00 2001 From: Katie Byers Date: Tue, 14 Sep 2021 09:51:31 -0700 Subject: [PATCH 4/5] move test files to match new module locations --- packages/tracing/test/integrations/{ => node}/mongo.test.ts | 4 ++-- .../tracing/test/integrations/{ => node}/postgres.test.ts | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) rename packages/tracing/test/integrations/{ => node}/mongo.test.ts (96%) rename packages/tracing/test/integrations/{ => node}/postgres.test.ts (96%) diff --git a/packages/tracing/test/integrations/mongo.test.ts b/packages/tracing/test/integrations/node/mongo.test.ts similarity index 96% rename from packages/tracing/test/integrations/mongo.test.ts rename to packages/tracing/test/integrations/node/mongo.test.ts index 0d4473f53dad..521e922b4f89 100644 --- a/packages/tracing/test/integrations/mongo.test.ts +++ b/packages/tracing/test/integrations/node/mongo.test.ts @@ -1,8 +1,8 @@ /* eslint-disable @typescript-eslint/unbound-method */ import { Hub, Scope } from '@sentry/hub'; -import { Mongo } from '../../src/integrations/node/mongo'; -import { Span } from '../../src/span'; +import { Mongo } from '../../../src/integrations/node/mongo'; +import { Span } from '../../../src/span'; class Collection { public collectionName: string = 'mockedCollectionName'; diff --git a/packages/tracing/test/integrations/postgres.test.ts b/packages/tracing/test/integrations/node/postgres.test.ts similarity index 96% rename from packages/tracing/test/integrations/postgres.test.ts rename to packages/tracing/test/integrations/node/postgres.test.ts index 6aa5e5e5b63b..d8c335f54d88 100644 --- a/packages/tracing/test/integrations/postgres.test.ts +++ b/packages/tracing/test/integrations/node/postgres.test.ts @@ -1,8 +1,8 @@ /* eslint-disable @typescript-eslint/unbound-method */ import { Hub, Scope } from '@sentry/hub'; -import { Postgres } from '../../src/integrations/node/postgres'; -import { Span } from '../../src/span'; +import { Postgres } from '../../../src/integrations/node/postgres'; +import { Span } from '../../../src/span'; class PgClient { // https://node-postgres.com/api/client#clientquery From 8652e867c66d9eb0fc11f045eae5ad4aecef815b Mon Sep 17 00:00:00 2001 From: Katie Byers Date: Tue, 14 Sep 2021 09:57:33 -0700 Subject: [PATCH 5/5] exclude dist versions, too --- packages/nextjs/src/config/webpack.ts | 2 ++ 1 file changed, 2 insertions(+) diff --git a/packages/nextjs/src/config/webpack.ts b/packages/nextjs/src/config/webpack.ts index 6a1efaca3af7..76dd5a8382da 100644 --- a/packages/nextjs/src/config/webpack.ts +++ b/packages/nextjs/src/config/webpack.ts @@ -72,6 +72,8 @@ export function constructWebpackConfigFunction( alias: { ...newConfig.resolve?.alias, [path.resolve(buildContext.dir, `./node_modules/@sentry/tracing/esm/${excludedTracingDir}`)]: false, + // TODO It's not clear if it will ever pull from `dist` (in testing it never does), so we may not need this. + [path.resolve(buildContext.dir, `./node_modules/@sentry/tracing/dist/${excludedTracingDir}`)]: false, }, }; }