Skip to content

Feature request: Support for manualSegment in captureAWSv3Client() #4197

@Jhamtanidev

Description

@Jhamtanidev

Use case

✨ Feature Request: Support for manualSegment in captureAWSv3Client()

Summary

Currently, the Tracer.captureAWSv3Client() method in AWS Lambda Powertools for TypeScript only accepts a single argument — the AWS SDK v3 client instance. This restricts users from passing a manual X-Ray segment or subsegment, which is supported in the underlying aws-xray-sdk-core via:

captureAWSv3Client<T>(client: T, segment?: SegmentLike): T

For use cases that require precise control over segment context — such as batch processing — this limitation makes trace hierarchy management difficult.


Use Case

When processing events using processPartialResponse() or similar batch utilities, each item may require a dedicated subsegment. The ability to pass this subsegment to captureAWSv3Client() ensures AWS SDK calls are correctly nested within the item’s trace. Without this, SDK calls may attach to incorrect segments or appear disconnected in X-Ray.


Contribution

I'm open to contributing a pull request if this enhancement aligns with the maintainers’ vision for the library.

Solution/User Experience

Proposed Solution

Update the Tracer.captureAWSv3Client() method to accept an optional second parameter for a manual SegmentLike. This would internally forward both arguments to the X-Ray SDK’s native method, preserving existing behavior while enhancing flexibility:

captureAWSv3Client<T>(client: T, segment?: SegmentLike): T

This change would remain backward compatible and enable more advanced tracing scenarios.


Alternative solutions

Using the X-Ray SDK directly. This bypasses Powertools but loses consistency and built-in annotations.
Subclassing the Tracer to reintroduce the missing parameter. Functional, but not ideal for long-term maintainability.

Acknowledgment

Future readers

Please react with 👍 and your use case to help us understand customer demand.

Metadata

Metadata

Assignees

No one assigned

    Labels

    rejectedThis is something we will not be working on. At least, not in the measurable futuretracerThis item relates to the Tracer Utility

    Type

    No type

    Projects

    Status

    Closed

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions