Skip to content

Commit f3ad016

Browse files
committed
add bundler plugin metrics to plugin factory
1 parent 62cab8f commit f3ad016

File tree

1 file changed

+44
-2
lines changed

1 file changed

+44
-2
lines changed

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

Lines changed: 44 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,18 @@ import { type NormalizedOptions } from "../utils/normalizeOptions.ts";
1010
import { detectProvider } from "../utils/provider.ts";
1111
import { uploadStats } from "../utils/uploadStats.ts";
1212
import { sendSentryBundleStats } from "../utils/sentryUtils.ts";
13+
import { type SentryClient } from "../sentry.ts";
1314

1415
interface BundleAnalysisUploadPluginArgs {
1516
options: NormalizedOptions;
1617
bundleAnalysisUploadPlugin: BundleAnalysisUploadPlugin;
18+
sentryClient: SentryClient;
1719
}
1820

1921
export const bundleAnalysisPluginFactory = ({
2022
options,
2123
bundleAnalysisUploadPlugin,
24+
sentryClient,
2225
}: BundleAnalysisUploadPluginArgs): UnpluginOptions => {
2326
const output: Output = {
2427
version: "1",
@@ -66,26 +69,65 @@ export const bundleAnalysisPluginFactory = ({
6669
const inputs: ProviderUtilInputs = { envs, args };
6770
const provider = await detectProvider(inputs);
6871

72+
const getPreSignedURLStart = Date.now();
6973
let url = "";
7074
try {
7175
url = await getPreSignedURL({
72-
apiURL: options?.apiUrl ?? "https://api.codecov.io",
76+
apiURL: options?.apiUrl,
7377
uploadToken: options?.uploadToken,
7478
serviceParams: provider,
7579
retryCount: options?.retryCount,
7680
});
81+
sentryClient?.metricsAggregator?.add(
82+
"c",
83+
"request_presigned_url.success",
84+
1,
85+
);
7786
} catch (error) {
87+
sentryClient?.metricsAggregator?.add(
88+
"c",
89+
"request_presigned_url.error",
90+
1,
91+
);
7892
return;
93+
} finally {
94+
sentryClient?.metricsAggregator?.add(
95+
"d",
96+
"request_presigned_url",
97+
Date.now() - getPreSignedURLStart,
98+
"millisecond",
99+
);
79100
}
80101

102+
const uploadStart = Date.now();
81103
try {
82104
await uploadStats({
83105
preSignedUrl: url,
84106
bundleName: output.bundleName,
85107
message: JSON.stringify(output),
86108
retryCount: options?.retryCount,
109+
sentryClient,
87110
});
88-
} catch {}
111+
sentryClient?.metricsAggregator?.add(
112+
"c",
113+
"upload_bundle_stats.success",
114+
1,
115+
);
116+
} catch {
117+
sentryClient?.metricsAggregator?.add(
118+
"c",
119+
"upload_bundle_stats.error",
120+
1,
121+
);
122+
return;
123+
} finally {
124+
sentryClient?.metricsAggregator?.add(
125+
"d",
126+
"upload_bundle_stats",
127+
Date.now() - uploadStart,
128+
"millisecond",
129+
);
130+
}
89131
},
90132
};
91133
};

0 commit comments

Comments
 (0)