|
1 | 1 | import { detectProvider } from "../utils/provider.ts"; |
2 | 2 | import { |
3 | 3 | type BundleAnalysisUploadPlugin, |
4 | | - type Options, |
5 | 4 | type Output, |
6 | 5 | type ProviderUtilInputs, |
7 | 6 | type UploadOverrides, |
8 | 7 | } from "../types.ts"; |
9 | 8 | import { type UnpluginOptions } from "unplugin"; |
10 | 9 | import { getPreSignedURL } from "../utils/getPreSignedURL.ts"; |
11 | 10 | import { uploadStats } from "../utils/uploadStats.ts"; |
| 11 | +import { type SentryClient } from "../sentry.ts"; |
| 12 | +import { type NormalizedOptions } from "src/utils/normalizeOptions.ts"; |
12 | 13 |
|
13 | 14 | interface BundleAnalysisUploadPluginArgs { |
14 | | - userOptions: Options; |
| 15 | + userOptions: NormalizedOptions; |
15 | 16 | bundleAnalysisUploadPlugin: BundleAnalysisUploadPlugin; |
| 17 | + sentryClient: SentryClient; |
16 | 18 | } |
17 | 19 |
|
18 | 20 | export const bundleAnalysisPluginFactory = ({ |
19 | 21 | userOptions, |
20 | 22 | bundleAnalysisUploadPlugin, |
| 23 | + sentryClient, |
21 | 24 | }: BundleAnalysisUploadPluginArgs): UnpluginOptions => { |
22 | 25 | const output: Output = { |
23 | 26 | version: "1", |
@@ -55,25 +58,64 @@ export const bundleAnalysisPluginFactory = ({ |
55 | 58 | const inputs: ProviderUtilInputs = { envs, args }; |
56 | 59 | const provider = await detectProvider(inputs); |
57 | 60 |
|
| 61 | + const getPreSignedURLStart = Date.now(); |
58 | 62 | let url = ""; |
59 | 63 | try { |
60 | 64 | url = await getPreSignedURL({ |
61 | | - apiURL: userOptions?.apiUrl ?? "https://api.codecov.io", |
| 65 | + apiURL: userOptions?.apiUrl, |
62 | 66 | uploadToken: userOptions?.uploadToken, |
63 | 67 | serviceParams: provider, |
64 | 68 | retryCount: userOptions?.retryCount, |
65 | 69 | }); |
| 70 | + sentryClient?.metricsAggregator?.add( |
| 71 | + "c", |
| 72 | + "request_presigned_url.success", |
| 73 | + 1, |
| 74 | + ); |
66 | 75 | } catch (error) { |
| 76 | + sentryClient?.metricsAggregator?.add( |
| 77 | + "c", |
| 78 | + "request_presigned_url.error", |
| 79 | + 1, |
| 80 | + ); |
67 | 81 | return; |
| 82 | + } finally { |
| 83 | + sentryClient?.metricsAggregator?.add( |
| 84 | + "d", |
| 85 | + "request_presigned_url", |
| 86 | + Date.now() - getPreSignedURLStart, |
| 87 | + "millisecond", |
| 88 | + ); |
68 | 89 | } |
69 | 90 |
|
| 91 | + const uploadStart = Date.now(); |
70 | 92 | try { |
71 | 93 | await uploadStats({ |
72 | 94 | preSignedUrl: url, |
73 | 95 | message: JSON.stringify(output), |
74 | 96 | retryCount: userOptions?.retryCount, |
| 97 | + sentryClient, |
75 | 98 | }); |
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 | + } |
77 | 119 | }, |
78 | 120 | }; |
79 | 121 | }; |
0 commit comments