Skip to content

feat: Add Sentry to the bundler plugins #224

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

Merged
merged 23 commits into from
Jan 8, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
fd4fcb7
refactor how we define and access the plugin name and version
nsdeschenes Dec 5, 2024
d83cb03
setup Sentry in the bundler plugin core
nsdeschenes Dec 6, 2024
26b4a73
add to the plugins
nsdeschenes Dec 6, 2024
bd34936
disable telemetry in the integration tests
nsdeschenes Dec 6, 2024
b9d057d
update lock file
nsdeschenes Dec 6, 2024
56421c7
add in changeset
nsdeschenes Dec 6, 2024
5f6b20e
fix type issues
nsdeschenes Dec 6, 2024
4c6b2e7
add in fix for next js webpack plugin not using the correct webpack
nsdeschenes Dec 6, 2024
937c3cd
set owner and repo tags
nsdeschenes Dec 6, 2024
8e60f72
add op's to the spans
nsdeschenes Dec 6, 2024
92352c3
collect some more info about meta frameworks and bundlers
nsdeschenes Dec 6, 2024
83c8e0c
add in some more comments
nsdeschenes Dec 9, 2024
d04efd9
Update .changeset/green-goats-thank.md
nsdeschenes Jan 2, 2025
a8bfd11
actually send the sentry config to the Output constructor
nsdeschenes Jan 2, 2025
e23ed03
force transaction span wrapping all of output.write method
nsdeschenes Jan 6, 2025
04dcead
default values to 0 not undefined
nsdeschenes Jan 6, 2025
6343834
manually set the parent span
nsdeschenes Jan 6, 2025
5b16c22
mock out startSpan from Sentry
nsdeschenes Jan 7, 2025
c26a9e1
remove mocks for getScope and clone
nsdeschenes Jan 7, 2025
11ac6b9
wrap outer span in a try catch to actually throw any errors if they'r…
nsdeschenes Jan 7, 2025
e5ba3cc
bring back early returns if no provider or upload url
nsdeschenes Jan 7, 2025
e31749a
add in emitError wrapper
nsdeschenes Jan 8, 2025
e167fcb
use common naming for telemetry
nsdeschenes Jan 8, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 telemetry
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
},
},
});
35 changes: 31 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,
} 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
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#L20

Added line #L20 was not covered by tests

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

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

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What do these 2 keys represent again? bundler vs. metaFramework? On first glance, I would have expected the values to be flipped here with bundler being "astro" and the metaFramework being from the enum from unplugin.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bundler is the underlying bundler (Rollup, Vite, Webpack), this value is derived from Unplugin itself, whereas the meta-framework value is what we pass through as things like Astro are built on-top of bundlers (Vite in this case), bundlers being the "lowest" system in the stack.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Got it, thanks!
If we can declare an enum or type for the acceptable strings that may be nice in the future.

});
const output = new Output(options, sentryConfig);

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

View check run for this annotation

Codecov Notifications / codecov/patch

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

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

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

View check run for this annotation

Codecov Notifications / codecov/patch

packages/astro-plugin/src/index.ts#L57-L72

Added lines #L57 - L72 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 @@ import {
Output,
red,
} from "./utils";
import {
createSentryInstance,
telemetryPlugin,
safeFlushTelemetry,
setTelemetryDataOnScope,
} from "./sentry/telemetry.ts";

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

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