Repository navigation
feat(telemetry): record the template a project is created with - #2907
Conversation
agentcore create now sets project_template on cli.command_run, from the --template flag and from the create wizard. Config-based (harness) creates leave it unset.
|
Claude Security Review: no high-confidence findings. (run) |
Package TarballHow to installgh release download pr-2907-tarball --repo aws/agentcore-cli --pattern "*.tgz" --dir /tmp/pr-tarball
npm install -g /tmp/pr-tarball/aws-agentcore-1.2.0.tgz |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## v1.x #2907 +/- ##
=======================================
Coverage 96.57% 96.57%
=======================================
Files 734 734
Lines 60950 60956 +6
=======================================
+ Hits 58863 58869 +6
Misses 2087 2087 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
|
Thanks for the report, @codecov-commenter — feedback like this is exactly Would you mind opening a new issue so we can track it properly? If this is a security issue, please report it privately via |
There was a problem hiding this comment.
AgentCore Harness Review
Verdict: Changes requested
The feature, the derived enum, and the test coverage (default --template, explicit template, failed create, wizard template vs. harness) all look right. One real behavioral issue.
project_template: undefined is emitted as a valueless attribute, not left unset
src/handlers/project/create/screen.tsx:213-215
ctx.value(CommandRunMetricEventKey)?.setAttributes({
project_template: values.kind === "agent" ? values.template : undefined,
});For a config-based (harness) create this writes the key with an undefined value rather than omitting it, and the key survives all the way to the collector:
InMemoryMetricEvent.setAttributesspreadsnewDatain, sothis.datanow ownsproject_template(src/telemetry/client.tsx:169).commandRunSchema.parsekeeps an explicitly present optional key: zod's object parse assignsnewResult[key] = valuewheneverkey in input, so the parsed attrs still containproject_template: undefined.OtelHistogramSink.sendpasses the attrs straight tohistogram.record(the defaultAttributesProcessoris a pass-through), and the OTLP transformer'stoAnyValue(undefined)returns{}— so the exported datapoint carries{ key: "project_template", value: {} }.
Net effect: harness-wizard creates land in a different attribute/dimension set than runs where the attribute is genuinely absent (every non-create command), which is the opposite of the PR description's "leaves the attribute unset for config-based (harness) projects." Anything that filters or groups on "project_template absent" will treat these as a separate, empty-valued series.
The new test can't catch this: FileSystemSink serializes with JSON.stringify, which drops undefined-valued keys, so the expect(...).not.toHaveProperty("project_template") assertion in src/handlers/project/create/create.screen.test.tsx passes either way (it does still catch the more important regression — recording DEFAULT_TEMPLATE for a harness create — so it's worth keeping).
Two ways to fix, author's choice:
- Only set the attribute when there is one (local, smallest change):
(or a conditional spread — matches how the rest of the codebase sets optional attributes, e.g.
if (values.kind === "agent") { ctx.value(CommandRunMetricEventKey)?.setAttributes({ project_template: values.template }); }
src/index.ts:84only setsproject_formatinsideif (projectRoot)). - Make
InMemoryMetricEvent.setAttributes(src/telemetry/client.tsx:169) skipundefinedvalues, so "set to undefined" means "unset" for every caller. This is the more robust option since this PR introduces the firstundefined-valued attribute in the codebase; if you take it, please add a unit test insrc/telemetry/client.test.tsxasserting the key is absent from the emitted attrs.
Everything else checks out: empty is part of PROJECT_TEMPLATE_NAMES so the flag-path default validates, the enum import creates no import cycle (handlers/project/shortcuts only reaches projectSchemas/errors at runtime), the TUI middleware only bypasses handle when no flags are passed so the flag-path recording isn't double-counted, and the failure test's InputValidationError does map to exit_reason: "failure" via shouldRecordCommandFailure.
Description
What:
agentcore createrecords the chosen template as a newproject_templateattribute on thecli.command_runmetric. The flag path records the--templatevalue (emptywhen omitted). The create wizard records the template for code-based projects and leaves the attribute unset for config-based (harness) projects.Why: 1.x telemetry had no way to tell which templates projects are created from. The attribute is an enum built from the template registry, so it stays a closed set and new templates are accepted without a second edit.
Related Issue
No issue filed for this change.
Documentation PR
Not applicable.
Type of Change
Testing
Unit tests for the flag path (default, explicit template, failed create) and the wizard (template flow sets it, harness flow leaves it unset). The template assertions fail when the source change is reverted.
End to end with the built CLI: flag-path creates and a wizard create in a real terminal, checked through the telemetry audit file.
I ran
bun testbun run test:e2enot applicable: no deploy path changesI ran
bun run typecheckI ran
bun run lint:checkI ran
bun run format:checkI ran
bun run auditI ran
bun run secrets:checkI ran
bun run buildThis PR does not change
command.md(the release workflow regenerates it)Checklist
By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the
terms of your choice.