Skip to content

Commit bdd4d32

Browse files
committed
add bundler plugin metrics to plugin factory
1 parent 7bb38b0 commit bdd4d32

File tree

1 file changed

+46
-4
lines changed

1 file changed

+46
-4
lines changed

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

Lines changed: 46 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,26 @@
11
import { detectProvider } from "../utils/provider.ts";
22
import {
33
type BundleAnalysisUploadPlugin,
4-
type Options,
54
type Output,
65
type ProviderUtilInputs,
76
type UploadOverrides,
87
} from "../types.ts";
98
import { type UnpluginOptions } from "unplugin";
109
import { getPreSignedURL } from "../utils/getPreSignedURL.ts";
1110
import { uploadStats } from "../utils/uploadStats.ts";
11+
import { type SentryClient } from "../sentry.ts";
12+
import { type NormalizedOptions } from "src/utils/normalizeOptions.ts";
1213

1314
interface BundleAnalysisUploadPluginArgs {
14-
userOptions: Options;
15+
userOptions: NormalizedOptions;
1516
bundleAnalysisUploadPlugin: BundleAnalysisUploadPlugin;
17+
sentryClient: SentryClient;
1618
}
1719

1820
export const bundleAnalysisPluginFactory = ({
1921
userOptions,
2022
bundleAnalysisUploadPlugin,
23+
sentryClient,
2124
}: BundleAnalysisUploadPluginArgs): UnpluginOptions => {
2225
const output: Output = {
2326
version: "1",
@@ -55,26 +58,65 @@ export const bundleAnalysisPluginFactory = ({
5558
const inputs: ProviderUtilInputs = { envs, args };
5659
const provider = await detectProvider(inputs);
5760

61+
const getPreSignedURLStart = Date.now();
5862
let url = "";
5963
try {
6064
url = await getPreSignedURL({
61-
apiURL: userOptions?.apiUrl ?? "https://api.codecov.io",
65+
apiURL: userOptions?.apiUrl,
6266
uploadToken: userOptions?.uploadToken,
6367
serviceParams: provider,
6468
retryCount: userOptions?.retryCount,
6569
});
70+
sentryClient?.metricsAggregator?.add(
71+
"c",
72+
"request_presigned_url.success",
73+
1,
74+
);
6675
} catch (error) {
76+
sentryClient?.metricsAggregator?.add(
77+
"c",
78+
"request_presigned_url.error",
79+
1,
80+
);
6781
return;
82+
} finally {
83+
sentryClient?.metricsAggregator?.add(
84+
"d",
85+
"request_presigned_url",
86+
Date.now() - getPreSignedURLStart,
87+
"millisecond",
88+
);
6889
}
6990

91+
const uploadStart = Date.now();
7092
try {
7193
await uploadStats({
7294
preSignedUrl: url,
7395
bundleName: output.bundleName,
7496
message: JSON.stringify(output),
7597
retryCount: userOptions?.retryCount,
98+
sentryClient,
7699
});
77-
} catch {}
100+
sentryClient?.metricsAggregator?.add(
101+
"c",
102+
"upload_bundle_stats.success",
103+
1,
104+
);
105+
} catch {
106+
sentryClient?.metricsAggregator?.add(
107+
"c",
108+
"upload_bundle_stats.error",
109+
1,
110+
);
111+
return;
112+
} finally {
113+
sentryClient?.metricsAggregator?.add(
114+
"d",
115+
"upload_bundle_stats",
116+
Date.now() - uploadStart,
117+
"millisecond",
118+
);
119+
}
78120
},
79121
};
80122
};

0 commit comments

Comments
 (0)