Skip to content

Commit 01de9e5

Browse files
authored
feat: Add Sentry to the bundler plugins (#224)
1 parent 0542128 commit 01de9e5

File tree

74 files changed

+1718
-142
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

74 files changed

+1718
-142
lines changed

.changeset/green-goats-thank.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
---
2+
"@codecov/nextjs-webpack-plugin": minor
3+
"@codecov/bundler-plugin-core": minor
4+
"@codecov/remix-vite-plugin": minor
5+
"@codecov/solidstart-plugin": minor
6+
"@codecov/sveltekit-plugin": minor
7+
"@codecov/webpack-plugin": minor
8+
"@codecov/rollup-plugin": minor
9+
"@codecov/astro-plugin": minor
10+
"@codecov/nuxt-plugin": minor
11+
"@codecov/vite-plugin": minor
12+
"@codecov/bundle-analyzer": minor
13+
---
14+
15+
Add Sentry to the bundler plugins to start collecting issues and telemetry

.changeset/wise-toys-hug.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
---
2+
"@codecov/nextjs-webpack-plugin": patch
3+
"@codecov/bundler-plugin-core": patch
4+
"@codecov/remix-vite-plugin": patch
5+
"@codecov/solidstart-plugin": patch
6+
"@codecov/sveltekit-plugin": patch
7+
"@codecov/webpack-plugin": patch
8+
"@codecov/rollup-plugin": patch
9+
"@codecov/astro-plugin": patch
10+
"@codecov/nuxt-plugin": patch
11+
"@codecov/vite-plugin": patch
12+
---
13+
14+
Fix issue not using the correct webpack in the nextjs plugin

integration-tests/fixtures/generate-bundle-stats/astro/astro-base.config.mjs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ export default defineConfig({
2626
bundleName: "test-astro-v4",
2727
uploadToken: "test-token",
2828
apiUrl: process.env.API_URL,
29+
telemetry: false,
2930
}),
3031
],
3132
});

integration-tests/fixtures/generate-bundle-stats/nextjs/next-base.config.mjs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ export default {
1010
uploadToken: "test-token",
1111
apiUrl: process.env.API_URL,
1212
webpack: options.webpack,
13+
telemetry: false,
1314
debug: true,
1415
}),
1516
);

integration-tests/fixtures/generate-bundle-stats/nuxt/nuxt-base.config.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ const config: ReturnType<typeof defineNuxtConfig> = defineNuxtConfig({
1111
bundleName: "test-nuxt-v3",
1212
uploadToken: "test-token",
1313
apiUrl: process.env.API_URL,
14+
telemetry: false,
1415
},
1516
],
1617
],

integration-tests/fixtures/generate-bundle-stats/remix/vite-base.config.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ export default defineConfig({
2626
bundleName: "test-remix-v2",
2727
uploadToken: "test-token",
2828
apiUrl: process.env.API_URL,
29+
telemetry: false,
2930
}),
3031
],
3132
});

integration-tests/fixtures/generate-bundle-stats/rollup/rollup-base.config.cjs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ module.exports = defineConfig({
2222
bundleName: "test-rollup-v3",
2323
uploadToken: "test-token",
2424
apiUrl: process.env.API_URL,
25+
telemetry: false,
2526
}),
2627
],
2728
});

integration-tests/fixtures/generate-bundle-stats/solidstart/app-base.config.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ export default defineConfig({
2222
bundleName: "test-solidstart-v1",
2323
uploadToken: "test-token",
2424
apiUrl: process.env.API_URL,
25+
telemetry: false,
2526
// eslint-disable-next-line @typescript-eslint/no-explicit-any
2627
}) as any,
2728
],

integration-tests/fixtures/generate-bundle-stats/sveltekit/vite-base.config.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ export default defineConfig({
2222
bundleName: "test-sveltekit-v2",
2323
uploadToken: "test-token",
2424
apiUrl: process.env.API_URL,
25+
telemetry: false,
2526
}),
2627
],
2728
});

integration-tests/fixtures/generate-bundle-stats/vite/vite-base.config.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ export default defineConfig({
2424
bundleName: "test-vite-v5",
2525
uploadToken: "test-token",
2626
apiUrl: process.env.API_URL,
27+
telemetry: false,
2728
}),
2829
],
2930
});

integration-tests/fixtures/generate-bundle-stats/webpack/webpack-base.config.cjs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ module.exports = {
1919
bundleName: "test-webpack-v5",
2020
uploadToken: "test-token",
2121
apiUrl: process.env.API_URL,
22+
telemetry: false,
2223
}),
2324
],
2425
};

packages/astro-plugin/src/astro-bundle-analysis/__tests__/astroBundleAnalysisPlugin.test.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,11 @@ import { Output } from "@codecov/bundler-plugin-core";
22
import { describe, it, expect } from "vitest";
33
import { astroBundleAnalysisPlugin } from "../astroBundleAnalysisPlugin";
44

