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 bundler plugins #72

Open
wants to merge 24 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
4822616
create sentry util for tracking traces, issues, and metrics
nicholas-codecov Feb 13, 2024
e6c5c29
add sentry node
nicholas-codecov Feb 13, 2024
b9f202c
setup unbuild to inline replace __PACKAGE_VERSION with the current re…
nicholas-codecov Feb 13, 2024
1f7d135
add telemetry option to the plugin config
nicholas-codecov Feb 13, 2024
b963fbe
configure sentry client to be used across bundler plugins
nicholas-codecov Feb 13, 2024
7ce2799
add guage metric to fetchWithRetry function
nicholas-codecov Feb 13, 2024
62cab8f
pass through sentry client in getPreSignedURL and uploadStats
nicholas-codecov Feb 13, 2024
f3ad016
add bundler plugin metrics to plugin factory
nicholas-codecov Feb 13, 2024
e4ae897
use new normalizeOptions function and create sentry client if conditi…
nicholas-codecov Feb 13, 2024
22e2fe1
add in changeset
nicholas-codecov Feb 13, 2024
8167a07
swap to using gauge factory function for fetchWithRetry, and add tags…
nicholas-codecov Feb 13, 2024
84ebd39
fix up a few things with sentry setup
nicholas-codecov Feb 13, 2024
9486589
fix up bundle analysis type error in test
nicholas-codecov Feb 13, 2024
6ca1025
rework how sentry metrics are collected
nicholas-codecov Feb 16, 2024
a50562f
fix type error
nicholas-codecov Feb 16, 2024
ab9d98d
disable telemetry in integration tests
nicholas-codecov Feb 20, 2024
f042bc9
checking sentrt debug logs
nicholas-codecov Feb 21, 2024
f97223d
create telem plugin
nicholas-codecov Feb 21, 2024
22afbd4
use telem plugin
nicholas-codecov Feb 21, 2024
49d8b7a
inline replace in all plugin build configs
nicholas-codecov Feb 23, 2024
1c997de
maybe we just need to reassign the options?
nicholas-codecov Feb 23, 2024
90582e6
that didn't work
nicholas-codecov Feb 23, 2024
6799747
small tweaks post rebase
nicholas-codecov Mar 5, 2024
9b08536
small fix for telemetry type issue
nicholas-codecov Mar 5, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 8 additions & 0 deletions .changeset/rare-cats-reflect.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
"@codecov/bundler-plugin-core": patch
"@codecov/rollup-plugin": patch
"@codecov/vite-plugin": patch
"@codecov/webpack-plugin": patch
---

