Skip to content

feat(box): Send box telemetry to Langfuse, LangSmith, and OTLP endpoints on AgentCore Runtime - #2917

Open
SaiAbhishek98 wants to merge 9 commits into
aws:box-integrationfrom
SaiAbhishek98:sa/box-third-party-telemetry
Open

SaiAbhishek98 wants to merge 9 commits into
aws:box-integrationfrom
SaiAbhishek98:sa/box-third-party-telemetry

Conversation

@SaiAbhishek98

@SaiAbhishek98 SaiAbhishek98 commented Nov 25, 2026 •

Copy link
Copy Markdown

Description

Problem. Today, agentcore build stops with RUNTIME_TELEMETRY_NOT_CLOUDWATCH when a box profile has a langfuse, langsmith, or otlp telemetry target. Each of these targets needs an API key. With agentcore dev, box reads the key from an environment variable (secret.ref = "env://VAR"). On AgentCore Runtime, that variable is not there.

Solution.

  • Build reads the key from the variable that the target names. It writes the key into agentcore/.env.local as AGENTCORE_CREDENTIAL_<RUNTIME>_TELEMETRY_<TARGET>.
  • Deploy writes one AWS Secrets Manager secret for each runtime, agentcore/<project>/<runtime>/box, with one field for each target. Deploy uses the Secrets Manager API. Thus, the secret is not a stack resource, and no key goes into a template. A new deploy without the key keeps the value in the secret. When no runtime uses a secret, deploy schedules its deletion.
  • The Runtime profile gets plugins = ["@box/aws-secrets-manager"]. Each target gets secret.ref = "aws-secretsmanager://agentcore/<project>/<runtime>/box#telemetry.<target>". Box 0.3.0 has this plugin. The box trusted process reads the key before the agent starts, and the agent does not see the key.
  • The execution role gets secretsmanager:GetSecretValue on that secret and on no other secret, in agentcore/box-telemetry-policy-<runtime>.json.
  • The container image build adds the AWS CLI after a signature check, because the plugin runs aws.
  • CodeZip: build stops, because the CodeZip image does not have the AWS CLI.
  • PRIVATE_VPC: build keeps the configuration and shows a warning that the VPC has no path to the host. Box tries to send, and the sends work after the customer gives the VPC a path to the host. Build also sets network.secretsManagerEndpoint on the runtime. The L3 then adds an AWS Secrets Manager endpoint to the secure VPC. Without the endpoint, box cannot read the key and does not start the agent. This part needs aws/agentcore-l3-cdk-constructs#491.
  • agentcore dev gives the env:// key of each third-party telemetry target to box, for a container runtime and for a CodeZip runtime.
  • This change removes the AGENTCORE_BOX_SECRETS_MANAGER switch of box-integration-development.

The first commit holds five commits of box-integration-development, resolved against box-integration: 7ad00c39, 212d17f1, 96cc7341, 3ad5f5c3, and 71801dfd. The tree of this branch is the same as the tree of box-integration-development at 42a8975e.

Tests on AgentCore Runtime (a test account, container template):

Test Result
Default network, us-west-2, dummy keys The runtime answers. CloudTrail shows GetSecretValue by the execution role, with no error. Box sends to Langfuse (401) and LangSmith (403), which shows that box read the keys and sent them. No key is in the logs or in the environment of the agent.
PRIVATE_VPC, us-west-2, dummy keys The runtime answers. GetSecretValue goes through the VPC endpoint, with no error. Each send fails with a DNS error for the host. This is correct, because the VPC has no path to the internet. The lock of the runtime role does not stop the endpoint call.
Default network, us-east-1, a Langfuse key that works GetSecretValue by the execution role, with no error. Box shows no telemetry export failed line, with STRANDS_BOX_TELEMETRY_DEBUG=1.

Not in the tests: LangSmith with a key that works, an otlp target on AgentCore Runtime, and CodeZip (refused by design).

Related Issue

No issue. This change is part of the Box on AgentCore integration.

Documentation PR

Documentation is in this PR: docs/box-local-testing.md.

Type of Change

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

Testing

  • I ran bun test (6558 pass, 9 skip, 0 fail)
  • I ran the relevant end-to-end tests with bun run test:e2e, or explained why they are not applicable: the live tests above replace them for this change
  • 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 with bun test <test-file> --update-snapshots and committed them
  • If I re-recorded fixtures or golden files, every change beyond account identifiers is explained by this PR
  • This PR does not change command.md (the release workflow regenerates it)

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: aws/agentcore-l3-cdk-constructs#491 is open

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 5 commits November 24, 2026 17:33
… the Runtime

This commit holds five commits of box-integration-development, resolved against
box-integration: 7ad00c3, 212d17f, 96cc734, 3ad5f5c, and 71801df.

