Skip to content

feat(box): Send the spans of a boxed agent to the log group of its runtime - #2914

Merged
SaiAbhishek98 merged 5 commits into
aws:box-integrationfrom
SaiAbhishek98:sa/box-traces-runtime-stream-pr
Nov 25, 2026
Merged

SaiAbhishek98 merged 5 commits into
aws:box-integrationfrom
SaiAbhishek98:sa/box-traces-runtime-stream-pr

Conversation

@SaiAbhishek98

Copy link
Copy Markdown

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, stream spans. A boxed agent does not. The default target [telemetry.agentcore_traces] that build adds to the Runtime profile has no log_group and no log_stream. Thus box sends the spans to X-Ray without these headers, and X-Ray writes them to aws/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_traces target name its log group and its stream. This PR uses that change.

Solution.

  • The default target [telemetry.agentcore_traces] gets log_group = "${{ inputs.runtime.traces_log_group }}" and log_stream = "${{ inputs.runtime.traces_log_stream }}".
  • The generated @box/agentcore pack declares the two inputs. Each input reads one key of OTEL_EXPORTER_OTLP_TRACES_HEADERS, which the Runtime sets. This is the same method that the logs target uses for OTEL_EXPORTER_OTLP_LOGS_HEADERS.
  • The profile header line and the X-Ray grant accept the default target with the two keys and without them.

Decisions

  • Version gate. Build adds the two keys only when the box.version of the runtime is BOX_TRACES_LOG_GROUP_VERSION or later (in templates/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.
  • No new grant. The execution role has xray:PutSpans from 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.
  • A target of the user is not changed. If the profile has its own cloudwatch_traces target, 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 main at 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".

  • The spans stream of the -DEFAULT log group of the runtime got 41 spans: 23 decision spans of box and 18 spans of the agent. All spans of the agent have session.id.
  • aws/spans got 0 spans of this runtime.
  • With STRANDS_BOX_TELEMETRY_DEBUG=1, box recorded 0 telemetry export failed lines.
  • agentcore traces runtime list shows the traces, with the session ID of the agent.
  • A native agent (template agent-python-strands, CodeZip) sends its spans to the same spans stream, and 0 spans to aws/spans. Its OTEL_EXPORTER_OTLP_TRACES_HEADERS names this log group and the stream spans.

I did no test of a CodeZip runtime, a PRIVATE_VPC runtime, or the CloudWatch GenAI Observability console with spans in this stream.

Follow-ups

  • This PR is a draft. It waits for a strands-agents/box release that has strands-agents/box#629. Then set BOX_TRACES_LOG_GROUP_VERSION to that release, and change the box pin in boxRelease.json to it. Until then, the change has no effect with the pin 0.3.0.
  • Do the live test again with CodeZip and with PRIVATE_VPC before you change the PR from a draft.

Related Issue

Closes #

Documentation PR

Included: docs/box-local-testing.md tells where the spans of a boxed agent go on AgentCore Runtime.

Type of Change

  • Bug fix
  • New feature
  • Breaking change
  • Documentation update
  • Other (please describe):

Testing

How have you tested the change?

  • I ran 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.
  • I ran the relevant end-to-end tests with bun run test:e2e, or explained why they are not applicable: not run. The live test above covers the Runtime.
  • I ran bun run typecheck
  • I ran bun run lint:check
  • I ran bun run format:check
  • I ran bun run audit
  • I ran bun run secrets:check
  • I ran bun run build
  • If I modified src/assets/, I updated affected snapshots: not applicable.
  • If I re-recorded fixtures or golden files: not applicable.
  • This PR does not change command.md

Checklist

  • I have read the CONTRIBUTING document
  • I have added any necessary tests that prove my fix is effective or my feature works
  • I have updated the documentation accordingly
  • I have added an appropriate example to the documentation to outline the feature, or no new docs are needed
  • My changes generate no new warnings
  • Any dependent changes have been merged and published: strands-agents/box#629 is merged, but no release has it yet.

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the
terms of your choice.

Sai Abhishek added 2 commits November 24, 2026 15:42
…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-commenter

codecov-commenter commented Nov 24, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 96.89%. Comparing base (4235b7b) to head (0924206).
⚠️ Report is 18 commits behind head on box-integration.

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.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@leo237 leo237 left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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, and 0.3.2 with semver.gte is the correct gate. 0.4.0 also 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/agentcore pack is staged only into the Runtime dist, so agentcore dev is not affected.
  • User targets. If the user has their own cloudwatch_traces target, build still adds no default target. With enableOtel=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 has logs:PutResourcePolicy on /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 in spans, 0 in aws/spans) confirms it.
  • Backward compatibility. defaultTracesTargets matches 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, drop log_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_VPC paths, 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.

Comment thread docs/box-local-testing.md Resolved
@SaiAbhishek98
SaiAbhishek98 marked this pull request as ready for review November 25, 2026 00:31
@SaiAbhishek98
SaiAbhishek98 requested a review from a team November 25, 2026 00:31
@SaiAbhishek98
SaiAbhishek98 requested a review from leo237 November 25, 2026 18:32

@leo237 leo237 left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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 typecheck and oxlint: 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 ignores boxVersion, pack drops the stream input, profile ignores context.boxVersion, profile falls back to box.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.

@SaiAbhishek98
SaiAbhishek98 merged commit 0d2b52f into aws:box-integration Nov 25, 2026
6 checks passed
SaiAbhishek98 added a commit that referenced this pull request Nov 25, 2026
…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)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants