Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: add upload duration and sourcemap size to metrics #6194

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .changeset/fair-actors-appear.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
"wrangler": minor
---

chore: Add duration and sourcemap size to upload metrics event

Wrangler will now send the duration and the total size of any sourcemaps uploaded with your Worker to Cloudflare if you have metrics enabled.
23 changes: 17 additions & 6 deletions packages/wrangler/src/deploy/deploy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<void> {
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) {
Expand All @@ -324,14 +326,14 @@ export default async function deploy(props: Props): Promise<void> {
`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) {
Expand Down Expand Up @@ -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 {};
}
}

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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");

Expand All @@ -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
Expand All @@ -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(
Expand Down
24 changes: 14 additions & 10 deletions packages/wrangler/src/deploy/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -231,15 +231,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");
Expand Down Expand Up @@ -287,7 +278,8 @@ export async function deployHandler(
await standardPricingWarning(config);
}

await deploy({
const beforeUpload = Date.now();
const { sourceMapSize } = await deploy({
config,
accountId,
name: getScriptName(args, config),
Expand Down Expand Up @@ -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,
}
);
}
Loading