Deploy writes the key of each third-party telemetry target (otlp, langfuse, langsmith)
into one AWS Secrets Manager secret for each runtime, agentcore/<project>/<runtime>/box,
outside the stack. The Runtime profile gets plugins = ["@box/aws-secrets-manager"] and
an aws-secretsmanager:// reference for each target. The execution role gets
secretsmanager:GetSecretValue on that secret only. The container image installs the
AWS CLI after a signature check, because the plugin runs aws.
…er, and remove the AGENTCORE_BOX_SECRETS_MANAGER switch
…arn that its VPC has no path to the host, and ask the L3 for an AWS Secrets Manager endpoint
@SaiAbhishek98
SaiAbhishek98 requested review from a team, leo237 and tejaskash November 25, 2026 01:42
@codecov-commenter

codecov-commenter commented Nov 25, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 97.71987% with 14 lines in your changes missing coverage. Please review.
✅ Project coverage is 96.90%. Comparing base (4235b7b) to head (ed28c3a).

Files with missing lines Patch % Lines
src/core/project/backends/cdk/telemetrySecrets.ts 93.43% 13 Missing ⚠️
src/core/project/boxNetwork/network.ts 98.57% 1 Missing ⚠️
Additional details and impacted files
@@                Coverage Diff                @@
##           box-integration    #2917    +/-   ##
=================================================
  Coverage            96.89%   96.90%            
=================================================
  Files                  776      778     +2     
  Lines                69346    69941   +595     
=================================================
+ Hits                 67194    67775   +581     
- Misses                2152     2166    +14     

☔ 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.

…emetry build test

The step message names ENV_LOCAL_RELATIVE_PATH, which has a backslash on Windows. The test now
expects that constant, as the other tests in this file do.

@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.

Adversarial security review of the third-party telemetry key flow, at 00168c4. Decision: COMMENT. I found no leaks and no over-broad grants. I have one merge-order dependency and two medium items. None of them blocks.

Secret lifecycle, as I traced it

  • Where the key comes from. The key comes from env://VAR in the shell. Build copies it into agentcore/.env.local as AGENTCORE_CREDENTIAL_<RT>_TELEMETRY_<T>, and .env.local is gitignored. Deploy reads that variable from the env or .env.local.
  • How it gets to Secrets Manager. Deploy calls CreateSecret/PutSecretValue directly with the deploy credentials, in the target region, before synth. The secret is not a stack resource.
  • Name and encryption. The name is agentcore/<project>/<runtime>/box. The secret uses the AWS-managed KMS key. It has no tags and no resource policy.
  • Runtime read and IAM. The execution role gets only secretsmanager:GetSecretValue on arn:<partition>:secretsmanager:<region>:*:secret:agentcore/<project>/<runtime>/box-??????, one policy file per runtime.
  • Box side. Box 0.3.0 reads the key through @box/aws-secrets-manager (resources/plugins/aws-secrets-manager/plugin.toml at v0.3.0), outside the sandbox. split_reference in crates/credentials/src/sources/command.rs accepts name#telemetry.<target>.
  • Profile keys. The copied keys are destination, project, include, accepts, headers, and secret.header/prefix/placement. Every one is a field of the deny_unknown_fields TelemetryEntry/TelemetrySecret in box v0.3.0, and plugins is a top-level profile key there. Box should therefore accept the generated profile.
  • Removal and teardown. On removal, deploy deletes orphans after the stack update, with a 7-day recovery window, and keeps any secret another target records. Teardown deletes the secrets after the stack. If a write fails, deploy deletes the secrets it created in that run. A later deploy restores a secret that is scheduled for deletion.
  • No leaks found. The value is not in agentcore.json, the CDK context or template, deployed-state (ARN only), the Runtime profile (ref only), box-release.env (CLI URL, SHA, keyring), Dockerfile ARG/ENV, step messages or error text. The Docker build context is the agent folder, so agentcore/.env.local is not in it.
  • Egress. No agent egress route is added. Box sends telemetry from outside the sandbox, and box itself enforces https when a secret is set.

Findings (inline)

  1. Merge order (must land after aws/agentcore-l3-cdk-constructs#491). On L3 box-integration (fa72f21), ContainedNetworkSchema is a z.strictObject with no secretsManagerEndpoint. A PRIVATE_VPC runtime with a keyed target would fail synth with an unrecognized key until #491 merges. The PR body already says this; I am repeating it so that nobody merges in the wrong order.
  2. Medium: deploy adopts any existing secret with this name and, later, deletes it. It does not check ownership, and the CLI does not tag what it creates.
  3. Medium: build copies the key only from the shell, not from .env.local. agentcore dev reads both, so a setup that works in dev fails at deploy, and the error message is wrong for that case.
  4. Nits: the account is * in the IAM ARN; a failed delete is reported only as a step line; targets that share an account and region also share one secret (the last deploy wins), and the docs don't say so; the provenance of the fixture.

Tests.

  • bun run typecheck: pass.
  • bun test: 6558 pass, 9 skip, 0 fail.
  • CI: Linux, CodeQL and Analyze pass. macOS and Windows were pending when I checked. e2e is skipped.

Mutation checks (all reverted). Each mutant below failed the targeted tests, so each was caught:

  • Resource widened to *: 5 fail.
  • name* in place of name-??????: 5 fail.
  • The keep-other-target guard removed: 2 fail.
  • Force delete with no recovery window: 2 fail.
  • The rollback of created secrets removed: 1 fail.
  • The plugin not added: 4 fail.
  • The missing-key error removed: 2 fail.
  • The gpgv/VALIDSIG lines removed from the Dockerfile: 1 fail.
  • CodeZip carrying a keyed target: 1 fail.

Coverage gaps.

  • A pre-existing secret that this CLI did not create (finding 2).
  • A key that is only in .env.local (finding 3).
  • An otlp target with a key on the Runtime. The PR body says the live tests did not cover it.

Dependency. @aws-sdk/client-secrets-manager@^3.1121.0 is the same SDK v3 line as client-s3 (^3.1121.0) and the other SDK clients. It adds one small client package. Its transitive deps are the shared @aws-sdk/core and @smithy/*, so the bundle grows very little.

In the squash plan (https://pippin.amazon.dev/docs/XFRmP1pP9L90nl/box-integration-squash-and-pr-plan-v2), this PR is SA-6, and no later phase changes this code.

* Gives the VPC an AWS Secrets Manager endpoint, so the box of the runtime can read the keys of
* its third-party telemetry targets. Build sets it and removes it.
*/
secretsManagerEndpoint: z.boolean().optional(),

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Merge order: build writes this key into agentcore.json for a PRIVATE_VPC runtime with a keyed third-party target. On L3 box-integration (fa72f21), ContainedNetworkSchema in src/schema/schemas/agent-env.ts is a z.strictObject with no secretsManagerEndpoint, so synth would fail with an unrecognized key. Please merge this only after aws/agentcore-l3-cdk-constructs#491, or keep that ordering explicit in the squash plan.

...field,
value: env[field.variable] || undefined,
}));
const existing = await calls.describe(secret.name);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Medium: deploy finds the secret by name and then adopts it. It reads it, PutSecretValues it, and records its ARN. Later, an orphan removal or a teardown schedules its deletion. Nothing checks that this CLI created the secret.

Two projects with the same name in one account and region (two developers on a shared dev account is enough) would overwrite each other's keys. One project's teardown would also delete the other's secret, and the other runtime would fail to start, because box cannot resolve its ref. A secret that a user created with that name gets the same treatment.

Suggestion: tag the secrets on CreateSecret (for example agentcore:project, agentcore:runtime, and possibly the deployed-state target). Then refuse to adopt or delete a secret that lacks the tag, with a clear error. The tags also help with cost tracking and with finding these secrets later.

