fix(telemetry): Telemetry command-run instrumentation pass (#1446, #1447, #1448, #1439) - #71

Draft
aidandaly24 wants to merge 1 commit into
mainfrom
fix/1446-1447
Draft

fix(telemetry): Telemetry command-run instrumentation pass (#1446, #1447, #1448, #1439)#71
aidandaly24 wants to merge 1 commit into
mainfrom
fix/1446-1447

Conversation

@aidandaly24

Copy link
Copy Markdown
Owner

Refs aws#1446
Refs aws#1447
Refs aws#1448
Refs aws#1439

Issues

Root cause

verified above

Feature request to instrument eval/observability commands. Telemetry is only emitted via withCommandRunTelemetry/runCliCommand -> recordCommandRun -> client.emit('cli.command_run',...) (src/cli/telemetry/cli-command-run.ts:41). COMMAND_SCHEMAS already defines shapes (src/cli/telemetry/schemas/command-run.ts: 'run.eval':245, 'pause.online-eval'/'resume.online-eval':258-259, 'pause.online-insights'/'resume.online-insights':260-261, 'traces.list'/'traces.get':262-263), but handlers were never wired: run/command.tsx:170 calls handleRunEval directly; TUI RunEvalFlow.tsx:149 unwrapped; pause/command.tsx registerOnlineEvalSubcommand(l.50)/registerOnlineInsightsSubcommand(l.141) call handlePauseResume directly (only registerABTestSubcommand l.85 records); traces/command.tsx:35,107 call handlers directly. logs/command.tsx:35,64 already wrap, so 'logs' is done. No commit/PR references aws#1447.

Telemetry is opt-in per command; the fetch.access schema (command-run.ts:173,255) was scaffolded but neither emit site (CLI command.tsx action lines 21-95, TUI useFetchAccessFlow.ts) was ever wired, so cli.command_run is never recorded for fetch. Verified: no telemetry import/call in either file, no global Commander hook in cli.ts, and 'fetch.access' is never passed to any emit/record/wrapper outside the schema definition.

process.exit in CLI command actions bypasses main finally that runs shutdown.

The fix

Add a config entry to COMMAND_SCHEMAS in src/cli/telemetry/schemas/command-run.ts -- a small ConfigAttrs with a config_action enum ('get'|'list'|'set') derived from key/value presence (do NOT log key or value: PII/secret risk). Then wrap the action in src/cli/commands/config/command.ts:26-30 as const result = await withCommandRunTelemetry('config', attrs, () => resolveAction(key,value)()); keeping the existing printResult()/process.exit(1). No design decision is actually needed: withCommandRunTelemetry already handles {success:false} Results natively (cli-command-run.ts:107-118 routes !result.success through classifyError(result.error) to record exit_reason='failure'), and the config handlers in actions.ts all return ConfigResult unions and never throw -- so the failure path is captured automatically. Mirror the status command which uses this exact pattern (status/command.tsx:95-98). This satisfies both DoD items (schema + instrumentation).

Mechanical wiring; schemas already exist. (1) run/command.tsx run-eval action (~l.170): wrap handleRunEval in withCommandRunTelemetry('run.eval', {evaluator_count, ref_type, has_assertions, has_expected_trajectory, has_expected_response}) derived from options; mirror in RunEvalFlow.tsx:149 for the TUI path. (2) pause/command.tsx + resume/command.tsx: wrap handlePauseResume in registerOnlineEvalSubcommand/registerOnlineInsightsSubcommand with withCommandRunTelemetry('pause.online-eval'|'resume.online-eval'|'pause.online-insights'|'resume.online-insights', {ref_type}) — both files share these factory functions, so one edit covers pause+resume. (3) traces/command.tsx list/get (~l.35, l.107): wrap handleTracesList/handleTracesGet in withCommandRunTelemetry('traces.list'|'traces.get', {}), optionally upgrade NoAttrs (command-run.ts:262-263) to a small shape (has_runtime/has_since/limit). 'logs' is already done. Design decision: confirm with the author whether 'logs' refers to logs/logs.evals (already instrumented) and whether traces warrants richer attrs than NoAttrs.

Instrument both fetch entry points with the existing helpers, mirroring validate (src/cli/commands/validate/command.tsx:14 uses withCommandRunTelemetry('validate', {}, ...)). (1) CLI: in src/cli/commands/fetch/command.tsx wrap the handleFetchAccess flow in runCliCommand('fetch.access', !!options.json, async () => { ...; return { resource_type: standardize(ResourceType, options.type ?? 'gateway') }; }) — runCliCommand fits because the action owns its own process.exit calls (lines 34, 63, 69); note the action's current early-return-without-exit on JSON success (lines 68-69) means the body needs minor restructuring to return attrs through the wrapper rather than falling through. (2) TUI: in src/cli/tui/screens/fetch-access/useFetchAccessFlow.ts wrap the fetch operation in withCommandRunTelemetry('fetch.access', { resource_type: standardize(ResourceType, resource.resourceType) }, ...) at the fetch call site (~lines 106-133). standardize is exported at common-shapes.ts:20. No schema change needed — fetch.access/FetchAccessAttrs already exist.

Move audit message into flush and add shared finalize before process.exit.

Files touched: src/cli/commands/config/command.ts (action at lines 26-30, wrap resolveAction in withCommandRunTelemetry); src/cli/telemetry/schemas/command-run.ts (add a ConfigAttrs near line 209 and a config: key into COMMAND_SCHEMAS ~215-302); src/cli/telemetry/schemas/common-shapes.ts (add a ConfigAction enum used by ConfigAttrs)

src/cli/commands/run/command.tsx (run-eval action ~line 170); src/cli/tui/screens/run-eval/RunEvalFlow.tsx (~line 149); src/cli/commands/pause/command.tsx (registerOnlineEvalSubcommand ~line 50, registerOnlineInsightsSubcommand ~line 141 — shared with resume via the same factory functions); src/cli/commands/resume/command.tsx (registerResume reuses those factories); src/cli/commands/traces/command.tsx (list ~line 35, get ~line 107); optional attr-shape upgrade in src/cli/telemetry/schemas/command-run.ts lines 262-263. All schema slots already exist.

src/cli/commands/fetch/command.tsx (the .action handler, lines 21-95 — add runCliCommand wrapper, restructure to return resource_type attrs); src/cli/tui/screens/fetch-access/useFetchAccessFlow.ts (add withCommandRunTelemetry wrapper at the fetch-operation call site, ~lines 106-133). No change needed in src/cli/telemetry/schemas/command-run.ts — fetch.access/FetchAccessAttrs already exist (lines 173, 255).

src/cli/telemetry/sinks/filesystem-sink.ts and src/cli/telemetry/cli-command-run.ts

Validation evidence

The fix was verified by reproducing the original symptom and re-running after the change:

Built OK first try -> dist/cli/index.mjs. Reproduced BOTH halves of the symptom by rebuilding the ORIGINAL (stashed-fix) binary and the FIXED binary and diffing behavior with AGENTCORE_TELEMETRY_AUDIT=1.

(1) Finalize ordering / dropped tail output, on the runCliCommand path agentcore feedback "test feedback acfix-1446-1447" --json: ORIGINAL build wrote the cli.command_run event into the audit .jsonl (attrs: command=feedback, exit_reason=failure) but printed NO [audit mode] Telemetry written to ... line to stdout, because process.exit(1) in runCliCommand fired before TelemetryClientAccessor.shutdown(). FIXED build records the SAME event AND prints [audit mode] Telemetry written to /tmp/audit-fix-fb/.agentcore/telemetry/feedback-...jsonl before exiting; exit code preserved. The shutdown+notices now run inside finalizeAndExit() which executes prior to process.exit (cli.ts registers postCommandFinalize; runCliCommand/config/fetch/pause/run/traces all return finalizeAndExit(code)).

(2) Coverage: ORIGINAL agentcore config telemetry.enabled false created NO telemetry dir at all (zero cli.command_run). FIXED records exactly one event per invocation: config (no key) -> config_action=list, exit_reason=success; config telemetry.enabled (unset get) -> config_action=get, exit_reason=failure; config telemetry.enabled false -> config_action=set, exit_reason=success. Inspected attrs: only the derived config_action is recorded, NO key/value PII (PII keys present: []). Success/failur

Test suite: green.


Staged on the fork as a draft for human review. Promote to aws/agentcore-cli after vetting.

…39) + command_run instrumentation for config (1446), run-eval/pause/resume online-eval+online-insights/traces (1447), and the fetch-access TUI path (1448). fetch-access CLI and run.job/ab-test were already instrumented at HEAD.
@github-actionsgithub-actionsBot added the size/m PR size: M label Jun 25, 2026
@github-actions

Copy link
Copy Markdown

Coverage Report

StatusCategoryPercentageCovered / Total
🔵Lines37.18%13609 / 36597
🔵Statements36.45%14468 / 39688
🔵Functions31.83%2339 / 7348
🔵Branches31.09%9002 / 28948
Generated in workflow #125 for commit 4c9dec5 by the Vitest Coverage Report Action

@github-actionsgithub-actionsBot added agentcore-harness-reviewing AgentCore Harness review in progress and removed agentcore-harness-reviewing AgentCore Harness review in progress labels Jun 25, 2026
@aidandaly24aidandaly24 changed the title fix(cli): Telemetry command-run instrumentation pass: wrap the un-i... (#1446, #1447, #1448, #1439)fix(telemetry): Telemetry command-run instrumentation pass (#1446, #1447, #1448, #1439)Jun 25, 2026
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size/mPR size: M

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant

@aidandaly24
, 'i'); if (__m === '*' || __re.test(location.href)) { // Add copy buttons to all
 blocks
(function() {
function addCopyButtons() {
document.querySelectorAll('pre code').forEach(function(codeBlock) {
if (codeBlock.parentElement.hasAttribute('data-copy-added')) return;
codeBlock.parentElement.setAttribute('data-copy-added', 'true');
var btn = document.createElement('button');
btn.textContent = 'Copy';
btn.style.cssText = 'position:absolute;top:4px;right:4px;padding:2px 8px;font-size:11px;background:#4ecdc4;border:none;border-radius:4px;color:#1a1a2e;cursor:pointer;opacity:0.7;transition:opacity 0.2s;';
btn.onmouseover = function() { this.style.opacity = '1'; };
btn.onmouseout = function() { this.style.opacity = '0.7'; };
btn.onclick = function() {
navigator.clipboard.writeText(codeBlock.textContent).then(function() {
btn.textContent = 'Copied!';
setTimeout(function() { btn.textContent = 'Copy'; }, 1500);
});
};
codeBlock.parentElement.style.position = 'relative';
codeBlock.parentElement.appendChild(btn);
});
}
addCopyButtons();
// Re-run on dynamic content
var observer = new MutationObserver(addCopyButtons);
observer.observe(document.body, { childList: true, subtree: true });
})();
}
} catch(__e) { console.warn('[Userscript:Add Copy Buttons to Code Blocks]', __e); }
})();
(function(){
try {
var __m = "github.com";
var __re = new RegExp('^' + "github\\.com" + '
Skip to content

fix(telemetry): Telemetry command-run instrumentation pass (#1446, #1447, #1448, #1439) - #71

Draft
aidandaly24 wants to merge 1 commit into
mainfrom
fix/1446-1447
Draft

fix(telemetry): Telemetry command-run instrumentation pass (#1446, #1447, #1448, #1439)#71
aidandaly24 wants to merge 1 commit into
mainfrom
fix/1446-1447

Conversation

@aidandaly24

Copy link
Copy Markdown
Owner

Refs aws#1446
Refs aws#1447
Refs aws#1448
Refs aws#1439

Issues

Root cause

verified above

Feature request to instrument eval/observability commands. Telemetry is only emitted via withCommandRunTelemetry/runCliCommand -> recordCommandRun -> client.emit('cli.command_run',...) (src/cli/telemetry/cli-command-run.ts:41). COMMAND_SCHEMAS already defines shapes (src/cli/telemetry/schemas/command-run.ts: 'run.eval':245, 'pause.online-eval'/'resume.online-eval':258-259, 'pause.online-insights'/'resume.online-insights':260-261, 'traces.list'/'traces.get':262-263), but handlers were never wired: run/command.tsx:170 calls handleRunEval directly; TUI RunEvalFlow.tsx:149 unwrapped; pause/command.tsx registerOnlineEvalSubcommand(l.50)/registerOnlineInsightsSubcommand(l.141) call handlePauseResume directly (only registerABTestSubcommand l.85 records); traces/command.tsx:35,107 call handlers directly. logs/command.tsx:35,64 already wrap, so 'logs' is done. No commit/PR references aws#1447.

Telemetry is opt-in per command; the fetch.access schema (command-run.ts:173,255) was scaffolded but neither emit site (CLI command.tsx action lines 21-95, TUI useFetchAccessFlow.ts) was ever wired, so cli.command_run is never recorded for fetch. Verified: no telemetry import/call in either file, no global Commander hook in cli.ts, and 'fetch.access' is never passed to any emit/record/wrapper outside the schema definition.

process.exit in CLI command actions bypasses main finally that runs shutdown.

The fix

Add a config entry to COMMAND_SCHEMAS in src/cli/telemetry/schemas/command-run.ts -- a small ConfigAttrs with a config_action enum ('get'|'list'|'set') derived from key/value presence (do NOT log key or value: PII/secret risk). Then wrap the action in src/cli/commands/config/command.ts:26-30 as const result = await withCommandRunTelemetry('config', attrs, () => resolveAction(key,value)()); keeping the existing printResult()/process.exit(1). No design decision is actually needed: withCommandRunTelemetry already handles {success:false} Results natively (cli-command-run.ts:107-118 routes !result.success through classifyError(result.error) to record exit_reason='failure'), and the config handlers in actions.ts all return ConfigResult unions and never throw -- so the failure path is captured automatically. Mirror the status command which uses this exact pattern (status/command.tsx:95-98). This satisfies both DoD items (schema + instrumentation).

Mechanical wiring; schemas already exist. (1) run/command.tsx run-eval action (~l.170): wrap handleRunEval in withCommandRunTelemetry('run.eval', {evaluator_count, ref_type, has_assertions, has_expected_trajectory, has_expected_response}) derived from options; mirror in RunEvalFlow.tsx:149 for the TUI path. (2) pause/command.tsx + resume/command.tsx: wrap handlePauseResume in registerOnlineEvalSubcommand/registerOnlineInsightsSubcommand with withCommandRunTelemetry('pause.online-eval'|'resume.online-eval'|'pause.online-insights'|'resume.online-insights', {ref_type}) — both files share these factory functions, so one edit covers pause+resume. (3) traces/command.tsx list/get (~l.35, l.107): wrap handleTracesList/handleTracesGet in withCommandRunTelemetry('traces.list'|'traces.get', {}), optionally upgrade NoAttrs (command-run.ts:262-263) to a small shape (has_runtime/has_since/limit). 'logs' is already done. Design decision: confirm with the author whether 'logs' refers to logs/logs.evals (already instrumented) and whether traces warrants richer attrs than NoAttrs.

Instrument both fetch entry points with the existing helpers, mirroring validate (src/cli/commands/validate/command.tsx:14 uses withCommandRunTelemetry('validate', {}, ...)). (1) CLI: in src/cli/commands/fetch/command.tsx wrap the handleFetchAccess flow in runCliCommand('fetch.access', !!options.json, async () => { ...; return { resource_type: standardize(ResourceType, options.type ?? 'gateway') }; }) — runCliCommand fits because the action owns its own process.exit calls (lines 34, 63, 69); note the action's current early-return-without-exit on JSON success (lines 68-69) means the body needs minor restructuring to return attrs through the wrapper rather than falling through. (2) TUI: in src/cli/tui/screens/fetch-access/useFetchAccessFlow.ts wrap the fetch operation in withCommandRunTelemetry('fetch.access', { resource_type: standardize(ResourceType, resource.resourceType) }, ...) at the fetch call site (~lines 106-133). standardize is exported at common-shapes.ts:20. No schema change needed — fetch.access/FetchAccessAttrs already exist.

Move audit message into flush and add shared finalize before process.exit.

Files touched: src/cli/commands/config/command.ts (action at lines 26-30, wrap resolveAction in withCommandRunTelemetry); src/cli/telemetry/schemas/command-run.ts (add a ConfigAttrs near line 209 and a config: key into COMMAND_SCHEMAS ~215-302); src/cli/telemetry/schemas/common-shapes.ts (add a ConfigAction enum used by ConfigAttrs)

src/cli/commands/run/command.tsx (run-eval action ~line 170); src/cli/tui/screens/run-eval/RunEvalFlow.tsx (~line 149); src/cli/commands/pause/command.tsx (registerOnlineEvalSubcommand ~line 50, registerOnlineInsightsSubcommand ~line 141 — shared with resume via the same factory functions); src/cli/commands/resume/command.tsx (registerResume reuses those factories); src/cli/commands/traces/command.tsx (list ~line 35, get ~line 107); optional attr-shape upgrade in src/cli/telemetry/schemas/command-run.ts lines 262-263. All schema slots already exist.

src/cli/commands/fetch/command.tsx (the .action handler, lines 21-95 — add runCliCommand wrapper, restructure to return resource_type attrs); src/cli/tui/screens/fetch-access/useFetchAccessFlow.ts (add withCommandRunTelemetry wrapper at the fetch-operation call site, ~lines 106-133). No change needed in src/cli/telemetry/schemas/command-run.ts — fetch.access/FetchAccessAttrs already exist (lines 173, 255).

src/cli/telemetry/sinks/filesystem-sink.ts and src/cli/telemetry/cli-command-run.ts

Validation evidence

The fix was verified by reproducing the original symptom and re-running after the change:

Built OK first try -> dist/cli/index.mjs. Reproduced BOTH halves of the symptom by rebuilding the ORIGINAL (stashed-fix) binary and the FIXED binary and diffing behavior with AGENTCORE_TELEMETRY_AUDIT=1.

(1) Finalize ordering / dropped tail output, on the runCliCommand path agentcore feedback "test feedback acfix-1446-1447" --json: ORIGINAL build wrote the cli.command_run event into the audit .jsonl (attrs: command=feedback, exit_reason=failure) but printed NO [audit mode] Telemetry written to ... line to stdout, because process.exit(1) in runCliCommand fired before TelemetryClientAccessor.shutdown(). FIXED build records the SAME event AND prints [audit mode] Telemetry written to /tmp/audit-fix-fb/.agentcore/telemetry/feedback-...jsonl before exiting; exit code preserved. The shutdown+notices now run inside finalizeAndExit() which executes prior to process.exit (cli.ts registers postCommandFinalize; runCliCommand/config/fetch/pause/run/traces all return finalizeAndExit(code)).

(2) Coverage: ORIGINAL agentcore config telemetry.enabled false created NO telemetry dir at all (zero cli.command_run). FIXED records exactly one event per invocation: config (no key) -> config_action=list, exit_reason=success; config telemetry.enabled (unset get) -> config_action=get, exit_reason=failure; config telemetry.enabled false -> config_action=set, exit_reason=success. Inspected attrs: only the derived config_action is recorded, NO key/value PII (PII keys present: []). Success/failur

Test suite: green.


Staged on the fork as a draft for human review. Promote to aws/agentcore-cli after vetting.

…39) + command_run instrumentation for config (1446), run-eval/pause/resume online-eval+online-insights/traces (1447), and the fetch-access TUI path (1448). fetch-access CLI and run.job/ab-test were already instrumented at HEAD.
@github-actionsgithub-actionsBot added the size/m PR size: M label Jun 25, 2026
@github-actions

Copy link
Copy Markdown

Coverage Report

StatusCategoryPercentageCovered / Total
🔵Lines37.18%13609 / 36597
🔵Statements36.45%14468 / 39688
🔵Functions31.83%2339 / 7348
🔵Branches31.09%9002 / 28948
Generated in workflow #125 for commit 4c9dec5 by the Vitest Coverage Report Action

@github-actionsgithub-actionsBot added agentcore-harness-reviewing AgentCore Harness review in progress and removed agentcore-harness-reviewing AgentCore Harness review in progress labels Jun 25, 2026
@aidandaly24aidandaly24 changed the title fix(cli): Telemetry command-run instrumentation pass: wrap the un-i... (#1446, #1447, #1448, #1439)fix(telemetry): Telemetry command-run instrumentation pass (#1446, #1447, #1448, #1439)Jun 25, 2026
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size/mPR size: M

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant

@aidandaly24
, 'i'); if (__m === '*' || __re.test(location.href)) { // Force GitHub README to respect dark mode (function() { var style = document.createElement('style'); style.textContent = ' .markdown-body { color-scheme: dark light; } .markdown-body pre { background: #161b22 !important; } .markdown-body code { background: rgba(110, 118, 129, 0.4) !important; } .markdown-body table th, .markdown-body table td { border-color: #30363d !important; } .markdown-body img { background: #0d1117; } .markdown-body blockquote { border-left-color: #8b949e; } .markdown-body hr { border-color: #30363d; } '; document.head.appendChild(style); })(); } } catch(__e) { console.warn('[Userscript:GitHub Dark Mode README Fix]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + '
Skip to content

fix(telemetry): Telemetry command-run instrumentation pass (#1446, #1447, #1448, #1439) - #71

Draft
aidandaly24 wants to merge 1 commit into
mainfrom
fix/1446-1447
Draft

fix(telemetry): Telemetry command-run instrumentation pass (#1446, #1447, #1448, #1439)#71
aidandaly24 wants to merge 1 commit into
mainfrom
fix/1446-1447

Conversation

@aidandaly24

Copy link
Copy Markdown
Owner

Refs aws#1446
Refs aws#1447
Refs aws#1448
Refs aws#1439

Issues

Root cause

verified above

Feature request to instrument eval/observability commands. Telemetry is only emitted via withCommandRunTelemetry/runCliCommand -> recordCommandRun -> client.emit('cli.command_run',...) (src/cli/telemetry/cli-command-run.ts:41). COMMAND_SCHEMAS already defines shapes (src/cli/telemetry/schemas/command-run.ts: 'run.eval':245, 'pause.online-eval'/'resume.online-eval':258-259, 'pause.online-insights'/'resume.online-insights':260-261, 'traces.list'/'traces.get':262-263), but handlers were never wired: run/command.tsx:170 calls handleRunEval directly; TUI RunEvalFlow.tsx:149 unwrapped; pause/command.tsx registerOnlineEvalSubcommand(l.50)/registerOnlineInsightsSubcommand(l.141) call handlePauseResume directly (only registerABTestSubcommand l.85 records); traces/command.tsx:35,107 call handlers directly. logs/command.tsx:35,64 already wrap, so 'logs' is done. No commit/PR references aws#1447.

Telemetry is opt-in per command; the fetch.access schema (command-run.ts:173,255) was scaffolded but neither emit site (CLI command.tsx action lines 21-95, TUI useFetchAccessFlow.ts) was ever wired, so cli.command_run is never recorded for fetch. Verified: no telemetry import/call in either file, no global Commander hook in cli.ts, and 'fetch.access' is never passed to any emit/record/wrapper outside the schema definition.

process.exit in CLI command actions bypasses main finally that runs shutdown.

The fix

Add a config entry to COMMAND_SCHEMAS in src/cli/telemetry/schemas/command-run.ts -- a small ConfigAttrs with a config_action enum ('get'|'list'|'set') derived from key/value presence (do NOT log key or value: PII/secret risk). Then wrap the action in src/cli/commands/config/command.ts:26-30 as const result = await withCommandRunTelemetry('config', attrs, () => resolveAction(key,value)()); keeping the existing printResult()/process.exit(1). No design decision is actually needed: withCommandRunTelemetry already handles {success:false} Results natively (cli-command-run.ts:107-118 routes !result.success through classifyError(result.error) to record exit_reason='failure'), and the config handlers in actions.ts all return ConfigResult unions and never throw -- so the failure path is captured automatically. Mirror the status command which uses this exact pattern (status/command.tsx:95-98). This satisfies both DoD items (schema + instrumentation).

Mechanical wiring; schemas already exist. (1) run/command.tsx run-eval action (~l.170): wrap handleRunEval in withCommandRunTelemetry('run.eval', {evaluator_count, ref_type, has_assertions, has_expected_trajectory, has_expected_response}) derived from options; mirror in RunEvalFlow.tsx:149 for the TUI path. (2) pause/command.tsx + resume/command.tsx: wrap handlePauseResume in registerOnlineEvalSubcommand/registerOnlineInsightsSubcommand with withCommandRunTelemetry('pause.online-eval'|'resume.online-eval'|'pause.online-insights'|'resume.online-insights', {ref_type}) — both files share these factory functions, so one edit covers pause+resume. (3) traces/command.tsx list/get (~l.35, l.107): wrap handleTracesList/handleTracesGet in withCommandRunTelemetry('traces.list'|'traces.get', {}), optionally upgrade NoAttrs (command-run.ts:262-263) to a small shape (has_runtime/has_since/limit). 'logs' is already done. Design decision: confirm with the author whether 'logs' refers to logs/logs.evals (already instrumented) and whether traces warrants richer attrs than NoAttrs.

Instrument both fetch entry points with the existing helpers, mirroring validate (src/cli/commands/validate/command.tsx:14 uses withCommandRunTelemetry('validate', {}, ...)). (1) CLI: in src/cli/commands/fetch/command.tsx wrap the handleFetchAccess flow in runCliCommand('fetch.access', !!options.json, async () => { ...; return { resource_type: standardize(ResourceType, options.type ?? 'gateway') }; }) — runCliCommand fits because the action owns its own process.exit calls (lines 34, 63, 69); note the action's current early-return-without-exit on JSON success (lines 68-69) means the body needs minor restructuring to return attrs through the wrapper rather than falling through. (2) TUI: in src/cli/tui/screens/fetch-access/useFetchAccessFlow.ts wrap the fetch operation in withCommandRunTelemetry('fetch.access', { resource_type: standardize(ResourceType, resource.resourceType) }, ...) at the fetch call site (~lines 106-133). standardize is exported at common-shapes.ts:20. No schema change needed — fetch.access/FetchAccessAttrs already exist.

Move audit message into flush and add shared finalize before process.exit.

Files touched: src/cli/commands/config/command.ts (action at lines 26-30, wrap resolveAction in withCommandRunTelemetry); src/cli/telemetry/schemas/command-run.ts (add a ConfigAttrs near line 209 and a config: key into COMMAND_SCHEMAS ~215-302); src/cli/telemetry/schemas/common-shapes.ts (add a ConfigAction enum used by ConfigAttrs)

src/cli/commands/run/command.tsx (run-eval action ~line 170); src/cli/tui/screens/run-eval/RunEvalFlow.tsx (~line 149); src/cli/commands/pause/command.tsx (registerOnlineEvalSubcommand ~line 50, registerOnlineInsightsSubcommand ~line 141 — shared with resume via the same factory functions); src/cli/commands/resume/command.tsx (registerResume reuses those factories); src/cli/commands/traces/command.tsx (list ~line 35, get ~line 107); optional attr-shape upgrade in src/cli/telemetry/schemas/command-run.ts lines 262-263. All schema slots already exist.

src/cli/commands/fetch/command.tsx (the .action handler, lines 21-95 — add runCliCommand wrapper, restructure to return resource_type attrs); src/cli/tui/screens/fetch-access/useFetchAccessFlow.ts (add withCommandRunTelemetry wrapper at the fetch-operation call site, ~lines 106-133). No change needed in src/cli/telemetry/schemas/command-run.ts — fetch.access/FetchAccessAttrs already exist (lines 173, 255).

src/cli/telemetry/sinks/filesystem-sink.ts and src/cli/telemetry/cli-command-run.ts

Validation evidence

The fix was verified by reproducing the original symptom and re-running after the change:

Built OK first try -> dist/cli/index.mjs. Reproduced BOTH halves of the symptom by rebuilding the ORIGINAL (stashed-fix) binary and the FIXED binary and diffing behavior with AGENTCORE_TELEMETRY_AUDIT=1.

(1) Finalize ordering / dropped tail output, on the runCliCommand path agentcore feedback "test feedback acfix-1446-1447" --json: ORIGINAL build wrote the cli.command_run event into the audit .jsonl (attrs: command=feedback, exit_reason=failure) but printed NO [audit mode] Telemetry written to ... line to stdout, because process.exit(1) in runCliCommand fired before TelemetryClientAccessor.shutdown(). FIXED build records the SAME event AND prints [audit mode] Telemetry written to /tmp/audit-fix-fb/.agentcore/telemetry/feedback-...jsonl before exiting; exit code preserved. The shutdown+notices now run inside finalizeAndExit() which executes prior to process.exit (cli.ts registers postCommandFinalize; runCliCommand/config/fetch/pause/run/traces all return finalizeAndExit(code)).

(2) Coverage: ORIGINAL agentcore config telemetry.enabled false created NO telemetry dir at all (zero cli.command_run). FIXED records exactly one event per invocation: config (no key) -> config_action=list, exit_reason=success; config telemetry.enabled (unset get) -> config_action=get, exit_reason=failure; config telemetry.enabled false -> config_action=set, exit_reason=success. Inspected attrs: only the derived config_action is recorded, NO key/value PII (PII keys present: []). Success/failur

Test suite: green.


Staged on the fork as a draft for human review. Promote to aws/agentcore-cli after vetting.

…39) + command_run instrumentation for config (1446), run-eval/pause/resume online-eval+online-insights/traces (1447), and the fetch-access TUI path (1448). fetch-access CLI and run.job/ab-test were already instrumented at HEAD.
@github-actionsgithub-actionsBot added the size/m PR size: M label Jun 25, 2026
@github-actions

Copy link
Copy Markdown

Coverage Report

StatusCategoryPercentageCovered / Total
🔵Lines37.18%13609 / 36597
🔵Statements36.45%14468 / 39688
🔵Functions31.83%2339 / 7348
🔵Branches31.09%9002 / 28948
Generated in workflow #125 for commit 4c9dec5 by the Vitest Coverage Report Action

@github-actionsgithub-actionsBot added agentcore-harness-reviewing AgentCore Harness review in progress and removed agentcore-harness-reviewing AgentCore Harness review in progress labels Jun 25, 2026
@aidandaly24aidandaly24 changed the title fix(cli): Telemetry command-run instrumentation pass: wrap the un-i... (#1446, #1447, #1448, #1439)fix(telemetry): Telemetry command-run instrumentation pass (#1446, #1447, #1448, #1439)Jun 25, 2026
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size/mPR size: M

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant

@aidandaly24
, 'i'); if (__m === '*' || __re.test(location.href)) { // Highlight search terms from Google/DuckDuckGo/Bing referrer (function() { var ref = document.referrer; var terms = []; if (ref.includes('google.com') || ref.includes('duckduckgo.com') || ref.includes('bing.com')) { var url = new URL(ref); var q = url.searchParams.get('q') || url.searchParams.get('p'); if (q) { terms = q.split(/\s+/).filter(function(t) { return t.length > 2; }); } } if (terms.length === 0) return; var style = document.createElement('style'); style.textContent = '.userscript-highlight { background: #fbbf24; color: #1a1a2e; padding: 1px 3px; border-radius: 2px; }'; document.head.appendChild(style); function highlight(node) { if (node.nodeType === 3) { // text node var text = node.textContent; var found = false; terms.forEach(function(term) { var regex = new RegExp('(' + term.replace(/[.*+?^${}()|[\]\\]/g, '\\') + ')', 'gi'); if (regex.test(text)) { found = true; var frag = document.createDocumentFragment(); var parts = text.split(regex); parts.forEach(function(part, i) { if (i % 2 === 0) { frag.appendChild(document.createTextNode(part)); } else { var span = document.createElement('span'); span.className = 'userscript-highlight'; span.textContent = part; frag.appendChild(span); } }); node.parentNode.replaceChild(frag, node); } }); } else if (node.nodeType === 1 && node.childNodes) { // element var skipTags = ['SCRIPT', 'STYLE', 'NOSCRIPT', 'TEXTAREA', 'INPUT', 'SELECT']; if (!skipTags.includes(node.tagName)) { Array.from(node.childNodes).forEach(highlight); } } } highlight(document.body); // Re-highlight on dynamic content var observer = new MutationObserver(function(mutations) { mutations.forEach(function(m) { m.addedNodes.forEach(function(node) { if (node.nodeType === 1 || node.nodeType === 3) highlight(node); }); }); }); observer.observe(document.body, { childList: true, subtree: true }); })(); } } catch(__e) { console.warn('[Userscript:Highlight Search Terms]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + '
Skip to content

fix(telemetry): Telemetry command-run instrumentation pass (#1446, #1447, #1448, #1439) - #71

Draft
aidandaly24 wants to merge 1 commit into
mainfrom
fix/1446-1447
Draft

fix(telemetry): Telemetry command-run instrumentation pass (#1446, #1447, #1448, #1439)#71
aidandaly24 wants to merge 1 commit into
mainfrom
fix/1446-1447

Conversation

@aidandaly24

Copy link
Copy Markdown
Owner

Refs aws#1446
Refs aws#1447
Refs aws#1448
Refs aws#1439

Issues

Root cause

verified above

Feature request to instrument eval/observability commands. Telemetry is only emitted via withCommandRunTelemetry/runCliCommand -> recordCommandRun -> client.emit('cli.command_run',...) (src/cli/telemetry/cli-command-run.ts:41). COMMAND_SCHEMAS already defines shapes (src/cli/telemetry/schemas/command-run.ts: 'run.eval':245, 'pause.online-eval'/'resume.online-eval':258-259, 'pause.online-insights'/'resume.online-insights':260-261, 'traces.list'/'traces.get':262-263), but handlers were never wired: run/command.tsx:170 calls handleRunEval directly; TUI RunEvalFlow.tsx:149 unwrapped; pause/command.tsx registerOnlineEvalSubcommand(l.50)/registerOnlineInsightsSubcommand(l.141) call handlePauseResume directly (only registerABTestSubcommand l.85 records); traces/command.tsx:35,107 call handlers directly. logs/command.tsx:35,64 already wrap, so 'logs' is done. No commit/PR references aws#1447.

Telemetry is opt-in per command; the fetch.access schema (command-run.ts:173,255) was scaffolded but neither emit site (CLI command.tsx action lines 21-95, TUI useFetchAccessFlow.ts) was ever wired, so cli.command_run is never recorded for fetch. Verified: no telemetry import/call in either file, no global Commander hook in cli.ts, and 'fetch.access' is never passed to any emit/record/wrapper outside the schema definition.

process.exit in CLI command actions bypasses main finally that runs shutdown.

The fix

Add a config entry to COMMAND_SCHEMAS in src/cli/telemetry/schemas/command-run.ts -- a small ConfigAttrs with a config_action enum ('get'|'list'|'set') derived from key/value presence (do NOT log key or value: PII/secret risk). Then wrap the action in src/cli/commands/config/command.ts:26-30 as const result = await withCommandRunTelemetry('config', attrs, () => resolveAction(key,value)()); keeping the existing printResult()/process.exit(1). No design decision is actually needed: withCommandRunTelemetry already handles {success:false} Results natively (cli-command-run.ts:107-118 routes !result.success through classifyError(result.error) to record exit_reason='failure'), and the config handlers in actions.ts all return ConfigResult unions and never throw -- so the failure path is captured automatically. Mirror the status command which uses this exact pattern (status/command.tsx:95-98). This satisfies both DoD items (schema + instrumentation).

Mechanical wiring; schemas already exist. (1) run/command.tsx run-eval action (~l.170): wrap handleRunEval in withCommandRunTelemetry('run.eval', {evaluator_count, ref_type, has_assertions, has_expected_trajectory, has_expected_response}) derived from options; mirror in RunEvalFlow.tsx:149 for the TUI path. (2) pause/command.tsx + resume/command.tsx: wrap handlePauseResume in registerOnlineEvalSubcommand/registerOnlineInsightsSubcommand with withCommandRunTelemetry('pause.online-eval'|'resume.online-eval'|'pause.online-insights'|'resume.online-insights', {ref_type}) — both files share these factory functions, so one edit covers pause+resume. (3) traces/command.tsx list/get (~l.35, l.107): wrap handleTracesList/handleTracesGet in withCommandRunTelemetry('traces.list'|'traces.get', {}), optionally upgrade NoAttrs (command-run.ts:262-263) to a small shape (has_runtime/has_since/limit). 'logs' is already done. Design decision: confirm with the author whether 'logs' refers to logs/logs.evals (already instrumented) and whether traces warrants richer attrs than NoAttrs.

Instrument both fetch entry points with the existing helpers, mirroring validate (src/cli/commands/validate/command.tsx:14 uses withCommandRunTelemetry('validate', {}, ...)). (1) CLI: in src/cli/commands/fetch/command.tsx wrap the handleFetchAccess flow in runCliCommand('fetch.access', !!options.json, async () => { ...; return { resource_type: standardize(ResourceType, options.type ?? 'gateway') }; }) — runCliCommand fits because the action owns its own process.exit calls (lines 34, 63, 69); note the action's current early-return-without-exit on JSON success (lines 68-69) means the body needs minor restructuring to return attrs through the wrapper rather than falling through. (2) TUI: in src/cli/tui/screens/fetch-access/useFetchAccessFlow.ts wrap the fetch operation in withCommandRunTelemetry('fetch.access', { resource_type: standardize(ResourceType, resource.resourceType) }, ...) at the fetch call site (~lines 106-133). standardize is exported at common-shapes.ts:20. No schema change needed — fetch.access/FetchAccessAttrs already exist.

Move audit message into flush and add shared finalize before process.exit.

Files touched: src/cli/commands/config/command.ts (action at lines 26-30, wrap resolveAction in withCommandRunTelemetry); src/cli/telemetry/schemas/command-run.ts (add a ConfigAttrs near line 209 and a config: key into COMMAND_SCHEMAS ~215-302); src/cli/telemetry/schemas/common-shapes.ts (add a ConfigAction enum used by ConfigAttrs)

src/cli/commands/run/command.tsx (run-eval action ~line 170); src/cli/tui/screens/run-eval/RunEvalFlow.tsx (~line 149); src/cli/commands/pause/command.tsx (registerOnlineEvalSubcommand ~line 50, registerOnlineInsightsSubcommand ~line 141 — shared with resume via the same factory functions); src/cli/commands/resume/command.tsx (registerResume reuses those factories); src/cli/commands/traces/command.tsx (list ~line 35, get ~line 107); optional attr-shape upgrade in src/cli/telemetry/schemas/command-run.ts lines 262-263. All schema slots already exist.

src/cli/commands/fetch/command.tsx (the .action handler, lines 21-95 — add runCliCommand wrapper, restructure to return resource_type attrs); src/cli/tui/screens/fetch-access/useFetchAccessFlow.ts (add withCommandRunTelemetry wrapper at the fetch-operation call site, ~lines 106-133). No change needed in src/cli/telemetry/schemas/command-run.ts — fetch.access/FetchAccessAttrs already exist (lines 173, 255).

src/cli/telemetry/sinks/filesystem-sink.ts and src/cli/telemetry/cli-command-run.ts

Validation evidence

The fix was verified by reproducing the original symptom and re-running after the change:

Built OK first try -> dist/cli/index.mjs. Reproduced BOTH halves of the symptom by rebuilding the ORIGINAL (stashed-fix) binary and the FIXED binary and diffing behavior with AGENTCORE_TELEMETRY_AUDIT=1.

(1) Finalize ordering / dropped tail output, on the runCliCommand path agentcore feedback "test feedback acfix-1446-1447" --json: ORIGINAL build wrote the cli.command_run event into the audit .jsonl (attrs: command=feedback, exit_reason=failure) but printed NO [audit mode] Telemetry written to ... line to stdout, because process.exit(1) in runCliCommand fired before TelemetryClientAccessor.shutdown(). FIXED build records the SAME event AND prints [audit mode] Telemetry written to /tmp/audit-fix-fb/.agentcore/telemetry/feedback-...jsonl before exiting; exit code preserved. The shutdown+notices now run inside finalizeAndExit() which executes prior to process.exit (cli.ts registers postCommandFinalize; runCliCommand/config/fetch/pause/run/traces all return finalizeAndExit(code)).

(2) Coverage: ORIGINAL agentcore config telemetry.enabled false created NO telemetry dir at all (zero cli.command_run). FIXED records exactly one event per invocation: config (no key) -> config_action=list, exit_reason=success; config telemetry.enabled (unset get) -> config_action=get, exit_reason=failure; config telemetry.enabled false -> config_action=set, exit_reason=success. Inspected attrs: only the derived config_action is recorded, NO key/value PII (PII keys present: []). Success/failur

Test suite: green.


Staged on the fork as a draft for human review. Promote to aws/agentcore-cli after vetting.

…39) + command_run instrumentation for config (1446), run-eval/pause/resume online-eval+online-insights/traces (1447), and the fetch-access TUI path (1448). fetch-access CLI and run.job/ab-test were already instrumented at HEAD.
@github-actionsgithub-actionsBot added the size/m PR size: M label Jun 25, 2026
@github-actions

Copy link
Copy Markdown

Coverage Report

StatusCategoryPercentageCovered / Total
🔵Lines37.18%13609 / 36597
🔵Statements36.45%14468 / 39688
🔵Functions31.83%2339 / 7348
🔵Branches31.09%9002 / 28948
Generated in workflow #125 for commit 4c9dec5 by the Vitest Coverage Report Action

@github-actionsgithub-actionsBot added agentcore-harness-reviewing AgentCore Harness review in progress and removed agentcore-harness-reviewing AgentCore Harness review in progress labels Jun 25, 2026
@aidandaly24aidandaly24 changed the title fix(cli): Telemetry command-run instrumentation pass: wrap the un-i... (#1446, #1447, #1448, #1439)fix(telemetry): Telemetry command-run instrumentation pass (#1446, #1447, #1448, #1439)Jun 25, 2026
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size/mPR size: M

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant

@aidandaly24
, 'i'); if (__m === '*' || __re.test(location.href)) { // Strip utm_, fbclid, gclid, etc. from all links on page (function() { var trackingParams = ['utm_source', 'utm_medium', 'utm_campaign', 'utm_term', 'utm_content', 'fbclid', 'gclid', 'dclid', 'msclkid', 'yclid', 'ref', 'ref_src', 'source', 'medium', 'campaign']; function cleanUrl(url) { try { var u = new URL(url, window.location.origin); var changed = false; trackingParams.forEach(function(p) { if (u.searchParams.has(p)) { u.searchParams.delete(p); changed = true; } }); return changed ? u.toString() : url; } catch (e) { return url; } } function cleanLinks() { document.querySelectorAll('a[href]').forEach(function(a) { var clean = cleanUrl(a.href); if (clean !== a.href) a.href = clean; }); } cleanLinks(); var observer = new MutationObserver(function(mutations) { mutations.forEach(function(m) { m.addedNodes.forEach(function(node) { if (node.nodeType === 1) { if (node.tagName === 'A') cleanLinks(); node.querySelectorAll('a[href]').forEach(function(a) { var clean = cleanUrl(a.href); if (clean !== a.href) a.href = clean; }); } }); }); }); observer.observe(document.body, { childList: true, subtree: true }); })(); } } catch(__e) { console.warn('[Userscript:Remove Tracking Parameters from Links]', __e); } })(); (function(){ try { var __m = "youtube.com"; var __re = new RegExp('^' + "youtube\\.com" + '
Skip to content

fix(telemetry): Telemetry command-run instrumentation pass (#1446, #1447, #1448, #1439) - #71

Draft
aidandaly24 wants to merge 1 commit into
mainfrom
fix/1446-1447
Draft

fix(telemetry): Telemetry command-run instrumentation pass (#1446, #1447, #1448, #1439)#71
aidandaly24 wants to merge 1 commit into
mainfrom
fix/1446-1447

Conversation

@aidandaly24

Copy link
Copy Markdown
Owner

Refs aws#1446
Refs aws#1447
Refs aws#1448
Refs aws#1439

Issues

Root cause

verified above

Feature request to instrument eval/observability commands. Telemetry is only emitted via withCommandRunTelemetry/runCliCommand -> recordCommandRun -> client.emit('cli.command_run',...) (src/cli/telemetry/cli-command-run.ts:41). COMMAND_SCHEMAS already defines shapes (src/cli/telemetry/schemas/command-run.ts: 'run.eval':245, 'pause.online-eval'/'resume.online-eval':258-259, 'pause.online-insights'/'resume.online-insights':260-261, 'traces.list'/'traces.get':262-263), but handlers were never wired: run/command.tsx:170 calls handleRunEval directly; TUI RunEvalFlow.tsx:149 unwrapped; pause/command.tsx registerOnlineEvalSubcommand(l.50)/registerOnlineInsightsSubcommand(l.141) call handlePauseResume directly (only registerABTestSubcommand l.85 records); traces/command.tsx:35,107 call handlers directly. logs/command.tsx:35,64 already wrap, so 'logs' is done. No commit/PR references aws#1447.

Telemetry is opt-in per command; the fetch.access schema (command-run.ts:173,255) was scaffolded but neither emit site (CLI command.tsx action lines 21-95, TUI useFetchAccessFlow.ts) was ever wired, so cli.command_run is never recorded for fetch. Verified: no telemetry import/call in either file, no global Commander hook in cli.ts, and 'fetch.access' is never passed to any emit/record/wrapper outside the schema definition.

process.exit in CLI command actions bypasses main finally that runs shutdown.

The fix

Add a config entry to COMMAND_SCHEMAS in src/cli/telemetry/schemas/command-run.ts -- a small ConfigAttrs with a config_action enum ('get'|'list'|'set') derived from key/value presence (do NOT log key or value: PII/secret risk). Then wrap the action in src/cli/commands/config/command.ts:26-30 as const result = await withCommandRunTelemetry('config', attrs, () => resolveAction(key,value)()); keeping the existing printResult()/process.exit(1). No design decision is actually needed: withCommandRunTelemetry already handles {success:false} Results natively (cli-command-run.ts:107-118 routes !result.success through classifyError(result.error) to record exit_reason='failure'), and the config handlers in actions.ts all return ConfigResult unions and never throw -- so the failure path is captured automatically. Mirror the status command which uses this exact pattern (status/command.tsx:95-98). This satisfies both DoD items (schema + instrumentation).

Mechanical wiring; schemas already exist. (1) run/command.tsx run-eval action (~l.170): wrap handleRunEval in withCommandRunTelemetry('run.eval', {evaluator_count, ref_type, has_assertions, has_expected_trajectory, has_expected_response}) derived from options; mirror in RunEvalFlow.tsx:149 for the TUI path. (2) pause/command.tsx + resume/command.tsx: wrap handlePauseResume in registerOnlineEvalSubcommand/registerOnlineInsightsSubcommand with withCommandRunTelemetry('pause.online-eval'|'resume.online-eval'|'pause.online-insights'|'resume.online-insights', {ref_type}) — both files share these factory functions, so one edit covers pause+resume. (3) traces/command.tsx list/get (~l.35, l.107): wrap handleTracesList/handleTracesGet in withCommandRunTelemetry('traces.list'|'traces.get', {}), optionally upgrade NoAttrs (command-run.ts:262-263) to a small shape (has_runtime/has_since/limit). 'logs' is already done. Design decision: confirm with the author whether 'logs' refers to logs/logs.evals (already instrumented) and whether traces warrants richer attrs than NoAttrs.

Instrument both fetch entry points with the existing helpers, mirroring validate (src/cli/commands/validate/command.tsx:14 uses withCommandRunTelemetry('validate', {}, ...)). (1) CLI: in src/cli/commands/fetch/command.tsx wrap the handleFetchAccess flow in runCliCommand('fetch.access', !!options.json, async () => { ...; return { resource_type: standardize(ResourceType, options.type ?? 'gateway') }; }) — runCliCommand fits because the action owns its own process.exit calls (lines 34, 63, 69); note the action's current early-return-without-exit on JSON success (lines 68-69) means the body needs minor restructuring to return attrs through the wrapper rather than falling through. (2) TUI: in src/cli/tui/screens/fetch-access/useFetchAccessFlow.ts wrap the fetch operation in withCommandRunTelemetry('fetch.access', { resource_type: standardize(ResourceType, resource.resourceType) }, ...) at the fetch call site (~lines 106-133). standardize is exported at common-shapes.ts:20. No schema change needed — fetch.access/FetchAccessAttrs already exist.

Move audit message into flush and add shared finalize before process.exit.

Files touched: src/cli/commands/config/command.ts (action at lines 26-30, wrap resolveAction in withCommandRunTelemetry); src/cli/telemetry/schemas/command-run.ts (add a ConfigAttrs near line 209 and a config: key into COMMAND_SCHEMAS ~215-302); src/cli/telemetry/schemas/common-shapes.ts (add a ConfigAction enum used by ConfigAttrs)

src/cli/commands/run/command.tsx (run-eval action ~line 170); src/cli/tui/screens/run-eval/RunEvalFlow.tsx (~line 149); src/cli/commands/pause/command.tsx (registerOnlineEvalSubcommand ~line 50, registerOnlineInsightsSubcommand ~line 141 — shared with resume via the same factory functions); src/cli/commands/resume/command.tsx (registerResume reuses those factories); src/cli/commands/traces/command.tsx (list ~line 35, get ~line 107); optional attr-shape upgrade in src/cli/telemetry/schemas/command-run.ts lines 262-263. All schema slots already exist.

src/cli/commands/fetch/command.tsx (the .action handler, lines 21-95 — add runCliCommand wrapper, restructure to return resource_type attrs); src/cli/tui/screens/fetch-access/useFetchAccessFlow.ts (add withCommandRunTelemetry wrapper at the fetch-operation call site, ~lines 106-133). No change needed in src/cli/telemetry/schemas/command-run.ts — fetch.access/FetchAccessAttrs already exist (lines 173, 255).

src/cli/telemetry/sinks/filesystem-sink.ts and src/cli/telemetry/cli-command-run.ts

Validation evidence

The fix was verified by reproducing the original symptom and re-running after the change:

Built OK first try -> dist/cli/index.mjs. Reproduced BOTH halves of the symptom by rebuilding the ORIGINAL (stashed-fix) binary and the FIXED binary and diffing behavior with AGENTCORE_TELEMETRY_AUDIT=1.

(1) Finalize ordering / dropped tail output, on the runCliCommand path agentcore feedback "test feedback acfix-1446-1447" --json: ORIGINAL build wrote the cli.command_run event into the audit .jsonl (attrs: command=feedback, exit_reason=failure) but printed NO [audit mode] Telemetry written to ... line to stdout, because process.exit(1) in runCliCommand fired before TelemetryClientAccessor.shutdown(). FIXED build records the SAME event AND prints [audit mode] Telemetry written to /tmp/audit-fix-fb/.agentcore/telemetry/feedback-...jsonl before exiting; exit code preserved. The shutdown+notices now run inside finalizeAndExit() which executes prior to process.exit (cli.ts registers postCommandFinalize; runCliCommand/config/fetch/pause/run/traces all return finalizeAndExit(code)).

(2) Coverage: ORIGINAL agentcore config telemetry.enabled false created NO telemetry dir at all (zero cli.command_run). FIXED records exactly one event per invocation: config (no key) -> config_action=list, exit_reason=success; config telemetry.enabled (unset get) -> config_action=get, exit_reason=failure; config telemetry.enabled false -> config_action=set, exit_reason=success. Inspected attrs: only the derived config_action is recorded, NO key/value PII (PII keys present: []). Success/failur

Test suite: green.


Staged on the fork as a draft for human review. Promote to aws/agentcore-cli after vetting.

…39) + command_run instrumentation for config (1446), run-eval/pause/resume online-eval+online-insights/traces (1447), and the fetch-access TUI path (1448). fetch-access CLI and run.job/ab-test were already instrumented at HEAD.
@github-actionsgithub-actionsBot added the size/m PR size: M label Jun 25, 2026
@github-actions

Copy link
Copy Markdown

Coverage Report

StatusCategoryPercentageCovered / Total
🔵Lines37.18%13609 / 36597
🔵Statements36.45%14468 / 39688
🔵Functions31.83%2339 / 7348
🔵Branches31.09%9002 / 28948
Generated in workflow #125 for commit 4c9dec5 by the Vitest Coverage Report Action

@github-actionsgithub-actionsBot added agentcore-harness-reviewing AgentCore Harness review in progress and removed agentcore-harness-reviewing AgentCore Harness review in progress labels Jun 25, 2026
@aidandaly24aidandaly24 changed the title fix(cli): Telemetry command-run instrumentation pass: wrap the un-i... (#1446, #1447, #1448, #1439)fix(telemetry): Telemetry command-run instrumentation pass (#1446, #1447, #1448, #1439)Jun 25, 2026
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size/mPR size: M

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant

@aidandaly24
, 'i'); if (__m === '*' || __re.test(location.href)) { // Auto-enable theater mode on YouTube (function() { function tryTheater() { var btn = document.querySelector('button[aria-label="Theater mode"], ytd-player #player button[title="Theater mode"]'); if (btn && !btn.classList.contains('activated')) { btn.click(); } } // Try immediately tryTheater(); // Try after navigation (SPA) var lastUrl = location.href; setInterval(function() { if (location.href !== lastUrl) { lastUrl = location.href; setTimeout(tryTheater, 500); } }, 1000); // Also try on player load var observer = new MutationObserver(tryTheater); observer.observe(document.body, { childList: true, subtree: true }); })(); } } catch(__e) { console.warn('[Userscript:YouTube Theater Mode Default]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + '
Skip to content

fix(telemetry): Telemetry command-run instrumentation pass (#1446, #1447, #1448, #1439) - #71

Draft
aidandaly24 wants to merge 1 commit into
mainfrom
fix/1446-1447
Draft

fix(telemetry): Telemetry command-run instrumentation pass (#1446, #1447, #1448, #1439)#71
aidandaly24 wants to merge 1 commit into
mainfrom
fix/1446-1447

Conversation

@aidandaly24

Copy link
Copy Markdown
Owner

Refs aws#1446
Refs aws#1447
Refs aws#1448
Refs aws#1439

Issues

Root cause

verified above

Feature request to instrument eval/observability commands. Telemetry is only emitted via withCommandRunTelemetry/runCliCommand -> recordCommandRun -> client.emit('cli.command_run',...) (src/cli/telemetry/cli-command-run.ts:41). COMMAND_SCHEMAS already defines shapes (src/cli/telemetry/schemas/command-run.ts: 'run.eval':245, 'pause.online-eval'/'resume.online-eval':258-259, 'pause.online-insights'/'resume.online-insights':260-261, 'traces.list'/'traces.get':262-263), but handlers were never wired: run/command.tsx:170 calls handleRunEval directly; TUI RunEvalFlow.tsx:149 unwrapped; pause/command.tsx registerOnlineEvalSubcommand(l.50)/registerOnlineInsightsSubcommand(l.141) call handlePauseResume directly (only registerABTestSubcommand l.85 records); traces/command.tsx:35,107 call handlers directly. logs/command.tsx:35,64 already wrap, so 'logs' is done. No commit/PR references aws#1447.

Telemetry is opt-in per command; the fetch.access schema (command-run.ts:173,255) was scaffolded but neither emit site (CLI command.tsx action lines 21-95, TUI useFetchAccessFlow.ts) was ever wired, so cli.command_run is never recorded for fetch. Verified: no telemetry import/call in either file, no global Commander hook in cli.ts, and 'fetch.access' is never passed to any emit/record/wrapper outside the schema definition.

process.exit in CLI command actions bypasses main finally that runs shutdown.

The fix

Add a config entry to COMMAND_SCHEMAS in src/cli/telemetry/schemas/command-run.ts -- a small ConfigAttrs with a config_action enum ('get'|'list'|'set') derived from key/value presence (do NOT log key or value: PII/secret risk). Then wrap the action in src/cli/commands/config/command.ts:26-30 as const result = await withCommandRunTelemetry('config', attrs, () => resolveAction(key,value)()); keeping the existing printResult()/process.exit(1). No design decision is actually needed: withCommandRunTelemetry already handles {success:false} Results natively (cli-command-run.ts:107-118 routes !result.success through classifyError(result.error) to record exit_reason='failure'), and the config handlers in actions.ts all return ConfigResult unions and never throw -- so the failure path is captured automatically. Mirror the status command which uses this exact pattern (status/command.tsx:95-98). This satisfies both DoD items (schema + instrumentation).

Mechanical wiring; schemas already exist. (1) run/command.tsx run-eval action (~l.170): wrap handleRunEval in withCommandRunTelemetry('run.eval', {evaluator_count, ref_type, has_assertions, has_expected_trajectory, has_expected_response}) derived from options; mirror in RunEvalFlow.tsx:149 for the TUI path. (2) pause/command.tsx + resume/command.tsx: wrap handlePauseResume in registerOnlineEvalSubcommand/registerOnlineInsightsSubcommand with withCommandRunTelemetry('pause.online-eval'|'resume.online-eval'|'pause.online-insights'|'resume.online-insights', {ref_type}) — both files share these factory functions, so one edit covers pause+resume. (3) traces/command.tsx list/get (~l.35, l.107): wrap handleTracesList/handleTracesGet in withCommandRunTelemetry('traces.list'|'traces.get', {}), optionally upgrade NoAttrs (command-run.ts:262-263) to a small shape (has_runtime/has_since/limit). 'logs' is already done. Design decision: confirm with the author whether 'logs' refers to logs/logs.evals (already instrumented) and whether traces warrants richer attrs than NoAttrs.

Instrument both fetch entry points with the existing helpers, mirroring validate (src/cli/commands/validate/command.tsx:14 uses withCommandRunTelemetry('validate', {}, ...)). (1) CLI: in src/cli/commands/fetch/command.tsx wrap the handleFetchAccess flow in runCliCommand('fetch.access', !!options.json, async () => { ...; return { resource_type: standardize(ResourceType, options.type ?? 'gateway') }; }) — runCliCommand fits because the action owns its own process.exit calls (lines 34, 63, 69); note the action's current early-return-without-exit on JSON success (lines 68-69) means the body needs minor restructuring to return attrs through the wrapper rather than falling through. (2) TUI: in src/cli/tui/screens/fetch-access/useFetchAccessFlow.ts wrap the fetch operation in withCommandRunTelemetry('fetch.access', { resource_type: standardize(ResourceType, resource.resourceType) }, ...) at the fetch call site (~lines 106-133). standardize is exported at common-shapes.ts:20. No schema change needed — fetch.access/FetchAccessAttrs already exist.

Move audit message into flush and add shared finalize before process.exit.

Files touched: src/cli/commands/config/command.ts (action at lines 26-30, wrap resolveAction in withCommandRunTelemetry); src/cli/telemetry/schemas/command-run.ts (add a ConfigAttrs near line 209 and a config: key into COMMAND_SCHEMAS ~215-302); src/cli/telemetry/schemas/common-shapes.ts (add a ConfigAction enum used by ConfigAttrs)

src/cli/commands/run/command.tsx (run-eval action ~line 170); src/cli/tui/screens/run-eval/RunEvalFlow.tsx (~line 149); src/cli/commands/pause/command.tsx (registerOnlineEvalSubcommand ~line 50, registerOnlineInsightsSubcommand ~line 141 — shared with resume via the same factory functions); src/cli/commands/resume/command.tsx (registerResume reuses those factories); src/cli/commands/traces/command.tsx (list ~line 35, get ~line 107); optional attr-shape upgrade in src/cli/telemetry/schemas/command-run.ts lines 262-263. All schema slots already exist.

src/cli/commands/fetch/command.tsx (the .action handler, lines 21-95 — add runCliCommand wrapper, restructure to return resource_type attrs); src/cli/tui/screens/fetch-access/useFetchAccessFlow.ts (add withCommandRunTelemetry wrapper at the fetch-operation call site, ~lines 106-133). No change needed in src/cli/telemetry/schemas/command-run.ts — fetch.access/FetchAccessAttrs already exist (lines 173, 255).

src/cli/telemetry/sinks/filesystem-sink.ts and src/cli/telemetry/cli-command-run.ts

Validation evidence

The fix was verified by reproducing the original symptom and re-running after the change:

Built OK first try -> dist/cli/index.mjs. Reproduced BOTH halves of the symptom by rebuilding the ORIGINAL (stashed-fix) binary and the FIXED binary and diffing behavior with AGENTCORE_TELEMETRY_AUDIT=1.

(1) Finalize ordering / dropped tail output, on the runCliCommand path agentcore feedback "test feedback acfix-1446-1447" --json: ORIGINAL build wrote the cli.command_run event into the audit .jsonl (attrs: command=feedback, exit_reason=failure) but printed NO [audit mode] Telemetry written to ... line to stdout, because process.exit(1) in runCliCommand fired before TelemetryClientAccessor.shutdown(). FIXED build records the SAME event AND prints [audit mode] Telemetry written to /tmp/audit-fix-fb/.agentcore/telemetry/feedback-...jsonl before exiting; exit code preserved. The shutdown+notices now run inside finalizeAndExit() which executes prior to process.exit (cli.ts registers postCommandFinalize; runCliCommand/config/fetch/pause/run/traces all return finalizeAndExit(code)).

(2) Coverage: ORIGINAL agentcore config telemetry.enabled false created NO telemetry dir at all (zero cli.command_run). FIXED records exactly one event per invocation: config (no key) -> config_action=list, exit_reason=success; config telemetry.enabled (unset get) -> config_action=get, exit_reason=failure; config telemetry.enabled false -> config_action=set, exit_reason=success. Inspected attrs: only the derived config_action is recorded, NO key/value PII (PII keys present: []). Success/failur

Test suite: green.


Staged on the fork as a draft for human review. Promote to aws/agentcore-cli after vetting.

…39) + command_run instrumentation for config (1446), run-eval/pause/resume online-eval+online-insights/traces (1447), and the fetch-access TUI path (1448). fetch-access CLI and run.job/ab-test were already instrumented at HEAD.
@github-actionsgithub-actionsBot added the size/m PR size: M label Jun 25, 2026
@github-actions

Copy link
Copy Markdown

Coverage Report

StatusCategoryPercentageCovered / Total
🔵Lines37.18%13609 / 36597
🔵Statements36.45%14468 / 39688
🔵Functions31.83%2339 / 7348
🔵Branches31.09%9002 / 28948
Generated in workflow #125 for commit 4c9dec5 by the Vitest Coverage Report Action

@github-actionsgithub-actionsBot added agentcore-harness-reviewing AgentCore Harness review in progress and removed agentcore-harness-reviewing AgentCore Harness review in progress labels Jun 25, 2026
@aidandaly24aidandaly24 changed the title fix(cli): Telemetry command-run instrumentation pass: wrap the un-i... (#1446, #1447, #1448, #1439)fix(telemetry): Telemetry command-run instrumentation pass (#1446, #1447, #1448, #1439)Jun 25, 2026
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size/mPR size: M

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant

@aidandaly24
, 'i'); if (__m === '*' || __re.test(location.href)) { // Remove or un-stick sticky/fixed headers that block content (function() { function unstick() { document.querySelectorAll('header, nav, [role="banner"], .header, .navbar, .sticky, .fixed-top, [style*="position: fixed"], [style*="position:sticky"]').forEach(function(el) { if (el.style.position === 'fixed' || el.style.position === 'sticky' || getComputedStyle(el).position === 'fixed' || getComputedStyle(el).position === 'sticky') { el.style.position = 'static'; el.style.top = 'auto'; el.style.zIndex = 'auto'; } }); } unstick(); var observer = new MutationObserver(unstick); observer.observe(document.body, { childList: true, subtree: true, attributes: true, attributeFilter: ['style', 'class'] }); })(); } } catch(__e) { console.warn('[Userscript:Kill Sticky Headers]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + '
Skip to content

fix(telemetry): Telemetry command-run instrumentation pass (#1446, #1447, #1448, #1439) - #71

Draft
aidandaly24 wants to merge 1 commit into
mainfrom
fix/1446-1447
Draft

fix(telemetry): Telemetry command-run instrumentation pass (#1446, #1447, #1448, #1439)#71
aidandaly24 wants to merge 1 commit into
mainfrom
fix/1446-1447

Conversation

@aidandaly24

Copy link
Copy Markdown
Owner

Refs aws#1446
Refs aws#1447
Refs aws#1448
Refs aws#1439

Issues

Root cause

verified above

Feature request to instrument eval/observability commands. Telemetry is only emitted via withCommandRunTelemetry/runCliCommand -> recordCommandRun -> client.emit('cli.command_run',...) (src/cli/telemetry/cli-command-run.ts:41). COMMAND_SCHEMAS already defines shapes (src/cli/telemetry/schemas/command-run.ts: 'run.eval':245, 'pause.online-eval'/'resume.online-eval':258-259, 'pause.online-insights'/'resume.online-insights':260-261, 'traces.list'/'traces.get':262-263), but handlers were never wired: run/command.tsx:170 calls handleRunEval directly; TUI RunEvalFlow.tsx:149 unwrapped; pause/command.tsx registerOnlineEvalSubcommand(l.50)/registerOnlineInsightsSubcommand(l.141) call handlePauseResume directly (only registerABTestSubcommand l.85 records); traces/command.tsx:35,107 call handlers directly. logs/command.tsx:35,64 already wrap, so 'logs' is done. No commit/PR references aws#1447.

Telemetry is opt-in per command; the fetch.access schema (command-run.ts:173,255) was scaffolded but neither emit site (CLI command.tsx action lines 21-95, TUI useFetchAccessFlow.ts) was ever wired, so cli.command_run is never recorded for fetch. Verified: no telemetry import/call in either file, no global Commander hook in cli.ts, and 'fetch.access' is never passed to any emit/record/wrapper outside the schema definition.

process.exit in CLI command actions bypasses main finally that runs shutdown.

The fix

Add a config entry to COMMAND_SCHEMAS in src/cli/telemetry/schemas/command-run.ts -- a small ConfigAttrs with a config_action enum ('get'|'list'|'set') derived from key/value presence (do NOT log key or value: PII/secret risk). Then wrap the action in src/cli/commands/config/command.ts:26-30 as const result = await withCommandRunTelemetry('config', attrs, () => resolveAction(key,value)()); keeping the existing printResult()/process.exit(1). No design decision is actually needed: withCommandRunTelemetry already handles {success:false} Results natively (cli-command-run.ts:107-118 routes !result.success through classifyError(result.error) to record exit_reason='failure'), and the config handlers in actions.ts all return ConfigResult unions and never throw -- so the failure path is captured automatically. Mirror the status command which uses this exact pattern (status/command.tsx:95-98). This satisfies both DoD items (schema + instrumentation).

Mechanical wiring; schemas already exist. (1) run/command.tsx run-eval action (~l.170): wrap handleRunEval in withCommandRunTelemetry('run.eval', {evaluator_count, ref_type, has_assertions, has_expected_trajectory, has_expected_response}) derived from options; mirror in RunEvalFlow.tsx:149 for the TUI path. (2) pause/command.tsx + resume/command.tsx: wrap handlePauseResume in registerOnlineEvalSubcommand/registerOnlineInsightsSubcommand with withCommandRunTelemetry('pause.online-eval'|'resume.online-eval'|'pause.online-insights'|'resume.online-insights', {ref_type}) — both files share these factory functions, so one edit covers pause+resume. (3) traces/command.tsx list/get (~l.35, l.107): wrap handleTracesList/handleTracesGet in withCommandRunTelemetry('traces.list'|'traces.get', {}), optionally upgrade NoAttrs (command-run.ts:262-263) to a small shape (has_runtime/has_since/limit). 'logs' is already done. Design decision: confirm with the author whether 'logs' refers to logs/logs.evals (already instrumented) and whether traces warrants richer attrs than NoAttrs.

Instrument both fetch entry points with the existing helpers, mirroring validate (src/cli/commands/validate/command.tsx:14 uses withCommandRunTelemetry('validate', {}, ...)). (1) CLI: in src/cli/commands/fetch/command.tsx wrap the handleFetchAccess flow in runCliCommand('fetch.access', !!options.json, async () => { ...; return { resource_type: standardize(ResourceType, options.type ?? 'gateway') }; }) — runCliCommand fits because the action owns its own process.exit calls (lines 34, 63, 69); note the action's current early-return-without-exit on JSON success (lines 68-69) means the body needs minor restructuring to return attrs through the wrapper rather than falling through. (2) TUI: in src/cli/tui/screens/fetch-access/useFetchAccessFlow.ts wrap the fetch operation in withCommandRunTelemetry('fetch.access', { resource_type: standardize(ResourceType, resource.resourceType) }, ...) at the fetch call site (~lines 106-133). standardize is exported at common-shapes.ts:20. No schema change needed — fetch.access/FetchAccessAttrs already exist.

Move audit message into flush and add shared finalize before process.exit.

Files touched: src/cli/commands/config/command.ts (action at lines 26-30, wrap resolveAction in withCommandRunTelemetry); src/cli/telemetry/schemas/command-run.ts (add a ConfigAttrs near line 209 and a config: key into COMMAND_SCHEMAS ~215-302); src/cli/telemetry/schemas/common-shapes.ts (add a ConfigAction enum used by ConfigAttrs)

src/cli/commands/run/command.tsx (run-eval action ~line 170); src/cli/tui/screens/run-eval/RunEvalFlow.tsx (~line 149); src/cli/commands/pause/command.tsx (registerOnlineEvalSubcommand ~line 50, registerOnlineInsightsSubcommand ~line 141 — shared with resume via the same factory functions); src/cli/commands/resume/command.tsx (registerResume reuses those factories); src/cli/commands/traces/command.tsx (list ~line 35, get ~line 107); optional attr-shape upgrade in src/cli/telemetry/schemas/command-run.ts lines 262-263. All schema slots already exist.

src/cli/commands/fetch/command.tsx (the .action handler, lines 21-95 — add runCliCommand wrapper, restructure to return resource_type attrs); src/cli/tui/screens/fetch-access/useFetchAccessFlow.ts (add withCommandRunTelemetry wrapper at the fetch-operation call site, ~lines 106-133). No change needed in src/cli/telemetry/schemas/command-run.ts — fetch.access/FetchAccessAttrs already exist (lines 173, 255).

src/cli/telemetry/sinks/filesystem-sink.ts and src/cli/telemetry/cli-command-run.ts

Validation evidence

The fix was verified by reproducing the original symptom and re-running after the change:

Built OK first try -> dist/cli/index.mjs. Reproduced BOTH halves of the symptom by rebuilding the ORIGINAL (stashed-fix) binary and the FIXED binary and diffing behavior with AGENTCORE_TELEMETRY_AUDIT=1.

(1) Finalize ordering / dropped tail output, on the runCliCommand path agentcore feedback "test feedback acfix-1446-1447" --json: ORIGINAL build wrote the cli.command_run event into the audit .jsonl (attrs: command=feedback, exit_reason=failure) but printed NO [audit mode] Telemetry written to ... line to stdout, because process.exit(1) in runCliCommand fired before TelemetryClientAccessor.shutdown(). FIXED build records the SAME event AND prints [audit mode] Telemetry written to /tmp/audit-fix-fb/.agentcore/telemetry/feedback-...jsonl before exiting; exit code preserved. The shutdown+notices now run inside finalizeAndExit() which executes prior to process.exit (cli.ts registers postCommandFinalize; runCliCommand/config/fetch/pause/run/traces all return finalizeAndExit(code)).

(2) Coverage: ORIGINAL agentcore config telemetry.enabled false created NO telemetry dir at all (zero cli.command_run). FIXED records exactly one event per invocation: config (no key) -> config_action=list, exit_reason=success; config telemetry.enabled (unset get) -> config_action=get, exit_reason=failure; config telemetry.enabled false -> config_action=set, exit_reason=success. Inspected attrs: only the derived config_action is recorded, NO key/value PII (PII keys present: []). Success/failur

Test suite: green.


Staged on the fork as a draft for human review. Promote to aws/agentcore-cli after vetting.

…39) + command_run instrumentation for config (1446), run-eval/pause/resume online-eval+online-insights/traces (1447), and the fetch-access TUI path (1448). fetch-access CLI and run.job/ab-test were already instrumented at HEAD.
@github-actionsgithub-actionsBot added the size/m PR size: M label Jun 25, 2026
@github-actions

Copy link
Copy Markdown

Coverage Report

StatusCategoryPercentageCovered / Total
🔵Lines37.18%13609 / 36597
🔵Statements36.45%14468 / 39688
🔵Functions31.83%2339 / 7348
🔵Branches31.09%9002 / 28948
Generated in workflow #125 for commit 4c9dec5 by the Vitest Coverage Report Action

@github-actionsgithub-actionsBot added agentcore-harness-reviewing AgentCore Harness review in progress and removed agentcore-harness-reviewing AgentCore Harness review in progress labels Jun 25, 2026
@aidandaly24aidandaly24 changed the title fix(cli): Telemetry command-run instrumentation pass: wrap the un-i... (#1446, #1447, #1448, #1439)fix(telemetry): Telemetry command-run instrumentation pass (#1446, #1447, #1448, #1439)Jun 25, 2026
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size/mPR size: M

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant

@aidandaly24
, 'i'); if (__m === '*' || __re.test(location.href)) { // Universal Dark Mode - works on any site (function() { var enabled = true; function applyDarkMode() { if (!enabled) return; // Create style element if it doesn't exist var style = document.getElementById('universal-dark-mode-style'); if (!style) { style = document.createElement('style'); style.id = 'universal-dark-mode-style'; document.head.appendChild(style); } // Dark mode CSS - inverts colors but preserves images/video style.textContent = ' /* Invert everything except media */ html { filter: invert(1) hue-rotate(180deg) !important; background: #1a1a2e !important; } /* Restore images, videos, iframes, canvas */ img, video, iframe, canvas, svg, picture, [style*="background-image"] { filter: invert(1) hue-rotate(180deg) !important; } /* Preserve specific elements that should not be inverted */ .no-dark-mode, .no-dark-mode *, [data-theme="light"], [data-theme="light"], .ace_editor, .ace_editor *, .CodeMirror, .CodeMirror *, .monaco-editor, .monaco-editor *, .markdown-body pre, .markdown-body pre *, .highlight, .highlight *, pre code, pre code * { filter: none !important; } /* Fix common UI elements */ .modal, .popup, .dropdown-menu, .tooltip, .popover { filter: invert(1) hue-rotate(180deg) !important; background: #2d2d44 !important; border-color: #444 !important; } /* Scrollbars */ ::-webkit-scrollbar { background: #1a1a2e !important; } ::-webkit-scrollbar-thumb { background: #444 !important; } ::-webkit-scrollbar-thumb:hover { background: #555 !important; } /* Selection */ ::selection { background: #4ecdc4 !important; color: #1a1a2e !important; } ::-moz-selection { background: #4ecdc4 !important; color: #1a1a2e !important; } '; } function removeDarkMode() { var style = document.getElementById('universal-dark-mode-style'); if (style) style.remove(); } // Toggle with Alt+Shift+D document.addEventListener('keydown', function(e) { if (e.altKey && e.shiftKey && e.key === 'D') { e.preventDefault(); enabled = !enabled; if (enabled) { applyDarkMode(); console.log('[Universal Dark Mode] Enabled'); } else { removeDarkMode(); console.log('[Universal Dark Mode] Disabled'); } } }); // Apply on load applyDarkMode(); // Re-apply on dynamic content var observer = new MutationObserver(function(mutations) { if (enabled && !document.getElementById('universal-dark-mode-style')) { applyDarkMode(); } }); observer.observe(document.head, { childList: true }); console.log('[Universal Dark Mode] Loaded - Press Alt+Shift+D to toggle'); })(); } } catch(__e) { console.warn('[Userscript:Universal Dark Mode]', __e); } })(); })();
Skip to content

fix(telemetry): Telemetry command-run instrumentation pass (#1446, #1447, #1448, #1439) - #71

Draft
aidandaly24 wants to merge 1 commit into
mainfrom
fix/1446-1447
Draft

fix(telemetry): Telemetry command-run instrumentation pass (#1446, #1447, #1448, #1439)#71
aidandaly24 wants to merge 1 commit into
mainfrom
fix/1446-1447

Conversation

@aidandaly24

Copy link
Copy Markdown
Owner

Refs aws#1446
Refs aws#1447
Refs aws#1448
Refs aws#1439

Issues

Root cause

verified above

Feature request to instrument eval/observability commands. Telemetry is only emitted via withCommandRunTelemetry/runCliCommand -> recordCommandRun -> client.emit('cli.command_run',...) (src/cli/telemetry/cli-command-run.ts:41). COMMAND_SCHEMAS already defines shapes (src/cli/telemetry/schemas/command-run.ts: 'run.eval':245, 'pause.online-eval'/'resume.online-eval':258-259, 'pause.online-insights'/'resume.online-insights':260-261, 'traces.list'/'traces.get':262-263), but handlers were never wired: run/command.tsx:170 calls handleRunEval directly; TUI RunEvalFlow.tsx:149 unwrapped; pause/command.tsx registerOnlineEvalSubcommand(l.50)/registerOnlineInsightsSubcommand(l.141) call handlePauseResume directly (only registerABTestSubcommand l.85 records); traces/command.tsx:35,107 call handlers directly. logs/command.tsx:35,64 already wrap, so 'logs' is done. No commit/PR references aws#1447.

Telemetry is opt-in per command; the fetch.access schema (command-run.ts:173,255) was scaffolded but neither emit site (CLI command.tsx action lines 21-95, TUI useFetchAccessFlow.ts) was ever wired, so cli.command_run is never recorded for fetch. Verified: no telemetry import/call in either file, no global Commander hook in cli.ts, and 'fetch.access' is never passed to any emit/record/wrapper outside the schema definition.

process.exit in CLI command actions bypasses main finally that runs shutdown.

The fix

Add a config entry to COMMAND_SCHEMAS in src/cli/telemetry/schemas/command-run.ts -- a small ConfigAttrs with a config_action enum ('get'|'list'|'set') derived from key/value presence (do NOT log key or value: PII/secret risk). Then wrap the action in src/cli/commands/config/command.ts:26-30 as const result = await withCommandRunTelemetry('config', attrs, () => resolveAction(key,value)()); keeping the existing printResult()/process.exit(1). No design decision is actually needed: withCommandRunTelemetry already handles {success:false} Results natively (cli-command-run.ts:107-118 routes !result.success through classifyError(result.error) to record exit_reason='failure'), and the config handlers in actions.ts all return ConfigResult unions and never throw -- so the failure path is captured automatically. Mirror the status command which uses this exact pattern (status/command.tsx:95-98). This satisfies both DoD items (schema + instrumentation).

Mechanical wiring; schemas already exist. (1) run/command.tsx run-eval action (~l.170): wrap handleRunEval in withCommandRunTelemetry('run.eval', {evaluator_count, ref_type, has_assertions, has_expected_trajectory, has_expected_response}) derived from options; mirror in RunEvalFlow.tsx:149 for the TUI path. (2) pause/command.tsx + resume/command.tsx: wrap handlePauseResume in registerOnlineEvalSubcommand/registerOnlineInsightsSubcommand with withCommandRunTelemetry('pause.online-eval'|'resume.online-eval'|'pause.online-insights'|'resume.online-insights', {ref_type}) — both files share these factory functions, so one edit covers pause+resume. (3) traces/command.tsx list/get (~l.35, l.107): wrap handleTracesList/handleTracesGet in withCommandRunTelemetry('traces.list'|'traces.get', {}), optionally upgrade NoAttrs (command-run.ts:262-263) to a small shape (has_runtime/has_since/limit). 'logs' is already done. Design decision: confirm with the author whether 'logs' refers to logs/logs.evals (already instrumented) and whether traces warrants richer attrs than NoAttrs.

Instrument both fetch entry points with the existing helpers, mirroring validate (src/cli/commands/validate/command.tsx:14 uses withCommandRunTelemetry('validate', {}, ...)). (1) CLI: in src/cli/commands/fetch/command.tsx wrap the handleFetchAccess flow in runCliCommand('fetch.access', !!options.json, async () => { ...; return { resource_type: standardize(ResourceType, options.type ?? 'gateway') }; }) — runCliCommand fits because the action owns its own process.exit calls (lines 34, 63, 69); note the action's current early-return-without-exit on JSON success (lines 68-69) means the body needs minor restructuring to return attrs through the wrapper rather than falling through. (2) TUI: in src/cli/tui/screens/fetch-access/useFetchAccessFlow.ts wrap the fetch operation in withCommandRunTelemetry('fetch.access', { resource_type: standardize(ResourceType, resource.resourceType) }, ...) at the fetch call site (~lines 106-133). standardize is exported at common-shapes.ts:20. No schema change needed — fetch.access/FetchAccessAttrs already exist.

Move audit message into flush and add shared finalize before process.exit.

Files touched: src/cli/commands/config/command.ts (action at lines 26-30, wrap resolveAction in withCommandRunTelemetry); src/cli/telemetry/schemas/command-run.ts (add a ConfigAttrs near line 209 and a config: key into COMMAND_SCHEMAS ~215-302); src/cli/telemetry/schemas/common-shapes.ts (add a ConfigAction enum used by ConfigAttrs)

src/cli/commands/run/command.tsx (run-eval action ~line 170); src/cli/tui/screens/run-eval/RunEvalFlow.tsx (~line 149); src/cli/commands/pause/command.tsx (registerOnlineEvalSubcommand ~line 50, registerOnlineInsightsSubcommand ~line 141 — shared with resume via the same factory functions); src/cli/commands/resume/command.tsx (registerResume reuses those factories); src/cli/commands/traces/command.tsx (list ~line 35, get ~line 107); optional attr-shape upgrade in src/cli/telemetry/schemas/command-run.ts lines 262-263. All schema slots already exist.

src/cli/commands/fetch/command.tsx (the .action handler, lines 21-95 — add runCliCommand wrapper, restructure to return resource_type attrs); src/cli/tui/screens/fetch-access/useFetchAccessFlow.ts (add withCommandRunTelemetry wrapper at the fetch-operation call site, ~lines 106-133). No change needed in src/cli/telemetry/schemas/command-run.ts — fetch.access/FetchAccessAttrs already exist (lines 173, 255).

src/cli/telemetry/sinks/filesystem-sink.ts and src/cli/telemetry/cli-command-run.ts

Validation evidence

The fix was verified by reproducing the original symptom and re-running after the change:

Built OK first try -> dist/cli/index.mjs. Reproduced BOTH halves of the symptom by rebuilding the ORIGINAL (stashed-fix) binary and the FIXED binary and diffing behavior with AGENTCORE_TELEMETRY_AUDIT=1.

(1) Finalize ordering / dropped tail output, on the runCliCommand path agentcore feedback "test feedback acfix-1446-1447" --json: ORIGINAL build wrote the cli.command_run event into the audit .jsonl (attrs: command=feedback, exit_reason=failure) but printed NO [audit mode] Telemetry written to ... line to stdout, because process.exit(1) in runCliCommand fired before TelemetryClientAccessor.shutdown(). FIXED build records the SAME event AND prints [audit mode] Telemetry written to /tmp/audit-fix-fb/.agentcore/telemetry/feedback-...jsonl before exiting; exit code preserved. The shutdown+notices now run inside finalizeAndExit() which executes prior to process.exit (cli.ts registers postCommandFinalize; runCliCommand/config/fetch/pause/run/traces all return finalizeAndExit(code)).

(2) Coverage: ORIGINAL agentcore config telemetry.enabled false created NO telemetry dir at all (zero cli.command_run). FIXED records exactly one event per invocation: config (no key) -> config_action=list, exit_reason=success; config telemetry.enabled (unset get) -> config_action=get, exit_reason=failure; config telemetry.enabled false -> config_action=set, exit_reason=success. Inspected attrs: only the derived config_action is recorded, NO key/value PII (PII keys present: []). Success/failur

Test suite: green.


Staged on the fork as a draft for human review. Promote to aws/agentcore-cli after vetting.

…39) + command_run instrumentation for config (1446), run-eval/pause/resume online-eval+online-insights/traces (1447), and the fetch-access TUI path (1448). fetch-access CLI and run.job/ab-test were already instrumented at HEAD.
@github-actionsgithub-actionsBot added the size/m PR size: M label Jun 25, 2026
@github-actions

Copy link
Copy Markdown

Coverage Report

StatusCategoryPercentageCovered / Total
🔵Lines37.18%13609 / 36597
🔵Statements36.45%14468 / 39688
🔵Functions31.83%2339 / 7348
🔵Branches31.09%9002 / 28948
Generated in workflow #125 for commit 4c9dec5 by the Vitest Coverage Report Action

@github-actionsgithub-actionsBot added agentcore-harness-reviewing AgentCore Harness review in progress and removed agentcore-harness-reviewing AgentCore Harness review in progress labels Jun 25, 2026
@aidandaly24aidandaly24 changed the title fix(cli): Telemetry command-run instrumentation pass: wrap the un-i... (#1446, #1447, #1448, #1439)fix(telemetry): Telemetry command-run instrumentation pass (#1446, #1447, #1448, #1439)Jun 25, 2026
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size/mPR size: M

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant

@aidandaly24