Skip to content

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

Open
SaiAbhishek98 wants to merge 2 commits into
aws:box-integrationfrom
SaiAbhishek98:sa/box-traces-runtime-stream-pr
Open

SaiAbhishek98 wants to merge 2 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

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 (c118a51).

Additional details and impacted files
@@               Coverage Diff                @@
##           box-integration    #2914   +/-   ##
================================================
  Coverage            96.89%   96.89%           
================================================
  Files                  776      776           
  Lines                69346    69376   +30     
================================================
+ Hits                 67194    67224   +30     
  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.


# The runtime's own log group and the log stream of its spans, for the default X-Ray target. The
# Runtime names both in ${RUNTIME_TRACES_HEADERS_ENV}.
[inputs.runtime.traces_log_group]

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

These two inputs have no default, so if the Runtime does not set OTEL_EXPORTER_OTLP_TRACES_HEADERS, or sets it without one of the keys, box refuses to start the run. Box's own test (crates/cli/app/src/profile_tests.rs) shows the refusal: "inputs.cloudwatch.group has no value: UNSET is not set or is empty". So a missing env var gives no empty or garbage name. It is loud, but it stops the whole agent. Before this PR, the same runtime would run and its spans would go to aws/spans.

The log_group/log_stream inputs already depend on OTEL_EXPORTER_OTLP_LOGS_HEADERS in the same way, so this is a known pattern. But your live test shows the traces variable only on a container runtime with the default network. Before this leaves draft, please confirm that the Runtime sets OTEL_EXPORTER_OTLP_TRACES_HEADERS with both keys for CodeZip and for PRIVATE_VPC. You already list this as a follow-up. A default can't fix this, because box validates the name and an empty string fails. So I'd write the dependency in the docs instead (see the docs comment).

Comment thread docs/box-local-testing.md
permit, and trace spans, to X-Ray in the region of the Runtime. Build gives the execution role
permit, and trace spans, to X-Ray in the region of the Runtime. With box 0.3.2 or later
(`BOX_TRACES_LOG_GROUP_VERSION`), the target also names the runtime's own log group and its
`spans` stream, which box reads from `OTEL_EXPORTER_OTLP_TRACES_HEADERS`, so the spans go there

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

The text is accurate for the path you tested, but it leaves out the failure modes that the box#629 reviews raised:

  1. A wrong or unwritable log group loses spans silently, because the exporter checks only the HTTP status. The box#629 docs say that in one such case the spans reached neither group.
  2. The new requirement: the Runtime must set OTEL_EXPORTER_OTLP_TRACES_HEADERS, or box stops at start.

Suggest one or two sentences here. Say that if no spans reach the spans stream, the user can set STRANDS_BOX_TELEMETRY_DEBUG=1 and look for telemetry export failed. That is the check you used in the live test. Also say that the delivery depends on the logs:PutResourcePolicy grant that the L3 runtime role has on /aws/bedrock-agentcore/runtimes/* (AgentCoreRuntime.ts, "PutResourcePolicy lets X-Ray deliver spans to the agent log group"). The CLI adds no grant for it. This would also back up the "No new grant" decision in the PR body.

* Whether the box of `runtime` sends its spans to the log group that the Runtime names: its
* `box.version` is {@link BOX_TRACES_LOG_GROUP_VERSION} or later.
*/
export function tracesToRuntimeLogGroup(runtime: Pick<ProjectRuntime, "box">): boolean {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

nit: The gate reads runtime.box.version, but the binary that build stages is BOX_RELEASE (boxContainer.ts). The two agree only because boxVersionWriter runs first and rewrites box.version to the pin. I checked that the order is right. Still, a one-line comment saying so would help, or the gate could read BOX_RELEASE.version directly. Then nobody could make the profile name keys that the staged box refuses by reordering BOX_NETWORK_WRITERS.

},
]);
expect({ ...DEFAULT_TRACES_TARGET } as TomlTable).toEqual(rest);
expect([log_group, log_stream]).toEqual([

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

nit: This assertion only compares the test's own DEFAULT_TRACES fixture with literals. The expect({ ...DEFAULT_TRACES_TARGET }).toEqual(rest) two lines up repeats the same constant check on every row. Both could go, or move out of the test.each.

A more useful test: one that renders the profile and the @box/agentcore pack for the same runtime, and checks that every ${{ inputs.runtime.traces_* }} in the profile is declared in the pack. With my mutation that stops the pack from declaring the inputs, only the 2 direct pack unit tests failed. Nothing checks that the two halves agree.

@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

This branch has not been deployed

No deployments
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