Skip to content

Commit d547bdf

Browse files
committed
add bundler plugin metrics to plugin factory
1 parent 484cdb7 commit d547bdf

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,25 +58,64 @@ 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
message: JSON.stringify(output),
7496
retryCount: userOptions?.retryCount,
97+
sentryClient,
7598
});
76-
} catch {}
99+
sentryClient?.metricsAggregator?.add(
100+
"c",
101+
"upload_bundle_stats.success",
102+
1,
103+
);
104+
} catch {
105+
sentryClient?.metricsAggregator?.add(
106+
"c",
107+
"upload_bundle_stats.error",
108+
1,
109+
);
110+
return;
111+
} finally {
112+
sentryClient?.metricsAggregator?.add(
113+
"d",
114+
"upload_bundle_stats",
115+
Date.now() - uploadStart,
116+
"millisecond",
117+
);
118+
}
77119
},
78120
};
79121
};

0 commit comments

Comments
 (0)