Skip to content

Avoid metrics-only store analytics lookups#7478

Open
dmerand wants to merge 3 commits intomainfrom
dlm-store-command-metrics-followup
Open

Avoid metrics-only store analytics lookups#7478
dmerand wants to merge 3 commits intomainfrom
dlm-store-command-metrics-followup

Conversation

@dmerand
Copy link
Copy Markdown
Contributor

@dmerand dmerand commented May 6, 2026

Summary

  • align the CLI Monorail mirror to app_cli3_command/1.24
  • remove shop_id from the store command analytics payload
  • add store_fqdn_validated so requested store attribution is distinct from validated store attribution
  • rename the store analytics helper to attribution.ts

Why

  • follow the Slack-thread direction to avoid extra CLI network calls purely for analytics enrichment
  • keep store attribution owned by the store auth / execute flows instead of shared base parsing
  • preserve requested-store attribution even when store auth or store execute fail before an authenticated store context is established

Behavior changes

  • store auth records the requested store early and marks it validated only after token exchange succeeds
  • store execute records the requested store before request validation and records the validated store after loading the stored session
  • shop_id is no longer emitted, including from the publicApiVersions request path
Command/path Requested store recorded Validated store recorded Final store_fqdn_validated
store auth before OAuth completes yes no false
store auth after token exchange succeeds yes yes true
store execute before stored session load yes no false
store execute after stored session loads yes yes true
store execute with no stored auth / early failure yes no false

store_fqdn_validated=true means the FQDN was validated against an authenticated store context. It does not imply the command later completed successfully.

Depends on Shopify/monorail#23622.

@github-actions github-actions Bot added the no-changelog This PR doesn't include a changeset entry. Is an internal only change not relevant to end users. label May 6, 2026
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 6, 2026

Differences in type declarations

We 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:

  • Some seemingly private modules might be re-exported through public modules.
  • If the branch is behind main you might see odd diffs, rebase main into this branch.

New type declarations

We found no new type declarations in this PR

Existing type declarations

packages/cli-kit/dist/public/node/metadata.d.ts
@@ -34,7 +34,7 @@ export type SensitiveSchema<T> = T extends RuntimeMetadataManager<infer _TPublic
  * @returns A container for the metadata.
  */
 export declare function createRuntimeMetadataContainer<TPublic extends AnyJson, TSensitive extends AnyJson = Record<string, never>>(defaultPublicMetadata?: Partial<TPublic>): RuntimeMetadataManager<TPublic, TSensitive>;
