Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add Sentry to the bundler plugins #224

Open
wants to merge 12 commits into
base: main
Choose a base branch
from
15 changes: 15 additions & 0 deletions .changeset/green-goats-thank.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
---
"@codecov/nextjs-webpack-plugin": minor
"@codecov/bundler-plugin-core": minor
"@codecov/remix-vite-plugin": minor
"@codecov/solidstart-plugin": minor
"@codecov/sveltekit-plugin": minor
"@codecov/webpack-plugin": minor
"@codecov/rollup-plugin": minor
"@codecov/astro-plugin": minor
"@codecov/nuxt-plugin": minor
"@codecov/vite-plugin": minor
"@codecov/bundle-analyzer": minor
---

Add Sentry to the bundler plugins to start collecting issues and telemerty
14 changes: 14 additions & 0 deletions .changeset/wise-toys-hug.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
---
"@codecov/nextjs-webpack-plugin": patch
"@codecov/bundler-plugin-core": patch
"@codecov/remix-vite-plugin": patch
"@codecov/solidstart-plugin": patch
"@codecov/sveltekit-plugin": patch
"@codecov/webpack-plugin": patch
"@codecov/rollup-plugin": patch
"@codecov/astro-plugin": patch
"@codecov/nuxt-plugin": patch
"@codecov/vite-plugin": patch
---

Fix issue not using the correct webpack in the nextjs plugin
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ export default defineConfig({
bundleName: "test-astro-v4",
uploadToken: "test-token",
apiUrl: process.env.API_URL,
telemetry: false,
}),
],
});
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ export default {
uploadToken: "test-token",
apiUrl: process.env.API_URL,
webpack: options.webpack,
telemetry: false,
debug: true,
}),
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ const config: ReturnType<typeof defineNuxtConfig> = defineNuxtConfig({
bundleName: "test-nuxt-v3",
uploadToken: "test-token",
apiUrl: process.env.API_URL,
telemetry: false,
},
],
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ export default defineConfig({
bundleName: "test-remix-v2",
uploadToken: "test-token",
apiUrl: process.env.API_URL,
telemetry: false,
}),
],
});
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ module.exports = defineConfig({
bundleName: "test-rollup-v3",
uploadToken: "test-token",
apiUrl: process.env.API_URL,
telemetry: false,
}),
],
});
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ export default defineConfig({
bundleName: "test-solidstart-v1",
uploadToken: "test-token",
apiUrl: process.env.API_URL,
telemetry: false,
// eslint-disable-next-line @typescript-eslint/no-explicit-any
}) as any,
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ export default defineConfig({
bundleName: "test-sveltekit-v2",
uploadToken: "test-token",
apiUrl: process.env.API_URL,
telemetry: false,
}),
],
});
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ export default defineConfig({
bundleName: "test-vite-v5",
uploadToken: "test-token",
apiUrl: process.env.API_URL,
telemetry: false,
}),
],
});
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ module.exports = {
bundleName: "test-webpack-v5",
uploadToken: "test-token",
apiUrl: process.env.API_URL,
telemetry: false,
}),
],
};
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@ import { Output } from "@codecov/bundler-plugin-core";
import { describe, it, expect } from "vitest";
import { astroBundleAnalysisPlugin } from "../astroBundleAnalysisPlugin";

// @ts-expect-error this value is being replaced by rollup
const PLUGIN_NAME = __PACKAGE_NAME__ as string;
// @ts-expect-error this value is being replaced by rollup
const PLUGIN_VERSION = __PACKAGE_VERSION__ as string;

