Skip to content

feat(core): add enableTransactionSearch helper - #2355

Closed
jariy17 wants to merge 1 commit into
refactorfrom
feat/transaction-search-helper
Closed

jariy17 wants to merge 1 commit into
refactorfrom
feat/transaction-search-helper

Conversation

@jariy17

@jariy17 jariy17 commented Sep 21, 2026

Copy link
Copy Markdown
Contributor

Why

The old CLI enabled CloudWatch Transaction Search on every deploy; the refactor CLI dropped it. Without it, agent OTel spans never reach aws/spans, and evaluations (batch, A/B, insights, online) have nothing to score. This adds the helper back; a follow-up PR wires it into deploy.

What (PR 1 of 2)

src/core/transactionSearch.tsenableTransactionSearch(clients, { region, accountId, indexPercentage=100 }), four idempotent steps:

  1. Application Signals StartDiscovery (service-linked role)
  2. CloudWatch Logs resource policy letting X-Ray write aws/spans + /aws/application-signals/data (skipped if present)
  3. X-Ray UpdateTraceSegmentDestination → CloudWatchLogs (skipped if already set)
  4. X-Ray UpdateIndexingRule DefaultindexPercentage

Hard-fails with a new TransactionSearchSetupError (USER source, names the failed step) if any step errors. Clients are injectable; transactionSearchClients() builds the real ones. GovCloud/China partitions handled.

Adds deps @aws-sdk/client-xray, @aws-sdk/client-application-signals. No deploy behavior change yet (helper is unused until PR 2).

Tests

6 unit tests: full ordered setup, both idempotent skips, custom index %, hard-fail naming the denied step, GovCloud partition.

Ports the old CLI's CloudWatch Transaction Search enablement so evaluations have
agent spans in `aws/spans` to read. `enableTransactionSearch` runs four
idempotent steps — Application Signals discovery, the X-Ray CloudWatch Logs
resource policy, the trace-segment destination flip, and the indexing rule — and
hard-fails with a new TransactionSearchSetupError if any step is denied.

Standalone helper with injectable clients (transactionSearchClients builds the
real ones); no deploy wiring yet. Adds @aws-sdk/client-xray and
@aws-sdk/client-application-signals.
@agentcore-devx-automation agentcore-devx-automation Bot added the agentcore-harness-reviewing AgentCore Harness review in progress label Sep 21, 2026
@github-actions github-actions Bot added the size/m PR size: M label Sep 21, 2026
@agentcore-devx-automation agentcore-devx-automation Bot added the claude-security-reviewing Claude Code /security-review in progress label Sep 21, 2026
@agentcore-devx-automation

Copy link
Copy Markdown
Contributor

Claude Security Review: no high-confidence findings. (run)

@agentcore-devx-automation agentcore-devx-automation Bot removed the claude-security-reviewing Claude Code /security-review in progress label Sep 21, 2026

@agentcore-devx-automation agentcore-devx-automation Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

AgentCore Harness Review

Verdict: Looks good

Nice, self-contained module. The tests use a minimal fake send at the SDK boundary rather than mocking internals, which lines up with the mocking guidance, and the API shapes (resourcePolicies / policyName lowercase for CWL, Destination, Rule.Probabilistic.DesiredSamplingPercentage PascalCase for X-Ray, empty StartDiscovery input for Application Signals) all match the current SDKs.

A few small things worth being aware of, but none block merge:

  • enableTransactionSearch isn't wired into the deploy path in this PR. Assuming that's a follow-up — just calling it out so it doesn't get forgotten, since the module comment promises it runs on every deploy. Telemetry instrumentation for setup success/failure would be nice to add when that wiring lands.
  • Step 2 skips PutResourcePolicy whenever a policy named TransactionSearchXRayAccess exists, without checking its contents. That's fine for idempotency, but if the shape of the policy ever changes (e.g. adding a new log group or partition ARN), existing accounts won't be reconciled. Worth noting in a comment or handling with an explicit version bump when that happens.
  • DescribeResourcePolicies is paginated. In practice CWL caps resource policies at 10 per region so this is a non-issue today, but if that ever changes an unpaginated scan could miss the existing policy and overwrite a customer-modified one.
  • Only the StartDiscoveryCommand failure path is exercised in tests. Adding a case that fails on one of the later steps would give more confidence the same wrapping applies to every step (cheap to add given the harness).

None of these require changes before merging.

@codecov-commenter

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 87.05882% with 11 lines in your changes missing coverage. Please review.
✅ Project coverage is 97.24%. Comparing base (a23e472) to head (33c9fcb).

Files with missing lines Patch % Lines
src/core/transactionSearch.ts 86.41% 11 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff              @@
##           refactor    #2355      +/-   ##
============================================
- Coverage     97.26%   97.24%   -0.03%     
============================================
  Files           610      611       +1     
  Lines         40590    40675      +85     
============================================
+ Hits          39480    39554      +74     
- Misses         1110     1121      +11     

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

@jariy17

jariy17 commented Sep 21, 2026

Copy link
Copy Markdown
Contributor Author

Combined into #2356, which now carries both the helper and the deploy wiring against refactor.

@jariy17 jariy17 closed this Sep 21, 2026
@jariy17
jariy17 deleted the feat/transaction-search-helper branch September 21, 2026 18:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size/m PR size: M

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants