Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 2 additions & 0 deletions packages/bundler-plugin-core/src/options-mapping.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ export type NormalizedOptions = {
_metaOptions: {
telemetry: {
metaFramework: string | undefined;
bundlerMajorVersion: string | undefined;
};
};
applicationKey: string | undefined;
Expand Down Expand Up @@ -121,6 +122,7 @@ export function normalizeUserOptions(userOptions: UserOptions): NormalizedOption
_metaOptions: {
telemetry: {
metaFramework: userOptions._metaOptions?.telemetry?.metaFramework,
bundlerMajorVersion: userOptions._metaOptions?.telemetry?.bundlerMajorVersion,
},
},
applicationKey: userOptions.applicationKey,
Expand Down
2 changes: 2 additions & 0 deletions packages/bundler-plugin-core/src/sentry/telemetry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,8 @@ export function setTelemetryDataOnScope(
bundler: buildTool,
});

scope.setTag("bundler-major-version", options._metaOptions.telemetry.bundlerMajorVersion);

scope.setUser({ id: org });
}

Expand Down
4 changes: 4 additions & 0 deletions packages/bundler-plugin-core/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -418,6 +418,10 @@ export interface Options {
* The meta framework using the plugin.
*/
metaFramework?: string;
/**
* The major version of the bundler (e.g., "4" or "5" for webpack).
*/
bundlerMajorVersion?: string;
};
};
}
Expand Down
32 changes: 30 additions & 2 deletions packages/webpack-plugin/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,42 @@ const BannerPlugin = webpack4or5?.BannerPlugin || webpack4or5?.default?.BannerPl

const DefinePlugin = webpack4or5?.DefinePlugin || webpack4or5?.default?.DefinePlugin;

// Detect webpack major version for telemetry (helps differentiate webpack 4 vs 5 usage)
function getWebpackMajorVersion(): string | undefined {
try {
const webpack = webpack4or5 as unknown as
| { version?: string; default?: { version?: string } }
| undefined;
const version = webpack?.version ?? webpack?.default?.version;
const webpackMajorVersion = version?.split(".")[0]; // "4" or "5"
return webpackMajorVersion;
} catch (error) {
return undefined;
}
}

const webpackMajorVersion = getWebpackMajorVersion();

const sentryUnplugin = sentryWebpackUnpluginFactory({
BannerPlugin,
DefinePlugin,
});

// eslint-disable-next-line @typescript-eslint/no-explicit-any
export const sentryWebpackPlugin: (options?: SentryWebpackPluginOptions) => any =
sentryUnplugin.webpack;
export const sentryWebpackPlugin: (options?: SentryWebpackPluginOptions) => any = (options) => {
const enhancedOptions: SentryWebpackPluginOptions = {
...options,
_metaOptions: {
...options?._metaOptions,
telemetry: {
...options?._metaOptions?.telemetry,
bundlerMajorVersion:
options?._metaOptions?.telemetry?.bundlerMajorVersion ?? webpackMajorVersion,
},
},
};
return sentryUnplugin.webpack(enhancedOptions);
};

export { sentryCliBinaryExists } from "@sentry/bundler-plugin-core";

Expand Down
Loading