5+
// @ts-expect-error this value is being replaced by rollup
6+
const PLUGIN_NAME = __PACKAGE_NAME__ as string;
7+
// @ts-expect-error this value is being replaced by rollup
8+
const PLUGIN_VERSION = __PACKAGE_VERSION__ as string;
9+
510
describe("astroBundleAnalysisPlugin", () => {
611
describe("when called", () => {
712
it("returns a plugin object", () => {
@@ -15,7 +20,10 @@ describe("astroBundleAnalysisPlugin", () => {
1520
enableBundleAnalysis: true,
1621
retryCount: 1,
1722
uploadToken: "test-token",
23+
telemetry: false,
1824
}),
25+
pluginName: PLUGIN_NAME,
26+
pluginVersion: PLUGIN_VERSION,
1927
});
2028

2129
expect(plugin).toMatchSnapshot();

packages/astro-plugin/src/astro-bundle-analysis/astroBundleAnalysisPlugin.ts

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,6 @@ import {
55
} from "@codecov/bundler-plugin-core";
66
import { getBundleName } from "./getBundleName";
77

8-
// @ts-expect-error this value is being replaced by rollup
9-
const PLUGIN_NAME = __PACKAGE_NAME__ as string;
10-
// @ts-expect-error this value is being replaced by rollup
11-
const PLUGIN_VERSION = __PACKAGE_VERSION__ as string;
12-
138
interface AstroBundleAnalysisArgs extends BundleAnalysisUploadPluginArgs {
149
target: "client" | "server";
1510
}
@@ -21,10 +16,12 @@ type AstroBundleAnalysisPlugin = (
2116
export const astroBundleAnalysisPlugin: AstroBundleAnalysisPlugin = ({
2217
output,
2318
target,
19+
pluginName,
20+
pluginVersion,
2421
}) => ({
2522
version: output.version,
26-
name: PLUGIN_NAME,
27-
pluginVersion: PLUGIN_VERSION,
23+
name: pluginName,
24+
pluginVersion,
2825
vite: {
2926
generateBundle(this, options) {
3027
// TODO - remove this once we hard fail on not having a bundle name
@@ -46,7 +43,7 @@ export const astroBundleAnalysisPlugin: AstroBundleAnalysisPlugin = ({
4643
output.lockBundleName();
4744

4845
// manually set this to avoid resetting in the vite plugin
49-
output.setPlugin(PLUGIN_NAME, PLUGIN_VERSION);
46+
output.setPlugin(pluginName, pluginVersion);
5047
},
5148
},
5249
});

packages/astro-plugin/src/index.ts

Lines changed: 31 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,19 @@ import {
55
checkNodeVersion,
66
Output,
77
handleErrors,
8+
createSentryInstance,
9+
telemetryPlugin,
810
} from "@codecov/bundler-plugin-core";
911
import { _internal_viteBundleAnalysisPlugin } from "@codecov/vite-plugin";
1012
import { type AstroIntegration } from "astro";
1113
import { type PluginOption } from "vite";
1214

1315
import { astroBundleAnalysisPlugin } from "./astro-bundle-analysis/astroBundleAnalysisPlugin";
1416

15-
// @ts-expect-error - This is a placeholder for the package name.
17+
// @ts-expect-error this value is being replaced by rollup
1618
const PLUGIN_NAME = __PACKAGE_NAME__ as string;
19+
// @ts-expect-error this value is being replaced by rollup
20+
const PLUGIN_VERSION = __PACKAGE_VERSION__ as string;
1721

1822
interface AstroPluginFactoryOptions extends Options {
1923
// type can be found from the AstroIntegration type
@@ -37,12 +41,35 @@ const astroPluginFactory = createVitePlugin<AstroPluginFactoryOptions, true>(
3741
}
3842

3943
const plugins: UnpluginOptions[] = [];
40-
const output = new Output(normalizedOptions.options);
4144
const options = normalizedOptions.options;
45+
const sentryConfig = createSentryInstance({
46+
telemetry: options.telemetry,
47+
isDryRun: options.dryRun,
48+
pluginName: PLUGIN_NAME,
49+
pluginVersion: PLUGIN_VERSION,
50+
options,
51+
bundler: unpluginMetaContext.framework,
52+
metaFramework: "astro",
53+
});
54+
const output = new Output(options, sentryConfig);
4255
if (options.enableBundleAnalysis) {
4356
plugins.push(
44-
astroBundleAnalysisPlugin({ output, target }),
45-
_internal_viteBundleAnalysisPlugin({ output }),
57+
telemetryPlugin({
58+
sentryClient: sentryConfig.sentryClient,
59+
sentryScope: sentryConfig.sentryScope,
60+
telemetry: options.telemetry,
61+
}),
62+
astroBundleAnalysisPlugin({
63+
output,
64+
target,
65+
pluginName: PLUGIN_NAME,
66+
pluginVersion: PLUGIN_VERSION,
67+
}),
68+
_internal_viteBundleAnalysisPlugin({
69+
output,
70+
pluginName: PLUGIN_NAME,
71+
pluginVersion: PLUGIN_VERSION,
72+
}),
4673
);
4774
}
4875

packages/bundler-plugin-core/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
"dependencies": {
4242
"@actions/core": "^1.10.1",
4343
"@actions/github": "^6.0.0",
44+
"@sentry/core": "^8.42.0",
4445
"chalk": "4.1.2",
4546
"semver": "^7.5.4",
4647
"unplugin": "^1.10.1",

packages/bundler-plugin-core/src/index.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { type Client, type Scope } from "@sentry/core";
12
import {
23
type Asset,
34
type BundleAnalysisUploadPlugin,
@@ -22,6 +23,12 @@ import {
2223
Output,
2324
red,
2425
} from "./utils";
26+
import {
27+
createSentryInstance,
28+
telemetryPlugin,
29+
safeFlushTelemetry,
30+
setTelemetryDataOnScope,
31+
} from "./sentry/telemetry.ts";
2532

2633
export type {
2734
Asset,
@@ -36,6 +43,8 @@ export type {
3643
NormalizedOptions,
3744
ProviderUtilInputs,
3845
UploadOverrides,
46+
Client as SentryClient,
47+
Scope as SentryScope,
3948
};
4049

4150
export {
@@ -47,4 +56,8 @@ export {
4756
normalizePath,
4857
Output,
4958
red,
59+
createSentryInstance,
60+
telemetryPlugin,
61+
safeFlushTelemetry,
62+
setTelemetryDataOnScope,
5063
};

0 commit comments

Comments
 (0)