Skip to content

Commit 0131e86

Browse files
authored
feat(telemetry): Add bundler-major-version tag to webpack (#857)
* add bundler-major-version tag * format
1 parent a2dcf4d commit 0131e86

File tree

4 files changed

+38
-2
lines changed

4 files changed

+38
-2
lines changed

packages/bundler-plugin-core/src/options-mapping.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ export type NormalizedOptions = {
7676
_metaOptions: {
7777
telemetry: {
7878
metaFramework: string | undefined;
79+
bundlerMajorVersion: string | undefined;
7980
};
8081
};
8182
applicationKey: string | undefined;
@@ -121,6 +122,7 @@ export function normalizeUserOptions(userOptions: UserOptions): NormalizedOption
121122
_metaOptions: {
122123
telemetry: {
123124
metaFramework: userOptions._metaOptions?.telemetry?.metaFramework,
125+
bundlerMajorVersion: userOptions._metaOptions?.telemetry?.bundlerMajorVersion,
124126
},
125127
},
126128
applicationKey: userOptions.applicationKey,

packages/bundler-plugin-core/src/sentry/telemetry.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,8 @@ export function setTelemetryDataOnScope(
111111
bundler: buildTool,
112112
});
113113

114+
scope.setTag("bundler-major-version", options._metaOptions.telemetry.bundlerMajorVersion);
115+
114116
scope.setUser({ id: org });
115117
}
116118

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -418,6 +418,10 @@ export interface Options {
418418
* The meta framework using the plugin.
419419
*/
420420
metaFramework?: string;
421+
/**
422+
* The major version of the bundler (e.g., "4" or "5" for webpack).
423+
*/
424+
bundlerMajorVersion?: string;
421425
};
422426
};
423427
}

packages/webpack-plugin/src/index.ts

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,42 @@ const BannerPlugin = webpack4or5?.BannerPlugin || webpack4or5?.default?.BannerPl
88

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

11+
// Detect webpack major version for telemetry (helps differentiate webpack 4 vs 5 usage)
12+
function getWebpackMajorVersion(): string | undefined {
13+
try {
14+
const webpack = webpack4or5 as unknown as
15+
| { version?: string; default?: { version?: string } }
16+
| undefined;
17+
const version = webpack?.version ?? webpack?.default?.version;
18+
const webpackMajorVersion = version?.split(".")[0]; // "4" or "5"
19+
return webpackMajorVersion;
20+
} catch (error) {
21+
return undefined;
22+
}
23+
}
24+
25+
const webpackMajorVersion = getWebpackMajorVersion();
26+
1127
const sentryUnplugin = sentryWebpackUnpluginFactory({
1228
BannerPlugin,
1329
DefinePlugin,
1430
});
1531

1632
// eslint-disable-next-line @typescript-eslint/no-explicit-any
17-
export const sentryWebpackPlugin: (options?: SentryWebpackPluginOptions) => any =
18-
sentryUnplugin.webpack;
33+
export const sentryWebpackPlugin: (options?: SentryWebpackPluginOptions) => any = (options) => {
34+
const enhancedOptions: SentryWebpackPluginOptions = {
35+
...options,
36+
_metaOptions: {
37+
...options?._metaOptions,
38+
telemetry: {
39+
...options?._metaOptions?.telemetry,
40+
bundlerMajorVersion:
41+
options?._metaOptions?.telemetry?.bundlerMajorVersion ?? webpackMajorVersion,
42+
},
43+
},
44+
};
45+
return sentryUnplugin.webpack(enhancedOptions);
46+
};
1947

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

0 commit comments

Comments
 (0)