-type CmdFieldsFromMonorail = Pick<MonorailEventPublic, 'shop_id'> & PickByPrefix<MonorailEventPublic, 'cmd_all_'> & PickByPrefix<MonorailEventPublic, 'cmd_app_'> & PickByPrefix<MonorailEventPublic, 'cmd_create_app_'> & PickByPrefix<MonorailEventPublic, 'cmd_theme_'> & PickByPrefix<MonorailEventPublic, 'store_'> & PickByPrefix<MonorailEventPublic, 'env_auto_upgrade_'>;
+type CmdFieldsFromMonorail = PickByPrefix<MonorailEventPublic, 'cmd_all_'> & PickByPrefix<MonorailEventPublic, 'cmd_app_'> & PickByPrefix<MonorailEventPublic, 'cmd_create_app_'> & PickByPrefix<MonorailEventPublic, 'cmd_theme_'> & PickByPrefix<MonorailEventPublic, 'store_'> & PickByPrefix<MonorailEventPublic, 'env_auto_upgrade_'>;
 declare const coreData: RuntimeMetadataManager<CmdFieldsFromMonorail, {
     commandStartOptions: {
         startTime: number;
packages/cli-kit/dist/public/node/monorail.d.ts
@@ -2,7 +2,7 @@ import { JsonMap } from '../../private/common/json.js';
 import { DeepRequired } from '../common/ts/deep-required.js';
 export { DeepRequired };
 type Optional<T> = T | null;
-export declare const MONORAIL_COMMAND_TOPIC = "app_cli3_command/1.23";
+export declare const MONORAIL_COMMAND_TOPIC = "app_cli3_command/1.24";
 export interface Schemas {
     [MONORAIL_COMMAND_TOPIC]: {
         sensitive: {
@@ -32,7 +32,7 @@ export interface Schemas {
             node_version: string;
             is_employee: boolean;
             store_fqdn_hash?: Optional<string>;
-            shop_id?: Optional<number>;
+            store_fqdn_validated?: Optional<boolean>;
             user_id: string;
             cmd_all_alias_used?: Optional<string>;
             cmd_all_launcher?: Optional<string>;

@dmerand dmerand marked this pull request as ready for review May 6, 2026 17:20
@dmerand dmerand requested a review from a team as a code owner May 6, 2026 17:20
Copilot AI review requested due to automatic review settings May 6, 2026 17:20
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR refactors store-command analytics attribution to avoid extra network calls done solely for metrics enrichment, while updating the CLI’s Monorail schema/topic to support distinguishing “requested” vs “validated” store attribution.

Changes:

  • Removes the shared StoreCommand.parse()-time store metadata recording and replaces it with explicit attribution recording in store auth and store execute flows.
  • Deletes shop_id analytics enrichment (including the Admin API lookup and the publicApiVersions query path) to avoid metrics-only network calls.
  • Updates Monorail topic/schema from app_cli3_command/1.23 to app_cli3_command/1.24 and adds store_fqdn_validated to the public payload.

Reviewed changes

Copilot reviewed 19 out of 19 changed files in this pull request and generated no comments.

Show a summary per file
File Description
packages/store/src/cli/utilities/store-command.ts Removes base parsing side-effects that recorded store analytics metadata.
packages/store/src/cli/utilities/store-command.test.ts Updates expectations to ensure base parsing no longer records store attribution.
packages/store/src/cli/services/store/metrics.ts Deletes the previous metrics helpers (hash + shop_id enrichment + Admin API lookup).
packages/store/src/cli/services/store/metrics.test.ts Removes tests for deleted metrics helpers.
packages/store/src/cli/services/store/execute/index.ts Records requested store attribution at the start of store execute.
packages/store/src/cli/services/store/execute/index.test.ts Adds coverage ensuring requested store attribution is recorded even when request prep fails.
packages/store/src/cli/services/store/execute/admin-transport.ts Removes shop id selection/recording from the public API versions request.
packages/store/src/cli/services/store/execute/admin-transport.test.ts Updates tests to reflect removal of shop id behavior from the transport.
packages/store/src/cli/services/store/execute/admin-context.ts Records validated store attribution after loading the stored store session; removes shop_id enrichment call.
packages/store/src/cli/services/store/execute/admin-context.test.ts Updates assertions and adds coverage for attribution behavior around failures and store mismatch cases.
packages/store/src/cli/services/store/auth/index.ts Records requested attribution early and validated attribution after token exchange; removes shop_id enrichment.
packages/store/src/cli/services/store/auth/index.test.ts Adds coverage to ensure attribution is recorded at the intended points across failure modes.
packages/store/src/cli/services/store/attribution.ts Introduces recordStoreFqdnMetadata(store, validated) to centralize attribution recording.
packages/store/src/cli/services/store/attribution.test.ts Adds unit test for the new attribution helper (sensitive store + hashed public + validated state).
packages/store/src/cli/commands/store/execute.test.ts Updates mocks to reflect metrics helper rename/removal.
packages/store/src/cli/commands/store/auth.test.ts Updates mocks to reflect metrics helper rename/removal.
packages/cli-kit/src/public/node/monorail.ts Bumps Monorail topic to 1.24 and replaces shop_id with store_fqdn_validated.
packages/cli-kit/src/public/node/monorail.test.ts Adds coverage for publishing the real command topic including validated store attribution.
packages/cli-kit/src/public/node/metadata.ts Removes shop_id from the set of tracked Monorail-derived fields.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

no-changelog This PR doesn't include a changeset entry. Is an internal only change not relevant to end users.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants