Skip to content
Merged
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
5 changes: 5 additions & 0 deletions .changeset/app-logs-throttle-retry.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@shopify/app': patch
---

`shopify app logs` now says how long to wait when a search is throttled, and `--json` gives the wait in `error.details.retryAfterSeconds` and the remaining budget in `throttleStatus`.
6 changes: 6 additions & 0 deletions .changeset/node-22-20-floor.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'@shopify/cli-kit': minor
'@shopify/cli': minor
---

Require Node ^22.20.0 or >=24.5.0, the first releases built on OpenSSL 3.5
5 changes: 5 additions & 0 deletions .changeset/post-quantum-tunnel.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@shopify/plugin-cloudflare': patch
---

Cloudflare tunnels now require post-quantum key agreement; set `SHOPIFY_CLI_CLOUDFLARED_ENFORCE_POST_QUANTUM=0` to allow classical key agreement on networks that can't negotiate it.
4 changes: 2 additions & 2 deletions docs-shopify.dev/generated/generated_docs_data_v2.json
Original file line number Diff line number Diff line change
Expand Up @@ -3347,7 +3347,7 @@
"syntaxKind": "PropertySignature",
"name": "--sort <value>",
"value": "string",
"description": "Select the oldest/newest matches using server-side sorting. Omit for faster, less-throttled retrieval.",
"description": "Select the oldest/newest matches using server-side sorting. Costs 2 credits per search instead of 1.",
"isOptional": true,
"environmentValue": "SHOPIFY_FLAG_SORT"
},
Expand Down Expand Up @@ -3442,7 +3442,7 @@
"environmentValue": "SHOPIFY_FLAG_STORE"
}
],
"value": "export interface applogs {\n /**\n * Alias of the Shopify account to use for authentication.\n * @environment SHOPIFY_FLAG_AUTH_ALIAS\n */\n '--auth-alias <value>'?: string\n\n /**\n * The Client ID of your app.\n * @environment SHOPIFY_FLAG_CLIENT_ID\n */\n '--client-id <value>'?: string\n\n /**\n * The name of the app configuration.\n * @environment SHOPIFY_FLAG_APP_CONFIG\n */\n '-c, --config <value>'?: string\n\n /**\n * Exact app event or app billing event handle; excludes other record types.\n * @environment SHOPIFY_FLAG_EVENT_HANDLE\n */\n '--event-handle <value>'?: string\n\n /**\n * Exact Function extension handle; excludes non-Function records.\n * @environment SHOPIFY_FLAG_FUNCTION_HANDLE\n */\n '--function-handle <value>'?: string\n\n /**\n * Output the result as JSON. Automatically disables color output.\n * @environment SHOPIFY_FLAG_JSON\n */\n '-j, --json'?: ''\n\n /**\n * Print the command's JSON schemas.\n * @environment SHOPIFY_FLAG_JSON_SCHEMA\n */\n '--json-schema'?: ''\n\n /**\n * Maximum number of records to return, from 1 through 1000.\n * @environment SHOPIFY_FLAG_LIMIT\n */\n '--limit <value>'?: string\n\n /**\n * Exact REST HTTP method; excludes non-REST records.\n * @environment SHOPIFY_FLAG_METHOD\n */\n '--method <value>'?: string\n\n /**\n * Disable color output.\n * @environment SHOPIFY_FLAG_NO_COLOR\n */\n '--no-color'?: ''\n\n /**\n * Disable interactive prompts and browser authentication.\n * @environment SHOPIFY_FLAG_NO_INPUT\n */\n '--no-input'?: ''\n\n /**\n * Exact GraphQL operation name; excludes non-GraphQL records.\n * @environment SHOPIFY_FLAG_OPERATION_NAME\n */\n '--operation-name <value>'?: string\n\n /**\n * Exact GraphQL operation type; excludes non-GraphQL records.\n * @environment SHOPIFY_FLAG_OPERATION_TYPE\n */\n '--operation-type <value>'?: string\n\n /**\n * Sort direction: asc (oldest first, default with --sort) or desc (newest first).\n * @environment SHOPIFY_FLAG_ORDER\n */\n '--order <value>'?: string\n\n /**\n * The path to your app directory.\n * @environment SHOPIFY_FLAG_PATH\n */\n '--path <value>'?: string\n\n /**\n * Exact GraphQL or REST request ID; excludes other record types.\n * @environment SHOPIFY_FLAG_REQUEST_ID\n */\n '--request-id <value>'?: string\n\n /**\n * Exact REST request path; excludes non-REST records.\n * @environment SHOPIFY_FLAG_REQUEST_PATH\n */\n '--request-path <value>'?: string\n\n /**\n * Inclusive start: positive duration (s/m/h/d) or whole-second RFC 3339 timestamp.\n * @environment SHOPIFY_FLAG_SINCE\n */\n '--since <value>'?: string\n\n /**\n * Select the oldest/newest matches using server-side sorting. Omit for faster, less-throttled retrieval.\n * @environment SHOPIFY_FLAG_SORT\n */\n '--sort <value>'?: string\n\n /**\n * Recorded result status; not inferred from HTTP codes or response bodies.\n * @environment SHOPIFY_FLAG_STATUS\n */\n '--status <value>'?: string\n\n /**\n * Exact webhook or REST HTTP status code (100–599); no status classes.\n * @environment SHOPIFY_FLAG_STATUS_CODE\n */\n '--status-code <value>'?: string\n\n /**\n * Exact store handle or myshopify.com domain/URL.\n * @environment SHOPIFY_FLAG_STORE\n */\n '-s, --store <value>'?: string\n\n /**\n * Exact Function execution or UI extension target; excludes other record types.\n * @environment SHOPIFY_FLAG_TARGET\n */\n '--target <value>'?: string\n\n /**\n * Exact webhook topic; excludes non-webhook records.\n * @environment SHOPIFY_FLAG_TOPIC\n */\n '--topic <value>'?: string\n\n /**\n * Log type; repeat to select multiple. Defaults to all supported types.\n * @environment SHOPIFY_FLAG_TYPE\n */\n '--type <value>'?: string\n\n /**\n * Exclusive whole-second RFC 3339 end; defaults to the current time.\n * @environment SHOPIFY_FLAG_UNTIL\n */\n '--until <value>'?: string\n\n /**\n * Increase the verbosity of the output. May include sensitive data.\n * @environment SHOPIFY_FLAG_VERBOSE\n */\n '--verbose'?: ''\n}"
"value": "export interface applogs {\n /**\n * Alias of the Shopify account to use for authentication.\n * @environment SHOPIFY_FLAG_AUTH_ALIAS\n */\n '--auth-alias <value>'?: string\n\n /**\n * The Client ID of your app.\n * @environment SHOPIFY_FLAG_CLIENT_ID\n */\n '--client-id <value>'?: string\n\n /**\n * The name of the app configuration.\n * @environment SHOPIFY_FLAG_APP_CONFIG\n */\n '-c, --config <value>'?: string\n\n /**\n * Exact app event or app billing event handle; excludes other record types.\n * @environment SHOPIFY_FLAG_EVENT_HANDLE\n */\n '--event-handle <value>'?: string\n\n /**\n * Exact Function extension handle; excludes non-Function records.\n * @environment SHOPIFY_FLAG_FUNCTION_HANDLE\n */\n '--function-handle <value>'?: string\n\n /**\n * Output the result as JSON. Automatically disables color output.\n * @environment SHOPIFY_FLAG_JSON\n */\n '-j, --json'?: ''\n\n /**\n * Print the command's JSON schemas.\n * @environment SHOPIFY_FLAG_JSON_SCHEMA\n */\n '--json-schema'?: ''\n\n /**\n * Maximum number of records to return, from 1 through 1000.\n * @environment SHOPIFY_FLAG_LIMIT\n */\n '--limit <value>'?: string\n\n /**\n * Exact REST HTTP method; excludes non-REST records.\n * @environment SHOPIFY_FLAG_METHOD\n */\n '--method <value>'?: string\n\n /**\n * Disable color output.\n * @environment SHOPIFY_FLAG_NO_COLOR\n */\n '--no-color'?: ''\n\n /**\n * Disable interactive prompts and browser authentication.\n * @environment SHOPIFY_FLAG_NO_INPUT\n */\n '--no-input'?: ''\n\n /**\n * Exact GraphQL operation name; excludes non-GraphQL records.\n * @environment SHOPIFY_FLAG_OPERATION_NAME\n */\n '--operation-name <value>'?: string\n\n /**\n * Exact GraphQL operation type; excludes non-GraphQL records.\n * @environment SHOPIFY_FLAG_OPERATION_TYPE\n */\n '--operation-type <value>'?: string\n\n /**\n * Sort direction: asc (oldest first, default with --sort) or desc (newest first).\n * @environment SHOPIFY_FLAG_ORDER\n */\n '--order <value>'?: string\n\n /**\n * The path to your app directory.\n * @environment SHOPIFY_FLAG_PATH\n */\n '--path <value>'?: string\n\n /**\n * Exact GraphQL or REST request ID; excludes other record types.\n * @environment SHOPIFY_FLAG_REQUEST_ID\n */\n '--request-id <value>'?: string\n\n /**\n * Exact REST request path; excludes non-REST records.\n * @environment SHOPIFY_FLAG_REQUEST_PATH\n */\n '--request-path <value>'?: string\n\n /**\n * Inclusive start: positive duration (s/m/h/d) or whole-second RFC 3339 timestamp.\n * @environment SHOPIFY_FLAG_SINCE\n */\n '--since <value>'?: string\n\n /**\n * Select the oldest/newest matches using server-side sorting. Costs 2 credits per search instead of 1.\n * @environment SHOPIFY_FLAG_SORT\n */\n '--sort <value>'?: string\n\n /**\n * Recorded result status; not inferred from HTTP codes or response bodies.\n * @environment SHOPIFY_FLAG_STATUS\n */\n '--status <value>'?: string\n\n /**\n * Exact webhook or REST HTTP status code (100–599); no status classes.\n * @environment SHOPIFY_FLAG_STATUS_CODE\n */\n '--status-code <value>'?: string\n\n /**\n * Exact store handle or myshopify.com domain/URL.\n * @environment SHOPIFY_FLAG_STORE\n */\n '-s, --store <value>'?: string\n\n /**\n * Exact Function execution or UI extension target; excludes other record types.\n * @environment SHOPIFY_FLAG_TARGET\n */\n '--target <value>'?: string\n\n /**\n * Exact webhook topic; excludes non-webhook records.\n * @environment SHOPIFY_FLAG_TOPIC\n */\n '--topic <value>'?: string\n\n /**\n * Log type; repeat to select multiple. Defaults to all supported types.\n * @environment SHOPIFY_FLAG_TYPE\n */\n '--type <value>'?: string\n\n /**\n * Exclusive whole-second RFC 3339 end; defaults to the current time.\n * @environment SHOPIFY_FLAG_UNTIL\n */\n '--until <value>'?: string\n\n /**\n * Increase the verbosity of the output. May include sensitive data.\n * @environment SHOPIFY_FLAG_VERBOSE\n */\n '--verbose'?: ''\n}"
}
},
"apprelease": {
Expand Down
2 changes: 1 addition & 1 deletion packages/app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@
"@vitest/coverage-istanbul": "^3.2.7"
},
"engines": {
"node": ">=22.12.0"
"node": "^22.20.0 || >=24.5.0"
},
"os": [
"darwin",
Expand Down
65 changes: 65 additions & 0 deletions packages/app/src/cli/commands/app/logs.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,27 @@ import {prepareLogInput} from '../../services/historical-logs/input.js'
import {logsOutput, type LogsResult} from '../../services/historical-logs/types.js'
import {Config} from '@oclif/core'
import {afterEach, beforeEach, expect, test, vi} from 'vitest'
import {appManagementRequestDoc} from '@shopify/cli-kit/node/api/app-management'
import {Response, shopifyFetch} from '@shopify/cli-kit/node/http'
import {ensureAuthenticatedAppManagementAndBusinessPlatform} from '@shopify/cli-kit/node/session'
import {mockAndCaptureOutput, withCapturedStandardStreams} from '@shopify/cli-kit/node/testing/output'

vi.mock('../../services/historical-logs/service.js', async (importOriginal) => ({
...(await importOriginal<typeof import('../../services/historical-logs/service.js')>()),
retrieveLogs: vi.fn(),
}))
vi.mock('@shopify/cli-kit/node/http', async (importOriginal) => ({
...(await importOriginal<typeof import('@shopify/cli-kit/node/http')>()),
shopifyFetch: vi.fn(),
}))
vi.mock('@shopify/cli-kit/node/session', async (importOriginal) => ({
...(await importOriginal<typeof import('@shopify/cli-kit/node/session')>()),
ensureAuthenticatedAppManagementAndBusinessPlatform: vi.fn(),
}))
vi.mock('@shopify/cli-kit/node/api/app-management', async (importOriginal) => ({
...(await importOriginal<typeof import('@shopify/cli-kit/node/api/app-management')>()),
appManagementRequestDoc: vi.fn(),
}))

const originalColumns = Object.getOwnPropertyDescriptor(process.stdout, 'columns')

Expand Down Expand Up @@ -65,6 +80,56 @@ test('help states the backend time-window limits', () => {
expect(Logs.description).toContain('Maximum: 1-day window within the last 7 days, 1000 records.')
})

// The network, the session, the command's init hooks and process.exit are fake. The command, its service, the
// fatal-error handler and the JSON renderer are real, and the assertions read the bytes written to stdout.
test('a throttled --json search writes one JSON line that keeps line breaks in its messages', async () => {
const actualService = await vi.importActual<typeof import('../../services/historical-logs/service.js')>(
'../../services/historical-logs/service.js',
)
vi.mocked(retrieveLogs).mockImplementation(actualService.retrieveLogs)
vi.mocked(ensureAuthenticatedAppManagementAndBusinessPlatform).mockResolvedValue({
appManagementToken: 'test-identity-token',
userId: 'test-user',
businessPlatformToken: 'test-business-token',
})
vi.mocked(appManagementRequestDoc).mockResolvedValue({
app: {key: 'test-app', organizationId: 'gid://shopify/Organization/42'},
})
const errors = [
{
message: 'Usage throttled\n\nTry again',
path: ['app', 'logs'],
extensions: {code: 'THROTTLED', retryAfterSeconds: 42},
},
]
vi.mocked(shopifyFetch).mockResolvedValue(
new Response(JSON.stringify({data: {app: {logs: null}}, errors}), {
status: 200,
headers: {'x-request-id': 'request-123'},
}),
)
vi.stubEnv('SHOPIFY_CLI_NO_ANALYTICS', '1')
vi.spyOn(Logs.prototype as unknown as {init(): Promise<unknown>}, 'init').mockResolvedValue(undefined)
vi.spyOn(process, 'exit').mockImplementation(() => undefined as never)
const command = new Logs(['--client-id', 'test-app', '--json', '--no-input'], await Config.load())

await withCapturedStandardStreams(async ({stdout, stderr}) => {
await (command as unknown as {_run(): Promise<unknown>})._run()

expect(stdout().trimEnd().split('\n')).toHaveLength(1)
expect(JSON.parse(stdout())).toEqual({
error: {
type: 'abort',
message: 'App Logs throttled this query. Try again in about 42 seconds.\n\nRequest ID: request-123',
code: 'rate-limited',
details: {requestId: 'request-123', errors, retryAfterSeconds: 42},
},
})
expect(stderr()).toBe('')
})
expect(process.exit).toHaveBeenCalledWith(1)
})

test('parses space/equals forms and forwards effective defaults', async () => {
vi.mocked(retrieveLogs).mockResolvedValue(result())
await new Logs(
Expand Down
4 changes: 3 additions & 1 deletion packages/app/src/cli/commands/app/logs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,12 @@ export default class Logs extends BaseCommand {
static summary = 'Lists historical app logs.'
static descriptionWithMarkdown = `Returns a list of historical app logs and exits. Defaults to all supported log types. Use --type to select a type; repeat it to select multiple.

Fast retrieval is the default: leave out --sort. Prefer this mode with a narrow time window and selective filters to consume less throttle capacity. The CLI orders the returned records oldest first, but when the limit is reached they aren't necessarily the oldest or newest matches.
Fast retrieval is the default: leave out --sort. The CLI orders the returned records oldest first, but when the limit is reached they aren't necessarily the oldest or newest matches.

Use server-side sorting only when selecting the oldest or newest matching records matters: --sort timestamp selects oldest first; add --order desc for newest first. This sorts before the result limit and is subject to API query limits.

Each search spends credits from your throttle budget for the organization, which all your apps and CLI sessions there share. A search without --sort costs 1 credit; a search with --sort costs 2. The time window and --limit don't change the cost, and a throttled search costs nothing. With --json, a throttled search fails with the error code rate-limited, and error.details.retryAfterSeconds gives the seconds to wait when the API returns it.

When fewer than --limit records are returned, all matching records available at query time were returned. Sorting isn't needed to establish completeness.

Different filters combine with AND; each accepts one exact value. Type-specific filters, such as --topic, need a --type they apply to and exclude records without that field; combining --topic and --operation-name returns no records. --store, --status, --request-id and --status-code work without --type.
Expand Down
Loading
Loading