const entries: EnvLocalEntry[] = [];
for (const { runtime, fields } of secrets) {
for (const { target, variable, source } of fields) {
const value = env[source];

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Medium: this reads env[source] only, and env is this.processEnv (manager.tsx, around line 1884). boxKeyReads selects only route variables from .env.local, so a telemetry source variable is never read from there.

agentcore dev does read the source from .env.local (boxDevSecrets). So a user who keeps LANGFUSE_AUTH in agentcore/.env.local sees dev work, but build copies nothing. Deploy then fails, and the missingKeys text says "Build copies LANGFUSE_AUTH there when it is set", although it is set.

Suggestion: also read the source variables through boxKeyReads, as for an env:// route. Otherwise, make the docs and the error say "exported in the shell that runs build".

return new ProjectStateError(
`Runtime '${secret.runtime}' has no key for ${targets} to store in AWS Secrets Manager ` +
`secret '${secret.name}'. Set ${variables} in ${join(rootPath, ENV_LOCAL_RELATIVE_PATH)} ` +
`or in the environment you deploy from. Build copies ${sources} there when it is set.`,

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 hint is wrong when the source variable is only in .env.local (see the comment on boxTelemetrySecretEnvEntries). Say "when it is set in the shell that runs build", or fix the read.

): Record<string, unknown> | undefined {
if (secrets.length === 0) return undefined;
const arn = (name: string) =>
`arn:${partition(region).name}:secretsmanager:${region}:*:secret:${name}-??????`;

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 account is *. Each name is exact (the -?????? suffix) and a cross-account read would also need a resource policy on the other side, so I don't see a real exposure. Still, a reader expects the account here. If the policy file can take the account at deploy, or the L3 can fill in ${AWS::AccountId}, that would be tighter. If neither can, a comment that says why the account is * is enough.

failed[name] = { secretArn };
yield {
type: "step",
message: `Could not delete secret '${name}' (${secretArn}): ${(error as Error).message}.`,

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: a failed delete shows only as a step line in the deploy stream, and a user can miss it. The record stays, so the next deploy retries, which is good. Consider a warning event, so that a secret that stays in the account (and is billed) is visible.


/**
* The name of the secret that holds the telemetry keys of runtime `runtime`. Each deployment target
* of the project in one account and region shares it, because the AgentCore Runtime profile is the

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: when two deployment targets are in one account and region, they share this secret, so the last deploy's keys win for both. That is fine, but docs/box-local-testing.md should say it. If someone deploys a staging target with a different key, prod gets that key too.

"mcp": {}
}
},
"secretsManager": {

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: I checked these entries. They contain only env:// refs and the box-stand-in dummies, so nothing sensitive. The test compares only telemetry and plugins, so most of the +1053 lines are whole profiles that nothing asserts on. Consider trimming them, or say in the OLD_RENDERER comment which commit or renderer these secretsManager cases were recorded from, as the comment does for the other sets.

Sai Abhishek added 2 commits November 24, 2026 22:38
…me kind have different secret fields and Runtime profile refs
…third-party telemetry target that it does not carry
@SaiAbhishek98

Copy link
Copy Markdown
Author

Two new commits are on this branch:

  • 009fbee8 adds tests for two third-party telemetry targets of the same kind. Each target gets its own secret field and its own Runtime profile reference.
  • 52e61a1b corrects the build stop RUNTIME_TELEMETRY_NOT_CLOUDWATCH for a third-party target that build does not carry to AgentCore Runtime.

Problem. The stop told the operator to read "the warning for [telemetry.]". Build stops before it shows warnings, so the operator did not see the cause.

Change. The Box network model now gives the refusal rule each target that it does not carry, with the cause and the step that corrects it. The stop now shows both. For example, on a CodeZip runtime:

[telemetry.langfuse] kind is "langfuse", and build cannot carry it to AgentCore Runtime: Box reads its key on AgentCore Runtime with the AWS CLI, which a CodeZip runtime does not have. Use a container runtime, remove [telemetry.langfuse], or change its kind to "cloudwatch_logs" or "cloudwatch_traces".

The other four causes use the same shape: a value that build cannot copy, a secret.ref that is not env:// or secret://, a target name that cannot name a variable, and a deploy variable that another reader also uses. The warnings stay. Two of them now also give the correct step.

Tests. network.test.ts "stops build with the reason the model leaves a target out" sends each case through buildBoxNetwork, and it compares the full text of the stop. The refusals.test.ts cases compare the text with a cause and without a cause. The touched suites, typecheck, oxlint, and prettier pass. The full bun test run had one failure: a manager.boxNetwork.test.ts warning text that this commit changes. That test is now updated, and its file passes (73 of 73).

@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 71572e9...52e61a1. The stop now carries the cause and the fix, and it no longer points at a warning that build never shows. buildBoxNetwork is the only producer of the context, and it always passes leftOut. Every third-party target is either carried or left out with a reason, so I found no path where the stop loses its cause. The fixes for the CodeZip, ref, name, and collision causes are correct.

The six touched test files pass (599 tests), and so do typecheck and oxlint. Mutation checks: replacing the leftOutTelemetry lookup in refusals.ts with undefined fails 4 tests, passing leftOutTelemetry: [] in network.ts fails 3, and changing the CodeZip fix text fails 2.

Two nits are inline. My earlier comments (secret adoption by name, .env.local not read at build, and the nits) are not touched by these commits. They stay open and non-blocking.

if (uncopied.length > 0) {
leftOut.push({
name,
reason: `Box resolves its \`${uncopied[0]}\` to a value build cannot copy`,

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 is the only cause with no fix, but there is a step: give the key a string, a list of strings, or a table of strings (what copiedValue accepts). Something like fix: `Give \`${uncopied[0]}\` a string, a list of strings, or a table of strings` would do. Then the test title at network.test.ts:1718 ("has no step but to remove it") and the fix doc comment ("absent means no such step") should change too.

]);
});

test("a target with a value build cannot copy, which has no step but to remove it", () => {

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 PR comment says each case goes through buildBoxNetwork, but this block covers 3 of the 5 causes. The bad target name (telemetry.ts) and the variable collision (network.ts) are checked only through their warnings. Two more stopOf cases would also pin their "Rename the target, remove ..." text.

@SaiAbhishek98

Copy link
Copy Markdown
Author

The fix to the CodeZip stop message moves to its own pull request, aws/agentcore-cli#2919. ed28c3aa removes it from this pull request. The code of this pull request is now the same as at 009fbee8, which adds only the tests for two targets of the same kind.

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