Send analytics in background - #7615
Conversation
|
/snapit |
972e250 to
f72a8d8
Compare
f72a8d8 to
ddc22d9
Compare
|
This PR seems inactive. If it's still relevant, please add a comment saying so. Otherwise, take no action. |
375d96d to
a23f004
Compare
This stack of pull requests is managed by Graphite. Learn more about stacking. |
0427849 to
603e207
Compare
|
/snapit |
603e207 to
f022390
Compare
|
/snapit |
|
🫰✨ Thanks @gonzaloriestra! Your snapshot has been published to npm. Test the snapshot by installing your package globally: pnpm i -g --@shopify:registry=https://registry.npmjs.org @shopify/cli@0.0.0-snapshot-20260727091503Caution After installing, validate the version by running |
f022390 to
aed6ae1
Compare
f9bd5d4 to
5325d2d
Compare
|
I think we should replace these command-name and launcher exceptions with command metadata. For example, add This also covers This keeps command lifecycle knowledge on the command and removes the |
5325d2d to
be36637
Compare
|
@isaacroldan Good point. That's something we need to improve for other things like notifications, but it's better to do it now. Fixed! |
a610c01 to
91a8307
Compare
|
/snapit |
|
🫰✨ Thanks @isaacroldan! Your snapshot has been published to npm. Test the snapshot by installing your package globally: pnpm i -g --@shopify:registry=https://registry.npmjs.org @shopify/cli@0.0.0-snapshot-20260812085842Caution After installing, validate the version by running |
isaacroldan
left a comment
There was a problem hiding this comment.
One stale change remains from the earlier file-based implementation.
🤖 Generated by the review-pr skill
isaacroldan
left a comment
There was a problem hiding this comment.
Two more command shutdown paths need synchronous analytics.
🤖 Generated by the review-pr skill
355a0e0 to
d8c60f1
Compare
isaacroldan
left a comment
There was a problem hiding this comment.
One remaining issue with background delivery.
🤖 Generated by the review-pr skill
d8c60f1 to
dd09d45
Compare
isaacroldan
left a comment
There was a problem hiding this comment.
Approving! great work, wasn't an easy change. We should keep an eye on analytics after the next release
dd09d45 to
9e31ede
Compare
Differences in type declarationsWe detected differences in the type declarations generated by Typescript for this branch compared to the baseline ('main' branch). Please, review them to ensure they are backward-compatible. Here are some important things to keep in mind:
New type declarationsWe found no new type declarations in this PR Existing type declarationspackages/cli-kit/dist/private/node/otel-metrics.d.ts@@ -2,7 +2,7 @@ import { OtelService } from '../../public/node/vendor/otel-js/service/types.js';
import { DefaultOtelServiceOptions } from '../../public/node/vendor/otel-js/service/DefaultOtelService/DefaultOtelService.js';
type MetricRecorder = 'console' | {
type: 'otel';
- otel: Pick<OtelService, 'record'>;
+ otel: Pick<OtelService, 'getMeterProvider' | 'record'>;
};
interface Timing {
active: number;
packages/cli-kit/dist/public/node/analytics.d.ts@@ -6,6 +6,7 @@ interface ReportAnalyticsEventOptions {
errorMessage?: string;
exitMode: CommandExitMode;
}
+export declare function sendAnalyticsEventFromStdin(): Promise<void>;
/**
* Report an analytics event, sending it off to Monorail -- Shopify's internal analytics service.
*
packages/cli-kit/dist/public/node/base-command.d.ts@@ -10,6 +10,7 @@ export interface NonTTYFlagRequirement {
}
declare abstract class BaseCommand extends Command {
static baseFlags: FlagInput<{}>;
+ static get requiresSyncAnalytics(): boolean;
static nonTTYFlagRequirements(_flags: FlagOutput): NonTTYFlagRequirement[];
static descriptionWithoutMarkdown(): string | undefined;
static analyticsNameOverride(): string | undefined;
packages/cli-kit/dist/public/node/metadata.d.ts@@ -42,6 +42,7 @@ declare const coreData: RuntimeMetadataManager<CmdFieldsFromMonorail, {
startCommand: string;
startTopic?: string;
startArgs: string[];
+ requiresSyncAnalytics?: boolean;
};
} & {
environmentFlags: string;
@@ -63,6 +64,7 @@ export declare const getAllPublicMetadata: () => Partial<CmdFieldsFromMonorail>,
startCommand: string;
startTopic?: string;
startArgs: string[];
+ requiresSyncAnalytics?: boolean;
};
} & {
environmentFlags: string;
@@ -83,6 +85,7 @@ export declare const getAllPublicMetadata: () => Partial<CmdFieldsFromMonorail>,
startCommand: string;
startTopic?: string;
startArgs: string[];
+ requiresSyncAnalytics?: boolean;
};
} & {
environmentFlags: string;
packages/cli-kit/dist/public/node/system.d.ts@@ -128,6 +128,12 @@ interface WslDetectionOverrides {
* @returns True if the current environment is a WSL environment.
*/
export declare function isWsl(overrides?: WslDetectionOverrides): Promise<boolean>;
+/**
+ * Check if the current process is running inside a container.
+ *
+ * @returns True if the current process is running inside a container.
+ */
+export declare function isInsideContainer(): boolean;
/**
* Check if stdin has piped data available.
* This distinguishes between actual piped input (e.g., `echo "query" | cmd`)
packages/cli-kit/dist/public/node/vendor/otel-js/service/types.d.ts@@ -1,5 +1,5 @@
-import type { Counter, Histogram, MeterProvider, MetricAttributes, MetricOptions, UpDownCounter } from '@opentelemetry/api';
-import type { ViewOptions } from '@opentelemetry/sdk-metrics';
+import type { Counter, Histogram, MetricAttributes, MetricOptions, UpDownCounter } from '@opentelemetry/api';
+import type { MeterProvider, ViewOptions } from '@opentelemetry/sdk-metrics';
export type CustomMetricLabels<TLabels extends Record<TKeys, MetricAttributes>, TKeys extends string = keyof TLabels & string> = {
[P in TKeys]: TLabels[P] extends MetricAttributes ? TLabels[P] : never;
};
|

WHY are these changes introduced?
HackDays project: https://vault.shopify.io/hackdays/154/projects/24279-Shopify-CLI-UX-improvements
Analytics delivery currently blocks command completion, adding noticeable latency to every CLI invocation.
WHAT is this pull request doing?
Passes the completed analytics payload over stdin to a detached internal command, allowing the original command to exit immediately.
This works for Mac and Linux, but on Windows we still have to wait for the process because of a known issue. We also wait on CI to avoid issues with the job teardown.
Benchmark for
shopify version:4.5.0snapshotdemo.mp4
How to test your changes?
pnpm i -g @shopify/cli@0.0.0-snapshot-20260811121607shopify version --verboseshopify deploy --wrong-flag-analytics-testChecklist
patchfor bug fixes ·minorfor new features ·majorfor breaking changes) and added a changeset withpnpm changeset add