describe("astroBundleAnalysisPlugin", () => {
describe("when called", () => {
it("returns a plugin object", () => {
Expand All @@ -15,7 +20,10 @@ describe("astroBundleAnalysisPlugin", () => {
enableBundleAnalysis: true,
retryCount: 1,
uploadToken: "test-token",
telemetry: false,
}),
pluginName: PLUGIN_NAME,
pluginVersion: PLUGIN_VERSION,
});

expect(plugin).toMatchSnapshot();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,6 @@
} from "@codecov/bundler-plugin-core";
import { getBundleName } from "./getBundleName";

// @ts-expect-error this value is being replaced by rollup
const PLUGIN_NAME = __PACKAGE_NAME__ as string;
// @ts-expect-error this value is being replaced by rollup
const PLUGIN_VERSION = __PACKAGE_VERSION__ as string;

interface AstroBundleAnalysisArgs extends BundleAnalysisUploadPluginArgs {
target: "client" | "server";
}
Expand All @@ -21,10 +16,12 @@
export const astroBundleAnalysisPlugin: AstroBundleAnalysisPlugin = ({
output,
target,
pluginName,
pluginVersion,
}) => ({
version: output.version,
name: PLUGIN_NAME,
pluginVersion: PLUGIN_VERSION,
name: pluginName,
pluginVersion,
vite: {
generateBundle(this, options) {
// TODO - remove this once we hard fail on not having a bundle name
Expand All @@ -46,7 +43,7 @@
output.lockBundleName();

// manually set this to avoid resetting in the vite plugin
output.setPlugin(PLUGIN_NAME, PLUGIN_VERSION);
output.setPlugin(pluginName, pluginVersion);

Check warning on line 46 in packages/astro-plugin/src/astro-bundle-analysis/astroBundleAnalysisPlugin.ts

View check run for this annotation

Codecov Notifications / codecov/patch

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

Added line #L46 was not covered by tests
},
},
});
36 changes: 32 additions & 4 deletions packages/astro-plugin/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,19 @@
checkNodeVersion,
Output,
handleErrors,
createSentryInstance,
telemetryPlugin,

Check warning on line 9 in packages/astro-plugin/src/index.ts

View check run for this annotation

Codecov Notifications / codecov/patch

packages/astro-plugin/src/index.ts#L8-L9

Added lines #L8 - L9 were not covered by tests
} from "@codecov/bundler-plugin-core";
import { _internal_viteBundleAnalysisPlugin } from "@codecov/vite-plugin";
import { type AstroIntegration } from "astro";
import { type PluginOption } from "vite";

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

// @ts-expect-error - This is a placeholder for the package name.
// @ts-expect-error this value is being replaced by rollup

Check warning on line 17 in packages/astro-plugin/src/index.ts

View check run for this annotation

Codecov Notifications / codecov/patch

packages/astro-plugin/src/index.ts#L17

Added line #L17 was not covered by tests
const PLUGIN_NAME = __PACKAGE_NAME__ as string;
// @ts-expect-error this value is being replaced by rollup
const PLUGIN_VERSION = __PACKAGE_VERSION__ as string;

Check warning on line 20 in packages/astro-plugin/src/index.ts

View check run for this annotation

Codecov Notifications / codecov/patch

packages/astro-plugin/src/index.ts#L19-L20

Added lines #L19 - L20 were not covered by tests

interface AstroPluginFactoryOptions extends Options {
// type can be found from the AstroIntegration type
Expand All @@ -37,12 +41,36 @@
}

const plugins: UnpluginOptions[] = [];
const output = new Output(normalizedOptions.options);
const options = normalizedOptions.options;
const output = new Output(options);
const sentryConfig = createSentryInstance({
enableTelemetry: options.telemetry,
isDryRun: options.dryRun,
pluginName: PLUGIN_NAME,
pluginVersion: PLUGIN_VERSION,
options,
bundler: unpluginMetaContext.framework,
metaFramework: "astro",
});

Check warning on line 55 in packages/astro-plugin/src/index.ts

View check run for this annotation

Codecov Notifications / codecov/patch

packages/astro-plugin/src/index.ts#L45-L55

Added lines #L45 - L55 were not covered by tests
if (options.enableBundleAnalysis) {
plugins.push(
astroBundleAnalysisPlugin({ output, target }),
_internal_viteBundleAnalysisPlugin({ output }),
telemetryPlugin({
sentryClient: sentryConfig.sentryClient,
sentryScope: sentryConfig.sentryScope,
shouldSendTelemetry: options.telemetry,
}),
astroBundleAnalysisPlugin({
output,
target,
pluginName: PLUGIN_NAME,
pluginVersion: PLUGIN_VERSION,
}),
_internal_viteBundleAnalysisPlugin({
output,
pluginName: PLUGIN_NAME,
pluginVersion: PLUGIN_VERSION,
}),

Check warning on line 73 in packages/astro-plugin/src/index.ts

View check run for this annotation

Codecov Notifications / codecov/patch

packages/astro-plugin/src/index.ts#L58-L73

Added lines #L58 - L73 were not covered by tests
);
}

Expand Down
1 change: 1 addition & 0 deletions packages/bundler-plugin-core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
"dependencies": {
"@actions/core": "^1.10.1",
"@actions/github": "^6.0.0",
"@sentry/core": "^8.42.0",
"chalk": "4.1.2",
"semver": "^7.5.4",
"unplugin": "^1.10.1",
Expand Down
13 changes: 13 additions & 0 deletions packages/bundler-plugin-core/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { type Client, type Scope } from "@sentry/core";
import {
type Asset,
type BundleAnalysisUploadPlugin,
Expand All @@ -22,6 +23,12 @@
Output,
red,
} from "./utils";
import {
createSentryInstance,
telemetryPlugin,
safeFlushTelemetry,
setTelemetryDataOnScope,
} from "./sentry/telemetry.ts";

Check warning on line 31 in packages/bundler-plugin-core/src/index.ts

View check run for this annotation

Codecov Notifications / codecov/patch

packages/bundler-plugin-core/src/index.ts#L26-L31

Added lines #L26 - L31 were not covered by tests

export type {
Asset,
Expand All @@ -36,6 +43,8 @@
NormalizedOptions,
ProviderUtilInputs,
UploadOverrides,
Client as SentryClient,
Scope as SentryScope,

Check warning on line 47 in packages/bundler-plugin-core/src/index.ts

View check run for this annotation

Codecov Notifications / codecov/patch

packages/bundler-plugin-core/src/index.ts#L46-L47

Added lines #L46 - L47 were not covered by tests
};

export {
Expand All @@ -47,4 +56,8 @@
normalizePath,
Output,
red,
createSentryInstance,
telemetryPlugin,
safeFlushTelemetry,
setTelemetryDataOnScope,

Check warning on line 62 in packages/bundler-plugin-core/src/index.ts

View check run for this annotation

Codecov Notifications / codecov/patch

packages/bundler-plugin-core/src/index.ts#L59-L62

Added lines #L59 - L62 were not covered by tests
};
Loading
Loading