-
Notifications
You must be signed in to change notification settings - Fork 1.1k
refactor(wrangler): move telemetry events from yargs middleware to command handlers #12069
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
base: main
Are you sure you want to change the base?
Conversation
…mmand handlers This refactoring moves the telemetry events (wrangler command started/completed/errored) from the yargs middleware in index.ts to the command handler in register-yargs-command.ts. Benefits: - Telemetry is now sent after config is loaded, allowing access to send_metrics and hasAssets - Telemetry is only sent for commands that use defineCommand Key changes: - Add CommandHandledError wrapper class to signal when telemetry has been sent - Add getErrorType() function to classify errors for telemetry - Send telemetry events in register-yargs-command.ts after config is loaded - Preserve fallback telemetry in index.ts for yargs validation errors - Handle nested wrangler.parse() calls by not double-wrapping CommandHandledError - Properly unwrap CommandHandledError when writing command-failed output
|
…hers Move the requests tracking from per-dispatcher instance to module-level scope so that all dispatchers share the same Set of pending requests. This ensures all metrics requests are awaited before Wrangler exits, regardless of which dispatcher created them. - Add module-level pendingRequests Set with auto-cleanup via .finally() - Export waitForAllMetricsDispatches() to await all pending requests - Remove the per-dispatcher requests getter
| * Wait for all pending metrics requests to complete. | ||
| * This should be called before the process exits to ensure all metrics are sent. | ||
| */ | ||
| export function waitForAllMetricsDispatches(): Promise<void> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if you want to keep it sync getMetricsDispatchesCompleted could be a good name but looking at the call sites, making it async (+ keep the name) sounds like the best thing to do. There is only one call that is not awaited which is not a problem as it needs a promise.
Context: A lot (including me) have been confused by ctx.waitUntil being sync. My understanding is that the runtime team would change the name if it wasn't too late.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What do you mean by "make it async"? It returns a Promise, which makes it async from the outside. How it is implemented internally makes no difference.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
export async function waitForAllMetricsDispatches(): Promise<void>
or drop "waitFor" because sync function can't wait
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To be clearer:
export async function waitForAllMetricsDispatches(): Promise<void> {
await Promise.allSettled(pendingRequests);
}There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I still don't understand how this makes the function any clearer. It has the same signature: () => Promise<void>.
The caller doesn't see the async modifier in intellisense.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The comments for the PR review were taking from the previous PR (#12055)
be3fd85 to
e0829f5
Compare
create-cloudflare
@cloudflare/kv-asset-handler
miniflare
@cloudflare/pages-shared
@cloudflare/unenv-preset
@cloudflare/vite-plugin
@cloudflare/vitest-pool-workers
@cloudflare/workers-editor-shared
@cloudflare/workers-utils
wrangler
commit: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.

This refactoring moves the telemetry events (wrangler command started/completed/errored) from the yargs middleware in index.ts to the command handler in register-yargs-command.ts.
Benefits:
Telemetry is now sent after config is loaded, allowing access to send_metrics and hasAssets
Key changes:
A picture of a cute animal (not mandatory, but encouraged)