Add Sentry in to collect traces and metrics"
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ module.exports = defineConfig({
resolve(), // tells Rollup how to find date-fns in node_modules
commonjs(), // converts date-fns to ES modules
codecovRollupPlugin({
telemetry: false,
enableBundleAnalysis: true,
bundleName: "test-rollup-v3",
uploadToken: "test-token",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ module.exports = defineConfig({
resolve(), // tells Rollup how to find date-fns in node_modules
commonjs(), // converts date-fns to ES modules
codecovRollupPlugin({
telemetry: false,
enableBundleAnalysis: true,
bundleName: "test-rollup-v4",
uploadToken: "test-token",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ export default defineConfig({
},
plugins: [
codecovVitePlugin({
telemetry: false,
enableBundleAnalysis: true,
bundleName: "test-vite-v4",
uploadToken: "test-token",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ export default defineConfig({
},
plugins: [
codecovVitePlugin({
telemetry: false,
enableBundleAnalysis: true,
bundleName: "test-vite-v5",
uploadToken: "test-token",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ module.exports = {
mode: "production",
plugins: [
codecovWebpackPlugin({
telemetry: false,
enableBundleAnalysis: true,
bundleName: "test-webpack-v5",
uploadToken: "test-token",
Expand Down
9 changes: 8 additions & 1 deletion packages/bundler-plugin-core/build.config.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { defineBuildConfig } from "unbuild";
import { codecovRollupPlugin } from "codecovProdRollupPlugin";
import packageJson from "./package.json";

export default defineBuildConfig({
entries: ["./src/index"],
Expand All @@ -16,13 +17,19 @@ export default defineBuildConfig({
esbuild: {
minify: true,
},
replace: {
preventAssignment: true,
values: {
__PACKAGE_VERSION__: JSON.stringify(packageJson.version),
},
},
},
hooks: {
"rollup:options": (_ctx, opts) => {
if (process.env.PLUGIN_CODECOV_TOKEN && Array.isArray(opts.plugins)) {
// eslint-disable-next-line @typescript-eslint/no-unsafe-call
opts.plugins = [
...opts.plugins,
// eslint-disable-next-line @typescript-eslint/no-unsafe-call
codecovRollupPlugin({
enableBundleAnalysis:
typeof process.env.PLUGIN_CODECOV_TOKEN === "string",
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 @@ -36,6 +36,7 @@
"test:unit:ci": "jest --coverage"
},
"dependencies": {
"@sentry/node": "^7.100.1",
"chalk": "4.1.2",
"semver": "^7.5.4",
"unplugin": "^1.6.0",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { type UnpluginContextMeta } from "unplugin";
import { bundleAnalysisPluginFactory } from "../bundleAnalysisPluginFactory";

describe("bundleAnalysisPluginFactory", () => {
Expand All @@ -10,12 +11,18 @@ describe("bundleAnalysisPluginFactory", () => {
enableBundleAnalysis: true,
retryCount: 3,
uploadToken: "test-token",
telemetry: false,
},
bundleAnalysisUploadPlugin: () => ({
version: "1",
name: "plugin-name",
pluginVersion: "1.0.0",
}),
unpluginMetaContext: {} as UnpluginContextMeta,
sentryMetrics: undefined,
handleRecoverableError() {
return;
},
});

expect(plugin).toMatchSnapshot();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,24 +1,32 @@
import { type UnpluginOptions } from "unplugin";
import {
type BundleAnalysisUploadPlugin,
type Output,
type ProviderUtilInputs,
type UploadOverrides,
} from "../types.ts";
import { type UnpluginContextMeta, type UnpluginOptions } from "unplugin";
import { getPreSignedURL } from "../utils/getPreSignedURL.ts";
import { uploadStats } from "../utils/uploadStats.ts";
import { type SentryMetrics } from "../sentry.ts";
import { type NormalizedOptions } from "../utils/normalizeOptions.ts";
import { detectProvider } from "../utils/provider.ts";
import { uploadStats } from "../utils/uploadStats.ts";
import { sendSentryBundleStats } from "../utils/sentryUtils.ts";
import { createGauge } from "../utils/fetchWithRetry.ts";

interface BundleAnalysisUploadPluginArgs {
options: NormalizedOptions;
unpluginMetaContext: UnpluginContextMeta;
bundleAnalysisUploadPlugin: BundleAnalysisUploadPlugin;
sentryMetrics: SentryMetrics;
handleRecoverableError: (error: unknown) => void;
}

export const bundleAnalysisPluginFactory = ({
options,
unpluginMetaContext,
bundleAnalysisUploadPlugin,
sentryMetrics,
handleRecoverableError,
}: BundleAnalysisUploadPluginArgs): UnpluginOptions => {
const output: Output = {
version: "1",
Expand Down Expand Up @@ -67,25 +75,62 @@
const provider = await detectProvider(inputs);

let url = "";
const gauge = createGauge({

Check warning on line 78 in packages/bundler-plugin-core/src/bundle-analysis/bundleAnalysisPluginFactory.ts

View check run for this annotation

Codecov - Staging / codecov/patch

packages/bundler-plugin-core/src/bundle-analysis/bundleAnalysisPluginFactory.ts#L78

Added line #L78 was not covered by tests

Check warning on line 78 in packages/bundler-plugin-core/src/bundle-analysis/bundleAnalysisPluginFactory.ts

View check run for this annotation

Codecov / codecov/patch

packages/bundler-plugin-core/src/bundle-analysis/bundleAnalysisPluginFactory.ts#L78

Added line #L78 was not covered by tests
bundler: unpluginMetaContext.framework,
sentryMetrics,
});
const getPreSignedURLStart = Date.now();

Check warning on line 82 in packages/bundler-plugin-core/src/bundle-analysis/bundleAnalysisPluginFactory.ts

View check run for this annotation

Codecov - Staging / codecov/patch

packages/bundler-plugin-core/src/bundle-analysis/bundleAnalysisPluginFactory.ts#L82

Added line #L82 was not covered by tests

Check warning on line 82 in packages/bundler-plugin-core/src/bundle-analysis/bundleAnalysisPluginFactory.ts

View check run for this annotation

Codecov / codecov/patch

packages/bundler-plugin-core/src/bundle-analysis/bundleAnalysisPluginFactory.ts#L82

Added line #L82 was not covered by tests
try {
url = await getPreSignedURL({
apiURL: options?.apiUrl ?? "https://api.codecov.io",
apiURL: options?.apiUrl,
uploadToken: options?.uploadToken,
serviceParams: provider,
nicholas-codecov marked this conversation as resolved.
Show resolved Hide resolved
retryCount: options?.retryCount,
gauge,
});
sentryMetrics?.increment("request_presigned_url.success", 1, "none", {

Check warning on line 91 in packages/bundler-plugin-core/src/bundle-analysis/bundleAnalysisPluginFactory.ts

View check run for this annotation

Codecov - Staging / codecov/patch

packages/bundler-plugin-core/src/bundle-analysis/bundleAnalysisPluginFactory.ts#L91

Added line #L91 was not covered by tests

Check warning on line 91 in packages/bundler-plugin-core/src/bundle-analysis/bundleAnalysisPluginFactory.ts

View check run for this annotation

Codecov / codecov/patch

packages/bundler-plugin-core/src/bundle-analysis/bundleAnalysisPluginFactory.ts#L91

Added line #L91 was not covered by tests
bundler: unpluginMetaContext.framework,
});
} catch (error) {
sentryMetrics?.increment("request_presigned_url.error", 1, "none", {

Check warning on line 95 in packages/bundler-plugin-core/src/bundle-analysis/bundleAnalysisPluginFactory.ts

View check run for this annotation

Codecov - Staging / codecov/patch

packages/bundler-plugin-core/src/bundle-analysis/bundleAnalysisPluginFactory.ts#L95

Added line #L95 was not covered by tests

Check warning on line 95 in packages/bundler-plugin-core/src/bundle-analysis/bundleAnalysisPluginFactory.ts

View check run for this annotation

Codecov / codecov/patch

packages/bundler-plugin-core/src/bundle-analysis/bundleAnalysisPluginFactory.ts#L95

Added line #L95 was not covered by tests
bundler: unpluginMetaContext.framework,
});

handleRecoverableError(error);

Check warning on line 99 in packages/bundler-plugin-core/src/bundle-analysis/bundleAnalysisPluginFactory.ts

View check run for this annotation

Codecov - Staging / codecov/patch

packages/bundler-plugin-core/src/bundle-analysis/bundleAnalysisPluginFactory.ts#L99

Added line #L99 was not covered by tests

Check warning on line 99 in packages/bundler-plugin-core/src/bundle-analysis/bundleAnalysisPluginFactory.ts

View check run for this annotation

Codecov / codecov/patch

packages/bundler-plugin-core/src/bundle-analysis/bundleAnalysisPluginFactory.ts#L99

Added line #L99 was not covered by tests
return;
} finally {
sentryMetrics?.distribution(

Check warning on line 102 in packages/bundler-plugin-core/src/bundle-analysis/bundleAnalysisPluginFactory.ts

View check run for this annotation

Codecov - Staging / codecov/patch

packages/bundler-plugin-core/src/bundle-analysis/bundleAnalysisPluginFactory.ts#L102

Added line #L102 was not covered by tests

Check warning on line 102 in packages/bundler-plugin-core/src/bundle-analysis/bundleAnalysisPluginFactory.ts

View check run for this annotation

Codecov / codecov/patch

packages/bundler-plugin-core/src/bundle-analysis/bundleAnalysisPluginFactory.ts#L102

Added line #L102 was not covered by tests
"request_presigned_url",
Date.now() - getPreSignedURLStart,
"millisecond",
{ bundler: unpluginMetaContext.framework },
);
}

const uploadStart = Date.now();

Check warning on line 110 in packages/bundler-plugin-core/src/bundle-analysis/bundleAnalysisPluginFactory.ts

View check run for this annotation

Codecov - Staging / codecov/patch

packages/bundler-plugin-core/src/bundle-analysis/bundleAnalysisPluginFactory.ts#L110

Added line #L110 was not covered by tests

Check warning on line 110 in packages/bundler-plugin-core/src/bundle-analysis/bundleAnalysisPluginFactory.ts

View check run for this annotation

Codecov / codecov/patch

packages/bundler-plugin-core/src/bundle-analysis/bundleAnalysisPluginFactory.ts#L110

Added line #L110 was not covered by tests
try {
await uploadStats({
preSignedUrl: url,
bundleName: output.bundleName,
message: JSON.stringify(output),
retryCount: options?.retryCount,
gauge,
});
} catch {}
sentryMetrics?.increment("upload_bundle_stats.success", 1, "none", {

Check warning on line 119 in packages/bundler-plugin-core/src/bundle-analysis/bundleAnalysisPluginFactory.ts

View check run for this annotation

Codecov - Staging / codecov/patch

packages/bundler-plugin-core/src/bundle-analysis/bundleAnalysisPluginFactory.ts#L119

Added line #L119 was not covered by tests

Check warning on line 119 in packages/bundler-plugin-core/src/bundle-analysis/bundleAnalysisPluginFactory.ts

View check run for this annotation

Codecov / codecov/patch

packages/bundler-plugin-core/src/bundle-analysis/bundleAnalysisPluginFactory.ts#L119

Added line #L119 was not covered by tests
bundler: unpluginMetaContext.framework,
});
} catch (error) {
sentryMetrics?.increment("upload_bundle_stats.error", 1);
handleRecoverableError(error);
return;

Check warning on line 125 in packages/bundler-plugin-core/src/bundle-analysis/bundleAnalysisPluginFactory.ts

View check run for this annotation

Codecov - Staging / codecov/patch

packages/bundler-plugin-core/src/bundle-analysis/bundleAnalysisPluginFactory.ts#L123-L125

Added lines #L123 - L125 were not covered by tests

Check warning on line 125 in packages/bundler-plugin-core/src/bundle-analysis/bundleAnalysisPluginFactory.ts

View check run for this annotation

Codecov / codecov/patch

packages/bundler-plugin-core/src/bundle-analysis/bundleAnalysisPluginFactory.ts#L123-L125

Added lines #L123 - L125 were not covered by tests
} finally {
nicholas-codecov marked this conversation as resolved.
Show resolved Hide resolved
sentryMetrics?.distribution(

Check warning on line 127 in packages/bundler-plugin-core/src/bundle-analysis/bundleAnalysisPluginFactory.ts

View check run for this annotation

Codecov - Staging / codecov/patch

packages/bundler-plugin-core/src/bundle-analysis/bundleAnalysisPluginFactory.ts#L127

Added line #L127 was not covered by tests

Check warning on line 127 in packages/bundler-plugin-core/src/bundle-analysis/bundleAnalysisPluginFactory.ts

View check run for this annotation

Codecov / codecov/patch

packages/bundler-plugin-core/src/bundle-analysis/bundleAnalysisPluginFactory.ts#L127

Added line #L127 was not covered by tests
"upload_bundle_stats",
Date.now() - uploadStart,
"millisecond",
{ bundler: unpluginMetaContext.framework },
);
}
},
};
};
64 changes: 62 additions & 2 deletions packages/bundler-plugin-core/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,12 @@
import { red } from "./utils/logging.ts";
import { normalizePath } from "./utils/normalizePath.ts";
import { bundleAnalysisPluginFactory } from "./bundle-analysis/bundleAnalysisPluginFactory.ts";
import { normalizeOptions } from "./utils/normalizeOptions.ts";
import {
normalizeOptions,
type NormalizedOptions,
} from "./utils/normalizeOptions.ts";
import { createSentryInstance } from "./sentry.ts";
import { telemetryPlugin } from "./plugins/telemetry.ts";

const NODE_VERSION_RANGE = ">=18.18.0";

Expand All @@ -37,6 +42,8 @@
return [];
}

const options = normalizedOptions.options;

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

View check run for this annotation

Codecov - Staging / codecov/patch

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

Added line #L45 was not covered by tests

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

View check run for this annotation

Codecov / codecov/patch

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

Added line #L45 was not covered by tests

if (!satisfies(process.version, NODE_VERSION_RANGE)) {
red(
`Codecov ${unpluginMetaContext.framework} bundler plugin requires Node.js ${NODE_VERSION_RANGE}. You are using Node.js ${process.version}. Please upgrade your Node.js version.`,
Expand All @@ -45,12 +52,64 @@
return plugins;
}

const options = normalizedOptions.options;
const { sentryHub, sentryMetrics, sentryClient } = createSentryInstance(

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

View check run for this annotation

Codecov - Staging / codecov/patch

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

Added line #L55 was not covered by tests

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

View check run for this annotation

Codecov / codecov/patch

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

Added line #L55 was not covered by tests
options,
unpluginMetaContext.framework,
);

const sentrySession = sentryHub?.startSession();
sentryHub?.captureSession();

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

View check run for this annotation

Codecov - Staging / codecov/patch

packages/bundler-plugin-core/src/index.ts#L60-L61

Added lines #L60 - L61 were not covered by tests

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

View check run for this annotation

Codecov / codecov/patch

packages/bundler-plugin-core/src/index.ts#L60-L61

Added lines #L60 - L61 were not covered by tests

let sentEndSession = false; // Just to prevent infinite loops with beforeExit, which is called whenever the event loop empties out

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

View check run for this annotation

Codecov - Staging / codecov/patch

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

Added line #L63 was not covered by tests

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

View check run for this annotation

Codecov / codecov/patch

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

Added line #L63 was not covered by tests
// We also need to manually end sessions on errors because beforeExit is not called on crashes
process.on("beforeExit", () => {

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

View check run for this annotation

Codecov - Staging / codecov/patch

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

Added line #L65 was not covered by tests

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

View check run for this annotation

Codecov / codecov/patch

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

Added line #L65 was not covered by tests
if (!sentEndSession) {
sentryHub?.endSession();
sentEndSession = true;

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

View check run for this annotation

Codecov - Staging / codecov/patch

packages/bundler-plugin-core/src/index.ts#L67-L68

Added lines #L67 - L68 were not covered by tests

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

View check run for this annotation

Codecov / codecov/patch

packages/bundler-plugin-core/src/index.ts#L67-L68

Added lines #L67 - L68 were not covered by tests
}
});

function handleRecoverableError(unknownError: unknown) {

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

View check run for this annotation

Codecov - Staging / codecov/patch

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

Added line #L72 was not covered by tests

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

View check run for this annotation

Codecov / codecov/patch

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

Added line #L72 was not covered by tests
if (sentrySession) {
sentrySession.status = "abnormal";
try {

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

View check run for this annotation

Codecov - Staging / codecov/patch

packages/bundler-plugin-core/src/index.ts#L74-L75

Added lines #L74 - L75 were not covered by tests

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

View check run for this annotation

Codecov / codecov/patch

packages/bundler-plugin-core/src/index.ts#L74-L75

Added lines #L74 - L75 were not covered by tests
if (options.errorHandler) {
try {

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

View check run for this annotation

Codecov - Staging / codecov/patch

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

Added line #L77 was not covered by tests

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

View check run for this annotation

Codecov / codecov/patch

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

Added line #L77 was not covered by tests
if (unknownError instanceof Error) {
options.errorHandler(unknownError);
} else {
options.errorHandler(new Error("An unknown error occurred"));

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

View check run for this annotation

Codecov - Staging / codecov/patch

packages/bundler-plugin-core/src/index.ts#L79-L81

Added lines #L79 - L81 were not covered by tests

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

View check run for this annotation

Codecov / codecov/patch

packages/bundler-plugin-core/src/index.ts#L79-L81

Added lines #L79 - L81 were not covered by tests
}
} catch (e) {
sentrySession.status = "crashed";
throw e;

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

View check run for this annotation

Codecov - Staging / codecov/patch

packages/bundler-plugin-core/src/index.ts#L84-L85

Added lines #L84 - L85 were not covered by tests

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

View check run for this annotation

Codecov / codecov/patch

packages/bundler-plugin-core/src/index.ts#L84-L85

Added lines #L84 - L85 were not covered by tests
}
} else {
sentrySession.status = "crashed";
throw unknownError;

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

View check run for this annotation

Codecov - Staging / codecov/patch

packages/bundler-plugin-core/src/index.ts#L87-L89

Added lines #L87 - L89 were not covered by tests

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

View check run for this annotation

Codecov / codecov/patch

packages/bundler-plugin-core/src/index.ts#L87-L89

Added lines #L87 - L89 were not covered by tests
}
} finally {
sentryHub?.endSession();

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

View check run for this annotation

Codecov - Staging / codecov/patch

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

Added line #L92 was not covered by tests

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

View check run for this annotation

Codecov / codecov/patch

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

Added line #L92 was not covered by tests
}
}
}

plugins.push(

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

View check run for this annotation

Codecov - Staging / codecov/patch

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

Added line #L97 was not covered by tests

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

View check run for this annotation

Codecov / codecov/patch

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

Added line #L97 was not covered by tests
telemetryPlugin({
sentryClient,
sentryHub,
shouldSendTelemetry: options.telemetry,
}),
);

if (options?.enableBundleAnalysis) {
plugins.push(
bundleAnalysisPluginFactory({
options,
unpluginMetaContext,
bundleAnalysisUploadPlugin,
sentryMetrics,
handleRecoverableError,
}),
);
}
Expand All @@ -68,6 +127,7 @@
ProviderUtilInputs,
UploadOverrides,
Output,
NormalizedOptions,
};

export { normalizePath, codecovUnpluginFactory, red };
31 changes: 31 additions & 0 deletions packages/bundler-plugin-core/src/plugins/telemetry.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import { type Hub, type NodeClient } from "@sentry/node";
import { type UnpluginOptions } from "unplugin";
import { dim } from "../utils/logging";
import { safeFlushTelemetry } from "../sentry";

interface TelemetryPluginOptions {
sentryHub?: Hub;
sentryClient?: NodeClient;
shouldSendTelemetry: boolean;
}

export function telemetryPlugin({
sentryHub,
sentryClient,
shouldSendTelemetry,
}: TelemetryPluginOptions): UnpluginOptions {
return {

Check warning on line 17 in packages/bundler-plugin-core/src/plugins/telemetry.ts

View check run for this annotation

Codecov - Staging / codecov/patch

packages/bundler-plugin-core/src/plugins/telemetry.ts#L16-L17

Added lines #L16 - L17 were not covered by tests

Check warning on line 17 in packages/bundler-plugin-core/src/plugins/telemetry.ts

View check run for this annotation

Codecov / codecov/patch

packages/bundler-plugin-core/src/plugins/telemetry.ts#L16-L17

Added lines #L16 - L17 were not covered by tests
name: "codecov-telemetry-plugin",
async buildStart() {

Check warning on line 19 in packages/bundler-plugin-core/src/plugins/telemetry.ts

View check run for this annotation

Codecov - Staging / codecov/patch

packages/bundler-plugin-core/src/plugins/telemetry.ts#L19

Added line #L19 was not covered by tests

Check warning on line 19 in packages/bundler-plugin-core/src/plugins/telemetry.ts

View check run for this annotation

Codecov / codecov/patch

packages/bundler-plugin-core/src/plugins/telemetry.ts#L19

Added line #L19 was not covered by tests
if (shouldSendTelemetry && sentryHub && sentryClient) {
dim(

Check warning on line 21 in packages/bundler-plugin-core/src/plugins/telemetry.ts

View check run for this annotation

Codecov - Staging / codecov/patch

packages/bundler-plugin-core/src/plugins/telemetry.ts#L21

Added line #L21 was not covered by tests

Check warning on line 21 in packages/bundler-plugin-core/src/plugins/telemetry.ts

View check run for this annotation

Codecov / codecov/patch

packages/bundler-plugin-core/src/plugins/telemetry.ts#L21

Added line #L21 was not covered by tests
"Sending error and performance telemetry data to Sentry. To disable telemetry, set `options.telemetry` to `false`.",
);
sentryHub

Check warning on line 24 in packages/bundler-plugin-core/src/plugins/telemetry.ts

View check run for this annotation

Codecov - Staging / codecov/patch

packages/bundler-plugin-core/src/plugins/telemetry.ts#L24

Added line #L24 was not covered by tests

Check warning on line 24 in packages/bundler-plugin-core/src/plugins/telemetry.ts

View check run for this annotation

Codecov / codecov/patch

packages/bundler-plugin-core/src/plugins/telemetry.ts#L24

Added line #L24 was not covered by tests
.startTransaction({ name: "Codecov Bundler Plugin execution" })
.finish();
await safeFlushTelemetry(sentryClient);

Check warning on line 27 in packages/bundler-plugin-core/src/plugins/telemetry.ts

View check run for this annotation

Codecov - Staging / codecov/patch

packages/bundler-plugin-core/src/plugins/telemetry.ts#L27

Added line #L27 was not covered by tests

Check warning on line 27 in packages/bundler-plugin-core/src/plugins/telemetry.ts

View check run for this annotation

Codecov / codecov/patch

packages/bundler-plugin-core/src/plugins/telemetry.ts#L27

Added line #L27 was not covered by tests
}
},
};
}