Repository navigation
feat(box): Send the spans of a boxed agent to the log group of its runtime - #2914
SaiAbhishek98 merged 5 commits into
Conversation
…ntime The default X-Ray target of a Runtime profile sent the spans to X-Ray with no log group, so X-Ray put them in aws/spans, and the spans stream of the runtime's own log group stayed empty. With a box release that takes `log_group` and `log_stream` on a `cloudwatch_traces` target (strands-agents/box#629), the default target now names the log group and the log stream that the Runtime sets in OTEL_EXPORTER_OTLP_TRACES_HEADERS. The @box/agentcore pack reads the two values through the inputs `runtime.traces_log_group` and `runtime.traces_log_stream`. BOX_TRACES_LOG_GROUP_VERSION is the first box release that takes the two keys. A box.version before it gets the target without them, because an older box refuses them. Set the constant to the release that ships strands-agents/box#629. Tests: additions.test.ts and boxProfile.test.ts pin both sides of the version gate, the header line, and the grant. bun test: 6516 pass, 9 skip, 0 fail. Typecheck, lint and format pass.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## box-integration #2914 +/- ##
================================================
Coverage 96.89% 96.89%
================================================
Files 776 776
Lines 69346 69375 +29
================================================
+ Hits 67194 67223 +29
Misses 2152 2152 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
leo237
left a comment
There was a problem hiding this comment.
Reviewed at c118a51. I found no blockers. This is a draft and has no effect until the box pin moves past 0.3.0, so I'm commenting rather than approving.
What I checked
- Version gate. strands-agents/box#629 merged at a2a97ee, and that commit is 1 ahead of
v0.3.1. So v0.3.1 does not have it, and0.3.2withsemver.gteis the correct gate.0.4.0also passes it, and pre-releases are rejected, which is the safe choice. The pinned 0.3.0 gets neither the keys nor the pack inputs, so the pinned box can't refuse them. - Names. The CLI does not derive the group or stream itself. Box reads them at run time from
OTEL_EXPORTER_OTLP_TRACES_HEADERS(x-aws-log-group,x-aws-log-stream), the same way the logs target reads them. So a deploy-time runtime ID is not a problem, and no CDK token leaks in. Box enforces both-or-neither, and the CLI always writes both keys. - Local vs Runtime. The
@box/agentcorepack is staged only into the Runtime dist, soagentcore devis not affected. - User targets. If the user has their own
cloudwatch_tracestarget, build still adds no default target. WithenableOtel=false, build adds no traces target and declares no inputs (boxProfile.test.ts, the OTEL-off row). - IAM. The CLI already grants
xray:PutSpans. The L3 role already haslogs:PutResourcePolicyon/aws/bedrock-agentcore/runtimes/*for X-Ray delivery into the agent log group. This matches how a native runtime delivers its spans, and the live test (41 spans inspans, 0 inaws/spans) confirms it. - Backward compatibility.
defaultTracesTargetsmatches both forms of the target, so existing profiles keep the header line and the grant.
Results
bun run typecheck: pass.bun test: 6505 pass, 9 skip, 0 fail.- CI: Analyze, CodeQL and verify on Linux, Windows and macOS pass. e2e is skipped.
- Mutations: I tried 7 mutations (
gte→gt, droplog_stream, pack never declares the inputs, grant matches only the plain form, stream input reads the group key, target ignores the version). The tests caught each one. One more mutation, on the header text, failed to apply, so I did not test it.
Inline comments
- Missing env var stops box at start. This is a regression risk for the untested CodeZip and
PRIVATE_VPCpaths, so please run the live tests you planned before leaving draft. - The docs should name the silent-loss case and say how to debug it.
- Two nits.
Before merge: set BOX_TRACES_LOG_GROUP_VERSION to the real release and bump boxRelease.json, as your follow-ups say.
… profile names (review)
leo237
left a comment
There was a problem hiding this comment.
Re-reviewed at 0924206. Approving.
The three open items are fixed (see my replies on each thread). The gate now reads the staged box (BOX_RELEASE.version, 0.3.0). So with the current pin, the profile names no traces keys and the pack declares no traces inputs. An empty or unparsable version gives false, and pre-releases are still rejected. context.boxVersion is set only by tests. Production callers leave it unset, so the profile and the pack always agree on the box.
Results
bun run typecheckandoxlint: pass.bun test: 6508 pass, 9 skip, 0 fail.- Mutations: I tried 7 (gate defaults to a new box, gate always on,
gte→gt, pack ignoresboxVersion, pack drops the stream input, profile ignorescontext.boxVersion, profile falls back tobox.version). The tests caught all 7. The new pack/profile test is the one that catches the dropped input. I reverted everything.
Before or with the pin bump: set BOX_TRACES_LOG_GROUP_VERSION to the box release that ships strands-agents/box#629, and bump boxRelease.json to it. box v0.3.2 is not out yet. Until the pin moves, this feature does nothing, which is safe.
…ntime (#2914) * feat(box): Send the spans of a boxed agent to the log group of its runtime The default X-Ray target of a Runtime profile sent the spans to X-Ray with no log group, so X-Ray put them in aws/spans, and the spans stream of the runtime's own log group stayed empty. With a box release that takes `log_group` and `log_stream` on a `cloudwatch_traces` target (strands-agents/box#629), the default target now names the log group and the log stream that the Runtime sets in OTEL_EXPORTER_OTLP_TRACES_HEADERS. The @box/agentcore pack reads the two values through the inputs `runtime.traces_log_group` and `runtime.traces_log_stream`. BOX_TRACES_LOG_GROUP_VERSION is the first box release that takes the two keys. A box.version before it gets the target without them, because an older box refuses them. Set the constant to the release that ships strands-agents/box#629. Tests: additions.test.ts and boxProfile.test.ts pin both sides of the version gate, the header line, and the grant. bun test: 6516 pass, 9 skip, 0 fail. Typecheck, lint and format pass. * docs(box): Say where the spans of a boxed agent go on AgentCore Runtime * docs(box): Name the silent span loss and how to find it (review) * fix(box): Gate the traces log group on the staged box, not box.version (review) * test(box): Check that the pack declares each traces input the Runtime profile names (review) --------- Co-authored-by: Sai Abhishek <ksaiabhi@amazon.com> (cherry picked from commit 0d2b52f)
Description
Problem. On AgentCore Runtime, a native agent sends its spans to the log group of its runtime,
/aws/bedrock-agentcore/runtimes/<runtime ID>-DEFAULT, streamspans. A boxed agent does not. The default target[telemetry.agentcore_traces]that build adds to the Runtime profile has nolog_groupand nolog_stream. Thus box sends the spans to X-Ray without these headers, and X-Ray writes them toaws/spans. The spans of the agent and the decision spans of box are then not in the log group of the runtime.strands-agents/box#629 lets a
cloudwatch_tracestarget name its log group and its stream. This PR uses that change.Solution.
[telemetry.agentcore_traces]getslog_group = "${{ inputs.runtime.traces_log_group }}"andlog_stream = "${{ inputs.runtime.traces_log_stream }}".@box/agentcorepack declares the two inputs. Each input reads one key ofOTEL_EXPORTER_OTLP_TRACES_HEADERS, which the Runtime sets. This is the same method that the logs target uses forOTEL_EXPORTER_OTLP_LOGS_HEADERS.Decisions
box.versionof the runtime isBOX_TRACES_LOG_GROUP_VERSIONor later (intemplates/boxProfile.ts). A box release before strands-agents/box#629 refuses the two keys when the run starts. The value is"0.3.2". It must be equal to the first strands-agents/box release that has strands-agents/box#629. Release v0.3.1 does not have it.xray:PutSpansfrom the X-Ray grant of aws/agentcore-cli#2885. X-Ray writes into the log group with the resource policy that AgentCore puts on the log group.cloudwatch_tracestarget, build adds no default target, as before.Tests that CI does not do
The live test used a test account in us-west-2, a container runtime, the default network, and a box that I built from strands-agents/box
mainat cfff47d5, which has strands-agents/box#629. For the test only, I set the version gate to"0.3.0". The commit has"0.3.2".spansstream of the-DEFAULTlog group of the runtime got 41 spans: 23 decision spans of box and 18 spans of the agent. All spans of the agent havesession.id.aws/spansgot 0 spans of this runtime.STRANDS_BOX_TELEMETRY_DEBUG=1, box recorded 0telemetry export failedlines.agentcore traces runtime listshows the traces, with the session ID of the agent.agent-python-strands, CodeZip) sends its spans to the samespansstream, and 0 spans toaws/spans. ItsOTEL_EXPORTER_OTLP_TRACES_HEADERSnames this log group and the streamspans.I did no test of a CodeZip runtime, a
PRIVATE_VPCruntime, or the CloudWatch GenAI Observability console with spans in this stream.Follow-ups
BOX_TRACES_LOG_GROUP_VERSIONto that release, and change the box pin inboxRelease.jsonto it. Until then, the change has no effect with the pin0.3.0.PRIVATE_VPCbefore you change the PR from a draft.Related Issue
Closes #
Documentation PR
Included:
docs/box-local-testing.mdtells where the spans of a boxed agent go on AgentCore Runtime.Type of Change
Testing
How have you tested the change?
bun test: 6503 pass, 9 skip, 2 fail. The 2 failures are TUI tests (harness.screen.test.tsx,oauth.screen.test.tsx) that stop at their time limit in the full run. The two files pass alone (31 pass, 0 fail). This PR does not change them.bun run test:e2e, or explained why they are not applicable: not run. The live test above covers the Runtime.bun run typecheckbun run lint:checkbun run format:checkbun run auditbun run secrets:checkbun run buildsrc/assets/, I updated affected snapshots: not applicable.command.mdChecklist
By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the
terms of your choice.