diff --git a/.changeset/fair-actors-appear.md b/.changeset/fair-actors-appear.md new file mode 100644 index 000000000000..41766d67a3c6 --- /dev/null +++ b/.changeset/fair-actors-appear.md @@ -0,0 +1,5 @@ +--- +"wrangler": minor +--- + +Add duration and sourcemap size to upload metrics event diff --git a/packages/wrangler/src/deploy/deploy.ts b/packages/wrangler/src/deploy/deploy.ts index 108c922aa61c..b83f8bff9693 100644 --- a/packages/wrangler/src/deploy/deploy.ts +++ b/packages/wrangler/src/deploy/deploy.ts @@ -305,7 +305,9 @@ Update them to point to this script instead?`; return domains.map((domain) => renderRoute(domain)); } -export default async function deploy(props: Props): Promise { +export default async function deploy( + props: Props +): Promise<{ sourceMapSize?: number }> { // TODO: warn if git/hg has uncommitted changes const { config, accountId, name } = props; if (!props.dispatchNamespace && accountId && name) { @@ -324,14 +326,14 @@ export default async function deploy(props: Props): Promise { `You are about to publish a Workers Service that was last published via the Cloudflare Dashboard.\nEdits that have been made via the dashboard will be overridden by your local code and config.` ); if (!(await confirm("Would you like to continue?"))) { - return; + return {}; } } else if (default_environment.script.last_deployed_from === "api") { logger.warn( `You are about to publish a Workers Service that was last updated via the script API.\nEdits that have been made via the script API will be overridden by your local code and config.` ); if (!(await confirm("Would you like to continue?"))) { - return; + return {}; } } } catch (e) { @@ -441,7 +443,7 @@ See https://developers.cloudflare.com/workers/platform/compatibility-dates for m const yes = await confirmLatestDeploymentOverwrite(accountId, scriptName); if (!yes) { cancel("Aborting deploy..."); - return; + return {}; } } @@ -473,6 +475,8 @@ See https://developers.cloudflare.com/workers/platform/compatibility-dates for m ); } + let sourceMapSize; + try { if (props.noBundle) { // if we're not building, let's just copy the entry to the destination directory @@ -676,6 +680,11 @@ See https://developers.cloudflare.com/workers/platform/compatibility-dates for m limits: config.limits, }; + sourceMapSize = worker.sourceMaps?.reduce( + (acc, m) => acc + m.content.length, + 0 + ); + await printBundleSize( { name: path.basename(resolvedEntryPointPath), content: content }, modules @@ -810,7 +819,7 @@ See https://developers.cloudflare.com/workers/platform/compatibility-dates for m if (props.dryRun) { logger.log(`--dry-run: exiting now.`); - return; + return {}; } assert(accountId, "Missing accountId"); @@ -821,7 +830,7 @@ See https://developers.cloudflare.com/workers/platform/compatibility-dates for m // Early exit for WfP since it doesn't need the below code if (props.dispatchNamespace !== undefined) { deployWfpUserWorker(props.dispatchNamespace, deploymentId); - return; + return {}; } // deploy triggers @@ -831,6 +840,8 @@ See https://developers.cloudflare.com/workers/platform/compatibility-dates for m logger.log("Current Version ID:", deploymentId); logVersionIdChange(); + + return { sourceMapSize }; } function deployWfpUserWorker( diff --git a/packages/wrangler/src/deploy/index.ts b/packages/wrangler/src/deploy/index.ts index 4bf5b6bbe244..070753e0590b 100644 --- a/packages/wrangler/src/deploy/index.ts +++ b/packages/wrangler/src/deploy/index.ts @@ -217,6 +217,7 @@ export function deployOptions(yargs: CommonYargsArgv) { export async function deployHandler( args: StrictYargsOptionsToInterface ) { + const beforeUpload = Date.now(); await printWranglerBanner(); // Check for deprecated `wrangler publish` command @@ -231,15 +232,6 @@ export async function deployHandler( const projectRoot = configPath && path.dirname(configPath); const config = readConfig(configPath, args); const entry = await getEntry(args, config, "deploy"); - await metrics.sendMetricsEvent( - "deploy worker script", - { - usesTypeScript: /\.tsx?$/.test(entry.file), - }, - { - sendMetrics: config.send_metrics, - } - ); if (args.public) { throw new UserError("The --public field has been renamed to --assets"); @@ -287,7 +279,7 @@ export async function deployHandler( await standardPricingWarning(config); } - await deploy({ + const { sourceMapSize } = await deploy({ config, accountId, name: getScriptName(args, config), @@ -322,4 +314,16 @@ export async function deployHandler( dispatchNamespace: args.dispatchNamespace, experimentalVersions: args.experimentalVersions, }); + + await metrics.sendMetricsEvent( + "deploy worker script", + { + usesTypeScript: /\.tsx?$/.test(entry.file), + durationMs: Date.now() - beforeUpload, + sourceMapSize, + }, + { + sendMetrics: config.send_metrics, + } + ); }